akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int cards,n,i,p,q,r,x[5002],y[5002],counter;
  int numberStart[20001];
  int numberFast[20001];
  int numberEnd[20001];
  int searchB[20001];
int numberLong(int value){
	return numberEnd[value]-numberStart[value]+1;
}


int searchD(int seed){
		int l=0;
  for (int a=1;a<=counter+1;a++){
	if(seed>l+numberLong(searchB[a])){
	l+=numberLong(searchB[a]);
	}
	else{
	 return numberFast[searchB[a]];
	}
  }
 return -100;
	
}
int searchNumber(int value){
	int l=0;
  for (int a=1;a<=counter+1;a++){
	if(value>l+numberLong(searchB[a])){
	l+=numberLong(searchB[a]);
	}
	else{
	 return numberStart[searchB[a]]+value-l-1;
	}
  }
 return -100;
}

void cut(int g){
	if(searchD(g)==searchD(g+1)){
  //カットする場所が入ってる数列を求める
	int	searchNumberG=searchNumber(g);
  int seachX=searchB[searchD(g)];
  int seachXX=searchNumberG;
//数列ができる範囲の後ろの番号FASTを変える
     for(int j=1;j<=counter;j++){
      if (numberFast[j]>=numberFast[seachX]+1){
      numberFast[j]++;
     }
    }

  //の数列の後ろに新しい数列を作る
 counter++;
  numberFast[counter]=numberFast[seachX]+1;
  numberStart[counter] =searchNumberG+1;
  numberEnd[counter]=numberEnd[seachX];
  //できた数列の前の数列の最後を調整する
  numberEnd[seachX]=searchNumberG;
 

  
  for ( int a=1;a<=counter+1;a++){
	  searchB[numberFast[a]]=a;
    }
    }

}
void shuffle(int x,int y){
	
	int StartHead[10001];
	int  numberFastNew[10001];
	
	int longs=1;
	for (int i=1;i<=counter;i++){
		StartHead[searchB[i]]=longs;
		longs+=numberLong(searchB[i]);
	}
	int newCounter[3];
	for(int i=0;i<3;i++){
		newCounter[i]=0;
	}
	for(int j=1;j<=counter;j++){
		if (StartHead[j]>y){
			newCounter[0]++;
		numberFastNew[j]=0;
		}
		if (StartHead[j]>x && StartHead[j]+numberLong(j)-1<=y){
			newCounter[1]++;
		numberFastNew[j]=1;
		}
		if (StartHead[j]+numberLong(j)-1<=x){
			newCounter[2]++;
		numberFastNew[j]=2;
		}
	}
	
	for(int j=1;j<=counter;j++){
		switch(numberFastNew[j]){
			case 0:
				numberFast[j]+=-newCounter[1]-newCounter[2];
				break;
			case 1:
				numberFast[j]+=newCounter[0]-newCounter[2];
				break;
			case 2:
				numberFast[j]+=newCounter[1]+newCounter[0];
				break;
		}

	}
	  for ( int a=1;a<=counter+1;a++){
	  searchB[numberFast[a]]=a;
    }

}


int main(void)
{
	while(true){
	cards=0;
	n=0;
	counter=0;
	for (int i=0;i<20000;i++){
   numberStart[i]=0;
   numberFast[i]=0;
   numberEnd[i]=0;
   searchB[i]=0;
	}
	int points=0;
  counter=1;
  cin >> cards;
  if (cards==0){
	  break;
  }
  numberStart[1]=1;
  numberEnd[1]=cards;
  numberFast[1]=1;
  searchB[1]=1;
  cin >> n;
  cin >> p  >> q  >> r ;
  for (i=1;i<=n;i++){
    cin >> x[i] >> y[i];
  }
  for (i=1;i<=n;i++){
     cut(x[i]);
	 
      cut(y[i]);
	  
     shuffle(x[i],y[i]);
  }
  cut(p-1);
  cut(q);
 /*
  
  for(int j=1;j<=counter;j++){

    cout << numberStart[j] << " "  <<  numberEnd[j] << " " << numberFast[j] <<  endl;

  }
  cout << searchD(p) << searchD(q) <<endl;
  */
  for(int j=1;j<=counter;j++){
  if( searchD(p)<= numberFast[j] && numberFast[j] <= searchD(q)){
	  if(numberEnd[j]<=r){
	  points+=numberLong(j);
	  }
	  else if(numberStart[j]<=r){
	points+=numberLong(j)-(numberEnd[j]-r);
	  }
  }
  }
  cout << points << endl;
	}
}

Measured memory_bytes: 1572
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

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

Measured memory_bytes: 256
n, m = map(int, input().split())
nums = []
for i in range(1000):
    if len(str(i)) == n:
        nums.append(i)

for _ in range(m):
    s, c = map(int, input().split())
    next_nums = []
    for a in nums:
        if int(str(a)[s - 1]) == c:
            next_nums.append(a)
    nums = next_nums

print(nums[0] if nums else -1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define ITR(v, i) for(auto ite = v.begin(); ite != v.end(); ite++)
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    vl kasi(n, 0);
    rep(i, k) {
        cin >> x;
        rep(j, x) {
            cin >> a;
            a--;
            kasi[a]++;
        }
    }

    rep(i, n) {
        if(kasi[i] == 0)
            ans++;
    }

    cout << ans << endl;
}

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

long long power(long long n)
{
    return n * n * n * n * n;
}

int main()
{
    long long X;
    cin >> X;
    vector<pair<long long, long long>> number(1, make_pair(0ll, 0ll));
    for (long long i = 1; i <= 10000; i++)
    {
        number.push_back(make_pair(power(i), i));
        number.push_back(make_pair(power(-i), -i));
    }

    for (size_t i = 0; i < number.size(); i++)
    {
        for (size_t j = 0; j < number.size(); j++)
        {
            if (number[i].first - number[j].first == X)
            {
                cout << number[i].second << " " << number[j].second << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3924
#include <stdio.h>
#include <string.h>

int main() {
  char c[4];
  char *week[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  scanf("%s", c);
  for(int i = 0; i < 7; i++) {
    if(strcmp(c, week[i]) == 0) {
      printf("%d", 7 - i);
      break;
    }
  }
}

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

#define len(x) (int)((x).size())
#define show(x) cout << #x << " = " << x << "\n"

#define maxs(x, y) x = std::max(x, y)
#define mins(x, y) x = std::min(x, y)

using ll = long long;
using ull = unsigned long long;

const int INF = 10000000;
const ll LINF = 1000000000000;

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

    std::vector<int> w(N), v(N);
    for(int i = 0; i < N; ++i) {
        std::cin >> w[i] >> v[i];
    }

    // dp[weight]
    std::vector<ll> dp(W + 1);
    for(int i = 1; i <= N; ++i) {
        for(int j = W; j >= w[i - 1]; --j) {
            dp[j] = std::max(dp[j], dp[j - w[i - 1]] + v[i - 1]);
        }
    }

    std::cout << dp[W] << "\n";
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <stack>

using namespace std;

int main(){
    int n;
    while(cin >> n && n){
        int ret = 0;
        int last=-1;
        int cnt = 0;
        int stone;
        stack<int> st;
        for(int i=1;i<=n;i++){
            cin >> stone;
            if(i%2 == 0){
                if(last == stone){
                    if(stone == 0){
                        ret++;
                        cnt++;
                    }else{
                        cnt++;
                    }
                }else{
                    if(stone == 0){
                        ret += cnt;
                        if(!st.empty()){
                            cnt += st.top();
                            st.pop();
                        }
                        last = 0;
                        ret++;
                        cnt++;
                    }else{
                        ret -= cnt;
                        if(!st.empty()){
                            cnt += st.top();
                            st.pop();
                        }
                        last = 1;
                        cnt++;
                    }
                }
            }else{
                if(last != stone && last != -1){
                    st.push(cnt);
                    cnt = 0;
                }
                if(stone == 0){
                    cnt++;
                    ret++;
                    last = 0;
                }else{
                    cnt++;
                    last = 1;
                }
            }
        }
        cout << ret << endl;
    }
}

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

int main() {
    int N, M; cin >> N >> M;
    vector<int> x(M);
    for(int i = 0; i < M; ++i) {
        int A, B; cin >> A >> B;
        x[i] = max(0, N - A);
    }
    sort(begin(x), end(x));
    cout << accumulate(begin(x), end(x), 0) - x.back() << endl;
}



Measured memory_bytes: 3088
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const int MAXN = 200005;
int n, m, pre, suf;
pair<int ,int> s[MAXN];
vector<int> a;
priority_queue< int, vector<int>, greater<int> > q;
#define fi first
#define se second
#define MP make_pair

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) scanf("%d%d", &s[i].fi, &s[i].se);
	sort(s + 1, s + n + 1);
	
	for(int i = 1; i <= n; ++i)
	if(q.size() < s[i].fi) q.push(s[i].se);
	else if(!q.empty() && q.top() < s[i].se) a.push_back(q.top()), q.pop(), q.push(s[i].se);
	else a.push_back(s[i].se);
	
	pre = q.size();
	sort(a.begin(), a.end(), greater<int>());
	for(int i = 0; i < a.size(); ++i) if(suf + 1 <= min(m + 1 - a[i], m - pre)) ++suf;
	
	printf("%d\n", n - pre - suf);
	
	return 0;
}

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

int main(){
	int N,K,X,Y;
	cin >> N >> K >> X >> Y;
	if (N<K){
	  cout << N*X << endl;
    }
    else{
      cout << K*X+Y*(N-K) << endl;
    }
	
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())

using namespace std;
typedef pair<int,int> P;

// 最大公約数
int64_t gcd(int64_t a, int64_t b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
int64_t lcm(int64_t a, int64_t b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  int64_t a,b;
  cin >> a >> b;
  if ((a-b)%2 != 0){
    cout << "IMPOSSIBLE" << endl;
  }else{
    cout << (b+a)/2 << endl;
  }
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	static Scanner in = new Scanner(System.in);
 
	public static void main(String[] args) {
		int N = in.nextInt(), A = in.nextInt(), B = in.nextInt();
 
		if (A > B || (N == 1 && A != B)) {
			System.out.println("0");
		} else if (A == B && N == 1) {
			System.out.println("1");
		} else {
			long min = (long)A * (N - 2);
			long max = (long)B * (N - 2);
			System.out.println(max - min + 1);
		}
 
	}
}

Measured memory_bytes: 21844
#include <stdio.h>

int main ()
{
	int a=0,b=0,c=0;
	scanf("%d %d %d",&a,&b,&c);
	
	if(b-a==c-b)
	{
		printf("YES\n");
	}
	else if (b-a!=c-b)
	{
		printf("NO\n");
	}
	
	
	
	return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
typedef map<int,int> mp;

const int MOD = 1e9 + 7;


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

    int ans = 0;
    string s;
    cin >> s;

    int cnt = 0;
    rep(i, s.size()){
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            cnt ++;
        }else{
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
use io::*;

fn main() {
    let con = read_string();
    let mut sc = Scanner::new(&con);

    let n: usize = sc.next();
    let aa: Vec<i64> = sc.next_vec(n);

    let mut ans = 0;

    for &a in aa.iter() {
        ans += a.trailing_zeros();
    }

    println!("{}", ans);
}

//-----

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 4352
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
#print(n)
#print(a)
#print(b)
#print(c)
total=0
pre=0
for i in range(n):
  total+=b[i]
  if pre+1==a[i] and pre!=0:
    total+=c[pre-1]
  pre=a[i]
print(total)

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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");

ll pows(int a , int b)
{
	ll res=1;
	for(int i=0; i<b; ++i)
	{
		res*=a;
	}
	return res;
}

vi vis(100001,0);

int dp[100001][4];

vi adj[4];

int dpx(int n, int s)
{
	if(n==1 && s==1)
	{
		dp[1][1]=adj[1][1];
		return dp[1][1];
	}
	else if(n==1 && s==2)
	{
		dp[1][2]=adj[2][1];
		return dp[1][2];

	}	

	else if(n==1 && s==3)
	{
		dp[1][3]=adj[3][1];
		return dp[1][3];
	}
	if(s==1)
	{
		if(dp[n][s]==-1)
		{
			dp[n][s]=max(dpx(n-1,2),dpx(n-1,3))+adj[1][n];
			return dp[n][s];
		}
		return dp[n][s];
	}
	else if(s==2)
	{
		if(dp[n][s]==-1)
		{
			dp[n][s]=max(dpx(n-1,1),dpx(n-1,3))+adj[2][n];
			return dp[n][s];
		}
		return dp[n][s];
	}
	else if(s==3)
	{
		if(dp[n][s]==-1)
		{
			dp[n][s]=max(dpx(n-1,2),dpx(n-1,1))+adj[3][n];
			return dp[n][s];
		}
		return dp[n][s];
	}
}

int main()
{	
    std::ios::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    int n;
    cin>>n;
    adj[1].pb(0);
    adj[2].pb(0);
    adj[3].pb(0);
    for(int i=0; i<n; ++i)
    {
    	int a,b,c;cin>>a>>b>>c;
    	adj[1].pb(a);
    	adj[2].pb(b);
    	adj[3].pb(c);
    }
    int x,y,z;
    memset(dp, -1, sizeof dp);
    dpx(n,1);
    x=dp[n][1];
    memset(dp, -1, sizeof dp);
    dpx(n,2);
    y=dp[n][2];
    memset(dp, -1, sizeof dp);
    dpx(n,3);
    z=dp[n][3];
    //cout<<x<<" "<<y<<" "<<z<<"\n";
    cout<<max(x,max(y,z))<<"\n";

}

Measured memory_bytes: 8296
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <queue>
#include <vector>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define SORT(A) std::sort((A).begin(), (A).end())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())

using lli = long long int;
using pii = std::pair<int, int>;

template <typename T>
bool chmin(T& a, T b){
    if(b < a){ a = b; return true;}
    return false;
}

template <typename T>
bool chmax(T& a, T b){
    if(a < b){ a = b; return true;}
    return false;
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


std::vector<std::vector<int>> Edge;
std::vector<int> Dt, Da, Depth, In;

int main(void){
    int n, Tak, Aok; scanf("%d%d%d", &n, &Tak, &Aok); Tak--; Aok--;
    Edge.resize(n);
    REP(i, n-1){
        int u, v; scanf("%d%d", &u, &v); u--; v--;
        Edge[u].push_back(v);
        Edge[v].push_back(u);
    }
    std::queue<int> Q;
    Dt.assign(n, -1);
    Q.push(Tak); Dt[Tak] = 0;
    while(not Q.empty()){
        int v = Q.front(); Q.pop();
        for(int nv : Edge[v]) if(Dt[nv] == -1){
            Dt[nv] = Dt[v] + 1;
            Q.push(nv);
        }
    }

    Da.assign(n, -1);
    Q.push(Aok); Da[Aok] = 0;
    while(not Q.empty()){
        int v = Q.front(); Q.pop();
        for(int nv : Edge[v]) if(Da[nv] == -1){
            Da[nv] = Da[v] + 1;
            Q.push(nv);
        }
    }

    Depth.assign(n, 0); In.assign(n, 0);
    REP(i, n) if(i != Tak){
        bool flag = true;
        for(int v : Edge[i]){
            if(Da[i] > Da[v]){
                flag = false; break;
            }
            In[i]++;
        }
        if(flag){
            Depth[i] = 0;
            Q.push(i);
        }
    }
    while(not Q.empty()){
        int v = Q.front(); Q.pop();
        for(int nv : Edge[v]){
            In[nv]--;
            if(In[nv] == 0){
                Depth[nv] = Depth[v] + 1;
                Q.push(nv);
            }
        }
    }
    int ans = 0;
    REP(i, n) if(Dt[i] < Da[i]){
        //printf("%d : %d %d %d\n", i, Da[i] , Depth[i], Da[i] + Depth[i] - 1);
        chmax(ans, Da[i] + Depth[i] - 1);
    }
    printf("%d\n", ans);


    


    return 0;
}



Measured memory_bytes: 7424
n,m=map(int,input().split())
p=list(map(int,input().split()))
uf={i:i for i in range(1,n+1)}
def get_p(i):
    lst=[]
    while uf[i]!=i:
        lst.append(i)
        i=uf[i]
    for l in lst[:-1]:
        uf[l]=i 
    return i 

def unite(i,j):
    uf[get_p(i)]=get_p(j)
def same(i,j):
    return get_p(i)==get_p(j)

def main():
    for i in range(m):
        x,y=map(int,input().split())
        unite(x,y)
    cnt=0
    for i in range(1,n+1):
        cnt+=same(p[i-1],uf[i])
    print(cnt)    
if __name__=='__main__':
    main()  

Measured memory_bytes: 20704
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
int main() {
	int S;
	cin >> S;
	int hour;
	hour = S / (60 * 60);
	int minute;
	minute =( S % (60 * 60))/60;
	int second;
	second = S-hour*60*60-minute*60;
	

	cout << fixed << setprecision(0) << hour <<left<<":"<< minute <<left<<":"<< second << endl;

}

Measured memory_bytes: 3088
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
	ll i;
	ll a, b, n;
	ll ans = 0;
	ll tmp, start;
	cin >> a >> b >> n;
	start = min(n, b - 1);
	// for (i = start; i <= n; i += b) {
	// 	tmp = (a * i) / b - a * (i / b);
	// 	if (tmp > ans)
	// 		ans = tmp;
	// }
	if (n <= b - 1) {
		start = n;
		ans = (a * start) / b;
	} else {
		ll altans;
		start = n - (n % b + 1);
		altans = (a * n) / b - a * (n / b);
		ans = (a * start) / b - a * (start / b);
		ans = max(ans, altans);
	}

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


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
 
class UnionFind{
  int n;
  vector<int> data;
public:
  UnionFind(int _n):n(_n),data(_n,-1){}
  bool link(int a, int b){ //if new link, then true.
    int ra=find_root(a);
    int rb=find_root(b);
    if(ra!=rb){
      if(data[rb]<data[ra]) swap(ra,rb);
      data[ra]+=data[rb];
      data[rb]=ra;
    }
    return (ra!=rb);
  }
  bool check(int a, int b){ //if same set, then true.
    return (find_root(a)==find_root(b));
  }
  int find_root(int a){
    return ((data[a]<0)?a:(data[a]=find_root(data[a])));
  }
};
 
#define INF 1000000000000000000LL
 
int N, M;
int L[200005], R[200005], D[200005];
vector<pair<int,ll>> G[100005];
 
bool check(const vector<int>& v){
  if(v.size() == 1) return true;
  
  map<int,ll> pos;
  map<int,bool> checked;
  queue<int> que;
  que.push(v[0]);
  pos[0] = 0;
  while(!que.empty()){
    int p = que.front(); que.pop();
    if(checked.count(p) > 0) continue;
    checked[p] = true;
    
    rep(i,G[p].size()){
      int q = G[p][i].first;
      ll dist = G[p][i].second;
 
      if(pos.count(q) > 0){
        if(pos[p] + dist != pos[q]) return false;
      }else{
        pos[q] = pos[p] + dist;
        que.push(q);
      }
    }
  }
  
  return true;
}
 
 
 
int main(){
  cin >> N >> M;
  UnionFind uf(N+1);
  rep(i,M){
    cin >> L[i] >> R[i] >> D[i];
    G[L[i]].push_back(make_pair(R[i],D[i]));
    G[R[i]].push_back(make_pair(L[i],-D[i]));
    uf.link(L[i], R[i]);
  }
  
  map<int,vector<int>> memo;
  REP(i,1,N+1){
    memo[uf.find_root(i)].push_back(i);
  }
 
  FOR(it,memo){
    if(!check(it->second)){
      cout << "No" << endl;
      return 0;
    }
  }
 
  cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 26364
#include <iostream>

using namespace std;

int main()
{
    int N,K,large=0,small=0;
    cin >> N >> K;
    while (N-K>=0){
        N=N-K;
        large+=1;
        small+=1;
    }
    if (N>0){
        large+=1;
    }
    cout << large-small;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    int m = 1 << n;
    std::multiset<int> ss;
    for (int i = 0; i < m; i++) {
        int in;
        std::cin >> in;
        ss.insert(-in);
    }

    std::vector<int> v { *ss.begin() };
    ss.erase(ss.begin());
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < (1 << i); j++) {
            auto it = ss.upper_bound(v[j]);
            if (it == ss.end()) {
                std::cout << "No" << std::endl;
                return 0;
            }
            v.push_back(*it);
            ss.erase(it);
        }
    }

    std::cout << "Yes" << std::endl;

    return 0;
}


Measured memory_bytes: 13692
#include <bits/stdc++.h>   
using namespace std;     
int main()  
{  
    long long n,k,ans=0;  
    cin >> n>> k;  
    if(k==0) ans=n*n;  
    else  
    {  
        for(int b=k+1;b<=n;b++)  
        {  
        ans+=(n/b)*(b-k);  
        if(n%b>=k) ans+=n%b-k+1;  
        }  
    }  
    printf("%lld\n",ans);  
    return 0;  
}  

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort()
A=[a[0]]
for i in range(n-1):
  A.append(A[i]+a[i+1])
x=0
for i in range(n-1):
  if A[i]*2<a[i+1]:
    x=i+1
print(n-x)

Measured memory_bytes: 14308
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
from copy import copy

input = sys.stdin.readline

def main():
    N = int(input())
    P = list(map(int, input().split()))
    P2 = copy(P)
    P2.sort()

    cnt = 0
    for i in range(N):
        if P[i] != P2[i]:
            cnt += 1
            if cnt == 3:
                print("NO")
                return
    print("YES")

main()


Measured memory_bytes: 39884
using System;
using System.Linq;

class C
{
	static void Main()
	{
		Func<long[]> read = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
		var h = read();
		var t = read();
		Console.WriteLine(Enumerable.Range(0, (int)h[0] - 1).Sum(i => Math.Min(h[1], t[i + 1] - t[i])) + h[1]);
	}
}


Measured memory_bytes: 31008
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

ll dp[6][3010][3010];
ll v[3010][3010];

int main() {
  ll r, c, k;
  cin >> r >> c >> k;
  rep(i, k) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    v[a][b] = c;
  }
  rep(i, r + 1) rep(j, c + 1) rep(m, 4) {
    // printf("dp[%d][%d][%d]=%d\n", i, j, m, dp[i][j][m]);
    dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[m][i][j]);
    dp[m][i][j + 1] = max(dp[m][i][j + 1], dp[m][i][j]);
    if(m < 3) {
      dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[m][i][j] + v[i][j]);
      dp[m + 1][i][j + 1] = max(dp[m + 1][i][j + 1], dp[m][i][j] + v[i][j]);
    }
  }
  ll ans = 0;
  rep(m, 4) ans = max(ans, dp[m][r][c]);
  cout << ans << endl;
  // cout << 0 << endl;
}

Measured memory_bytes: 356292
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <complex>
#include <iomanip>

#define forin(i, f, t) for(auto i = f; i < t; i++)

using namespace std;
using ll = long long;

int main() {
    double m, d, n;
    cin >> n >> m >> d;
    
    double s;
    if (d == 0)
        s = 1;
    else
        s = (n - d) * 2 / n;
    
    double abs = s / n * (m - 1);
    cout << setprecision(7) << abs << endl;
    
    
    
    return 0;
}



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

int main() {
    ll n,k,q;
    std::cin >> n>>k>>q;
    vector<ll> a(q);
    vector<ll> cnt(n);
    for (int i = 0; i < q; i++) {
        std::cin >> a[i];
        a[i]--;
        cnt[a[i]]++;
    }
    for (int i = 0; i < n; i++) {
        if(k-(q-cnt[i])<= 0){
            std::cout << "No" << std::endl;
        }else{
            std::cout << "Yes" << std::endl;
        }
    }
}


Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok, flag;
ll dx[5] = { 1,-1,0,0,0 }, dy[5] = { 0,0,1,-1,0 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111

struct BinaryIndexed {
  ll num;
  vll bit;

  BinaryIndexed(ll x = MAX) {
	num = x;
	bit.resize(x + 1, 0);
  }

  ll sum(ll i) {
	ll ret = 0;
	while (i > 0) {
	  ret += bit[i];
	  i -= i & -i;
	}
	return ret;
  }

  void add(ll i, ll x) {
	if (i == 0) cout << "access 0 index" << endl;
	while (i <= num) {
	  bit[i] += x;
	  i += i & -i;
	}
  }
};

int main(void) {
  cin >> n;
  vll a(n), b(n);
  rep(i, n) scan(a[i]);
  if (n == 1) {
	cout << a[0] << endl;
	return 0;
  }
  ll low = 1, up = mod, mid, sum;

  while (up - low > 1) {
	BinaryIndexed BIT(3 * MAX);
	mid = (up + low) / 2;
	rep(i, n) a[i] >= mid ? b[i] = 1 : b[i] = -1;
	sum = MAX; cnt = 0;
	BIT.add(sum, 1);
	rep(i, n) {
	  sum += b[i];
	  cnt += BIT.sum(sum);
	  BIT.add(sum, 1);
	}
	if (cnt >= n * (n + 1) / 4) low = mid;
	else up = mid;
  }

  cout << low << endl;

  return 0;
}

Measured memory_bytes: 4432
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 1000000007
#define INIT -1

class UF {
  private:
	vector<int> root;
	vector<int> nodenum;

  public:
	UF(int n) {
		root = vector<int>(n, -1);
		nodenum = vector<int>(n, 1);
	}
	int getRoot(int x) {
		if (root[x] == -1) return x;
		return root[x] = getRoot(root[x]);
	}
	int getNodeNum(int x) { return nodenum[getRoot(x)]; }
	void connect(int x, int y) {
		x = getRoot(x);
		y = getRoot(y);
		if (x == y) return;
		if (x > y) swap(x, y);
		root[y] = x;
		nodenum[x] += nodenum[y];
	}
};

int main() {
	int n, k, l;
	cin >> n >> k >> l;
	UF passUF(n), railUF(n);
	for (int i = 0; i < k; i++) {
		int p, q;
		cin >> p >> q;
		p--;
		q--;
		passUF.connect(p, q);
	}
	for (int i = 0; i < l; i++) {
		int r, s;
		cin >> r >> s;
		r--;
		s--;
		railUF.connect(r, s);
	}
	map<pair<int, int>, int> cnt;
	for (int i = 0; i < n; i++) {
		pair<int, int> p = make_pair(passUF.getRoot(i), railUF.getRoot(i));
		if (cnt.find(p) == cnt.end()) cnt[p] = 0;
		cnt[p]++;
	}
	for (int i = 0; i < n; i++) {
		pair<int, int> p = make_pair(passUF.getRoot(i), railUF.getRoot(i));
		cout << cnt[p];
		if (i == n - 1)
			cout << endl;
		else
			cout << " ";
	}
}

Measured memory_bytes: 15104
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;

int main()
{
	int N, p;
	int ans = 0;
	bool skip = false;

	cin >> N;
	rep1(i, 1, N) {
		cin >> p;
		if (p == i && !skip) {
			ans++;
			skip = true;
		}
		else skip = false;
	}
	cout << ans << endl;

	return 0;
}


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

int main(){
  int n,d;
  cin >> d >> n;

  if(n==100)n++;
  if(d==0)cout << n << endl;
  else if(d==1)cout << n*100 << endl;
  else cout << n*10000 << endl;
}

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

int main(){
  ll n, m;
  cin >> n >> m;
  vector<vector<int>> s(m+1);
  vector<int> k(m+1);
  for(int i=1; i<=m; i++){
    cin >> k[i];
    s[i].assign(n+1, 0);
    for(int j=1; j<=k[i]; j++){
      int tmp;
      cin >> tmp;
      s[i][tmp] = 1;
    }
  }
  vector<int> p(m+1);
  for(int i=1; i<=m; i++){
  	cin >> p[i];
  }
  
  int ans = 0;
  for(int bit=0; bit<(1<<n); ++bit){
    vector<int> pls(m+1, 0);
    for (int i=0; i<n; ++i) {
      if (bit & (1<<i)){
        for(int j=1; j<=m; j++){
          pls[j] += s[j][i+1];
        }
      }
    }
    int how = 0;
    for(int i=1; i<=m; i++){
      if(pls[i] % 2 == p[i]){
        how++;
      }
    }
    if(how == m){
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n), f(n);
  for (auto& e : a) cin >> e;
  for (auto& e : f) cin >> e;
  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());

  ll bot = -1, top = 1e18, mid;
  while (bot + 1 < top) {
    mid = bot + (top - bot) / 2;
    bool b = true;
    ll t = k;
    for (int i = 0; i < n; i++) {
      if (a[i] * f[i] <= mid) continue;
      ll ax = mid / f[i];
      ll ad = a[i] - ax;
      if (ad > t) {
        b = false;
        break;
      }
      t -= ad;
    }
    if (b) {
      top = mid;
    } else {
      bot = mid;
    }
  }
  cout << top << endl;
}


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

int main(){
  int N,l,r;
  int all=0;
  cin >> N;
  
  for(int i=0; i < N; i++){
    cin >> l >> r;
    all += r - l + 1;
  }
  
  cout << all << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
const double EPS = 1e-9;
using namespace std;
class vector {
public:
	double x, y;
	vector(double a, double  b) {
		x = a;
		y = b;
	};
	vector operator * (const vector &v)const {
		return vector(x*v.x, y* v.y);
	}
	vector operator * (double a) {
		return vector(x * a, y * a);
	}
	vector operator - (vector v) {
		return vector(x - v.x, y - v.y);
	}
	vector operator + (vector v) {
		return vector(x + v.x, y + v.y);
	}
};
inline double dot(vector v1, vector v2) {
	return v1.x*v2.x + v1.y*v2.y;
}
inline double squ(vector v) {
	return v.x*v.x + v.y*v.y;
}
inline double norm(vector v) {
	return sqrt(squ(v));
}
inline void print(vector v) {
	printf("%.10f %.10f\n", v.x, v.y);
}
inline vector pro(vector base, vector v, vector be) {
	double a = dot(base, v) / squ(base);
	vector v1 = base * a;
	return v1 + be;
}
inline vector ref(vector v, vector be) {
	return (v - be)*2 + be;
}
inline double cross(vector v1, vector v2) {
	return v1.x*v2.y - v1.y*v2.x;
}
inline int ccw(vector v1, vector v2, vector v3) {
	vector a = v2 - v1;
	vector b = v3 - v1;
	if (cross(a, b) < 0.0) return -1;
	else if (cross(a, b) > 0.0) return 1;
	else if (dot(a, b) < 0.0) return -2;
	else if (dot(a, b) > squ(a)) return 2;
	else return 0;
}
inline int inter(vector v1, vector v2, vector v3, vector v4) {
	return (ccw(v1, v2, v3) * ccw(v1, v2, v4) <= 0) && (ccw(v3, v4, v1) * ccw(v3, v4, v2) <= 0);
}
inline double disPP(vector v1, vector v2) {
	return norm(v2 - v1);
}
inline double disLP(vector v1, vector v2, vector v3) {
	vector a = v2 - v1;
	vector b = v3 - v1;
	return fabs(cross(a, b) / norm(a));
}
inline double disSP(vector v1, vector v2, vector v3) {
	vector a = v2 - v1;
	vector b = v3 - v1;
	vector c = v1 - v2;
	vector d = v3 - v2;
	if (dot(a, b) < 0.0) return disPP(v1, v3);
	else if (dot(c, d) < 0.0) return disPP(v2, v3);
	else return disLP(v1, v2, v3);
}
inline double disSS(vector v1, vector v2, vector v3, vector v4) {
	if (inter(v1, v2, v3, v4)) return 0;
	double a = disSP(v1, v2, v3);
	double b = disSP(v1, v2, v4);
	double c = disSP(v3, v4, v1);
	double d = disSP(v3, v4, v2);
	return min(min(a, b), min(c, d));
}
/*int main() {
	//inter
	int n;
	double x0, x1, x2, x3, y0, y1, y2, y3;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		vector v1(x0,y0);
		vector v2(x1, y1);
		vector v3(x2, y2);
		vector v4(x3, y3);
		cout << inter(v1, v2, v3, v4) << endl;
	}
	return 0;
}*/
int main() {
	//clo
	int n;
	double x0, x1, x2, y0, y1, y2;
	cin >> x0 >> y0 >> x1 >> y1 >> n;
	vector v0(x0, y0);
	vector v1(x1, y1);
	for(int i = 0; i < n; i++) {
		cin >> x2 >> y2;
		vector v2(x2, y2);
		int ans = ccw(v0, v1, v2);
		 if(ans == -1) cout << "CLOCKWISE" << endl;
		 else if(ans == 1) cout << "COUNTER_CLOCKWISE" << endl;
		  else if(ans == -2)cout << "ONLINE_BACK" << endl;
		  else if(ans == 2)cout << "ONLINE_FRONT" << endl;
		else cout << "ON_SEGMENT" << endl;
	}
	return 0;
}

Measured memory_bytes: 3208
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP2_3_B
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = ReadInt();
            int[] line = ReadIntAr();

            int q = ReadInt();
            for (int i = 0 ; i < q ; i++)
            {
                int[] items = ReadIntAr();

                if (items[0] == 0)
                {
                    Console.WriteLine(line.Where((x,index) => items[1] <= index && index < items[2]).Min());
                }
                else
                {
                    Console.WriteLine(line.Where((x, index) => items[1] <= index && index < items[2]).Max());
                }
            }        
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



Measured memory_bytes: 18336
// Problem : 
// 			D - Xor Sum 2
// 			Editorial
// 		
// Contest : AtCoder - AtCoder Regular Contest 098
// URL : https://atcoder.jp/contests/arc098/tasks/arc098_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int N;
	cin>>N;
	vl v(N);
	F0R(x,N)
		cin>>v[x];
	ll sm=0,xr=0,ans=0;
	int l=0;
	F0R(r,N)
	{
		sm+=v[r];
		xr^=v[r];
		while(sm!=xr)
		{
			sm-=v[l];
			xr^=v[l];
			l++;
		}
		ans+=r-l+1;
	}
	cout<<ans<<nl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 4816
n = int(input())
x_org = []
for i in range(n):
    x_org.append(input().split())

x = sorted(x_org, key=lambda z: int(z[0]))
removed = 0
for i in range(1, n):
    before = int(x[i][0]) - int(x[i][1])
    after = int(x[i-1][0]) + int(x[i-1][1]) 
    if before < after:
        removed += 1
        if (int(x[i][0]) + int(x[i][1])) > (int(x[i-1][0]) + int(x[i-1][1])):
            x[i] = x[i-1]

print(n - removed)


Measured memory_bytes: 40052
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 64 * 1024
	maxBufSize     = 10000000
)

var (
	scanner = bufio.NewScanner(os.Stdin)
	writer  = bufio.NewWriter(os.Stdout)
)

func main() {
	scanner.Buffer(make([]byte, maxBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	s := scanText()
	q := scanInt()

	isReverse := false
	head, tail := "", ""
	for i := 0; i < q; i++ {

		if scanInt() == 1 {
			isReverse = !isReverse
			continue
		}

		if f := scanInt(); (f == 1 && !isReverse) || (f == 2 && isReverse) {
			head += scanText()
		} else {
			tail += scanText()
		}
	}

	ans := reverse(head) + s + tail

	if isReverse {
		fmt.Print(reverse(ans))
	} else {
		fmt.Print(ans)
	}
}

func reverse(s string) string {
	t := []byte(s)
	for i, j := 0, (len(s) - 1); i < j; i, j = i+1, j-1 {
		t[i], t[j] = t[j], t[i]
	}
	return string(t)
}

func scanInt() int {
	i, _ := strconv.Atoi(scanText())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func abs(n int) int {
	return int(math.Abs(float64(n)))
}

func pow(x, y int) int {
	return int(math.Pow(float64(x), float64(y)))
}


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

import sys
import os


def get_house():
    return [[0 for i in range(10)] for j in range(3)]

def print_house(h):
    for i in range(3):
        for j in range(10):
            print(' ', end='')
            print(h[i][j], end='')
        print()

houses = []
for i in range(4):
    houses.append(get_house())

N = int(input())
for i in range(N):
    b, f, r, v = list(map(int, input().split()))
    houses[b-1][f-1][r-1] += v

for i in range(4):
    print_house(houses[i])
    if i != 3:
        print('####################')

Measured memory_bytes: 7736
#include<stdio.h>

int main(void){
int N,a,b,c,i,j,temp;

scanf("%d",&N);
for(i=0;i<N;i++){
scanf("%d %d %d",&a,&b,&c);

if(a<b){temp=a;a=b;b=temp;}
if(a<c){temp=a;a=c;c=temp;}
if(b<c){temp=b;b=c;c=temp;}

if(a*a!=b*b+c*c){printf("NO\n");}else{printf("YES\n");}
}
return 0;
}

Measured memory_bytes: 576
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

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

	ll ans = 1000, left = 0;
	for (int i = 0; i < N ; i++) {
		if (i != N - 1&&A[i] > A[i + 1]) {
			ans = (ans / A[left]) * A[i] + ans - (ans / A[left]) * A[left];
			left = i + 1;
		}
		else if (i == N - 1) {
			if (left != N - 1) {
				ans = (ans / A[left]) * A[i] + ans - (ans / A[left]) * A[left];
				left = i + 1;
			}
		}

	}
	cout << ans << endl;
}



Measured memory_bytes: 3628
import math
A, B, N = map(int, input().split())
ans = 0
if N<10**6:
    for i in range(N+1):
        tmp = math.floor(A*i/B)-A*math.floor(i/B)
        if tmp>ans:
            ans = tmp
elif N>=10**6 and N>=B:
    ans = math.floor(A*(B-1)/B)-A*math.floor((B-1)/B)
elif N>=10**6 and N<B:
    ans = math.floor(A*N/B)-A*math.floor(N/B)
    

print(ans)

Measured memory_bytes: 9104
N,*t=`dd`.split.map &:to_i;d=t.shift N;M,*t=t
t,d=[t,d].map{|e|h=Hash.new 0;e.map{|f|h[f]+=1};h}
puts t.all?{|k,v|d[k]>=v}?:YES: :NO

Measured memory_bytes: 61848
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def conb(n,r): 
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = inp()
a = inpl()
c = Counter(a)
res = 0
d = dict()
for key in list(c):
    # print(c[key])
    if c[key] > 1:
        tmp = conb(c[key], 2)
        res += tmp
        d[key] = tmp
    else:
        d[key] = 0
for i,t in enumerate(a):
    if d[t] == 0:
        print(res)
        continue
    now = d[t] * max(0,c[t]-2) // c[t]
    # print(now)
    print(res - d[t] + now)


Measured memory_bytes: 125636
n = gets.to_i

nums = gets.split.map(&:to_i).sort.reverse

valid = true
res = 1
(n - 1).step(1, -2) do |i|
  idx = n - i - 1
  current_range = nums[idx, 2]
  unless current_range[0] == i && current_range[1] == i
    valid = false
    break
  end
  res *= 2
end
valid = false if n.odd? && nums.count(0) != 1

puts valid ? res % (10**9 + 7) : 0

Measured memory_bytes: 45292
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p=p*a%mod;a=a*a%mod;n>>=1;}return p;}

int main()
{
        ll m, n;
        cin >> m >> n;
        cout << intpow(m, n) << endl;
}


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

int main(){
  int A,B,tashi,hiki,kake,dekai,ans;
  cin >> A >> B;  
  tashi = A + B;
  hiki = A - B;
  kake = A * B;
  dekai = max({tashi,kake,hiki});
  cout << dekai <<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define opt ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long int
#define ull unsigned long long int
#define I int
#define S string
#define D long double
#define rep(i,a,b) for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
// I might be a loser, but I have nothing to lose :p
// g++ -std=gnu++14 A.cpp
int main()
{
opt;
I n,a,b;
cin>>n;
if(n==1)
{
    cout<<"Hello World";
    return 0;
}
cin>>a>>b;
cout<<a+b;
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    
    int n,b,f,r,v;
    int i,x,y;
    int room[15][10] = {0};
    
    scanf("%d",&n);
    
    for(i = 0; i < n; i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        room[4 * (b - 1) + (f - 1)] [r - 1] = room[4*(b-1)+(f-1)][r-1] + v;
    }
    for(y = 0; y < 15; y++){
        for(x = 0; x < 10; x++){
            if(y == 3 || y == 7 || y == 11) printf("##");
            else printf(" %d",room[y][x]);
        }
        printf("\n");
    }
    
}

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

using namespace std;

int main(){
    string str = "";
    int n = 0;
    cin >> str;
    for(int i = 0; i < str.size(); i++){
        if(str[i] == '+'){
            n++;
        }else{
            n--;
        }
    }
    cout << n << endl;

    return 0;
}

Measured memory_bytes: 256