akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

template<class Ty>
using passive_queue = priority_queue<Ty, vector<Ty>, greater<Ty>>;

struct Problem {

	void Solve() {
		UL N; cin >> N;
		if (N == 2) { cout << 1 << endl << 1 << endl; return; }

		vector<vector<pair<UL, UL>>> E(N);
		vector<pair<UL, UL>> J(N * 2 - 2);
		rep(i, N - 1) {
			UL u, v; cin >> u >> v; u--; v--;
			E[u].push_back({ v, i });
			J[i] = { u, v };
			E[v].push_back({ u, N - 1 + i });
			J[N - 1 + i] = { v, u };
		}

		static const ULL M = 1000000007;
		struct Comb {
			vector<ULL> Fact, Inv, iFact;
			Comb(UL N) {
				Fact.resize(N + 1); Fact[0] = 1;
				for (UL i = 1; i <= N; i++) Fact[i] = Fact[i - 1] * i % M;
				Inv.resize(N + 1); Inv[1] = 1;
				for (UL i = 2; i <= N; i++) Inv[i] = M - M / i * Inv[M % i] % M;
				iFact.resize(N + 1); iFact[0] = 1;
				for (UL i = 1; i <= N; i++) iFact[i] = iFact[i - 1] * Inv[i] % M;
			}
			ULL operator()(UL n, UL r) { return Fact[n] * iFact[r] % M * iFact[n - r] % M; }
		} C(N);

		vector<pair<UL, ULL>> Z((N - 1) * 2);
		{
			vector<UL> F(N); rep(i, N) F[i] = E[i].size();
			vector<pair<UL, ULL>> S(N, make_pair(0u, 1ull));
			queue<UL> Q;
			stack<UL> st;
			rep(i, N) { if (F[i] == 1) Q.push(E[i][0].second); }
			while (Q.size()) {
				UL p = Q.front(); Q.pop();
				UL ip = (p + N - 1) % ((N - 1) * 2);
				st.push(ip);
				Z[p] = S[J[p].first];
				Z[p].first++;

				UL v = J[p].second;
				F[v]--;
				S[v].second = S[v].second * C(S[v].first + Z[p].first, Z[p].first) % M;
				S[v].second = S[v].second * Z[p].second % M;
				S[v].first += Z[p].first;
				if (F[J[p].second] != 1) continue;
				for (auto e : E[v]) {
					if (e.first == J[p].first) continue;
					if (F[e.first] == 1) continue;
					Q.push(e.second);
				}
			}
			while (st.size()) {
				UL p = st.top(); st.pop();
				UL v = J[p].second;
				S[v].second = S[J[p].first].second;
				S[v].second = S[v].second * (S[v].first + 1) % M;
				S[v].second = S[v].second * C.Inv[N - (S[v].first + 1)] % M;
				S[v].first = N - 1;
			}
			rep(i, N) cout << S[i].second << endl;
		}
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 33520
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            var k = ReadInt();
            var x = ReadInt();
            var y = ReadInt();

            var ans = 0;
            for (int i = 1; i <= n; i++)
            {
                if (i <= k)
                {
                    ans += x;
                }
                else
                {
                    ans += y;
                }
            }
            WriteLine(ans);
        }
       

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        //最大公約数
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }

        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

    }
}


Measured memory_bytes: 11092
n,x = map(int,input().split())
suma = 0
ans = 0
for a in sorted(list(map(int,input().split()))):
  if suma + a == x:
    print(ans+1)
    exit()
  elif suma + a > x:
    print(ans)
    exit()
  else:
    suma += a
    ans += 1
print(ans if suma>=x else ans-1)

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;
#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(typeof(a) i=(a); i<(n); i++)


int N;
ll W;

int main() {
    cin >> N >> W;
    ll w1, v1; cin >> w1 >> v1;

    vector<ll> v[4]; v[0].push_back(v1);
    ll w_, v_;
    
    rep(i, N-1) {
        cin >> w_ >> v_;
        v[w_ - w1].push_back(v_);
    }
    
    rep(i, 4) {
        sort(v[i].begin(), v[i].end(), greater<ll>());
    }
    
    ll ans = 0;
    rep(n_w1, v[0].size()+1) {
        rep(n_w2, v[1].size()+1) {
            rep(n_w3, v[2].size()+1) {
                rep(n_w4, v[3].size()+1) {
                    w_ = 0; v_ = 0;
                    rep(i, n_w1) {
                        w_ += w1+0; v_ += v[0][i];
                    }
                    rep(i, n_w2) {
                        w_ += w1+1; v_ += v[1][i];
                    }
                    rep(i, n_w3) {
                        w_ += w1+2; v_ += v[2][i];
                    }
                    rep(i, n_w4) {
                        w_ += w1+3; v_ += v[3][i];
                    }
                    if(w_ <= W) ans = max(ans, v_);
                }
            }
        }
    }
    cout << ans << endl;
    
    
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	string S;
	cin >> S;
	int ans = 0;
	rep(i, S.size()) {
		if (S[i] == '1')ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
    public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int m;
        int n = 0;
        try {
            String str = reader.readLine();
            n = Integer.parseInt(str);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(n % 2 == 0){
            m = n / 2 - 1;
        } else{
            m = n / 2;
        }
        if(n <= 2){
            m = 0;
        }
        if(n == 3){
            m = 1;
        }
        System.out.println("" + m);
    }   
}

Measured memory_bytes: 21204
#include<cstdio>
#include<algorithm>
#include<cmath>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int mo=1000000007,inv2=(mo+1)/2;
int d[3000],f[3000];
int i,j,k,l,t,n,m,top,ans;
int qsm(int x,int y){
	if (!y) return 1;
	int t=qsm(x,y/2);
	t=(ll)t*t%mo;
	if (y%2) t=(ll)t*x%mo;
	return t;
}
int main(){
	scanf("%d%d",&n,&k);
	t=floor(sqrt(n));
	fo(i,1,t)
		if (n%i==0){
			d[++top]=i;
			if (i!=n/i) d[++top]=n/i;
		}
	sort(d+1,d+top+1);
	fo(i,1,top){
		f[i]=qsm(k,(d[i]+1)/2);
		fo(j,1,i-1)
			if (d[i]%d[j]==0) (f[i]-=f[j])%=mo;
		if (d[i]%2==0) (ans+=(ll)f[i]*d[i]%mo*inv2%mo)%=mo;
		else (ans+=(ll)f[i]*d[i]%mo)%=mo;
	}
	(ans+=mo)%=mo;
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
ll p[100002];
ll find(ll x)
{
  return p[x]==x ? x :p[x]=find(p[x]);
}
int main()
{
  IOS;
  ll n,m,i;
  cin>>n>>m;
  ll link[m][2],sum[n],ans[m];
  for(i=0;i<n;i++)
  {
    p[i]=i;
    sum[i]=1;
  }
  for(i=0;i<m;i++)
  {
    cin>>link[i][0]>>link[i][1];
  }
  ans[m-1]=(n*(n-1)/2);
  for(i=m-1;i>=0;i--)
  {
    ll q,w;
    q=find(link[i][0]);
    w=find(link[i][1]);
    if(q!=w)
    {
      ans[i-1]=ans[i]-(sum[q]*sum[w]);
      sum[w]+=sum[q];
      p[q]=w;
    }
    else ans[i-1]=ans[i];
  }
  for(auto g: ans) cout<<g<<endl;
  return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9
#define OO (ll)1e18
#define EPS 1e-7
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=132679;

int main()
{
    IO;
    int n,m;
    cin >> n >> m;
    cout<<n-m+1<<endl;
    re 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
        String[] line = s.split("", 10);
        int count = 0;
        int max = 0;
        for(int i=0; i<line.length; i++){
          for(int j=0; j<line.length; j++){
        	if(line[j].equals("A") || line[j].equals("T") || line[j].equals("G") || line[j].equals("C")) {
              count++;
              if(count > max) {
           		 max = count;
              }
            }
            else count = 0;
          }
          count = 0;
        }
		System.out.println(max);
	}
}

Measured memory_bytes: 23124
#include <iostream>

using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a<b){
    if(a<c && c<b){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    }else{
        if(b<c && c<a){
            cout<<"Yes"<<endl;
        }else{
           cout<<"No"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")

#include <bits/stdc++.h>
using namespace std;
 
#define len(x) (int)((x).size())
#define endl '\n'
#define int long long
#define x first 
#define y second
#define dbg(x) cout << #x << " = " << x << endl;

void solve(); signed main() {
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(10);
    solve();
    return 0;
}
 
const int MOD = 998244353, MAXN = 1e6 + 10, INF = 1e18 + 10, BASE = 37;

void solve() {
    int n, k;
    cin >> n >> k;

    n %= k;

    cout << min(n, k - n) << endl; 
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  inputs = input.split("\n");
 
  const N = Number(inputs[0]);
 
 
  console.log(N*2*Math.PI);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
    register int n,i;
    while(cin >> n,n){
		register int p;
        register int min = 1000;
        register int max = 0;
		register int total = 0;
		for(int i=0;i<n;i++){
			cin >> p;
			if(p > max) max = p;
			if(p < min) min = p;
			total += p;
        }
        cout << (total-max-min)/(n-2) << "\n";
    }
}

Measured memory_bytes: 1160
H,W=map(int,input().split())
if H%3==0 or W%3==0:
  print(0)
  exit(0)

e=[0]*2
e[0]=max(H,W)
e[1]=min(H,W)

ans=H*W
for i in range(2):
  a=e[i]
  b=e[i^1]
  # aを3等分で切ろうとして、切り捨てるか切り上げるかの二通り
  a2=[0]*2
  a2[0]=a//3
  a2[1]=a//3+1
  for j in range(2):
    area=[0]*3
    if a2[j]==0:
      continue
    area[0]=a2[j]*b
    # 一つ目の面積が決まり
    a_rest=a-a2[j]
    # 残りのa_rest * bを, どちらから切るか
    c=[0]*2
    c[0]=max(a_rest,b)
    c[1]=min(a_rest,b)
    for k in range(2):
      p=c[k]
      q=c[k^1]
      if p%2==0:
        area[1]=area[2]=p*q//2
      else:
        # pを二等分しようとして、切り捨てるか切り上げるかの二通り
        p2=[0]*2
        p2[0]=p//2
        p2[1]=p//2+1
        for u in range(2):
          if p2[u]==0:
            continue
          area[1]=p2[u]*q
          area[2]=(p-p2[u])*q
      if area[0]<=0 or area[1]<=0 or area[2]<=0:
        continue
      diff=max(area)-min(area)
      if ans>diff:
        ans=diff
print(ans)

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

	int main(){
      string O,E;
      cin >> O >> E;
      string A=O+E;
      for (int i;i<O.size()+E.size();i++){
        if (i%2==0){
          A[i]=O[i/2];
        }
        else{
          A[i]=E[i/2];
        }
      }
        cout << A;
    }

Measured memory_bytes: 256
n = int(input())
if n>1: a = list(map(int, input().split()))
else: a = int(input()); print(1); exit()
ans = 1; togU = 0; togD = 0
if a[1]>a[0]: togU = 1
elif a[1]<a[0]: togD = 1
for i in range(1,n):
  if not (togD or togU):
    if a[i]>a[i-1]: togU = 1; continue
    if a[i]<a[i-1]: togD = 1; continue
  if a[i]>a[i-1]:
    if togD:
      ans += 1
      togD = 0
      togU = 0
  elif a[i]<a[i-1]:
    if togU:
      ans += 1
      togU = 0
      togD = 0
print(ans)

Measured memory_bytes: 84784
/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 11/21/2018, 10:32:32 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main()
{
  char a, b;
  cin >> a >> b;
  if ((a == 'H') ^ (b == 'D'))
  {
    cout << "H" << endl;
  }
  else
  {
    cout << "D" << endl;
  }
}

Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split())

for _ in range(tx-sx):
    print('R', end='')

for _ in range(ty-sy):
    print('U', end='')

for _ in range(tx-sx):
    print('L', end='')

for _ in range(ty-sy+1):
    print('D', end='')

for _ in range(tx-sx+1):
    print('R', end='')

for _ in range(ty-sy+1):
    print('U', end='')

print('LU', end='')

for _ in range(tx-sx+1):
    print('L', end='')

for _ in range(ty-sy+1):
    print('D', end='')

print('R')


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

int main() {
  vector<int> haiku = {5,5,7};
  vector<int> input(3);
  rep(i,3) cin >> input[i];
  sort(input.begin(), input.end());
  
  if(haiku == input) cout << "YES" << endl;
  else cout <<"NO"<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        String ss1 = s.substring(0,s.length()/2);
        String ss2 = s.substring(s.length()/2,s.length());
        System.out.println(ss1.equals(ss2)?"Yes":"No");
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;
const int maxn = 1e6+7;

int main() {
	int n;
	cin>>n;
	ll *a=new ll[n];
	for(int i=0; i<n; i++) {
		cin>>a[i];
	}
	ll select=0,remain=0;
	ll min=1000000;
	select+=a[0];
	for(int k=1; k<n; k++) {
		remain+=a[k];
	}
	min = abs(select-remain);
	for(int i=1; i<n-1; i++) {
		select+=a[i];
		remain-=a[i];
		if(abs(select-remain)<min) {
			min=abs(select-remain);
		}
	}
	cout<<min<<endl;
	return 0;
}

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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

vector<ll> num_div(int N){
    vector<ll> table(N+1,0);
    for(int i=1;i<=N;i++){
        for(int j=i;j<=N;j+=i){
            table[j]++;
        }
    }
    return table;
}

int main(){
    ll N; cin >> N;
    ll ans=0;
    vector<ll> div=num_div(N);
    for(ll i=1;i<=N;i++){
        ans+=i*div[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 81360
#include<bits/stdc++.h>
using namespace std;
int main () {
    long long n,ret=LLONG_MAX;
    scanf ("%lld",&n);
    for (int i = 1; i*1LL*i <= n; i++) if (n%i==0){
        ret=min(ret,i+n/i-2);
    }
    printf ("%lld\n",ret);
    return 0;
}

Measured memory_bytes: 256
a,b,k=map(int,input().split())

if(a<=k):
  k-=a
  a=0
elif(a>k):
  a-=k
  k=0
if(b<=k):
  k-=b
  b=0
elif(b>k):
  b-=k
  k=0

print(a,b)

Measured memory_bytes: 3060
#include<stdio.h>
#define M 1000000
int main(){
  int X[]={0,1,0,-1};
  int Y[]={1,0,-1,0};
  int w,h,d,a,x,y;
  char s;
  while(scanf("%d %d",&w,&h),w||h){
    d=0;
    x=y=1;
    while(scanf(" %c%*s",&s)){
      if(s=='F'){
	scanf("%d",&a);
	x+=X[d]*a;
	y+=Y[d]*a;
      }
      if(s=='B'){
	scanf("%d",&a);
	x-=X[d]*a;
	y-=Y[d]*a;
      }
      if(s=='L')d--;
      if(s=='R')d++;
      if(s=='S'){
	printf("%d %d\n",x,y);
	break;
      }
      d+=4;
      d%=4;
      if(x<1)x=1;
      if(w<x)x=w;
      if(y<1)y=1;
      if(h<y)y=h;
    }
  }
  return 0;
}

      

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k; cin>>k;
	int cnt=1,x=7;
	while(x%k){
		cnt++;
		x*=10;x+=7;
		if(cnt>1e7)break;
		x%=k;
	}
	if(x%k)cout<<-1;
	else cout<<cnt;
	return 0;
}

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

int main() {
	int n, s;
	while (cin >> n >> s, n) {
		int cnt = 0;
		for (int i = (1 << n) - 1; i < 1 << 10; i++) {
			int use = 0, sum = 0;
			for (int j = 0; i >> j; j++) {
				if ((i >> j) & 1) { use++; sum += j; }
			}
			if (use == n&&sum == s)cnt++;
		}
		printf("%d\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 3044
#include <bits/stdc++.h>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{	
    int n, m;
	cin >> n >> m;
    vector<int> v(m);
    REP(i, m) cin >> v[i];
    int ans = -1;
    int sum = accumulate(ALL(v), 0);
    if(n - sum >= 0){
        ans = n - sum;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3668
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

using ll = long long;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)


/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) (LL((v).size()))
#define each(itr,v) for(auto (itr):(v))

#define FIND(v, k) (v).find(k) != (v).end()
#define VFIND(v, k) find(ALL(v), k) != (v).end()

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

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

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
	os << "[";
	for (auto vv : v)
		os << vv << ",";
	return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
	return os << "(" << p.fst << "," << p.snd << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
T sq(T a) {
	return a * a;
}

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

template <typename T, typename U>
T mypow(T b, U n) {
	if (n == 0) return 1;
	if (n == 1) return b /* % MOD */;
	if (n % 2 == 0) {
		return mypow(b * b /* % MOD */, n / 2);
	}
	else {
		return mypow(b, n - 1) * b /* % MOD */;
	}
}

ll pcnt(ll b) {
	return __builtin_popcountll(b);
}



// const ll dx[4] = {0, -1, 1, 0};
// const ll dy[4] = {-1, 0, 0, 1};
// const ll dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const ll dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	ll x;
	cin >> x;
	ll A[N];
	REP(i, N) {
		cin >> A[i];
	}
	ll ans = 0;
	REP(i, N) {
		if (A[i] > x) {
			ans += A[i] - x;
			A[i] = x;
		}
	}
	REP(i, N - 1) {
		if (A[i] + A[i + 1] > x) {
			ans += A[i] + A[i + 1] - x;
			A[i + 1] -= A[i] + A[i + 1] - x;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;

  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
const long long MOD = 998244353;
// const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<long long, long long>;

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

  ll n,m;

  std::cin>>n>>m;

  if(m%2==1){
    std::cout<<-1<<"\n";
    return 0;
  }

  std::vector<std::vector<ll>> graph(n),ans(n);

  std::map<P,bool> edge;

  rep(i,0,m){
    ll a,b;
    std::cin>>a>>b;
    a--;b--;
    graph[b].push_back(a);
    graph[a].push_back(b);
    edge[{std::min(a,b),std::max(a,b)}]=false;
  }

  std::vector<bool> used(n,false);

  used[0]=true;

  auto f=[&](auto f,ll now,ll par)->void{
    for(ll next:graph[now]){
      if(!edge[{std::min(now,next),std::max(now,next)}]){
        edge[{std::min(now,next),std::max(now,next)}]=true;
        if(!used[next]){
          used[next]=true;
          f(f,next,now);
        }else{
          ans[now].push_back(next);
        }
      }
    }

    if(par!=-1){
      if(ans[now].size()%2==1)ans[now].push_back(par);
      else ans[par].push_back(now);
    }
  };

  f(f,0,-1);

  rep(i,0,n){
    for(ll next:ans[i]){
      std::cout<<i+1<<" "<<next+1<<"\n";
    }
  }

  return 0;
}

Measured memory_bytes: 28800
#include <bits/stdc++.h>
#include<set>
#define ll long long 
#include <string>
#define pb push_back
#define mp make_pair
# define pi 3.14159265358979323846
using namespace std;
int main()
{
	char ch;
	cin>>ch;
	if (ch<=90 && ch>=65)
	cout<<"A"<<endl;
	else
	cout<<'a'<<endl;
	
	
}
	
		
	
	
	
	




Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;

int main() {
	int n;
	cin >> n;
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(i%2 == 0) continue; 
		int yakusu = 0;
		for(int j = 1; j <= i; j++){
			if(i%j == 0) yakusu++;
		}
		if(yakusu == 8) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <ctime>
 
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
typedef long long ll;
 
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int main(){
	int n, k;
	int ans = 0;
	
	cin >> n >> k;
	
	REP(i,n){
		int x;
		
		cin >> x;
		
		ans += min(abs(x*2), abs((k-x)*2));
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	string s;
	cin >> s;
	cout << "ABC" << s << endl;
}

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

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

defeat_sum = 0
for i, Bn in enumerate(reversed(B)):
    i = N-i-1

    defeat_num = min(Bn, A[i+1])
    Bn -= defeat_num
    A[i+1] -= defeat_num
    defeat_sum += defeat_num

    defeat_num = min(Bn, A[i])
    Bn -= defeat_num
    A[i] -= defeat_num
    defeat_sum += defeat_num

print(defeat_sum)


Measured memory_bytes: 18476
#include <iostream>
#include <vector>
#include <algorithm>
#include <ios>
#include <iomanip>
#include <cmath>
#include <regex>
using namespace std;

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a+b>c+d) {
    cout << "Left" << endl;
  } else if (a+b<c+d) {
    cout << "Right" << endl;
  } else {
    cout << "Balanced" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>

std::string reverse( std::string str ) {
	std::string buf = str;

	for ( int i = 0; i < str.size(); ++i ) {
		buf[i] = str[str.size() - 1 - i];
	}
	return buf;
}

int main()
{
	int m;
	std::cin >> m;

	for ( int i = 0; i < m; ++i ) {
		std::set<std::string> s;
		std::string str;

		std::cin >> str;
		for ( int j = 0; j < str.size()-1; ++j ) {
			std::string buf1 = str.substr(0, j+1);
			std::string buf2 = str.substr(j+1, str.size() - j - 1);

			s.insert(buf1 + buf2);
			s.insert(buf2 + buf1);

			s.insert(reverse(buf1) + buf2);
			s.insert(reverse(buf2) + buf1);

			s.insert(buf1 + reverse(buf2));
			s.insert(buf2 + reverse(buf1));

			s.insert(reverse(buf1) + reverse(buf2));
			s.insert(reverse(buf2) + reverse(buf1));
		}
		std::cout << s.size() << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    ll t,i,j,n,m,l,r;
    cin>>n>>m>>r;
    cout<<(double)(.5*(n+m)*r)<<"\n";
    return 0;
}



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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string w;
  cin >> w;
  vector<int> a(26, 0);
  for(int i = 0; i < w.size(); i++) {
    int index = w[i] - 'a';
    a[index]++;
  }
  bool flag = true;
  for(int i = 0; i < 26; i++) {
    if(a[i] % 2 != 0) {
      flag = false;
      break;
    }
  }
  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int k,s,ans=0;
cin>>k>>s;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      if(s>=i+j&&s-i-j<=k) ans++;
    }
  }
  cout<<ans<<"\n";
}

Measured memory_bytes: 256
X, Y, Z, K = map( int, input().split())
A = list( map( int, input().split()))
B = list( map( int, input().split()))
C = list( map( int, input().split()))
# A.sort( key=None, reverse = True)
# B.sort( key=None, reverse = True)
# C.sort( key=None, reverse = True)
AB = [0]*(X*Y)
for i in range(X):
    for j in range(Y):
        AB[i*Y+j] = A[i]+B[j]
AB.sort( key=None, reverse = True)
ABC = [0]*3000000
for i in range( min(X*Y, 3000)):
    for j in range(Z):
        ABC[i*Z + j] = AB[i]+C[j]
ABC.sort( key=None, reverse = True)
for i in range(K):
    print( ABC[i])


Measured memory_bytes: 100184
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  const long num = 1000000007;
  long long ans = 0;
  int i;
  if(abs(n-m)<=1){
    ans = 1;
    for(i=1;i<=n;i++){
      ans *= i;
      ans = ans%num;
    }
    for(i=1;i<=m;i++){
      ans *= i;
      ans = ans%num;
    }

    if(abs(n-m)==0)ans*=2;

    
  }
  cout << ans%num;
}

Measured memory_bytes: 256
const main = input => {
  const N = parseInt(input.trim())
  for (let i = 1; i <= 9; i++) {
    for (let j = 1; j <= 9; j++) {
      if (i * j === N) {
        console.log('Yes')
        return
      }
    }
  }
  console.log('No')
}
// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"));


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



int main() {
int N , K ;
int ans=0;
cin >> N>> K;
int x[100];
for(int i=0 ; i<N;i++){
	cin>>x[i];
	ans+=2*min(x[i]-0,K-x[i]);
	
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;


public class Main {


    public static void main(String[] args) {
    
  Scanner scan = new Scanner(System.in);
  
  	int a = scan.nextInt(); int b = scan.nextInt();
  	System.out.println(a * b);
    	
    }
    
}

Measured memory_bytes: 35684
import sys
from bisect import bisect_left
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(int(readline()) for _ in range(N))

    LIS = [INF]*(N+1)
    for a in A:
        i = bisect_left(LIS,a)
        LIS[i] = a
    print(LIS.index(INF))


if __name__ == '__main__':
    main()




Measured memory_bytes: 10288
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}

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

  int n; cin >> n;
  vector<int> a(n);
  int neg = 0, pos = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    neg += a[i] < 0;
    pos += a[i] >= 0;
  }
  assert(neg + pos == n);
  sort(all(a));

  if (neg == n) {
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      if (i == n - 1) ans += a[i];
      else ans -= a[i];
    }
    print(ans);
    int mx = a.back();
    for (int i = n - 2; i >= 0; --i) {
      cout << mx << " " << a[i] << '\n';
      mx -= a[i];
    } 

  } else if (pos == n) {
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      if (i == 0) ans -= a[i];
      else ans += a[i];
    }
    print(ans);
    int mn = a[0];
    for (int i = 1; i < n; ++i) {
      if (i == n - 1) {
        cout << a[i] << " " << mn << '\n';
      } else {
        cout << mn << " " << a[i] << '\n';
        mn -= a[i];
      }
    }
  } else {
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      ans += abs(a[i]);
    }
    print(ans);
    int mn = a[0];
    for (int i = 0; i < pos - 1; ++i) {
      cout << mn << " " << a[neg + i] << '\n';
      mn -= a[neg + i];
    }

    int mx = a.back();
    for (int i = 0; i < neg - 1; ++i) {
      cout << mx << " " << a[i + 1] << '\n';
      mx -= a[i + 1];
    }

    cout << mx << " " << mn << '\n';
  }

  return 0;
}

Measured memory_bytes: 2304
a,b,c,d=map(int,input().split())
if a <= c < b <= d:
    print(b-c)
elif c <= a < d <= b:
    print(d-a)
elif a <= c < d <= b:
    print(d-c)
elif c <= a < b <= d:
    print(b-a)
elif b <= c or d <= a:
    print(0)
else:
    print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
	int n;
	cin >> n;
	vector<int> a(n + 1), b(n + 1), p(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
	}
	for (int i = 1; i <= n; i++) {
		a[i] = (n + 1) * i;
		b[i] = (n + 1) * (n - i + 1);
	}  
	for (int i = 1; i <= n; i++) {
		a[p[i]] += i;
	}
	for (int i = 1; i <= n; i++) {
		cout << a[i] << ' ';
	}
	cout << '\n';
	for (int i = 1; i <=  n; i++) {
		cout << b[i] << ' ';
	}
	cout << '\n';
} 

Measured memory_bytes: 1152
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define llong long long
#define ldouble long double
#define uint unsigned int
#define ullong unsigned long long
#define udouble unsigned double
#define uldouble unsigned long double
#define modinc(x) {if(x>=P) x-=P;}
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>
#define piiii pair<pair<int,int>,pair<int,int> >
#define pli pair<llong,int>
#define pll pair<llong,llong>
#define Memset(a,x) {memset(a,x,sizeof(a));}
using namespace std;

const int N = 2e5;
int cnt[N+2];
int a[N+2];
int num[N+2];
int n,q,ans;

int main()
{
	scanf("%d%d",&n,&q);
	for(int i=1; i<=n; i++) {scanf("%d",&a[i]); cnt[a[i]]++;}
	for(int i=1; i<=n; i++)
	{
		for(int j=max(i-cnt[i]+1,0); j<=i; j++) num[j]++;
	}
	for(int i=1; i<=n; i++) if(num[i]==0) ans++;
//	for(int j=1; j<=n; j++) printf("cnt%d %d %d\n",j,cnt[j],num[j]);
//	printf("%d\n",ans);
	for(int i=1; i<=q; i++)
	{
		int x,y; scanf("%d%d",&x,&y);
//		printf("%d\n",a[x]-cnt[a[x]]);
		cnt[a[x]]--; if(a[x]-cnt[a[x]]>0) {num[a[x]-cnt[a[x]]]--; if(num[a[x]-cnt[a[x]]]==0) ans++;}
		a[x] = y;
		if(y-cnt[y]>0) {if(num[y-cnt[y]]==0) ans--; num[y-cnt[y]]++;} cnt[y]++;
//		for(int j=1; j<=n; j++) printf("cnt%d %d %d\n",j,cnt[j],num[j]);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3712
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

macro_rules! chmax {
    ($x:expr, $e:expr) => {
        if $x < $e {
            $x = $e;
        }
    };
}
macro_rules! chmin {
    ($x:expr, $e:expr) => {
        if $x > $e {
            $x = $e;
        }
    };
}

const INF: i64 = 1 << 60;
const MAX: usize = 100001;

fn is_prime(n: usize) -> bool {
    if n == 1{
        return false;
    }
    if n == 2 {
        return true;
    }
    for i in (2..).take_while(|i| i * i <= n) {
        if n % i == 0 {
            return false;
        }
    }
    true
}

fn like_2017(n: usize) -> bool {
    is_prime(n) && is_prime((n+1)/2)
}

fn main() {
    input!{
        Q: usize,
        lr: [(usize, usize); Q],
    }
    let mut c = vec![0; MAX];
    for i in 1..MAX {
        if i % 2 == 0 {
            continue;
        }
        if like_2017(i) {
            c[i] += 1;
        }
    }
    let mut s = vec![0; MAX+1];
    for i in 0..MAX {
        s[i+1] += c[i] + s[i];
    }
    for i in 0..Q {
        let (l, r) = lr[i];
        let ans = s[r+1] - s[l];
        println!("{}", ans);
    }
}


Measured memory_bytes: 8828
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 1010
 
int main(){
    int N;
    while(cin >> N, N > 0){
	int M[MAX],D[MAX],h[MAX],m[MAX],e[MAX],p[MAX];
	int Point[MAX] = {0},t[MAX];
	char ch;
	for(int i = 0 ; i < N ; i++){
	    scanf("%d/%d %d:%d %c %d",
		  &M[i],&D[i],&h[i],&m[i],&ch,&p[i]);
	    e[i] = (ch == 'I');
	}
	memset(t,-1,sizeof(t));
	for(int i = 0 ; i < N ; i++){
	    int totalm = 60*h[i]+m[i];
	    if(e[i] == 1){
		t[p[i]] = totalm;
	    }else{
		if(p[i] == 0){
		    for(int j = 1 ; j < MAX ; j++){
			if(t[j] == -1) continue;
			Point[j] += totalm-max(t[j],t[0]);
		    }
		}else{
		    if(t[0] != -1){
			Point[p[i]] += totalm-max(t[p[i]],t[0]);
		    }
		}
		t[p[i]] = -1;
	    }
	}
	cout << *max_element(Point+1,Point+MAX) << endl;
    }
    return 0;
}

Measured memory_bytes: 3120
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <cmath>
#include <limits>
#include <stack>

using namespace std;

int main(){
  long N,M;
  long ans;
  cin >> N >> M;
  ans = pow(2,M)*(1900*M+100*(N-M));
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int conn[100010] = {};

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

  int N, M;
  cin >> N >> M;

  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    conn[a]++;
    conn[b]++;
  }
  for (int i = 0; i < N + 1; i++) {
    if (conn[i] % 2 == 1) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int a[3000], b[3000], c = 1, d = 1, x = 0;
	int i;

	while(!(c == 0 && d == 0))
	{
		scanf("%d %d", &c, &d);
		a[x] = c;
		b[x] = d;
		x++;
	}

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

Measured memory_bytes: 624
#include <iostream>
using namespace std;
int main(void){
    int m,n,a,b,c,d,e,f,g;
    while(1){
        cin >> m;
        if(m==0){
            break;
        }
        a=1000-m;
        b=a/500;
        c=(a-500*b)/100;
        d=(a-500*b-100*c)/50;
        e=(a-500*b-100*c-50*d)/10;
        f=(a-500*b-100*c-50*d-e*10)/5;
        g=(a-500*b-100*c-50*d-e*10-f*5)/1;
        n=b+c+d+e+f+g;
        cout << n << endl;
    }
     
}


Measured memory_bytes: 3072
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String N = sc.next();
        int l = N.length();
        int K = sc.nextInt();
        int[][][] dp = new int[l+1][K+1][2];
        dp[0][0][1] = 1;
        for (int i = 0; i < l; i++) {
            for (int j = 0; j <= K; j++) {
                dp[i+1][j][0] += dp[i][j][0];
                if (j+1 <= K) {
                    dp[i+1][j+1][0] += 9*dp[i][j][0];
                }
                int a = N.charAt(i)-'0';
                if (a == 0) {
                    dp[i+1][j][1] += dp[i][j][1];
                } else {
                    dp[i+1][j][0] += dp[i][j][1];
                    if (j+1 <= K) {
                        dp[i+1][j+1][0] += (a-1)*dp[i][j][1];
                        dp[i+1][j+1][1] += dp[i][j][1];
                    }
                }
            }
        }
        System.out.println(dp[l][K][0]+dp[l][K][1]);
    }
}



Measured memory_bytes: 23764
// Date: 2020-02-27

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 3e5 + 10;
template <typename T> void chkMax(T &x, T y) { x = max(x, y); }
template <typename T> void chkMin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int n, sum[N][2];
char s[N];
int main() {
    scanf("%d%s", &n, s+1);
    rep(i, 1, n) {
        rep(j, 0, 2) sum[i][j] = sum[i-1][j];
        if(s[i] == 'E') sum[i][0]++;
        else sum[i][1]++;
    }
    int ans = inf;
    rep(i, 1, n) {
        chkMin(ans, sum[n][0]-sum[i][0]+sum[i-1][1]);
    }
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long ll;

template <typename T> inline bool chkmin(T &x,T y){ return y < x ? x = y,1 : 0; }
template <typename T> inline bool chkmax(T &x,T y){ return x < y ? x = y,1 : 0; }

const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;

int a[N],Sum[N],Tmp[N];
int n;ll val;

inline int read(){
	int x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-')ch = getchar();
	if(ch == '-')flag = -1,ch = getchar();
	while(isdigit(ch))x = (x << 3) + (x << 1) + ch - '0',ch = getchar();
	return x * flag;
}

struct BIT{
	int Sum[N << 1];
	inline int lowbit(int x){ return x & (-x); }
	inline void Modify(int pos){
		int Lim = (N << 1) - 5;
		for(;pos <= Lim;pos += lowbit(pos))Sum[pos]++;
	}
	inline int Query(int pos){
		int ans = 0;
		for(;pos;pos -= lowbit(pos))ans += Sum[pos];
		return ans;
	}
}T;

inline ll check(int res){
	For(i,1,n){
		if(a[i] > res)Tmp[i] = 1;
		else Tmp[i] = -1;
	}
	ll ans = 0;
	T.Modify(n + 1);
	For(i,1,n){
		Sum[i] = Sum[i - 1] + Tmp[i];
		ans += T.Query(n + n + 1) - T.Query(Sum[i] + n + 1);
		T.Modify(Sum[i] + n + 1);
	}
	memset(T.Sum,0,sizeof(T.Sum));
	return ans;
}

int main(){

	n = read();
	For(i,1,n)a[i] = read();

	val = 1ll * n * (n + 1) / 4 + 1;
	int l = 0,r = 1e9;
	while(l < r){
		int mid = (l + r) >> 1;
		if(check(mid) >= val)r = mid;
		else l = mid + 1;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 2176