akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            ans += r - l + 1;
        }
        System.out.println(ans);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21972
import sys
sys.setrecursionlimit(10**5)

N,M = map(int, input().split())

es = [[] for _ in range(N)]

for _ in range(M):
    a,b = map(int, input().split())
    es[a-1].append(b-1)
    es[b-1].append(a-1)


def solve(visited, node):
    visited[node] = True
    if all(visited):
        return 1

    cnt = 0
    for b in es[node]:
        if not visited[b]:
            cnt += solve(visited[:], b)

    return cnt


vis = [False] * N
ans = solve(vis, 0)
print(ans)

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


void solve(){
    int a;cin>>a;
    string s=to_string(a);
    int n=0;
    int k=s.size();
    fol(i,k){
        n+=(int)(s[i]-'0');
    }
    if(a%n){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
}

int main(){
    solve();
    return 0;
}


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

int main(){
	int N;
	cin >> N;
	long long A[N], ans = 0;
	for(int i=0; i<N; i++) cin >> A[i];
	for(int i=N-1; i>=0; i--){
		if(A[i] % 2 == 0) ans += A[i]/2;
		else{
			if(i > 0 && A[i-1] > 0){
				ans += (A[i] + 1)/2;
				A[i-1]--;
			}else{
				ans += A[i]/2;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
ans = 1
s1 = input()
s2 = input()
i = 0
last = ""
MOD = 1000000007

while i < n:
    if s1[i] == s2[i]:
        if last == "": ans = 3
        elif last == "V": ans = (ans*2) % MOD
        last = "V"
        i+= 1
    else:
        if last == "": ans = 6
        elif last == "V": ans = (ans*2) % MOD
        else: ans = (ans*3) % MOD
        last = "H"
        i+= 2
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int H, W, N, Sr, Sc;
string S, T;

int main() {
    cin >> H >> W >> N;
    cin >> Sr >> Sc;
    cin >> S;
    cin >> T;

    Sc--;
    Sr--;

    // 横   l < Sc < r で落ちない
    int l = -1;
    int r = W;

    if (S[N - 1] == 'L') l++;
    if (S[N - 1] == 'R') r--;
    for (int i = N - 2; i >= 0; i--) {
        if (r - l <= 1) break;
        if (T[i] == 'R') l = max(l - 1, -1);
        if (T[i] == 'L') r = min(r + 1, W);
        if (S[i] == 'L') l++;
        if (S[i] == 'R') r--;
    }
    if (Sc <= l || r <= Sc) {
        cout << "NO" << endl;
        return 0;
    }

    // 縦   u < Sr < d で落ちない
    int u = -1;
    int d = H;

    if (S[N - 1] == 'U') u++;
    if (S[N - 1] == 'D') d--;
    for (int i = N - 2; i >= 0; i--) {
        if (d - u <= 1) break;
        if (T[i] == 'D') u = max(u - 1, -1);
        if (T[i] == 'U') d = min(d + 1, H);
        if (S[i] == 'U') u++;
        if (S[i] == 'D') d--;
    }
    if (Sr <= u || d <= Sr) {
        cout << "NO" << endl;
        return 0;
    }

    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 904
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    rep(i, N) cin >> P[i];
    vector<int> order(N);
    rep(i, N) { order[P[i] - 1] = i; }
    int len = 1;
    int now = 1;
    for(int i = 0; i < N - 1; i++) {
        if(order[i] < order[i + 1])
            now++;
        else
            now = 1;
        len = max(len, now);
    }
    cout << N - len << endl;
    return 0;
}

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

int main()
{
  int H, W;
  cin >> H >> W;
  vector<string> vc(H);
  for (int i = 0; i < H; i++)
  {
    cin >> vc.at(i);
  }
  string firstAndLast = "";
  for (int i = 0; i < W + 2; i++)
  {
    firstAndLast += "#";
  }
  cout << firstAndLast << endl;
  for (int i = 0; i < H; i++)
  {
    cout << "#" + vc.at(i) + "#" << endl;
  }
  cout << firstAndLast << endl;
}


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

int N,a,ans=0;
int color[9]={0};
int main(){
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>a;
    if(a<3200)color[a/400]=1;
    else color[8]++;
  }
  for(int i=0;i<8;i++){
    if(color[i]==1)ans++;
  }
  cout<<max(ans,1)<<" "<<ans+color[8]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

int main()
{
	ll a, b;
	cin >> a >> b;
	

	
	cout << (a > b ? a - 1 : a) << endl;

	return 0;
}


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

int main() {
	int x,a;
  	cin>>x>>a;
  
  if(x<a){
  	cout<<0<<endl;
  }
  
  else{
  	cout<<10<<endl;
  }
}

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

#define MaxN 100005

using namespace std;

int N,pos=1,ok=1;
int f[MaxN];
long long Ans;
pair<int,int> A[MaxN],B[MaxN];

bool cond1(pair<int,int> a,pair<int,int> b)
{
    if (a.first == b.first)
        return a.second > b.second;
    return a.first<b.first;
}
bool cond2(pair<int,int> a,pair<int,int> b)
{
    if (a.first ==b.first)
        return a.second > b.second;
    return a.first>b.first;
}


int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        cin>>A[i].first>>B[i].first;
        A[i].second=B[i].second=i;
    }
    sort(A+1,A+1+N,cond1);
    sort(B+1,B+1+N,cond2);

    while(A[pos]<B[pos]&&pos<=N)
        Ans+=A[pos++].first;
    for(int i=pos;i<=N;i++)
        Ans+=B[i].first;

    for(int i=1;i<pos;i++)
        f[A[i].second]++;
    for(int i=1;i<pos;i++)
    {
        f[B[i].second]++;
        if(f[B[i].second]!=2)
            ok=0;
    }
    if(ok&&pos!=1&&pos!=N+1)
    {
        if((A[pos].second!=B[pos].second&&A[pos-1].second!=B[pos-1].second)||(pos==2&&A[pos].second!=B[pos].second)||(pos==N&&A[pos-1].second!=B[pos-1].second))
            cout<<Ans+min(A[pos].first,B[pos-1].first)-max(A[pos-1].first,B[pos].first);
        else if(A[pos].second!=B[pos].second&&A[pos-1].second==B[pos-1].second)
        {
            cout<<Ans+min(min(A[pos].first,B[pos-2].first)-max(A[pos-1].first,B[pos].first),min(A[pos].first,B[pos-1].first)-max(A[pos-2].first,B[pos].first));
        }
        else if(A[pos].second==B[pos].second&&A[pos-1].second!=B[pos-1].second)
        {
            cout<<Ans+min(min(A[pos+1].first,B[pos-1].first)-max(A[pos-1].first,B[pos].first),min(A[pos].first,B[pos-1].first)-max(A[pos-1].first,B[pos+1].first));
        }
        else if(A[pos].second==B[pos].second&&A[pos-1].second==B[pos-1].second)
        {
            if(N==2)
                cout<<min(A[1].first,B[2].first)+min(A[2].first,B[1].first);
            else
                cout<<Ans+min(min(A[pos].first,B[pos-2].first)-max(A[pos-1].first,B[pos+1].first),min(A[pos+1].first,B[pos-1].first)-max(A[pos-2].first,B[pos].first));
        }
    }
    else
        cout<<Ans;
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define pr_arr(name, a, b) \
  for (int i = (a); i < (b); i++) { \
    for (int j = (a); j < (b); j++) {\
      if (j > (a)) printf(" "); \
      printf("%lld", name[i][j]); \
    }\
    printf("\n");\
  }\

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

struct X { int p, n; };
//            1  2  3  4  5  6  7  8  9
int m[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> A;
X dp[10005];
int N, M;


//  1  2  3   4   5   6    7   8   9   10   11   
//  0  0  7   4   7   77  77  77 777  777  777

int main(void) {
    scanf("%d %d", &N, &M);
    rep(i, 0, M) {int a; scanf("%d", &a); A.pb(a);}
    sort(A.bg, A.en);

    rep(i, 0, A.size()) {
      dp[m[A[i]]].p = 1; dp[m[A[i]]].n = A[i];
    }

    for (int i = 0; i <= N; i++) {
      for (int j = 0; j < A.size(); j++) {
        if (i-m[A[j]]<0 || dp[i-m[A[j]]].p==0) continue;
        int pos = dp[i-m[A[j]]].p + 1;
        if (pos >= dp[i].p) {
          dp[i].p = pos; dp[i].n = A[j];
        }
      }
    }

    string s;

    int i = N;
    while(dp[i].p > 0) {
      s += (dp[i].n + '0');
      i -= m[dp[i].n];
    }

  
    printf("%s\n", s.c_str());

	return 0;
}


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

#pragma warning(disable : 4267) // "int n = (unsigned)size"

using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ll = long long int;
using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using cdouble = complex<double>;

const double eps = 1e-7;
const double INFD = numeric_limits<double>::infinity();
#define Loop(i, n) for(int i = 0; i < int(n); i++)
#define Loopll(i, n) for(ll i = 0; i < ll(n); i++)
#define Loop1(i, n) for(int i = 1; i <= int(n); i++)
#define Loopll1(i, n) for(ll i = 1; i <= ll(n); i++)
#define Loopr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = ll(n) - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = int(n); i >= 1; i--)
#define Looprll1(i, n) for(ll i = ll(n); i >= 1; i--)
#define Foreach(buf, container) for(auto buf : container)
#define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= (h) ? (h) - 1 : (sum)), j = (sum) - i; i >= 0 && j < (w); i--, j++)
#define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= (w) ? (w) - 1 : (sum)), i = (sum) - j; j >= 0 && i < (h); j--, i++)
#define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++)
#define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(ex_i, vector.size()) { cout << vector[ex_i] << " "; } cout << endl;
#define printmx(matrix) Loop(ex_i, matrix.size()) { Loop(ex_j, matrix[ex_i].size()) { cout << matrix[ex_i][ex_j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
#define Comp(type_t) bool operator<(const type_t &another) const
#define fst first
#define snd second
bool nearlyeq(double x, double y) { return abs(x - y) < eps; }
bool inrange(ll x, ll t) { return x >= 0 && x < t; }
bool inrange(vll xs, ll t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; }
int ceillog2(ll x) { int ret = 0;	x--; while (x > 0) { ret++; x >>= 1; } return ret; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m * m <= x ? 0 : -1); }
ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }

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

int main() {
	int n; cin >> n;
	vll v(n);
	vll c(n);
	Loop(i, n) cin >> v[i];
	Loop(i, n) cin >> c[i];
	ll ans = 0;
	Loop(i, n) {
		if (v[i] > c[i]) {
			ans += v[i] - c[i];
		}
	}
	cout << ans << endl;
}

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

char a,b,c,d,e,f;

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


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

int A, B, C, D, mx;

bool chk(int a, int b) {
    return b <= 1LL * mx * a;
}

struct Seg {
    int l, r, a, b;
};
vector<Seg> seg;

void main2() {
    scanf("%d %d %d %d", &A, &B, &C, &D);
    C--; D--;

    mx = (A + B) / min(A + 1, B + 1);

    if(B > 1LL * mx * A) {
        seg.clear();
        seg.push_back({ 0, B - mx * A - 1, 0, 1 });
        seg.push_back({ B - mx * A, A + B - 1, 1, mx });

        int pos = 0;
        for(int i = C; i <= D; i++) {
            while(i > seg[pos].r) pos++;
            printf("%c", ((i - seg[pos].l) % (seg[pos].a + seg[pos].b) < seg[pos].a? 'A' : 'B'));
        }
        printf("\n");
        return;
    }

    int s = 1, e = A, p;
    while(s <= e) {
        int m = (s + e)>>1;

        if(chk(A - m, B - m / mx)) {
            p = m;
            s = m + 1;
        }
        else e = m - 1;
    }

    seg.clear();
    if(p) seg.push_back({ 0, (mx + 1) * (p / mx) - 1, mx, 1 });
    if(p % mx) seg.push_back({ (mx + 1) * (p / mx), p + (p / mx) - 1, 1, 0 });

    if(p != A) {
        int cnt = (B - (p / mx)) - mx * (A - p - 1);
        seg.push_back({ p + (p / mx) - 1, p + (p / mx), 1, 0 });
        seg.push_back({ p + (p / mx) + 1, p + (p / mx) + cnt, 0, 1 });
        seg.push_back({ p + (p / mx) + cnt + 1, A + B - 1, 1, mx });
    }

    int pos = 0;
    for(int i = C; i <= D; i++) {
        while(i > seg[pos].r) pos++;
        printf("%c", ((i - seg[pos].l) % (seg[pos].a + seg[pos].b) < seg[pos].a? 'A' : 'B'));
    }
    printf("\n");
}

int Q;
int main() {
    scanf("%d", &Q);
    while(Q--) main2();
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	cout << n * n*n << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int n,i,j,tmp,now,count=0;
  int mochi[100];
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&mochi[i]);
  }
  
  for(i=n-1;i>0;i--){
    for(j=0;j<i;j++){
      if(mochi[j]<mochi[j+1]){
        tmp=mochi[j];
        mochi[j]=mochi[j+1];
        mochi[j+1]=tmp;
      }
    }
  }
  
  for(i=0;i<n;i++){
    if(i==0){
      now=mochi[i];
      count++;
    }
    
    if(now>mochi[i]){
      now=mochi[i];
      count++;
    }
  }
  printf("%d",count);
}

Measured memory_bytes: 128
# coding: utf-8
# Your code here!

n,m=map(int,input().split())
AC=[0]*n
WA=[0]*n
for i in range(m):
    p,s=input().split()
    p=int(p)-1
    if s=="WA":
        if AC[p]==0:
            WA[p]+=1
    else:
        AC[p]=1

ac=sum(AC)
wa=0
for i in range(n):
    if AC[i]==1:
        wa+=WA[i]
print(ac,wa)

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

int a[40004],b[40004],b_[40004];

signed main(){
    int n;
    while(1){
        cin >> n;
        if(n == 0)break;
        for(int i = 0; i < 40000; i++){
            a[i] = 0;
            b[i] = 0;
            b_[i] = 0;
        }
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        int t = 0;
        for(int i = 0; i < n; i++){
            cin >> b[i];
        }
        sort(a,a + n,greater<int>());
        sort(b,b + n,greater<int>());
        int ans = n;
        int a_ = 0,b_2 = 0;
        int k = 0;
        for(int i = 0; i < n; i++){
            while(t < n){
                if(b[i] >= a[t]){
             //       cout << i << " " << t << endl;
                    b_[t]++;
                    t++;
                    break;
                }
                t++;
            }
        }
        for(int i = 1; i < n; i++){
           // cout << "b_ "<<b_[i - 1] << endl;
            b_[i] += b_[i - 1];
           // cout << "b_ = "<<b_[i] << endl;
        }
        for(int i = 0; i < n; i++){
            if(((i + 1) - b_[i])*2 > (i + 1) ){
                ans = i + 1;
                break;
            }
        }
        if(ans == n){
            cout << "NA" << endl;
        }else{
            cout << ans << endl;
        }
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,q,v[200001],suma,f[200001],b,c;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        f[v[i]]++;
        suma+=v[i];
        
    }
    cin>>q;
    while(q--)
    {
        cin>>b>>c;
        suma-=b*f[b];
        suma+=c*f[b];
        f[c]+=f[b];
        f[b]=0;
        cout<<suma<<'\n';
    }
    return 0;
}


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

int main() {
  int n, d;
  cin >> n >> d;
  int x[n][d];
  double sum = 0;
  int cnt = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) {
      cin >> x[i][j];
    }
  }

  for (int i = 0; i < n-1; i++) {
    for (int j = i+1; j < n; j++) {
      sum = 0;
      for (int k = 0; k < d; k++) {
        int dif = (x[i][k] - x[j][k]);
        sum += dif * dif;
      }
      if (int(sqrt(sum)) * int(sqrt(sum)) == sum){
        cnt++;
      }
    }
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

void failure () {
  cout << -1 << endl;
  exit(0);
}

int cur [3] = {-1, -1, -1};

int main () {
  ios::sync_with_stdio(false);

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

  for (int i = 0; i < m; i++) {
    int pos, val;
    cin >> pos >> val;

    pos--;
    if (cur[pos] != -1 && cur[pos] != val) {
      failure();
    }
    cur[pos] = val;
  }

  if (n == 1 && cur[0] <= 0) {
    cout << 0 << endl;
    return 0;
  }

  if (cur[0] == 0) {
    failure();
  }

  for (int i = 0; i < n; i++) {
    if (cur[i] == -1) {
      if (i == 0) {
        cur[i] = 1;
      } else {
        cur[i] = 0;
      }
    }
    cout << cur[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll r;
    cin >> r;
    cout << 3 * r * r << "\n";

}

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

int main(){
	int n = 0;
	char c[4];
	cin >> c;
	for(int i = 0; i < 4; i++){
		if(c[i] == '+')
			n++;
		else
			n--;
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
static const int N = 100; 

int main() {
	int M[N][N];
	int n,u,k,v;
	
	cin>>n;
	
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			M[i][j]=0;
		}
	}
	
	for(int i=0;i<n;i++){
		cin>>u>>k;
		u--;
		for(int j=0;j<k;j++){
			cin>>v;
			v--;
			M[u][v]=1;
		}
	}
	
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(j) cout<<" ";
			cout<<M[i][j];
		}
		cout<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3088
#include<stdio.h>

int main(void)
{
  int n;

  scanf("%d", &n);

  int a[n-1], b[n];

  int i;

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

  for(i=0; i<n; i++){
	b[i] = 0;
  }

  for(i=0; i<n-1; i++){
	b[a[i]-1]++;
  }

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

  return 0;
}


Measured memory_bytes: 3292
N = int(input())
A_list = [int(i) for i in input().split()]

dic = {}
for i in range(N) :
    dic[i+1] = A_list[i]

dic = sorted(dic.items(), key=lambda x:x[1])
# print(dic)
s = ""
for item in dic :
    s += str(item[0]) + " "
s += "\r\n"
print(s)





Measured memory_bytes: 25560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N;
  int M;
  cin >> N >> M;
  vector<unsigned long long> A(M);
  long long sum = 0;
  for (int i= 0;i<M;++i){
    cin >> A[i];
    sum += A[i];
  }
  if(N - sum >= 0){
    cout << N - sum << endl;
  }else{ 
    cout << -1 << endl;
  }
}


Measured memory_bytes: 3628
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
using ll = long long;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define INF 1e9+7
#define rep(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int dp[3003][3003];

int main(){
   string s,t;
   cin>>s>>t;
   rep(i,s.size())rep(j,t.size()){
       if(s[i]==t[j])dp[i+1][j+1]=dp[i][j]+1;
       else{
           dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
       }
   }
   
   string res = "";
    int i = (int)s.size(), j = (int)t.size();
    while (i > 0 && j > 0)
    {
        // (i-1, j) -> (i, j) と更新されていた場合
        if (dp[i][j] == dp[i-1][j]) {
            --i; // DP の遷移を遡る
        }

        // (i, j-1) -> (i, j) と更新されていた場合
        else if (dp[i][j] == dp[i][j-1]) {
            --j; // DP の遷移を遡る
        }

        // (i-1, j-1) -> (i, j) と更新されていた場合
        else {
            res = s[i-1] + res; // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
            --i, --j; // DP の遷移を遡る
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 35456
x = gets.to_i
st = gets.chomp.split("")
st2 = st.size
array = []
array2 = ('A'..'Z').to_a
array3 = ('A'..'Z').to_a
array << array2
array << array3
array.flatten!
i = 0

st2.times do
  posi =  array.index("#{st[i]}")
  ans_posi = posi + x
  print array[ans_posi]
  i += 1
end

puts ""



Measured memory_bytes: 2684
/** 
 *                                                                   
 *   |    |                        ,   .              ,--.,--.,--.,--.
 *   |    |    ,---..    ,,---.    |   |,---..   .      -||  ||  ||  |
 *   |    |    |   | \  / |---'    `---'|   ||   |       ||  ||  ||  |
 *   `    `---'`---'  `'  `---'      |  `---'`---'    `--'`--'`--'`--'
 *                                   `                                
**/
#include <bits/stdc++.h>
using namespace std;

int n, k, a[55];
long long memo[55][55][2555];

long long solve(int id, int taken, int sum) {
	if (id == n) {
		if (sum != 0 && taken != 0 && sum == k * taken) return 1;
		else return 0;
	}

	if (memo[id][taken][sum] != -1) return memo[id][taken][sum];

	long long res = solve(id + 1, taken, sum) + solve(id + 1, taken + 1, sum + a[id]);
	return memo[id][taken][sum] = res;
}

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

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	memset(memo, -1, sizeof(memo));
	long long ans = solve(0, 0, 0);

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 60672
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
string s,lc,tc;
int q,a,b;
int main() {
	cin>>s,cin>>q;
	while(q--) {
		cin>>lc>>a>>b;;
		if(lc=="print")
			cout<<s.substr(a,b-a+1)<<endl;
		else if(lc=="replace")
			cin>>tc,s.replace(a,b-a+1,tc);
		else {
			tc=s.substr(a,b-a+1);
			reverse(tc.begin(),tc.end());
			s=s.replace(a,b-a+1,tc);
		}
	}
	return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int n; cin >> n;
    string s; cin >> s;
    string ans = "";
    for(int i = 0; i < s.size(); i++)
    {
        char ch = s[i];
        for(int j = 0; j < n; j++)
        {
            if(ch == 'Z')
            {
                ch = 'A';
            }
            else ch ++;
        }
        ans += ch;
    }
    cout << ans << endl;
}

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

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    string s;cin >> s;
    int ans = 753;
    int n = s.size();
    for(int i=0;i<n-2;i++){
        string t = s.substr(i, 3);
        ans = min(ans, abs(753-stoi(t)));
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int n, s;
    cin >> n >> s;
    vector<int> a(n), sum(n+1, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum[i+1] = sum[i] + a[i];
    }
    
    auto f = [&](int k) {
        bool flag = false;
        for (int i = 0; i+k <= n; i++) {
            int sec = sum[i+k] - sum[i];
            if (sec >= s) {
                flag = true;
                break;
            }
        }
        return flag;
    };
    
    int ok = n, ng = -1;
    while (abs(ok - ng) > 1) {
        int x = (ok + ng) / 2;
        if (f(x)) ok = x;
        else ng = x;
    }
    
    if (sum[n] < s) ok = 0;
    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 3632
def shuffleK(k, arr):
	arr[2*N-k:2*N], arr[0:2*N-k] = arr[0:k], arr[k:2*N]
	return arr


def shuffleR(arr):
	arr_after = arr[:]
	for i in range(2*N):
		if i%2==0:
			arr_after[i] = arr[i//2]
		else:
			arr_after[i] = arr[i//2+N]
	return arr_after


N = int(input())  #枚数
A = [x for x in range(1, 2*N+1)]
M = int(input())  #回数
for _ in range(M):
	m = int(input())
	if m==0:
		A = shuffleR(A)
	else:
		A = shuffleK(m, A)

for a in A:
	print(a)



Measured memory_bytes: 5624
#include<iostream>
#include<math.h>
#include<cmath>
#include<iomanip>
#include<string.h>
#include<stdio.h>
#include <algorithm>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int N;
	while(cin>>N)
	{
		if(N<=3)
		{
			cout<<"No"<<endl;
		}
		else
		{
			int temp=N;
			while(temp>0)
			{
				if(temp%4==0||temp%7==0)
				{
					cout<<"Yes"<<endl;
					break;
				}
				temp-=4;
			}
			if(temp<0)
			{
				cout<<"No"<<endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
from bisect import bisect,bisect_left
from fractions import gcd
MAXN = 1000002
T = 2**20*3**14*5**9
H = filter(lambda i:gcd(T,i)==i,xrange(MAXN))
while True:
    line = raw_input()
    if line == "0":
        break
    m,n = map(int,line.split())
    print bisect(H,n)-bisect_left(H,m)

Measured memory_bytes: 21400
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
const ll MAX = 30000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<vector<ll>> p;
    rep(i,n){
        vector<ll> s(3);
        rep(j,3) cin >> s[j];
        SORT(s);
        p.push_back(s);
    }
    SORT(p);
    ll c = 0;
    rep(i,n-1){
        if (p[i] == p[i+1]) c++;
    }
    PRINT(c);
}



Measured memory_bytes: 3244
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			string s = Console.ReadLine();
			int q = int.Parse(Console.ReadLine());
			var ks = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

			var sb = new StringBuilder();
			for (int i = 0; i < q; i++) {
				int k = ks[i];

				long d = 0;
				long m = 0;
				long dm = 0;
				long ans = 0;
				for (int j = 0; j < n; j++) {
					if(j >= k){
						if (s[j - k] == 'D') {
							--d;
							dm -= m;
						} else if (s[j - k] == 'M') {
							--m;
						}
					}

					if (s[j] == 'D') {
						++d;
					} else if (s[j] == 'M') {
						++m;
						dm += d;
					} else if (s[j] == 'C') {
						ans += dm;
					}
				}

				sb.AppendLine(ans.ToString());
			}

			Console.Write(sb.ToString());
		}
	}
}

Measured memory_bytes: 16992
from collections import deque

N = int(input())
inpt = input()
A = [int(a) for a in inpt.split()]
A = deque(sorted(A))
outputs = []
negative = 0
positive = 0

for a in A:
    if a > 0:
        positive += 1
    elif a <= 0:
        negative += 1
for i in range(N-1):
    maxA = A[-1]
    minA = A[0]
    if minA>0:
        positive -= 1
    else:
        negative -= 1
    if maxA>0:
        positive -= 1
    else:
        negative -= 1
    A.pop()
    A.popleft()
    if positive > negative:
        newnum = minA-maxA
        A.appendleft(newnum)
        outputs.append(str(minA)+" "+str(maxA))
    else:
        newnum = maxA - minA
        A.append(newnum)
        outputs.append(str(maxA)+" "+str(minA))
    if newnum > 0:
        positive += 1
    else:
        negative += 1

print(A[0])
for output in outputs:
    print(output)


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i, j;
  //ll n;
  //cin >> n;
  ll n,d,x;
  cin >> n>>d>>x;
  //string s; cin >> s;
  ll result = x;
  bool judge = true;

  
  vector<ll> a(n);
  for(i=0;i<n;i++){
    cin >> a[i];
    result+=(d-1)/a[i]+1;
  }
  //for(i=0;<n;i++)
  cout<<result<<endl;
  





  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100001;
const ll mod = 1e9+7;
int n, tot;
struct coo
{
    int x, y;
    int id;
}c[maxn];
bool cmp1(coo a, coo b){
  return a.x < b.x;
}
bool cmp2(coo a, coo b){
  return a.y < b.y;
}
int dx[maxn],dy[maxn];
struct Edge{
  int u, v;
  int cost;
}e[maxn];
bool cmp(Edge a, Edge b){
  return a.cost < b.cost;
}
int p[maxn];
int find(int x){return p[x] == x ? x : p[x] = find(p[x]);}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  scanf("%d", &n);
  for(int i = 0; i <= n; i++) p[i] = i;
  for(int i = 1; i <= n; i++){
    scanf("%d%d", &dx[i], &dy[i]);
  }
  for(int i = 1; i <= n; i++)
  {
    c[i].x = dx[i]; c[i].y = dy[i];c[i].id = i;
  }
  sort(c+1,c+1+n,cmp1);
  for(int i = 1; i < n; i++){
    e[tot].u = c[i].id;
    e[tot].v = c[i+1].id;
    e[tot].cost = c[i+1].x - c[i].x;
    tot++;
  }
  sort(c+1,c+1+n,cmp2);
  for(int i = 1; i < n; i++){
    e[tot].u = c[i].id;
    e[tot].v = c[i+1].id;
    e[tot].cost = c[i+1].y - c[i].y;
    tot++;
  }
  sort(e,e+tot,cmp);
  ll ans = 0;
  int cnt = 0;
  for(int i = 0; i < tot; i++){
    int f = find(e[i].u);
    int t = find(e[i].v);
    if(f!=t){ans+=e[i].cost;p[p[e[i].u]] = p[e[i].v];cnt++;}
    if(cnt == n-1)break;
  }
  printf("%lld\n", ans);
  return 0;
}



Measured memory_bytes: 3840
<?php

fscanf(STDIN, "%d %d", $n, $k);
$ds = [];
for ($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%d %d", $t, $d);
    --$t;
    $ds[$t][] = $d;
}
const PRI = 1000000000;

$S = [];
foreach ($ds as $key => $arr) {
    rsort($arr);
    $ds[$key] = $arr;
    $S[] = [$arr[0], 1];
    for ($i = 1; $i < count($arr); ++$i) {
        $S[] = [$arr[$i], 0];
    }
}
$type_cnt = count($ds);

usort($S, function ($a, $b) {
    return $a[0] < $b[0];
});

$X = 0;
$type = 0;
$q1 = new SplPriorityQueue(); // 選択済みのネタを持つpq
$q2 = new SplPriorityQueue(); // 未選択のネタを持つpq

for ($i = 0; $i < $k; ++$i) {
    $X += $S[$i][0];
    $type += $S[$i][1];
    $q1->insert($S[$i], -1 * ($S[$i][1] * PRI + $S[$i][0]));
}
for ($i = $k; $i < $n; ++$i) {
    $q2->insert($S[$i], $S[$i][1] * PRI + $S[$i][0]);
}
$max = $X + $type * $type;
/* echo "X: $X, type: $type, max: $max", PHP_EOL; */

while ($q2->valid()) {
    $tmp1 = $q2->extract();

/* echo "tmp1: " . json_encode($tmp1), PHP_EOL; */
    if ($tmp1[1] == 0) break;

    $tmp2 = $q1->extract();
/* echo "  tmp1: " . json_encode($tmp1) . ", tmp2: " . json_encode($tmp2), PHP_EOL; */

    $X -= $tmp2[0];
    if ($tmp2[1] == 1) break;

    $X += $tmp1[0];
    $q1->insert($tmp1, -1 * ($tmp1[1] * PRI + $tmp1[0]));
    ++$type;

    $max = max($max, $X + $type * $type);
}

echo $max, PHP_EOL;


Measured memory_bytes: 138456
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
int main(){

    int n;
    while(cin>>n,n){
        map < int , int > a;

        for(int i=0;i<n;i++){
            int t;
            cin>>t;
            int z=0;
            for(int j=0;j<4;j++){
                int x,y;
                cin>>x>>y;
                z += x*60+y;
            }
            a[z] = t;


        }
        map<int, int>::iterator it = a.begin();

        cout<<(*it).second<<endl;
        it++;
        cout<<(*it).second<<endl;
        it = a.end();
        it--;
        it--;
        cout<<(*it).second<<endl;
    }

    return 0;
}

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

int main() {
	int H, M;
	for (;;) {
		cin >> H >> M;
		if (H == 0 && M == 0)break;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < M; j ++ ) {
				if (i == 0 ||i == (H-1)) { cout << "#"; }
				else if (j==0||j == (M-1)) { cout << "#"; }
				else { cout << "."; }
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vvll = vector<vector<ll>>;
using vll = vector<ll>;
const ll MOD=1000000007;

template <class type> void printVector(vector<type> vec){
    stringstream ss;
    ll n=vec.size();
    for(ll i=0;i<n;i++)
    {
        ss<<vec[i]<<" ";
        if(i!=n-1)ss<<" ";
    }
    cout<<ss.str()<<endl;
}

template <class type> void inputVector(vector<type>& vec){
    for(ll i=0;i<vec.size();i++)
    {
        cin>>vec[i];
    }
}

template<ll MOD> struct Fp {
    ll val;
    constexpr Fp(ll v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr ll getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        ll a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, ll n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;//1bit目が1=奇数,1ならここは2になる。
        return t;
    }
};

using mint = Fp<MOD>;

mint calc(ll N, ll K) {
    mint res = 1;
    for (ll n = 0; n < K; ++n) {
        res *= (N - n);
        res /= (n + 1);
    }//Cの計算
    return res;
}

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    mint res = modpow(mint(2), N) - 1;
    res -= calc(N, A) + calc(N, B);
    cout << res << endl;
}

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

int main(){
  int N;
  cin>>N;
  vector<long> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
    vec.at(i)=1000000*vec.at(i)+i+1;
  }
  sort(vec.begin(),vec.end());
  for(int i=0;i<N;i++){
    if(i!=N-1)
      cout<<vec.at(i)%1000000<<' ';
    else
      cout<<vec.at(i)%1000000<<endl;
  }
}

Measured memory_bytes: 1664
'use strict'
function Main(input){
  input=input.trim().split(/\s+/).map(x=>x-0);
  var N=input.shift();
  var counter=0;
  var head=0;
  var body=0;
  var tail=0;
  var value=0;
  while(head<N){
    if(value&input[head]){
      counter+=(body-tail)*(head-body)+(head-body)*(head-body+1)/2;
      body=head;
      while(value&input[head]){
        value^=input[tail];
        tail++;
      }
    }else{
      value|=input[head];
      head++;
    }
  }
  counter+=(body-tail)*(head-body)+(head-body)*(head-body+1)/2;
  console.log(counter);
}

Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 33740
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,ra,re) for((i)=ra;(i)<(re);(i)++)
#define rep_(i,ra,re) for((i)=ra;(i)<=(re);(i)++)
#define put(n) cout << n << " "; 
#define puts(n) cout << n << endl;
#define INF 10e9

static const int MAX_N=10e5,MAX_M=10e5;
int N,M,K,X,Y,Z;
int maxs=-1,mini=INF,ans,res;
int A[MAX_N],B[MAX_N],C[MAX_N];
int prime[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
int P[25];
void tt(int a){
	if(a==1)
		return ;
	int i=0;
	int b=a;
	while(a!=1){
		if(!(a%prime[i])){
			P[i]++;
			a/=prime[i];
		}
		else
			i++;
	}
	tt(b-1);
	return ;
}
int num(int k){
	int res=0;
	int i;
	rep(i,0,25){
		res+=(P[i]>=k?1:0);
	}
	return res;
}

int main(void){
	cin >> N;
	tt(N);
	int i;
	
	ans+=num(4)*(num(4)-1)*(num(2)-2)/2;
   	ans+=num(14)*(num(4)-1);
 	ans+=num(24)*(num(2)-1);
 	ans+=num(74);
	puts(ans);
	return 0;
}

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

int main() {
  int n; cin >> n;
  int min_cnt = 1000000000;
  for (int i = 0; i < n; ++i) {
    int a, cnt = 0;
    cin >> a;
    while (a % 2 == 0) {
      a /= 2;
      cnt++;
    }
    min_cnt = min(min_cnt, cnt);
  }
  
  cout << min_cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  // Cで割り切れる数
  ll c1 = (A - 1) / C;
  ll c2 = B / C;
  // Dで割り切れる数
  ll d1 = (A - 1) / D;
  ll d2 = B / D;
  // CかつD
  ll cd1 = (A - 1) / lcm(C, D);
  ll cd2 = B / lcm(C, D);
  // CまたはD
  ll or1 = c1 + d1 - cd1;
  ll or2 = c2 + d2 - cd2;
  ll ans1 = (A - 1) - or1;
  ll ans2 = B - or2;
  cout << ans2 - ans1 << endl;
  return 0;
}

Measured memory_bytes: 256