akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <math.h>

using namespace std;
int p[201];
int m,mi,ma;
int gap=0,ans;
int solve(){
    for(int i=0;i<m;i++){
        
        cin>>p[i];
        
        }
     for(int i=mi-1;i<ma;i++){
            if(gap<=p[i]-p[i+1]){
            //cout<<p[i]<<"  "<<i+1<<endl;
                gap=max(gap,p[i]-p[i+1]);
                ans=i+1;
            }
            
        }
        return 0;

}
int main()
{
   
   while(1){
    cin>>m>>mi>>ma;
    gap=0;
    
    if(m==0)return 0;
    solve();
    cout<<ans<<endl;
   }return 0; 
}



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}



int main() {
  ll N;
  cin >> N;
  string s;
  cin >> s;
  ll i;
  ll ans=0;
  
  for(ll v=0; v<1000; v++) {
    ll t=0;
    ll f=0;
    
    for(i=0; i<N; i++) {
      if(s[i]-'0'==(v/100)%10) {
        t=i;
        f=1;
        break;
      }
    }
    if(!f) continue;
    
    f=0;
    for(i=t+1; i<N; i++) {
      if(s[i]-'0'==(v/10)%10) {
        t=i;
        f=1;
        break;
      }
    }
    if(!f) continue;
    
    f=0;
    for(i=t+1; i<N; i++) {
      if(s[i]-'0'==v%10) {
        t=i;
        f=1;
        break;
      }
    }
    if(!f) continue;
    
    
    ans++;
  }
  
  pt(ans);
}

















Measured memory_bytes: 256
#include<iostream>
#include<cmath>

using namespace std;

#define MAX 1e6+1

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

    long temp;
    for(long i = 1; i<=sqrt(N); i++){
        if(N % i == 0){
            temp = i;
        }
    }
    long div = N / temp;
    cout << div + temp - 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int mi=a[0],cnt=1;
    for(int i=1;i<n;i++)
    {
        if(a[i]<mi)
        {
            mi=a[i];
            cnt++;
        }
    }
    cout<<cnt;

}


Measured memory_bytes: 1024
#include <stdio.h>

int N;

 void makestr(char *str,int cnt, char max)
 {
   if(cnt == N)
   {
     str[cnt]='\0';
     printf("%s\n", str);
   }
   else
   {
     for(char add='a';add<=max;add++)
     {
       str[cnt]=add;
       if (add==max)
         makestr(str,cnt+1,1+max);
       else
         makestr(str,cnt+1,max);
     }
   }
 }

 int main(void)
 {
   scanf("%d",&N);
   char str[N+1];
   for (int i=0;i<N;i++)
     str[i]=0;
   makestr(str,0,'a');
 }

Measured memory_bytes: 1408
N = int(input())
s = ['']*N
 
for i in range(N):
	str = input()
	s[i] = ''.join(sorted(str))
 
s.sort()
ans = 0

#for i in range(N):
i = 0
while (i < N):
	current = s[i]
	same = 1
	while(i < N-1):
		if(s[i+1] == current):
			i += 1
			same += 1
		else:
			break

	ans += same * (same - 1)//2
	#print(i, same, ans)
	i += 1

print(ans)


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

void solve(){
	int n;
	double  d;
	cin >> n >> d;
	int ans = 0;
	while(n--){
		int x, y;
		cin >> x  >> y;
		double a = 1.0 * x * x;
		double b = 1.0 * y * y;
		double qwe = sqrt(a + b);
		if(qwe <= d) ans++;
	}
	cout << ans << "\n";
}

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

	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
		
	int t = 1;

	while(t--){
		solve();
	}

	return 0;
}

Measured memory_bytes: 3724
#include <stdio.h>

int main(){
	int a,b,c;
	int r=0;
	int d=0;
	while(scanf("%d,%d,%d",&a,&b,&c)!=EOF){
		if(c*c==a*a+b*b) r++;
		if(a==b) d++;
	}
	printf("%d\n%d\n",r,d);
	return 0;
}

Measured memory_bytes: 596
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;
const int Maxn = 5000;
const int Maxm = 200;
const int Maxlog = 14;

int N, M;
ll dis[Maxn + 5];
int B[Maxn + 5][Maxm + 5];

int log_2[Maxn + 5];
int tab[Maxm + 5][Maxn + 5][Maxlog + 5];
void Init() {
	for(int i = 2; i <= N; i++)
		log_2[i] = log_2[i >> 1] + 1;
	for(int i = 1; i <= M; i++) {
		for(int j = 1; j <= N; j++)
			tab[i][j][0] = B[j][i];
		for(int k = 1; k <= Maxlog; k++)
			for(int j = 1; j + (1 << k) <= N + 1; j++)
				tab[i][j][k] = max(tab[i][j][k - 1],
					tab[i][j + (1 << (k - 1))][k - 1]);
	}
}
inline int query(int typ, int lef, int rig) {
	int t = log_2[rig - lef + 1];
	return max(tab[typ][lef][t], tab[typ][rig - (1 << t) + 1][t]);
}

ll f[Maxn + 5];
void DFS(int lb, int ub, int optl, int optr) {
	if(lb > ub) return;
	int mid = (lb + ub) >> 1, pos;
	for(int i = optl; i <= optr && i <= mid; i++) {
		ll tmp = dis[i] - dis[mid];
		for(int j = 1; j <= M; j++)
			tmp += query(j, i, mid);
		if(tmp > f[mid]) f[mid] = tmp, pos = i;
	}
	DFS(lb, mid - 1, optl, pos);
	DFS(mid + 1, ub, pos, optr);
}

int main() {
#ifdef LOACL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	scanf("%d %d", &N, &M);
	for(int i = 2; i <= N; i++) {
		scanf("%lld", &dis[i]);
		dis[i] += dis[i - 1];
	}
	for(int i = 1; i <= N; i++)
		for(int j = 1; j <= M; j++)
			scanf("%d", &B[i][j]);
	Init();
	DFS(1, N, 1, N);
	ll ans = 0;
	for(int i = 1; i <= N; i++)
		ans = max(ans, f[i]);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 80000
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

struct node{
  vector< pair<ll,ll> > next;
};

void dfs(){

}

int main(void){

  ll n,m;
  cin>>n>>m;

  auto pair_cout = []( pair<ll,ll> c ){ cout << c.first << "," << c.second << endl; };

  vector< vector<node> > g( 3,vector<node>(n+1) );
  vector< vector<ll> > cost( 3,vector<ll>(n+1,10*n) );
  vector< vector<bool> > been(3,vector<bool>(n+1,false));

  rep(i,m){
    ll u,v;
    cin>>u>>v;
    
    //g[0][u].next.pb( &g[1][v] );
    g[0][u].next.pb( make_pair(1,v) );
    //g[1][u].next.pb( &g[2][v] );
    g[1][u].next.pb( make_pair(2,v) );
    //g[2][u].next.pb( &g[0][v] );
    g[2][u].next.pb( make_pair(0,v) );

  }
  ll s,t;
  cin>>s>>t;

  queue< pair<ll,ll> > que;

  cost[0][s]=0;

  que.push( make_pair(0,s) );

  while(que.size()>0){
    auto q=que.front();
    que.pop();
    //pair_cout(q);
    
    ll c=cost[q.first][q.second];

    for(auto n: g[q.first][q.second].next ){
      if( cost[n.first][n.second] > c+1 ){
        cost[n.first][n.second]=c+1;
        que.push( n );
      }
      
    }

  }


  if( cost[0][t]==10*n ) cout << -1 << endl;
  else cout << cost[0][t]/3 << endl;

  return 0;

}


Measured memory_bytes: 19032
#pragma region
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 1e9
using namespace std;
template <class T = int>
T in() {
  T x;
  cin >> x;
  return (x);
}

typedef long long ll;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

#pragma endregion

int main() {
  int a = in(), b = in();

  int ans = 0;
  if (b == 1) {
    cout << 0 << endl;
  } else {
    while (b > 0) {
      b -= a;
      if (b > 0) {
        b++;
      }
      ans++;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
use proconio::input;
fn main() {
    input!(n: usize);
    input!(a: [usize; n]);
    let mut v = vec![];
    for i in 1..n {
        v.push(a[0] ^ a[i]);
    }

    let x1 = a.iter().fold(a[0], |acc, &e| acc ^ e);
    let mut ans = vec![x1];
    for i in 0..n - 1 {
        ans.push(v[i] ^ x1);
    }
    for i in 0..n {
        print!("{} ", ans[i]);
    }
}


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


int binarySearch(vector<int> v,int right,int left,int k){
    if(right > left){
        int mid  = left + (right - left) / 2;
        if(v[mid] == k)
            return mid;
        
        if(v[mid] > k)
            return binarySearch(v,mid-1,left,k);
            
        return binarySearch(v,right,mid+1,k);
    }
    if(right < 0)
        return 0;
    else if (left > v.size()-1)
        return v.size()-1;
    else 
        return (left < right) ? left : right;
}

int main(int argc, char **argv)
{
    int n,k,h,counter = 0;
    vector<int> heights;
    cin>>n>>k;
    for(int i = 0;i < n;i++){
        cin>>h;
        if(h >= k) counter++;
    }
    cout<<counter;
//    sort(heights.begin(),heights.end());
//    int index = binarySearch(heights,n-1,0,k);
//    cout<<n-index;
    
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int cnt=0,i,r[5],x,y;
int main()
{
	for(i=1;i<=3;i++)
	{
		scanf("%d%d",&x,&y);
		r[x]++;r[y]++;
	}
	sort(r+1,r+5);
	if(r[1]==1&&r[2]==1&&r[3]==2&&r[4]==2)printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
n = input()
if n[-1:] == str(2) or  n[-1:] ==  str(4)  or  n[-1:] ==  str(5) or  n[-1:] == str(7) or  n[-1:] == str(9):
  print('hon')
if (n[-1:]) == str(0) or  n[-1:] == str(1) or  n[-1:] == str(6) or  n[-1:] == str(8):
  
  print('pon')
if (n[-1:]) == str(3):
  print('bon')


Measured memory_bytes: 9072
#include<stdio.h>
#include<stdlib.h>
int main(){
  int i=0,T[100];
  char S[100];
  while (scanf("%s", S) != EOF){
    if(S[0] == '+') {T[i-2] = T[i-2] + T[i-1]; i--;}
    else if (S[0] == '-') {T[i-2] = T[i-2] - T[i-1]; i--;}
    else if (S[0] == '*') {T[i-2] = T[i-2] * T[i-1]; i--;}
    else {T[i] = atoi(S);i++;}
} 



  printf("%d\n",T[0]);

return 0;
}

Measured memory_bytes: 548
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll long long
#define cat(p) cout<<p<<endl
#define catA(p,n) for(int i=0;i<n;i++)cout<<p[i]<<((i==n-1)?"\n":" ")

int n,m;
int rui[111111];

int main(){ 
  cin>>n>>m;
  rep(i,m){
    int l,r;
    cin>>l>>r;
    rui[l]++;
    rui[r+1]--;
  }
  int ans=0;
  for(int i=1;i<=n-1;i++)rui[i+1]+=rui[i];
  for(int i=1;i<=n;i++)if(rui[i]==m)ans++;

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 640
a, b, ab, aa,bb = (int(i) for i in input().split())  

aok = 0
bok = 0
buya = 0
buyb = 0
buyab = 0
if a + b > ab*2:
  buyab = min(aa,bb)  * 2
  aok += buyab//2
  bok += buyab//2
buya = aa - aok
buyb = bb - bok

p1 = (buya*a + buyb*b + buyab*ab)

p2 = (ab*max(aa,bb)*2)
print(min(p1,p2))



Measured memory_bytes: 3064
object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
    for (Array(n, r) <- in if n > 0 && r > 0) {
        val m = in.take(r).foldRight(0){
            case (Array(p, c), i) => if (i >= p - 1 + c) i else if (i >= c) i - c else i + p - 1 
        }
        println(n - m)
    }
}

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

int main(){
    int L,R;
    cin >> L >> R;
    if (R >= L + 2019){
        cout << 0 << endl;
    }
    else{
        int ans = 2019;
        for (int i = L; i < R;i++){
            for (int j = i+1; j <= R; j++){
                int I = i % 2019;
                int J = j % 2019;
                int k = I * J;
                ans = min(ans, k%2019);
            }
        }
        cout << ans << endl;
    }
}

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

#define MAX_N 100
#define MAX_W 10000

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

    int v[1001], w[1001];
    for(int i=0;i<N;i++)
        cin >> v[i] >> w[i];

    int dp[MAX_N+1][MAX_W+1];   //dp[i][j] : 品物i個重さjの時の価値

    for(int i=1;i<=N;i++){      //扱う品物の数を増やしていく
        for(int j=0;j<=W;j++){      //重さの総和を増やしていく
            if(j < w[i-1])              //i-1番目の品物の重さがj未満
                dp[i][j] = dp[i-1][j];
            else
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]]+v[i-1]);
        }
    }
    
    cout << dp[N][W] << endl;

    return 0;
}


Measured memory_bytes: 7008
# -*- coding: utf-8 -*-
"""
Created on Sat May 11 19:46:09 2019
divertaC
@author: maezawa
"""

n = int(input())
s = []
end_a = 0
begin_b = 0
b_to_a = 0
ab = 0
for _ in range(n):
    si = input()
    s.append(si)
    if si[-1] == 'A':
        end_a += 1
        if si[0] == 'B':
            b_to_a += 1
            end_a -= 1
    if si[0] == 'B':
        begin_b += 1
        if si[-1] == 'A':
            begin_b -= 1
    for i in range(len(si)-1):
        if si[i:i+2] == 'AB':
            ab += 1
cnt = ab 
if b_to_a > 0:
    cnt += b_to_a-1
    if end_a > 0:
        cnt += 1
        end_a -= 1
    if begin_b > 0:
        cnt += 1
        begin_b -= 1
cnt += min(end_a, begin_b)
print(cnt)


Measured memory_bytes: 46680
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;
const ll INF = 1LL<<50;

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
    return a / GCD(a, b) * b;
}

int main(){

int N;
cin>>N;
ll A,ans=0;
rep(i,N){
    cin>>A;
    ans+=A-1;
}
cout<<ans<<endl;


return 0;
}

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS(N) resize(N)
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

ll n, m, d;

void init()
{
	cin >> n >> m >> d;
}

void print(double x)
{
	cout << fixed << setprecision(12) << x * (m - 1) << endl;
}

void solve()
{
	if (d == 0) {
		double res = (double) 1 / n;
		print(res);
		return;
	}
	double res = 0;
	res += max((ll) 0, n - d) * 2;
	res /= n * n;
	print(res);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int year[2],month[2],day[2];
    while(cin>>year[0]>>month[0]>>day[0]>>year[1]>>month[1]>>day[1]){
        bool en=0;
        for(int i=0;i<2;i++)if(year[i]<0||month[i]<0||day[i]<0)en=1;
        if(en)break;
        int ans=0;
        for(int i=year[0];i<=year[1];i++){
            ans+=365;
            if(i%4==0&&i%100!=0||i%400==0)ans+=1;
        }
        ans+=day[1]-day[0];
        for(int i=1;i<month[0];i++){
            if(i==2)ans-=28;
            else if(i==4||i==6||i==9||i==11)ans-=30;
            else ans-=31;
        }
        if((year[0]%4==0&&year[0]%100!=0||year[0]%400==0)&&month[0]>=2)ans-=1;
        for(int i=month[1];i<13;i++){
            if(i==2)ans-=28;
            else if(i==4||i==6||i==9||i==11)ans-=30;
            else ans-=31;
        }
        if((year[1]%4==0&&year[1]%100!=0||year[1]%400==0)&&month[1]<=2)ans+=1;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1156
/**
 *    author:  tourist
 *    created: 20.05.2018 15:03:48       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k % 2 == 0) {
    cout << a - b << '\n';
  } else {
    cout << b - a << '\n';
  }
  return 0;
}


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

int main()
{
    int n;

    while( cin >> n )
    {
        if( n == 0 )
            break;
    
        int sum = 0;
        while( n != 1 )
        {
            if( n % 2 == 0 )
                n /= 2;
            else
                n = n * 3 + 1;
            sum++;
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3000
#include<iostream>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;

const int MAX = 10000;

struct Sheet {int left, bottom, right, top;};
bool operator<(const Sheet& lhs, const Sheet& rhs) {
    if(lhs.bottom != rhs.bottom) return lhs.bottom < rhs.bottom;
    return lhs.top < rhs.top;
}

struct Range {
    int bottom, top;
    Range(const int bottom, const int top) :bottom(bottom), top(top) {}
};

int main() {
    int n, r;
    while(cin >> n >> r, n | r) {
        vector<vector<Range>> list(MAX + 1);
        vector<Sheet> sheet(n);
        for(auto& s: sheet) cin >> s.left >> s.bottom >> s.right >> s.top;

        sort(sheet.begin(), sheet.end());
        for(auto s: sheet) for(int x = s.left; x < s.right; ++x) {
            for(int i = 0; i < list[x].size(); ++i) {
                if(list[x][i].top < s.bottom) continue;
                list[x][i].top = max(list[x][i].top, s.top);
                while(i + 1 < list[x].size() && list[x][i].top >= list[x][i + 1].bottom) {
                    list[x][i].top = max(list[x][i].top, list[x][i + 1].top);
                    list[x].erase(list[x].begin() + i + 1);
                }
                break;
            }
            if(list[x].empty() || list[x].back().top < s.bottom) list[x].emplace_back(s.bottom, s.top);
        }

        int area = 0, circumference = 0;
        int length, touch_left = 0, touch_right;
        for(int x = 0; x < list.size(); ++x) {
            if(list[x].empty()) continue;
            length = touch_right = 0;
            for(const auto& l: list[x]) {
                length += l.top - l.bottom;
                for(const auto& l2: list[x + 1]) {
                    if(l.top < l2.bottom || l2.top < l.bottom) continue;
                    touch_right += min(l.top, l2.top) - max(l.bottom, l2.bottom);
                }
            }
            area += length;
            circumference += list[x].size() * 2;
            circumference += 2 * length - touch_left - touch_right;
            touch_left = touch_right;
        }

        cout << area << endl;
        if(r == 2) cout << circumference << endl;
    }
}

Measured memory_bytes: 1860
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

void main() {
    while(true) {
        int N = readln.chomp.to!int;
        if (N==0) break;

        alias Node = Tuple!(int, "l", int, "u", int, "a", int, "p");
        Node[] data = new Node[N];
        foreach(i; 0..N) {
            readf("%d %d %d %d\n", &data[i].l, &data[i].u, &data[i].a, &data[i].p);
        }
        int[] ary = new int[1000];
        int num = 0;
        data.tee!(x=>x.u--).array.sort!((x, y) {
            if (x.a!=y.a) return x.a>y.a;
            if (x.p!=y.p) return x.p<y.p;
            return x.l<y.l;
        }).each!((x) {
            if ((num<10&&ary[x.u]<3) || (num<20&&ary[x.u]<2) || (num<26&&ary[x.u]<1)) {
                num++;
                ary[x.u]++;
                x.l.writeln;
            }
        });
    }
}

Measured memory_bytes: 2576
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++)cin>>a.at(i);
  sort(a.begin(),a.end());
  cout<<a.at(n-1)-a.at(0)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
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; }
using namespace std;

string S, T;

int main() {
    cin >> S >> T;
    int ans = 0;
    rep(i, 3) {
        if (S[i] == T[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
use std::io::{BufRead, Write, stdin, stdout};

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut s = String::new();
    input.read_line(&mut s).unwrap();
    let mut split = s.split_whitespace();
    let n: u64 = split.next().unwrap().parse().unwrap();
    let mut result = n / 11 * 2;
    result += match n % 11 {
        0 => 0,
        x if x >= 1 && x <= 6 => 1,
        x if x >= 7 && x <= 11 => 2,
        _ => unreachable!(),
    };
    writeln!(output, "{}", result).unwrap();
}

fn main() {
    let stdin = stdin();
    solve(stdin.lock(), stdout());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v = Vec::<u8>::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }
    #[test]
    fn case1() {
        test("7\n", "2\n");
    }
    #[test]
    fn case2() {
        test("149696127901\n", "27217477801\n");
    }
}

Measured memory_bytes: 380
#include<iostream>
#include<vector>

using std::cin;
using std::cout;
using std::endl;

template<class T,class F>
struct segment_tree{
  std::vector<T> data;
  int n;
  F f;
  T identity;
  segment_tree(){}
  segment_tree(int sz,T ide,F _f):f(_f),identity(ide){
    n = 1;while(n<sz)n<<=1;
    data.resize(2*n,identity);
  }
  segment_tree(std::vector<T> const& v,T ide,F _f):f(_f),identity(ide){
    build(v);
  }
  void build(std::vector<T> const& v){
    int sz = v.size();
    n = 1;while(n<sz)n<<=1;
    data.resize(2*n,identity);
    for(int i=0;i<sz;++i)data[i+n]=v[i];
    for(int i=n-1;i>0;--i)data[i]=f(data[i<<1|0],data[i<<1|1]);
  }
  void set(int i,T x){
    i += n;
    data[i] = x;
    while(i,i>>=1)data[i] = f(data[i<<1|0],data[i<<1|1]);
  }
  T query(int l,int r)const{
    l += n, r += n;
    T x = identity;
    while(l<r){
      if(l&1)x = f(x,data[l++]);
      if(r&1)x = f(x,data[--r]);
      l>>=1, r>>=1;
    }
    return x;
  }
  T operator[](int i)const{
    return data[i+n];
  }
};
template<class T,class F>
auto make_segtree(int n,T ide,F f){
  return segment_tree<T,F>(n,ide,f);
}
template<class T,class F>
auto make_segtree(std::vector<T>const& v,T ide,F f){
  return segment_tree<T,F>(v,ide,f);
}

signed main(){
  int n;
  cin>>n;
  std::vector<int64_t> a(n);
  for(auto& ai:a)cin>>ai;
  auto gcd = [](auto a,auto b){
    while(b){
      a %= b;
      std::swap(a,b);
    }
    return a;
  };
  auto seg = make_segtree<int64_t>(a,0,gcd);
  int64_t ans = 1;
  for(int i=0;i<n;++i){
    ans = std::max(ans,gcd(seg.query(0,i),seg.query(i+1,n)));
  }
  cout<<(ans)<<endl;
}

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K, Q;
    cin >> N >> K >> Q;
    vector<ll> nums(N);
    vector<pll> sortNums;
    for (int i = 0; i < N; i++)
    {
        ll A;
        cin >> A;
        nums.at(i) = A;
    }
    ll answer = 1e12;
    for (int i = 0; i < N; i++)
    {
        ll minValue = nums.at(i);
        vector<vector<ll>> dividedNums;
        dividedNums.push_back(vector<ll>());
        for (int j = 0; j < N; j++)
        {
            if (nums.at(j) < minValue)
            {
                if (dividedNums.back().size() > 0)
                {
                    dividedNums.push_back(vector<ll>());
                }
            }
            else
            {
                dividedNums.back().push_back(nums.at(j));
            }
        }
        vector<ll> kouhoNums;
        for (auto dividedNum : dividedNums)
        {
            if (dividedNum.size() < K)
            {
                continue;
            }
            sort(dividedNum.begin(), dividedNum.end());
            for (int j = 0; j < min(Q, (ll)dividedNum.size() - K + 1); j++)
            {
                kouhoNums.push_back(dividedNum.at(j));
            }
        }
        if (kouhoNums.size() < Q)
        {
            continue;
        }
        sort(kouhoNums.begin(), kouhoNums.end());
        answer = min(answer, kouhoNums.at(Q - 1) - kouhoNums.at(0));
    }
    cout << answer << endl;
    return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INFLL=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

const int max_v=100000;
vector<int> graph[max_v],articulations;
bool used_v[max_v];
map<int,bool> used_e[max_v];
int ord[max_v],lowlink[max_v];

void dfs(int v,int p,int &k){ //vが根のときp=-1
    used_v[v]=true;
    ord[v]=lowlink[v]=k++;
    
    bool is_articulation=false;
    int count=0;
    for(int u:graph[v]){
        if(!used_v[u]){
            ++count;
            used_e[v][u]=true;
            dfs(u,v,k);
            lowlink[v]=min(lowlink[v],lowlink[u]);
            if(p!=-1 and ord[v]<=lowlink[u]) is_articulation=true;
        }else if(!used_e[u][v]) lowlink[v]=min(lowlink[v],ord[u]);
    }
    
    if(p==-1 and count>1) is_articulation=true;
    if(is_articulation) articulations.push_back(v);
}

void solve(){
    int v,e;
    cin >> v >> e;
    
    rep(i,0,e){
        int s,t;
        cin >> s >> t;
        graph[s].push_back(t);
        graph[t].push_back(s);
    }
    
    int k=0;
    dfs(0,-1,k);
    
    sort(articulations.begin(),articulations.end());
    articulations.erase(unique(articulations.begin(),articulations.end()),articulations.end());
    
    for(auto &v:articulations) cout << v << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	solve();
	return 0;
}

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

int main(){
  int A,B,c = 0;
  cin >> A >> B;
  for(int i = A; i <= B; i++){
    int s1,s2,s3,s4,s5;
    s1 = i / 10000;
    s2 = (i - s1 * 10000) / 1000;
    s3 = (i - (s1 * 10000 + s2 * 1000)) / 100;
    s4 = (i - (s1 * 10000 + s2 * 1000 + s3 * 100)) / 10;
    s5 = i - (s1 * 10000 + s2 * 1000 + s3 * 100 + s4 * 10);
    if(s1 == s5 && s2 == s4){
      c++;
    }
  }
  cout << c << endl;
}

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

int main(){
  
  int x;
  cin >> x;
  vector<bool> ex(1001, false);
  ex[1] = 1;
  for(int i = 2; i <=32; i++){
    int now = i * i;
    while(now <= 1000){
      ex[now] = 1;
      now *= i;
    }
  }
  int ans = x;
  while(1){
    if(ex[ans]) break;
    else ans--;
  }
  cout << ans << endl;
}

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

int n, k;
double ans;

double power(double a, int n)
{
    if (!n) return 1.0;
    double p = power(a, n / 2);
    if (n & 1) return p * p * a;
    return p * p;
}

double process(int x)
{
    int c;
    for (c = 0; x <= k - 1; ++c, x <<= 1);
    return power(1.0 / 2, c);
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);   cout.tie(nullptr);
    if (ifstream("test.inp"))
    {
        freopen("test.inp", "r", stdin);
        #ifdef CHECKING
            freopen(taskname".out", "w", stdout);
        #else
            freopen("test.out", "w", stdout);
        #endif //CHECKING
    }
    else if (ifstream(taskname".inp"))
    {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }

    cin >> n >> k;
    ans = 0;
    for (int i = 1; i <= n; ++i) ans += 1.0 / n * process(i);
    cout << setprecision(12) << fixed << ans;
}


Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
s.find_by_order(x) xth element in set
x.order_of_key(x) number of elements <x*/
#define ll long long
#define vi vector<int>
#define si set<int>
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) (int)s.size()
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}

ll pow(ll a,ll b)
{
    if(b==0)
    return 1;
    else if(b&1)
    return (a*pow((a*a)%1000000007,b/2))%1000000007;
    else
    return pow((a*a)%1000000007,b/2);
}
void solve()
{
fastio
ll n;
cin>>n;
if(n==1)
cout<<0;
else
{
	ll ans1=pow(10ll,n);
	ll ans3=(pow(9ll,n)+pow(9ll,n)-pow(8ll,n))%1000000007;
	ll k=(ans1-ans3+1000000007)%1000000007;
	cout<<k;
}
}
int main()
{
//code
fastio
int t;
t=1;
while(t--)
{
solve();
cout<<endl;
}
}


Measured memory_bytes: 3648
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};

// 二分探索
// llrep(i,N){
//     b = B[i];
//     auto cntA = lower_bound(A.begin(), A.end(), b);//イテレータなのでそのままllに変換とかはできない
//     auto cntC = upper_bound(C.begin(), C.end(), b);
//     ll cntA_ll = distance(A.begin(), cntA);
//     ll cntC_ll = C.size() - distance(C.begin(), cntC);
//     cnt += (cntA_ll * cntC_ll);
// }


int main(){
    int A,P;
    cin >> A >> P;
    cout << (3 * A + P) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	long Q, H, S, D, N,A;
	A = 0;
	cin >> Q >> H >> S >> D >> N;
	if (Q * 4 < S)
	{
		S = Q * 4;
	}
	if (H * 2 < S)
	{
		S = H * 2;
	}
	if (S * 2 < D)
	{
		D = S * 2;
	}
	while (N > 0) {
		if (N % 2 == 1)
		{
			A = A + S;
			N = N - 1;
		}
		else
		{
			A = A + D;
			N = N - 2;
		}
	}
	cout << A << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

using namespace std;

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    int X, Y;
    cin >> X >> Y;
    ll ans = A * X + B * Y;
    if(A + B > 2 * C){
        ans = 2 * C * min(X, Y);
        int p = X > Y ? A : B;
        ans += (max(X, Y) - min(X, Y)) * min(p, 2 * C);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            li = []
            while self.parents[x] >= 0:
                if self.parents[self.parents[x]] >= 0:
                    self.parents[x] = self.parents[self.parents[x]]
                x = self.parents[x]
            return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

import sys
input = sys.stdin.buffer.readline
N,Q = map(int,input().split())
uf = UnionFind(N)
for i in range(Q):
    t,u,v = map(int,input().split())
    if t == 0:
        uf.union(u,v)
    else:
        if uf.same(u,v):
            print(1)
        else:
            print(0)


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

int main(){
    string s;
    cin >> s;
    string s2 = s;
    int l = s.size();
    int count = 0;
    for(int i = 1; i < l; i++){
        if(s.at(i) == s.at(i - 1)){
            if(s.at(i) == '1') s.at(i) = '0';
            else s.at(i) = '1';
            count++;
        }
    }
    
    int count2 = 0;
    for(int i = 1; i < l; i++){
        if(s2.at(l - i) == s2.at(l - i - 1)){
            if(s2.at(l - i - 1) == '1') s2.at(l - i - 1) = '0';
            else s2.at(l - i - 1) = '1';
            count2++;
        }
    }
    count = min(count, count2);
    cout << count << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    ll c;
    c = a-k;

    a = a-k;
    if(a<0) a =0;
    if(c<0) b = b+c;
    if(b<0) b =0;
    cout << a << " " << b <<endl;
}

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

int
main(int argc, char *argv[])
{
        int n, m;
        int *A;
        int *b;
        int *itrA, *itrb;
        int i, j;
        int tmp;

        scanf("%d %d", &n, &m);
        A = (int *)malloc(n * m * sizeof(int));
        b = (int *)malloc(m * sizeof(int));
        
        /* Read A */
        itrA = A;
        for (i = 0; i < n; i++)
                for (j = 0; j < m; j++)
                        scanf("%d", itrA++);
        /* Read b */
        itrb = b;
        for (i = 0; i < m; i++)
                scanf("%d", itrb++);

        for (i = 0; i < n; i++) {
                tmp = 0;
                itrA = A + i * m;
                itrb = b;
                for (j = 0; j < m; j++)
                        tmp += *itrA++ * *itrb++;
                printf("%d\n", tmp);
        }
        
        return 0;
}

Measured memory_bytes: 636
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

int cmpAsc(const void* a, const void* b){
    int x = *(int*)a, y = *(int*)b;
    if(x > y){
        return 1;
    }
    if(x < y){
        return -1;
    }
    return 0;
}

int main(){
    int n, ans = 0;
    scanf("%d", &n);
    int a[n];
    rep(i, 0, n){
        scanf("%d", &a[i]);
    }
    qsort(a, n, sizeof(int), cmpAsc);
    int x=0;
    while(x<n){
        int y=x+1;
        while(y<n){
            if(a[y] != a[x]){
                break;
            }
            y++;
        }
        if((y - x) % 2){
            ans++;
        }
        x = y;
    }
    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    set<int> se;
    int cnt = 0;
    rep(i,n) {
        int a;
        cin >> a;
        if(a < 400) se.insert(1);
        else if(a < 800) se.insert(2);
        else if(a < 1200) se.insert(3);
        else if(a < 1600) se.insert(4);
        else if(a < 2000) se.insert(5);
        else if(a < 2400) se.insert(6);
        else if(a < 2800) se.insert(7);
        else if(a < 3200) se.insert(8);
        else cnt++;
    }
    int sz = se.size();
    cout << max(sz,(cnt > 0 ? 1 : 0)) << " " << se.size()+cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
#define int long long
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
double a[114];
signed main(){
	double n;
	cin>>n;
	int sum=0;
	rep(0,i,n){
		cin>>a[i];
		sum+=a[i];
	}	
	double av=sum/n;
	double di=1145141919810;
	int ans=0;
	rep(0,i,n){
		if(abs(a[i]-av)<di){
			di=abs(a[i]-av);
			ans=i;
		}
	}
	c(ans)
}			

Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    g = [[] for _ in range(N)]

    A, B = [0]*M, [0]*M
    for i in range(M):
        A[i], B[i] = map(int, input().split())
        g[A[i]-1].append(B[i]-1)
        g[B[i]-1].append(A[i]-1)

    ans_list = [-1] * N

    queue = [0]
    seen = [False]*N

    while queue:
        qi = queue.pop(0)
        # qi から 1 遠い頂点が gi
        for gi in g[qi]:
            if seen[gi] == False:
                queue.append(gi)
                if ans_list[gi] == -1:
                    ans_list[gi] = qi
                    seen[gi] = True

    print("Yes")
    for ans in ans_list[1:]:
        print(ans+1)  # 1-index に直す

if __name__ == "__main__":
    main()


Measured memory_bytes: 50768
from string import ascii_lowercase as alph

def gen_pattern(N, pre="", m=-1):
  for i in range(m+2):
    pat = pre+alph[i]
    if len(pat) == N:
      yield pat
    else:
      yield from gen_pattern(N, pat, max(i,m))

for pattern in gen_pattern(int(input())):
  print(pattern)


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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a.begin(), a.end());

    int len = 0;
    for (int i = 1; i < n; ++i) len += a[i] - a[i - 1];

    cout << len << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int c[999999];
int main(){
      int a,b,i,j,q=0;
      cin>>a>>b;
      for (i=0;i<a;++i){
            cin>>c[i];
            if (c[i]==1){
                  break;
            }
      }
      while (a>0){
            q++;
            a=a-b;
            if (a>0){
                  a++;
            }
            else {  
                  cout <<q;
                  return 0;
            }
      }
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N, M; cin >> N >> M;
    vector<pii> edge(M+1); REP1(i, M) cin >> edge[i].first >> edge[i].second;
    vb ok(N+1, false);
    REP1(i, M) if(edge[i].first == 1) ok[edge[i].second] = true;
    REP1(i, M) if(edge[i].second == N && ok[edge[i].first])
    {
        cout << "POSSIBLE" << endl;
        return;
    }
    cout << "IMPOSSIBLE" << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

Measured memory_bytes: 1792
//#typedef int ll
// include
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <tuple>
// namespace
using namespace std;
// typedef
typedef long long ll;
typedef long double ld;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pint;
// const
const int inf = 1e9;
const ll mod = ((ll)1e9 + 7);
// loop
#define rep(i, n) for(ll i = 0, i##_mx = n; i < i##_mx; i++)
#define brep(i, b, e) for(ll i = b; i < e; i++)
#define erep(i, b, e) for(ll i = b; i <= e; i++)
#define rrep(i, b, e) for(ll i = b; i >= e; i--)
// STL
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(), (v).end()
// sort
#define vsort(v, b) sort(all(v), [](auto l, auto r){return (b);})
// access
#define gt(i, n) get<n>(i)
// debug
#define debug(x) cout << (#x) << ": " << x << endl;
// function
ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
void prime(vll& v, ll n){brep(i, 2, n){bool fg = false; for(auto e : v){if(i % e == 0){fg = true;}} if(fg){continue;} v.pb(i);}}
void in(vint& v){for(auto& i : v){cin >> i;}}
void in(vll& v){for(auto& i : v){cin >> i;}}
ll egcd(ll a, ll b, ll& x, ll& y){if(b == 0){x = 1; y = 0; return a;} ll d = egcd(b, a % b, y, x); y -= a / b * x; return d;}

signed main(){
    string s;
    cin >> s;
    
    int ans = 0;
    rep(i, s.length() / 2){
        if(s[i] != s[s.length() - i - 1]){
            ans++;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	string s; cin >> s;
	int bound = s.l_ength();
	int x = 0, y = 0;
	for( int i = 0; i < bound; ++i ){
		if( s[i] == '1' ) ++x;
		else ++y;
	}
	int cnt = min(x, y);
	cout << cnt * 2 << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
  int H,W,i,j,n;
  cin >> H;
  cin >> W;
    
  while(H != 0 && W != 0){
      for(i = 0; i < H; i++){
          for(j = 0; j < W; j++){
              if((i + j) % 2 == 0){
                  cout << "#";
              }
              else{
                  cout << ".";
              }
          }
          cout << endl;
      }
      cin >> H;
      cin >> W;
      cout << endl;
  }
}


Measured memory_bytes: 3072
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 200000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
int a[N];
int main() {
    int n;
    scanf("%d",&n);

    int num4=0,num2=0,numOdd=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(a[i]%4==0)
            num4++;
        else if(a[i]%2==0)
            num2++;
        else
            numOdd++;
    }
    if(numOdd>num4+1)
       printf("No\n");
    else if(num4+1==numOdd&&num2!=0)
        printf("No\n");
    else
        printf("Yes\n");

    return 0;
}


Measured memory_bytes: 640
import heapq
import math

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(map(lambda x: x*(-1), A))
heapq.heapify(A)
for _ in range(M):
    tmp = heapq.heappop(A)*(-1)
    heapq.heappush(A, (tmp/2)*(-1))
ans = 0
for _ in range(N):
    ans += math.floor(heapq.heappop(A)*(-1))
print(ans)

Measured memory_bytes: 20176
from fractions import gcd
from math import ceil,sqrt
a, b = map(int, input().split())

g = gcd(a,b)
# print(g)
s = set()
for i in range(2,ceil(sqrt(g))+1):
    while g % i == 0:
        g //= i
        s.add(i)
if g != 1:
    s.add(g)
# print(g)
# print(s)
print(len(s)+1)


Measured memory_bytes: 65808