akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

vector<vector<ll>> tree(100010);
vector<ll> taka(100010), aoki(100010);
void dfs(ll pos, ll parent, ll dist, bool istaka){
    if(istaka)taka[pos] = dist;
    else aoki[pos] = dist;

    rep(i, tree[pos].size()){
        if(tree[pos][i] == parent)continue;
        dfs(tree[pos][i], pos, dist+1, istaka);
    }
}

int main(){
    ll n, u, v;
    cin >> n >> u >> v;
    u--, v--;

    rep(i, n-1){
        ll a, b;
        cin >> a >> b;
        a--, b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    dfs(u, u, 0, true);
    dfs(v, v, 0, false);

    ll ans =  0;
    rep(i, n){
        if(taka[i] <= aoki[i]){
            ans = max(ans, aoki[i]-1);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 12544
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vpi = vector<pii>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpl = vector<pll>;
using vs = vector<string>;

int main()
{
    ll a, b, n;
    cin >> a >> b >> n;
    ll x = min(b-1, n);
    cout << a*x/b - a * (x/b) << endl;

    return 0;
}


Measured memory_bytes: 3568
#include<stdio.h>
int main(){
  int n,b,c,f;
  char s[3];
  while(scanf("%d",&n),n){
      b=c=f=0;
    while(n--){
      scanf("%s",s);
      if(s[0]-'r')s[1]-'d'?(f|=2):(f&=1);
      else        s[1]-'d'?(f|=1):(f&=2);
      if(b+f==3&&f*b==0){
	c++;
	b=f;
      }
    }
    printf("%d\n",c);
  }
  return 0;
}

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

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e5 +11;
int n,m,a[N],b[N],c[N],cnt;
struct uzi
{
	int l,r;
	bool operator <(const uzi & t)const{
		return r>t.r;
	}
}p[N];
LL s[N],t[N];
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+1+n);
	for(int i=1;i<=m;i++)cin>>p[i].l>>p[i].r;
	sort(p+1,p+1+m);
	for(int i=1;i<=m;i++)for(int j=1;j<=p[i].l&&cnt+1<=n;j++)c[++cnt]=p[i].r;
	for(int i=1;i<=cnt;i++)s[i]=s[i-1]+c[i];
	for(int i=1;i<=n;i++)t[i]=t[i-1]+a[i];
	LL ans=0;
	for(int i=0;i<=cnt;i++)ans=max(s[i]+t[n]-t[i],ans);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6016
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)

#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;

int main() {
	ll n, a, b; cin >> n >> a >> b;
	cout << (((b - a - 1) & 1) ? "Alice" : "Borys") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#define rep(i,n) for(int i = 0; i < n; i++)

using namespace std;

int main()
{
    int n = 0;
    rep(i, 4) {
        char c;
        cin >> c;
        if (c=='+') n++;
        if (c=='-') n--;
    }
    cout << n << endl;
}

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

## Lを降順に並び替える
# L_desc = sorted(L, reverse=True)

# 別解
L_desc = []
while len(L) > 0:
  maxVal = 0
  for i in range(len(L)):
    if L[i] > maxVal:
      maxVal = L[i]
  L_desc.append(maxVal)
  L.remove(maxVal)

snakeLength = 0
for l in range(K):
  snakeLength += L_desc[l]

print(snakeLength)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <stdio.h>
#define ff(i,x,y)for(int i=x;i<y+1;i++)
#define fs(i,x,y)for(int i=x;i>y-1;i--)
#define all(x) x.begin(),x.end()
#define Ins(x) inserter(x,x.begin())
using namespace std;
typedef unsigned long long ll;
ll v1,v2,v3,v4,n,res,vv;
int main()
{
    scanf("%llu%llu%llu%llu%llu",&v1,&v2,&v3,&v4,&n);
    if(v4<=v3*2&&v4<=v2*4&&v4<=v1*8)
    {
        res+=(n/2)*v4;
        n=n%2;
    }
    vv=v3;
    vv=min(vv,v2*2);
    vv=min(vv,v1*4);
    res+=n*vv;
    printf("%llu\n",res);
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int main(){
	int s=0,t=0;
	int tmp[4];
	
	scanf("%d %d %d %d",&tmp[0],&tmp[1],&tmp[2],&tmp[3]);
	for(int i=0;i<4;i++){
		s += tmp[i];
	}

	scanf("%d %d %d %d",&tmp[0],&tmp[1],&tmp[2],&tmp[3]);
	for(int i=0;i<4;i++){
		t += tmp[i];
	}

	if(s < t){
		printf("%d\n",t);
	}
	else{
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 1020
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

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

#define int long long
#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 FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class ARedOrNot {
public:
    static constexpr int kStressIterations = 0;
    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int a;
        cin >> a;
        string s;
        cin >> s;
        if (a >= 3200) {
            cout << s << endl;
        }
        else {
            cout << "red" << endl;
        }

    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ARedOrNot solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i = (begin); i < (end); i++)
#define rep(i, n) FOR(i, 0, n)
using ll = long long;
using namespace std;
#define all(x) (x).begin(),(x).end()
using pii = pair<int, int>;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

struct Ddeque {
    deque<char> s;
    bool flipped = false;
    void push_back(char c) {
        if(!flipped) s.push_back(c);
        else s.push_front(c);
    }
    void push_front(char c) {
        if(!flipped) s.push_front(c);
        else s.push_back(c);
    }
    void print() {
        if(!flipped)
            for(auto iter = s.begin(); iter != s.end(); ++iter) {
                cout << *iter;
            }
        else
            for(auto iter = s.rbegin(); iter != s.rend(); ++iter) {
                cout << *iter;
            }
        cout << endl;
    }
};

int main(int argc, char const *argv[])
{
    string s0;
    cin >> s0;
    Ddeque s;
    rep(i, s0.size()) {
        s.push_back(s0[i]);
    }
    int q;
    cin >> q;
    rep(i, q) {
        int t;
        cin >> t;
        if (t == 1) {
            s.flipped = !s.flipped;
        } else {
            char c;
            cin >> t >> c;
            if(t == 1) s.push_front(c);
            else s.push_back(c);
        }
    }
    s.print();
    return 0;
}


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

int main(){
  double R;//現在のレーティング
  double G;//目標レーティング
  double P;//今回出すべきパフォーマンス
  
  cin >> R >> G;

  P = 2 * G - R ;
  
  cout << P << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

ll n,k;

int main(){
	cin>>n>>k;
	ll ans=0;
	ans=(n/k)*(n/k)*(n/k);
	if(k%2==0)
		ans+=((n+(k/2))/k)*((n+(k/2))/k)*((n+(k/2))/k);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<double, double> pdd;

void solve() {
  int r;
  cin >> r;
  cout << 3*r*r << "\n";
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << " ";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


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

using namespace std;

const int MAXN = 200010;

int main(){
  int N;
  while(scanf("%d", &N) > 0){
    vector<int> subord[N+1];

    for(int i = 2; i <= N; i++){
      int A;
      scanf("%d", &A);
      subord[A].push_back(i);
    }

    for(int i = 1; i <= N; i++){
      printf("%d\n", (int)subord[i].size());
    }
  }
}


Measured memory_bytes: 14696
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;


int main() {
    ld N;
    cin >> N;
    cout << setprecision(10) << 2 * N * PI << endl;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
using namespace std;
int n,m,q;
int sim[100];
int dt[100][4];
int ans;

int main(){
    ll a,b,n; cin >> a >> b >> n;
    ll x;
    if(n>=b) x=b-1;
    else x=n;
    cout << (a*x)/b << endl;

return 0;
}


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

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

  int n, m;
  cin >> n >> m;

  char A[n][n];
  memset(A, 0, sizeof(A));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) cin >> A[i][j];
  }

  char B[m][m];
  memset(B, 0, sizeof(B));
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; ++j) cin >> B[i][j];
  }

  for (int i = 0; i < (n + 1) - m; ++i) {
    for (int j = 0; j < (n + 1) - m; ++j) {
      bool match_found = true;

      for (int x = 0; x < m && match_found; ++x) {
        for (int y = 0; y < m && match_found; ++y) {
          if (A[i + x][j + y] != B[x][y]) match_found = false;
        }
      }

      if (match_found) {
        cout << "Yes" << "\n";
        return 0;
      }
    }
  }

  cout << "No" << "\n";
}


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

int main() {
    int n, d;
    cin >> n >> d;
    int x[n][d];
    rep(i,n)rep(j,d) cin >> x[i][j];
    int ans = 0;
    rep(i,n-1) for (int j = i+1; j < n; j++) {
        int s = 0;
        rep(k,d) s += pow(x[i][k]-x[j][k], 2);
        double r = pow(s, 1/2.);
        if (int(r)-r == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4028
# -*- coding: utf-8 -*-

N = int(input())
v = list(map(int, input().split()))

v = sorted(v)
a = v.pop(0)
b = v.pop(0)

result = (a + b)/2
while len(v) > 0:
    a = v.pop(0)
    b = result
    result = (a + b)/2

print(result)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int lim = 151200;

int main(){
  vector<int> cubic, tetra;
  for(int i=0;;i++){
    int x = i*i*i;
    if(x>lim)break;
    cubic.push_back(x);
  }

  for(int i=0;;i++){
    int x = i*(i+1)*(i+2)/6;
    if(x>lim)break;
    tetra.push_back(x);
  }

  vector<int> can;
  for(int i=0;i<(int)cubic.size();i++){
    for(int j=0;j<(int)tetra.size();j++){
      if(cubic[i] + tetra[j] > lim)break;
      can.push_back(cubic[i] + tetra[j]);
    }
  }

  sort(can.begin(),can.end());
  can.erase(unique(can.begin(),can.end()),can.end());

  int n;
  while(cin >> n, n){
    int p = upper_bound(can.begin(),can.end(),n) - can.begin();
    cout << can[p-1] << endl;
  }
}

  

Measured memory_bytes: 1272
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N; cin>>N;
	int A[N][N];
	rep(i,0,N)rep(j,0,N) cin>>A[i][j];
	long dp[(1<<N)] = {}; dp[0] = 1;
	rep(i,0,(1<<N)){
		int k = 0;
		rep(j,0,N)if(i & (1<<j)) k++;
		rep(j,0,N){
			if(i & (1<<j)) continue;
			if(A[j][k]) (dp[i | (1<<j)] += dp[i]) %= mod;
		}
	}cout<<dp[(1<<N)-1]<<endl;
}

Measured memory_bytes: 16640
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <cstdio>


using namespace std;

class stack
{
	public:
	int s[10000];
	int t,temp;

public:
	void initialize();
	void push(int x);
	int pop();
};

void stack::initialize()
{
	t = 0;
}

void stack::push(int x)
{
	t++;
	s[t] = x;
}

int stack::pop()
{
	temp = s[t];
	t--;
	return temp;
}



int main()
{
	stack Lake_right;
	queue<int> Lake;
	int depth = 0,A=0,i=0,last=0,n=0,k=0;
	double S=0;
	string str;


	Lake_right.initialize();

	getline(cin,str);
	n = str.length();

	while(i != n)
	{
		if (str[i] == '\\')
		{
			S += 0.5 + depth;
			depth++;

		}else if (S != 0 && str[i] == '/')
		{
			depth--;
			S += 0.5 + depth;
		}else if (S != 0 && str[i] == '_')
		{
			S += depth;
		}

		//cout << "S=" << S << endl;

		if (S != 0 && depth == 0 )
		{
			Lake.push((int)S);
			A += (int)S;
			S = 0;
			last = i;
			k++;
		}

		i++;
	}

	S = 0;
	depth = 0;

	i = n-1;

	while(i != last-1)
	{
		if (str[i] == '/')
		{
			S += 0.5 + depth;
			depth++;

		}else if (S != 0 && str[i] == '\\')
		{
			depth--;
			S += 0.5 + depth;
		}else if (S != 0 && str[i] == '_')
		{
			S += depth;
		}

		//cout << "S=" << S << endl;

		if (S != 0 && depth == 0 )
		{
			Lake_right.push((int)S);
			A += (int)S;
			S = 0;
			k++;
		}

		i--;
	}

	while(Lake_right.t != 0)
	{
		Lake.push(Lake_right.pop());
	}

	printf("%d\n", A);
	printf("%d", k);

	while(!Lake.empty())
	{
		printf(" %d", Lake.front());
		Lake.pop();
	}

	printf("\n");

	return 0;
}
	

Measured memory_bytes: 3376
n=int(input())
f=[]
p=[]
for i in range(n):
    q=[int(j) for j in input().split()]
    f.append(q)
for i in range(n):
    q=[int(j) for j in input().split()]
    p.append(q)

def base(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out.rjust(10,'0')
ans=-10**100
for i in range(1,1024):
    i=base(i,2)
    res=0
    for j in range(n):
        c=0
        for k in range(10):
            if f[j][k]==1 and int(i[k])==1:
                c+=1
        res+=p[j][c]
    ans=max(ans,res)
print(ans)

    




Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int A = int.Parse(str[0]);
		int B = int.Parse(str[1]);
		int C = int.Parse(str[2]);
		int X = int.Parse(str[3]);
		int Y = int.Parse(str[4]);
		int ans = 0;
		int ac = X;
		int bc = Y;
		int cc = 0;
		int min = 0;
		while(true){
			int n = ac*A+bc*B+cc*C;
			if(cc==0){
				min = n;
			} else {
				min = Math.Min(n,min);
			}
			if(ac == 0 && bc == 0){
				break;
			} else {
				cc += 1;
				ac = Math.Max(0, X - cc / 2);
				bc = Math.Max(0, Y - cc / 2);
			}
		}
		Console.WriteLine(min);
	}
}

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

using namespace std;

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

typedef long long int ll;


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

	string str1,str2;
	cin >> str1 >> str2;

	for(int i=1 ; i<=str1.size() ; i++)
	{
		if(str1 == str2)
		{
			cout << "Yes";
			return 0;
		}
		
		str1 = str1.back() + str1.substr(0 , str1.size()-1);
	}

	cout << "No";
	return 0;
}

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

int quickSort(int *,int,int);
int partition(int *,int,int);

int main()
{
  int *A,n,i,p=0,r,x,q;

  scanf("%d",&n);

  A = (int *)malloc(n * sizeof(int));

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

  r = n-1;
  
  q = quickSort(A,p,r);

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

  free(A);

  return 0;
}

int quickSort(int *A,int p,int r)
{
  int q;
  
  /* if(p<r){ */
    q = partition(A,p,r);
    /*  quickSort(A,p,q-1);
	quickSort(A,q+1,r); 
	} */

  return q;
}

int partition(int *A,int p,int r)
{
  int x,i,cmp,j;

  x = A[r];
  i = p-1;

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

  return i+1;
}
    



Measured memory_bytes: 2108
#include "bits/stdc++.h"
using namespace std;

int main(void) {
    string S, T;
    cin >> S >> T;
    int len = S.length();
    map<char, char> dict;
    for (int i = 0; i < len; ++i) {
        auto ite = dict.find(S[i]);
        if (ite == dict.end()) {
            dict.insert(make_pair(S[i], T[i]));
            continue;
        }
        if (ite->second != T[i]) {
            cout << "No";
            return 0;
        }
    }

    set<char> uniq;
    for (const auto &d : dict) {
        uniq.insert(d.second);
    }

    if (uniq.size() == dict.size()) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 776
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int X = sc.nextInt();

        if(500 * K >= X){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }

}


Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a >= b&& a >= c&& b >= c) {
		cout << a - c << endl;
	}
	else if (a >= c&& a >= b&& c >= b) {
		cout << a - b << endl;
	}
	else if (b >= a&& b >= c&& a >= c) {
		cout << b - c << endl;
	}
	else if (b >= c&& b >= a&& c >= a) {
		cout << b - a << endl;
	}
	else if (c >= a&& c >= b&& a >= b) {
		cout << c - b << endl;
	}
	else cout << c - a << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const ll inf = 1e18 + 9;
const ll mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);

int n, q;
int c[500001];
int l[500001], r[500001];

int cnt[500001];
int k = 0;

void add(int v) {
    if (cnt[c[v]] == 0) k++;
    cnt[c[v]]++;
}

void del(int v) {
    cnt[c[v]]--;
    if (cnt[c[v]] == 0) k--;
}

void solve() {
    int sq = (int)sqrt(n);
    vector<pair<int, int>> qs[n/sq+1];
    for (int i = 0; i < q; i++) {
        qs[l[i]/sq].push_back(make_pair(r[i], i));
    }

    // [nl, nr)
    int nl, nr;
    int res[q];
    for (int i = 0; i <= n/sq; i++) {
        if (qs[i].size() == 0) continue;
        sort(ALL(qs[i]));
        // 初期化処理
        nl = nr = qs[i][0].first;
        memset(cnt, 0, sizeof(cnt));
        k = 0;

        for (const pair<int, int>& p : qs[i]) {
            int idx = p.second;
            while (nl > l[idx]) {
                nl--;
                add(nl);
            }
            while (nr < r[idx]) {
                add(nr);
                nr++;
            }
            while (nl < l[idx]) {
                del(nl);
                nl++;
            }

            res[idx] = k;
        }
    }

    for (int i = 0; i < q; i++) {
        printf("%d\n", res[i]);
    }
}

void input() {
    scanf("%d%d", &n, &q);
    for (int i = 0; i < n; i++) scanf("%d", c+i);
    for (int i = 0; i < q; i++) {
        scanf("%d%d", l+i, r+i);
        l[i]--;
    }
}

int main() {
    input();
    solve();
}


Measured memory_bytes: 19508
#include<bits/stdc++.h>
#include<stdio.h>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn=2e5+500;
const int inf=0x3f3f3f3f;
const int p=1e9+7;
int n;
//int a[maxn],b[maxn];
ll a,b;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    while(cin>>a>>b){
        cout<<a*b/__gcd(a,b)<<endl;
    }
    return 0;

}



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

int main(void){
    int n, m, a, b;
    cin >> n >> m;
    vector<int> roads(n, 0);
    for (int i=0; i<m; i++){
        cin >> a >> b;
        roads[a-1]++;
        roads[b-1]++;
    }
    for (int i=0; i<n; i++){
        cout << roads[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	vector <int> v(n);
	for(int i = 0; i < n; i++) cin >> v[i];
	sort(v.begin(), v.end());
	ll r = v[n - 1];
	ll l = 0;
	while(r - l > 1) {
		ll m = (l + r)/2;
		ll sum = 0;
		for(int i = 0; i < n; i++) {
			if(v[i] > b * m) {
				if((v[i] - b*m) % (a-b)) sum += (v[i] - b*m) / (a-b) + 1;
				else sum += (v[i] - b*m) / (a-b);
			}
		}
		if(sum > m) l = m;
		else r = m;
	}
	cout << r << "\n";
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+10,mod=1e9+7;
int n,X,f[N],Ans,g[N],s[N];
int cmp(int a,int b) {return a>b;}
int main()
{
	cin>>n>>X;
	f[X]=1;
	for(int i=1;i<=n;i++) cin>>s[i];
	sort(s+1,s+n+1,cmp);
	for(int i=1,x;i<=n;i++)
	{
		x=s[i];
		for(int j=0;j<=X;j++) g[j]=0;
		for(int j=0;j<=X;j++)
		{
			(g[j%x]+=f[j])%=mod;
			(g[j]+=1ll*f[j]*(n-i)%mod)%=mod;
		}
		for(int j=0;j<=X;j++) f[j]=g[j];		
	}
	for(int j=0;j<=X;j++) (Ans+=1ll*f[j]*j%mod)%=mod;
	cout<<Ans<<endl;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{

    internal class Solution
    {
        public long A, B, C, K;

        public void Run()
        {
            {
                var line = Input.ReadLongArray();
                A = line[0];
                B = line[1];
                C = line[2];
                K = line[3];
            }

            if(K % 2 == 0) Console.WriteLine(A - B);
            else Console.WriteLine(B - A);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

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

vector<int> seen;
vector<vector<int>> g;
vector<int> c;
int p=0;

void dfs(int x=0){
  if(seen[x]) return;
  seen[x]=c[p];
  p++;
  for(auto nx:g[x]){
    dfs(nx);
  }
}

int main(){
  int n;
  cin>>n;
  g.resize(n);
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--; b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  c.resize(n);
  rep(i,n) cin>>c[i];
  
  seen.resize(n);
  sort(c.begin(),c.end(),greater<int>());
  
  dfs();
  
  int ans=0;
  rep(i,n-1) ans+=c[i+1];
  cout<<ans<<endl;
  rep(i,n){
    cout<<seen[i]<<" ";
  }
}

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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	ll N;
	cin >> N;
	vector<ll> A(N);
	for (ll i = 0; i < N; ++i)
	{
		cin >> A[i];
	}

	vector<pair<ll, ll>> p(N), n(N);
	for (ll i = 0; i < N; ++i)
	{
		p[i] = make_pair(i, A[i] + (i + 1));
		n[i] = make_pair(i, A[i] - (i + 1));
	}

	sort(p.begin(), p.end(), [](const pair<ll, ll>& l, const pair<ll, ll>& r) { return l.second < r.second; });
	sort(n.begin(), n.end(), [](const pair<ll, ll>& l, const pair<ll, ll>& r) { return l.second < r.second; });

	vector<set<ll>> set(N);
	ll sum = 0;
	for (ll i = 0; i < N; ++i)
	{
		auto l = lower_bound(n.begin(), n.end(), make_pair(-1, -p[i].second), [](const pair<ll, ll>& l, const pair<ll, ll>& r) { return l.second < r.second; });
		auto u = upper_bound(n.begin(), n.end(), make_pair(-1, -p[i].second), [](const pair<ll, ll>& l, const pair<ll, ll>& r) { return l.second < r.second; });
		sum += u - l;
		/*
		while (it != n.end() && it->second == -p[i].second)
		{
			if (it != n.end() && it->first != p[i].first && it->second == -p[i].second)
			{
				set[p[i].first].insert(it->first);
				set[it->first].insert(p[i].first);
			}
			++it;
		}
		*/
	}
	/*
	for (ll i = 0; i < N; ++i)
	{
		sum += set[i].size();
	}
	sum /= 2;
	*/
	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 20384
#include <iostream>
using namespace std;
int main(){
    for(int i=0;i<9;i++){
        for(int j=0;j<9;j++){
            cout << i+1
                 << "x"
                 << j+1
                 << "="
                 << (i+1)*(j+1)
                 << endl;
        }
    }
    return 0;
}

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

int main(){
    string S;
    cin >> S;
    if((S[0] == S[1] && S[2] == S[3] && S[1] != S[2]) || (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) || (S[0] == S[3] && S[1] == S[2] && S[0] != S[1])){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
using namespace std;
void read(int &x){
	char ch;bool ok;
	for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
	for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=5e5+10;
int n,m;
double sum,now,a[maxn],b[maxn],ans[maxn];
struct oo{double a,b;}q[maxn];
int main(){
	read(n),read(m);
	for(rg int i=1,x,y;i<=n;i++)read(x),read(y),a[i]=x,b[i]=y;
	int l=1,r=0;ans[1]=a[1];
	for(rg int i=1;i<=n;i++){
		sum=sum+a[i]*b[i],now=now+b[i];
		q[++r]=(oo){a[i],b[i]};
		while(l<=r){
			if(now<=m)break;
			if(now-q[l].b<m){
	    		sum=sum-q[l].b*q[l].a;
				q[l].b=q[l].b-(now-m);
				sum=sum+q[l].b*q[l].a;
				now=m;
				break;
			}
			else now-=q[l].b,sum-=q[l].b*q[l].a,l++;
		}
	    ans[i]=sum/m;
		while(l<r&&q[r].a<q[r-1].a){
			double tot=q[r-1].b+q[r].b;
			sum=sum-q[r].a*q[r].b-q[r-1].a*q[r-1].b,now=now-q[r].b-q[r-1].b;
		    q[r-1].a=(q[r].a*q[r].b+q[r-1].a*q[r-1].b)/tot;
			q[r-1].b=tot;
			sum=sum+q[r-1].a*q[r-1].b,now=now+q[r-1].b;
		    r--;
		}
	}
	for(rg int i=1;i<=n;i++)printf("%.7lf\n",ans[i]);
}


Measured memory_bytes: 28544
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

yes = "Yes"
no = "No"


def main():
    n = ii()
    a = li()
    s = sum(a)
    ss = 0
    for i in a:
        ss += i**2
    print(((s**2 - ss) // 2) % 1000000007)


main()


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

int main(){
	int x, y;
	
	while(1){
		cin >> x >> y;
		if(x==0 && y==0){
			break;
		}
		if(x<y){
			cout<<x<<" "<<y<<endl;
		}
		else{
		    cout<<y<<" "<<x<<endl;
		}
	}
	
}


Measured memory_bytes: 3088
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
#define ll long long
#define vr vector<ll>
#define pb push_back

using namespace std;

main ()
{
  ll n,num=0;
  cin>>n;
  
  for(ll i=1;i<n;i++)
  {
      ll r,q;
      r=n%i;
      q=n/i;
      if(r==0)
      {
          num+=q-1;
      }
      else
      {
          num+=q;
      }
      
  }
  cout<<num;

  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
// #include <bits/stdc++.h>


using namespace std;
typedef long long li;

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

    li x;
    cin >> x;

    li k;
    cin >> k;
    priority_queue<pair<li, li>> pq;
    for (int i = 0; i < k; ++i) {
        li r;
        cin >> r;
        pq.emplace(-r, -1);
    }

    li q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        li t, a;
        cin >> t >> a;
        pq.emplace(-t, a);
    }

    // a < lb        => v = offset
    // lb <= a <= ub => b = offset + (a - lb)
    // ub < l        => b = offset + (ub - lb)
    li lb = 0, ub = x, offset = 0;
    li cur = 0, d = -1, prev_t = 0;
    while (not pq.empty()) {
        auto tup = pq.top();
        pq.pop();
        const li t = -tup.first;
        const li query = tup.second;

        cur += (t - prev_t) * d;
        lb = max(lb, -cur);
        ub = min(ub, x - cur);

        offset += (t - prev_t) * d;
        offset = min(offset, x);
        offset = max(offset, 0LL);
        if (query == -1) {
            d *= -1;
        } else {
            const li a = query;
            li ans;
            if (a <= lb || ub <= lb) {
                ans = offset;
            } else if (a <= ub) {
                ans = offset + (a - lb);
            } else {
                ans = offset + (ub - lb);
            }
            cout << ans << endl;
        }
        prev_t = t;
    }


    return 0;
}


Measured memory_bytes: 6512
#include <stdio.h>
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_D
//LIS
//got TLE with O(n*n)
/*int findNumberOfLIS(int nums[],int n) {
        int l = n;
        int lis[l];
        for(int i= 0; i<l; i++){//as the last one
            lis[i] = 1;//for 1
            for(int j = 0; j<i; j++){
                if(nums[i]>nums[j]&&lis[j]>=lis[i]){
                    lis[i] = lis[j]+1; 
                }
            }   
        }
        int res = 0;
        for(int i =0; i<l; i++){
            if(lis[i]>res)
                res = lis[i];
            
        }
        return res;  
    }*/
//binary search to find the first ele bigger than key
//return index of the ele    
int ceilindex(int sec_array[],int l,int r,int key){
	while(r-l>1){
		int m = l+(r-l)/2;
		if(sec_array[m]>=key)
			r = m;
		else l = m;
	}
	return r;
}
int findNumberOfLIS(int nums[],int n){
	int sec_array[n];
	int len;
	sec_array[0] = nums[0];
	len = 1;
	for(int i  =1; i<n; i++){
		if(nums[i]<sec_array[0])
			sec_array[0] = nums[i];
		else if(nums[i]>sec_array[len-1])
			sec_array[len++] = nums[i];
		else {
			sec_array[ceilindex(sec_array,-1,len-1,nums[i])] = nums[i];
		}
	}
	//the sec_array is not LIS: smallest elements
	/*for(int i = 0; i<len; i++){
		printf("%d ",sec_array[i]);
	}
	printf("\n");*/
	return len;
} 

int main(){
	int n;
	scanf("%d",&n);
	int nums[n];
	for(int i = 0; i<n; i++){
		scanf("%d",&nums[i]);
	}
	printf("%d\n",findNumberOfLIS(nums,n));
	return 0;
}


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

int main(){
  int n,m;
  cin>>n>>m;
  
  int a[n];
  int sum = 0;
  for(int i =0;i<n;i++)
  {cin>>a[i];sum+=a[i];}
  
  float crit = sum / ( 4 * m * 1.0);
  
  int cnt  =0;
  for(int i =0;i < n;i++)
    if(a[i] * 1.0 < crit)
      cnt++;
  
  if((n -cnt) >= m)
    cout<<"Yes";
  else
    cout<<"No";
  
  return 0;
}
  
  
  

Measured memory_bytes: 256
N,L = map(int,input().split())
li = [L+i-1 for i in range(1,N+1)]
li2 = []
for i in range(N):
    li2.append([abs(sum(li)-(sum(li)-li[i])),(sum(li)-li[i])])
li2.sort()
print(li2[0][1])

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <string>
using namespace std;

int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
 
	int n,k,i,j,r,a,b,sum;
  vector<int> v;
  vector<int> av, bv,x,y,c;
  cin>>a>>b>>n;
  int min_a = 1000000;
  for(int i=0; i<a;i++){
    int tmp;
    cin>>tmp;
    av.push_back(tmp);
    if(min_a > tmp) min_a = tmp;
  }
  int min = 1000000;
  for(int i=0; i<b;i++){
    int tmp;
    cin>>tmp;
    bv.push_back(tmp);
    int q = min_a + tmp;
    if(min > q) min = q;
  }
  for(int i=0; i<n; i++){
    int x,y,c;
    cin>>x>>y>>c;
    int q = av[x-1] + bv[y-1] - c;
    if(min > q) min = q;
  }
  cout<<min;
  

  return 0;
}

Measured memory_bytes: 1400
N, K = map(int ,input().split())
A = [int(x) for x in input().split()]
checked = [False] * N
root=[0]

idx = 0
checked[0]=True

for k in range(K):
  root.append(A[idx]-1)
  idx = A[idx]-1
  if (checked[idx]):
    break
  checked[idx]=True
else:
  print(idx+1)
  exit(0)

for i, r in enumerate(root):
  if r == root[-1]:
    break

root2=root[i:]
l = len(root2)-1
idx = root2[(K-i)%(l)]
print(idx+1)


Measured memory_bytes: 32120
#include<cstdio>
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<set>
#include<stack>
#include<cstring>
#include<map>
#include<vector>
#define ll long long int
using namespace std;
int main()
{
    char c;
    cin>>c;
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
        cout<<"vowel";
    else
        cout<<"consonant";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define repr(i, n) for (ll i = n - 1; i >= 0; --i)
const int MOD = 1000000007;
const ll INF = 10000000000;
using namespace std;

void solve(void)
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    map<int, int> mp;
    rep(i, n) mp[a[i] % 2]++;
    if (mp[1] % 2 == 1 && mp[0] > 0)
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
}
int main(void)
{
    solve();
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int n, m, p, x;
int t[100];

int main(int argc, char **argv) {
	int s = 0;
	cin >> n;
	REP(i, n) {
		cin >> t[i];
		s += t[i];
	}
	cin >> m;
	REP(i, m) {
		cin >> p >> x;
		--p;
		cout << (s - t[p] + x) << endl;
	}
	return 0;
}


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



Measured memory_bytes: 3536
from collections import deque

s = deque(input())
Q = int(input())
    
t = True
    
for i in range(Q):
    query = input().split()
    if query[0] == '1':
        t = not t
    else:
        if(t and query[1] == '1') or (not t and query[1] == '2'):
            s.appendleft(query[2])
        else:
            s.append(query[2])
            
s = ''.join(s)
    
if not t:
    s = s[::-1]
        
print(s)

Measured memory_bytes: 8436
from bisect import bisect_left, bisect_right
N, Q = map(int, input().split())

ans = 0
tate = [[-N, N-2]]
tateL = 1
yoko = [[-N, N-2]]
yokoL = 1
ans = (N-2) * (N-2)
for _ in range(Q):
    s, x = input().split()
    x = int(x)
    if s == '1':
        idx = bisect_left(tate, [-x, 0])
        ans -= tate[idx-1][1]
        if idx == tateL:
            tate.append([-x, tate[idx-1][1]])
            tateL += 1
            yoko[-1][1] = x - 2
    else:
        idx = bisect_left(yoko, [-x, 0])
        ans -= yoko[idx-1][1]
        if idx == yokoL:
            yoko.append([-x, yoko[idx-1][1]])
            yokoL += 1
            tate[-1][1] = x - 2
print(ans)


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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

st solve(st) ;

int main ()
{
    st s ;
    cin >> s ;
    cout << solve (s) ;
    return 0 ;
}

/*___________________________________________________________________functions_____________________________________________________________________________*/

st solve (st s)
{
    ll len = s . size() ;
    bool t = true , t1 = true ;
    forr(1 , len + 1)
    {
        if (i % 2 == 1)
            {
            if (s[i - 1] == 'L')
                t = false ;
            }
        else if (i % 2 == 0)
            {
            if (s[i - 1] == 'R')
                t1 = false ;
            }
    }
    return (t && t1 ?  "Yes" : "No") ;
    //return z ;
}


Measured memory_bytes: 256
#include <iostream>			// 백준 12840
#include <algorithm>
using namespace std;

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

	int n, m;
	cin >> n >> m;

	int* vote = new int[n];
	int sum(0);
	for (int i = 0; i < n; i++)
	{
		cin >> vote[i];
		sum += vote[i];
	}
	sort(vote, vote + n);

	for (int i = 0; i < m; i++)
	{
		if (vote[n - i - 1] * 4 * m < sum)
		{
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";

	return 0;
}


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

int main(void){
    bool flag = true;
    string buf;

    cin >> buf;

    rep(i,4){
        if(buf.at(0) == buf.at(1) || buf.at(1) == buf.at(2) ||  buf.at(2) == buf.at(3)){
            flag = false;
        }
    }
    
    if(flag){
        cout << "Good" << endl;
    }else{
        cout << "Bad" << endl;
    }

    return 0;
}

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

int main() {
  ll n; cin >> n;
  string s = "";
  while (n) {
    n--;
    s += (char)('a' + n % 26);
    n /= 26;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3644
import Data.Char
ans s =
  let c1 = (length s) >= 6
      c2 = [] /= (filter isDigit s)
      c3 = [] /= (filter isLower s)
      c4 = [] /= (filter isUpper s)
  in
    if c1 && c2 && c3 && c4 then "VALID" else "INVALID"

main = do
  l <- getLine
  let o = ans l
  putStrLn o
  



Measured memory_bytes: 3632
#include <string>
#include <string.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <tuple>
#include <functional>
#include <set>

using namespace std;
int n;
int k;
int x[50];
int y[50];

int main()
{
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		cin >> x[i] >> y[i];
	}
	long long ans = 6e18;
	for (int x1 : x) {
		for (int x2 : x) {
			for (int y1 : y) {
				for (int y2 : y) {
					if (x1 >= x2 || y1 >= y2)continue;
					int cnt = 0;
					for (int i = 0; i < n; ++i) {
						if (x1 <= x[i] && x[i] <= x2&&y1 <= y[i] && y[i] <= y2) {
							++cnt;
						}
					}
					if (cnt >= k) {
						ans = min(ans, (long long)(x2 - x1)*(y2 - y1));
					}

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



Measured memory_bytes: 384
N, K = map(int, input().split())
P = list(map(int, input().split()))

pos = 0
n = m = sum(P[0:K])
for i in range(1,N):
    if i+K > N:
        break
    n = n - P[i-1] + P[K-1+i]
    if n > m:
        pos = i
        m = n

print((sum(P[pos:pos+K]) + K) / 2)

Measured memory_bytes: 32128
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T>
T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T>
T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}
template <class T>
bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    map<ll, int> M;
    cin >> N;
    REP(i, N) {
        ll A;
        cin >> A;
        M[A]++;
    }
    int res = 0;
    for (auto x : M) {
        if (x.second % 2 == 1) {
            res++;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  	int N=0,i=0,j=0,rs=1;
  	bool f = true;
  	
  	cin >> N;
  	int H[N]={};
  	for(i=0;i<N;i++){
    	cin >> H[i];
    }
    for(i=1;i<N;i++){
      f=true;
 		for(j=i-1;j>=0;j--){
          if((H[i] - H[j])<0){
            f = false;
            break;
          }
        }
      if(f){
        rs++;
      }
    }
  cout << rs <<endl;
  	
	return 0;
}

Measured memory_bytes: 256
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N = int(input())
A = [0] + list(map(int, input().split()))

ans = 0
for i in range(1,N):
    if A[i] == i:
        ans += 1
        A[i] = A[i+1]
        A[i+1] = i

if A[N] == N:
    ans += 1

print(ans) 

Measured memory_bytes: 23480
n = int(input())
S = input()

idx = n//2
x = S[:idx]
y = S[idx:]
if x == y:
    print(1)
    exit()

cs = 0
for i in range(idx):
    x = S[:idx-i]
    y = S[idx-i:]
    cs = max(cs, len(set(x) & set(y)))

    x = S[:idx+i]
    y = S[idx+i:]
    cs = max(cs, len(set(x) & set(y)))

print(cs)

Measured memory_bytes: 3064