akhauriyash/Code-Regression huggingface dataset:
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> Q;
//ll longinf=1ll<<60;
int inf=1<<29;
int dh[4]={1,0,-1,0};
int dw[4]={0,1,0,-1};
ll longinf=(1ll<<31)-1;
struct segTree{
      ll n;
      vector<ll> dat;
      segTree(ll n_){
            n = 1;
            //かんたんのため要素数を2冪にする
            while(n < n_) n *= 2;
            //すべての値をinfにする
            for(ll i = 0; i < 2*n-1; i++) dat.push_back(longinf);
      }
      //k番目の値(0-indexed)をaに変更
      void update(ll k,ll a){
            //葉の節点
            k += n - 1;
            dat[k] = a;
            while(k > 0){
                  k = (k - 1) / 2;
                  dat[k] = min (dat[k * 2 + 1], dat[k * 2 + 2]);
            }
      }
      //[a,b)の最小値を求める
      //後ろの方の引数は、計算のかんたんのための引数
      //kは節点の番号,l,rはその節点が[l,r)に対応づいていることを表す
      //したがって外からはq(a, b, 0, 0, n)と呼ぶ
      ll q(ll a,ll b,ll k,ll l,ll r){
            //[a,b)と[l,r)が交差しなければ,inf
            if(r<=a||b<=l) return longinf;
            //[a,b)が[l,r)を完全に含んでいればこの節点の値
            if(a<=l&&r<=b) return dat[k];
            else{
                  //そうでなければ2つの子の最小値
                  ll vl = q(a,b,k*2+1,l,(l+r)/2);
                  ll vr = q(a,b,k*2+2,(l+r)/2,r);
                  return min(vl,vr);
            }
      }
      ll query(ll a,ll b){
            return q(a,b,0,0,n);
      }
};


int main(){
      int n,q;
      cin>>n>>q;
      segTree seg(n);
      /*rep0(i,n){
            ll a;
            cin>>a;
            seg.update(i,a);
      }*/
      rep0(i,q){
            ll f,g,h;
            cin>>f>>g>>h;
            if(f==1){
                  cout<<seg.query(g, h+1)<<endl;
            }
            else{
                  seg.update(g,h);
            }
      }
      return 0;
}


Measured memory_bytes: 5016
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n;
	cin >> n;
	vector<ll> v(n);
	vector<ll> u(n);
	rep(i,n) {
		cin >> v[i];
		u[i] = v[i] - (i+1);
	}
	sort(ALL(u));
	ll b = u[n/2];
	ll ans = 0;
	rep(i,n) {
		ans += abs(u[i] - b);
	}
	cout << ans << endl;
}

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

#define int long long

int ten[300];

signed main(){
    int n, k;
    cin >> n >> k;
    int r, ss, p;
    cin >> r >> ss >> p;
    ten['r'] = p;
    ten['s'] = r;
    ten['p'] = ss;

    string s;
    cin >> s;

    int no[100010] = {};


    int ans = 0;
    for(int i = 0;i < n;i++){
        if(i - k < 0){
            ans += ten[s[i]];
        }else if(s[i-k] != s[i]){
            ans += ten[s[i]];
        }else if(no[i-k] == 1){
            ans += ten[s[i]];
        }else{
            no[i] = 1;
        }
    }

    cout << ans << endl;

    return 0;
}


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

#define jaldi ios_base::sync_with_stdio(false)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%ld",&x)
#define sll(x) scanf("%lld",&x)
#define sc(x) scanf("%c",&x)
#define ss(x) scanf("%s",x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%ld",x)
#define pll(x) printf("%lld",x)
#define pc(x) printf("%c",x)
#define ps(x) printf("%s",x)
#define vi vector<int> 
#define vl vector<long> 
#define vll vector<long long>
#define vc vector<char>  
#define vs vector<string>
#define vvi vector<vector<int>> 
#define vvll vector<vector<long long>> 
#define F first
#define S second
#define ll long long
#define pb push_back
#define PI 3.1415926535897932384626
#define precision(x) cout<<fixed<<setprecision(x) 
#define mod 1000000007

int x_d[8] = {-1,1,0,0,-1,-1,1,1};
int y_d[8] = {0,0,-1,1,-1,1,-1,1};

ll power(ll b,ll e)
{
    if(b==0)
        return 0;
    
    ll r=1;
    while(e>0)
    {
        if(e%2)
            r=(r*b)%mod;
        b=(b*b)%mod;
        e/=2;
    }
    return r;
}

ll root(ll a,vll &head)
{
    while(a!=head[a])
    {
        head[a]=head[head[a]];
        a=head[a];
    }
    return a;
}

void merge(ll a,ll b,vll &head, vll &size)
{
    ll p_a = root(a,head);
    ll p_b = root(b,head);
    if(p_a==p_b)
        return;
    
    if(size[p_a]>size[p_b])
    {
        size[p_a]+=size[p_b];
        head[p_b]=head[p_a];
    }
    else
    {
        size[p_b]+=size[p_a];
        head[p_a]=head[p_b];
    }
    
}

int main()
{
    jaldi;
    precision(20);
    ll i,j;

    ll a,b,c,k;
    cin>>a>>b>>c>>k;

    if(k<=a)
        cout<<k<<endl;
    else if(k<=a+b)
        cout<<a<<endl;
    else if(k<=a+b+c)
    {
        ll x=a;
        k=k-(a+b);
        cout<<a-k<<endl;
    }

    return 0;
}

Measured memory_bytes: 3652
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
a,b,c = LI()
if a <= c <= b:
    print("Yes")
else:
    print("No")
"""
#B
n,m = LI()
d = [0 for i in range(n+1)]
for i in range(m):
    a,b = LI()
    d[a] += 1
    d[b] += 1
for i in range(1,n+1):
    print(d[i])
#C

#D
"""
def bellman_ford(start):
    dist = [float("inf") for i in range(n)]
    dist[start] = 0
    for i in range(n-1):
        update = False
        for j, k, l in adj:
                if dist[k] > dist[j] + l:
                    dist[k] = dist[j] + l
                    update = True
        if not update:
            break
    negative = [False for i in range(n)]
    for j, k, l in adj:
        if dist[k] > dist[j] + l:
            dist[k] = dist[j] + l
            negative[k] = True
    return dist,negative[n-1]
n,m = LI()
adj = []
for i in range(m):
    a,b,c = LI()
    a -= 1
    b -= 1
    adj.append([a,b,-c])
d,ne = bellman_ford(0)
if ne:
    print("inf")
else:
    print(-d[-1])
"""

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 38512
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi   = vec<int>;
using vvi  = vec<vi>;
using vvvi = vec<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int n,x; cin>>x>>n;
  set<int> p; int p_;
  rep(i,n) {cin>>p_; p.insert(p_); }
  int m = 200; int mini = -1;
  rep(i,-3,103) {
    if(p.find(i)!=p.end()) continue;
    if(m>abs(x-i)) { m = abs(x-i); mini = i; }
  }
  cout << mini << endl;
  return 0;
}


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

int main() {

  int N;
  cin >> N;

  string tmp;
  map<string, int> m;
  int max = 0;
  for(int i = 0; i < N; i++){
    cin >> tmp;
    m[tmp]++;
  }

  for(auto &mm : m){
    if(mm.second > max){
      max = mm.second;
    }
  }

  for(auto iter = m.begin(); iter != m.end(); iter++){
    if(iter->second == max){
      cout << iter->first << endl;
    }
  }
}

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

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    ll a;
    long double b = 0;
    cin >> a >> b;
    long double num = a * b;
    ll ans = num;
    
    cout << ans << endl;
    return 0;
}

//int main() {
//    ll n;
//    cin >> n;
//    unsigned long long ans = 1;
//    vector<unsigned long long> a(n);
//    int flag = 0;
//    rep(i, n) {
//        cin >> a[i];
//        if (a[i] == 0)
//            flag = 1;
//    }
//    if (flag == 1) {
//        cout << 0 << endl;
//        return 0;
//    }
//    rep(i, n) {
//        //unsigned long long a;
//        //cin >> a;
//        ans *= a[i];
//        if (ans > 1000000000000000000 || ans < 0) {
//            cout << "-1" << endl;
//            return 0;
//        }
//    }
//
//    
//
//    cout << ans << endl;
//    return 0;
//}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

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

int main() {
	int n;
	cin >> n;
	vector<int> item(n);
	for (int i = 0; i < n; i++) {
		cin >> item[i];
	}
	int sum = 0;
	sort(item.begin(),item.end());
	for (int i = 0; i < n; i++) {
		if (i == n-1) {
			sum += item[i] /2;
		}
		else {
			sum += item[i];
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 256
#n = int(input())
#a = int(input())
#ls = list(input().split(" "))
#ls = list(map(int,input().split(" ")))
a,b = list(map(int,input().split(" ")))
#a,b,c = list(input().split())
#string = input()

def ans(n):
  an = 0
  for i in range(1,n+1):
    an += i
  return an

print(ans(b - a) - b)


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

using namespace std;
using ll = long long;

vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            ll j = n / i;
            if(i != j)res.push_back(j);
        }
    }
    sort(res.begin(),res.end(), greater<ll>());
    return res;
}


int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> as(n);
    for(ll i = 0; i < n; i++)cin >> as[i];
    ll sum = accumulate(as.begin(), as.end(), 0);
    vector<ll> div = divisor(sum);


    for(auto D : div) 
    {
        vector<ll> b = as;
        for(auto &i : b)i %= D;
        sort(b.begin(), b.end());


        for(ll i = 0; i <= n; i++) {
            ll up = 0, dw = 0;

            for(ll j = 0; j < i; j++)up += b[j];
            for(ll j = i; j < n; j++)dw += D - b[j];
            if(max(up, dw) <= k) {
                cout << D << endl;
                return 0;
            }

        }
    }
    cout << 1 << endl;
}

Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int f(int s, int t, int M, vector<int>& p, vector<int>& sum) {
	int l = lower_bound(p.begin(), p.end(), s) - p.begin() - 1;
	int r = lower_bound(p.begin(), p.end(), t) - p.begin() - 1;
	if (l == r) return t - s;
	int x = p[l + 1] - s;
	if ((r - l) % 2 == 0) x += t - p[r];
	l++; r = l + (r - l) / 2 * 2;
	x += sum[r + 1] - sum[l + 1];
	return x;
}

int main() {
	int N, M; cin >> N >> M;
	vector<int> s(N), t(N);
	for (int i = 0; i < N; i++) {
		int x, y; cin >> x >> y;
		if (x < y) { s[i] = x; t[i] = y; }
		else { s[i] = -x; t[i] = -y; }
	}
	vector<int> p;
	for (int j = 0; j < M; j++) {
		int x; cin >> x;
		p.push_back(x);
		p.push_back(-x);
	}
	M *= 2;
	sort(p.begin(), p.end());
	vector<int> sum(M + 1);
	for (int j = 2; j <= M; j++)
		sum[j] = sum[j - 2] + p[j - 1] - p[j - 2];
	ll ans = 0;
	for (int i = 0; i < N; i++)
		ans += f(s[i], t[i], M, p, sum);
	cout << ans << endl;
}

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

#define DEBUG 0
#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
	lli n,m;
	cin>>n>>m;

	lli ans = 1;
	COMinit();
	for(lli i=2;i*i<=m;i++){
		lli cnt=0;
		while(m%i == 0){
			cnt++;
			m/=i;
		}
		ans *= COM(n+cnt-1,cnt);
		ans %= MOD;
	}
	if(m!=1){
		ans *= n;
		ans %= MOD;
	}

	cout<<ans%MOD<<endl;

	return 0;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define mod 1000000007
int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    ll ret = 0;
    for (int i = 0; i < n - k; i++) {
        ret += h[i];
    }
    cout << ret << endl;
    return 0;
}

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

using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define fill(a, x) memset(a, x, sizeof(a))
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
long long MOD=1e9+7;


int main()
{	
	ios_base:: sync_with_stdio(0);
	cin.tie(0);
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	int i,x,y,a,b;
	cin>>x>>y;
	a = x*2;
	b = x*4;
	if((a<=y && y<=b) && y%2==0) cout<<"Yes";
	else cout<<"No";
	}



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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> s, t;
  rep(i,n) {
    cin >> a[i];
    if (a[i] < 0) t.push_back(a[i]);
    else s.push_back(a[i]);
  }

  int S = s.size();
  int T = t.size();
  bool ok = false;
  if (S > 0) {
    if (n == k) ok = (T%2==0);
    else ok = true;
  } else {
    ok = (k%2==0);
  }

  mint ans = 1;
  if (!ok) {
    sort(a.begin(), a.end(), [](int x, int y) {
      return abs(x) < abs(y);
    });
    rep(i,k) ans *= a[i];
  } else {
    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());
    if (k%2 == 1) {
      ans *= s.back();
      s.pop_back();
    }
    vector<ll> p;
    while (s.size() >= 2) {
      ll x = s.back(); s.pop_back();
      x *= s.back(); s.pop_back();
      p.push_back(x);
    }
    while (t.size() >= 2) {
      ll x = t.back(); t.pop_back();
      x *= t.back(); t.pop_back();
      p.push_back(x);
    }
    sort(p.rbegin(), p.rend());
    rep(i,k/2) ans *= p[i];
  }

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


Measured memory_bytes: 6368
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int D, contests[370];
lint c[30], s[370][30];
set<int> held_days[30];

lint get_score(int dd){
    For(i, 1, 27){
        held_days[i].clear();
        held_days[i].insert(0);
        held_days[i].insert(D+1);
    }
    lint ret = 0;
    For(day, 1, dd+1){
        For(i, 1, 27){
            if(contests[day] == i){
                ret += s[day][i];
                held_days[i].insert(day);
            }
            else ret -= c[i] * (day - *next(held_days[i].rbegin()));
        }
    }
    return ret;
}

lint fsum(int n){
    return n*(n+1)/2;
}

lint score_diff(int day, int idx){
    lint ret = 0;
    int prev_id = contests[day];
    contests[day] = idx;

    ret += s[day][idx];
    auto r = held_days[idx].lower_bound(day), l = prev(r);
    ret += c[idx] * fsum(*r-1-*l);
    ret -= c[idx] * (fsum(day-1-*l) + fsum(*r-1-day));
    held_days[idx].insert(day);

    ret -= s[day][prev_id];
    auto m = held_days[prev_id].find(day);
    r = next(m); l = prev(m);
    ret += c[prev_id] * (fsum(day-1-*l) + fsum(*r-1-day));
    ret -= c[prev_id] * fsum(*r-1-*l);
    held_days[prev_id].erase(day);

    return ret;
}

int main(){
    scanf("%d", &D);
    For(i, 1, 27) scanf("%lld", &c[i]);
    For(i, 1, D+1)For(j, 1, 27) scanf("%lld", &s[i][j]);
    For(i, 1, D+1) scanf("%d", &contests[i]);
    lint score = get_score(D);

    int m;
    scanf("%d", &m);
    rep(_, m){
        int d, q;
        scanf("%d%d", &d, &q);
        score += score_diff(d, q);
        printf("%lld\n", score);
    }
}

Measured memory_bytes: 3924
N = int(input())
S = input().strip()

dp = [[0 for _ in range(N+1)] for _ in range(N+1)]

for i in reversed(range(N)):
    for j in reversed(range(i+1, N)):
        if S[i] != S[j]:
            dp[i][j] = 0
        if S[i] == S[j]:
            dp[i][j] = dp[i+1][j+1] + 1

ans = 0
for i in range(N):
    for j in range(i+1, N):
        now = min([dp[i][j], j-i])
        ans = max(ans, now)

print(ans)


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    map<int, int> cnt;
    vi a(n);
    forn(i, n) cin >> a[i], cnt[a[i]]++;
    ll cur = 0;
    for (const pii &p:cnt) {
        cur += p.snd * 1ll * (p.snd - 1) / 2;
    }
    forn(i, n) {
        cout << cur - cnt[a[i]] + 1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
	string s;
	cin>>s;
	int n=s.size();
	int bwbw=0,wbwb=0;
	for(int i=0;i<n;i++){
		if(i%2&&s[i]=='0')bwbw++;
		if(i%2==0&&s[i]=='1')bwbw++;
		if(i%2&&s[i]=='1')wbwb++;
		if(i%2==0&&s[i]=='0')wbwb++;
	}
	cout<<min(bwbw,wbwb);
    return 0;
}


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

ll N , M , q ;
ll a[100] , b[100] , c[100], d[100] ;

ll dfs(ll val , vector<ll> &v) {
    ll ans = 0 ,i ;
    if (v.size()==N) {
        for ( i = 0 ; i<q ;i++) {
            if ( v[b[i]-1]-v[a[i]-1]==c[i] )
                ans+=d[i] ;
        }
    }
    else {
        for ( i = val ; i<=M ;i++) {
            v.push_back(i) ;
            ans = max(ans , dfs(i,v)) ;
            v.pop_back() ;
        }
    }
    return ans ;

}

int main() {
    cin >> N >> M >> q ;
    for ( ll i = 0 ; i< q ;i++) {
        cin >> a[i] >> b[i] >> c [i] >> d[i] ;
    }
    vector<ll> v ;
    cout << dfs(1,v) ;

    return 0 ;
}


Measured memory_bytes: 3592
s = input()
t = input()
check = {}
ans = 0
for i in range(len(s)):
    if s[i] in check.keys():
        if t[i] != check[s[i]]:
            ans = 1
            break
    else:
        check[s[i]] = t[i]
if ans == 1 or len(check.values()) != len(set(check.values())):
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3632
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int MAX_SIZE = 200000;
const int MAX_N    = 3000;
const int MOD      = 1000000007;

typedef long long Int;

Int fac[MAX_SIZE + 1];
Int inv[MAX_SIZE + 1], ifac[MAX_SIZE + 1];

Int comb(int n, int r)
{
  Int ret = fac[n];
  ret = (ret * ifac[r]) % MOD;
  ret = (ret * ifac[n - r]) % MOD;
  return ret;
}

Int dp[MAX_N + 2][2];

int main()
{
  int h, w, n;
  scanf("%d %d %d", &h, &w, &n);
  
  inv[1] = 1;
  fac[0] = ifac[0] = 1;
  fac[1] = ifac[1] = 1;
  for (int i = 2; i <= h + w; i++) {
    fac[i] = (fac[i - 1] * i) % MOD;
    inv[i] = (inv[MOD % i] * (MOD - MOD / i)) % MOD;
    ifac[i] = ifac[i - 1] * inv[i] % MOD;
  }
  
  vector< pair<int, int> > pos;
  pos.push_back(make_pair(1, 1));
  pos.push_back(make_pair(h, w));
  for (int i = 0; i < n; i++) {
    int r, c;
    scanf("%d %d", &r, &c);
    pos.push_back(make_pair(r, c));
  }
  sort(pos.begin(), pos.end());
  
  dp[0][0] = 1;
  for (int i = 1; i < pos.size(); i++) {
    for (int j = 0; j < i; j++) {
      if (pos[j].first <= pos[i].first && pos[j].second <= pos[i].second) {
        int dr = pos[i].first - pos[j].first;
        int dc = pos[i].second - pos[j].second;
        Int coef = comb(dr + dc, dc);
        dp[i][0] = (dp[i][0] + dp[j][1] * coef) % MOD;
        dp[i][1] = (dp[i][1] + dp[j][0] * coef) % MOD;
      }
    }
  }
  
  printf("%lld\n", (dp[n + 1][1] - dp[n + 1][0] + MOD) % MOD);
  
  return 0;
}


Measured memory_bytes: 4992
MOD = 10**9+7
import sys
sys.setrecursionlimit(100000)


def kaijo(n):
    s = 1
    for i in range(1, n+1):
        s *= i
        s %= MOD
    return s


n,m = map(int,input().split())
if abs(n-m) > 1:
    print(0)
elif abs(n-m) == 1:
    print(kaijo(m) * kaijo(n) % MOD)
else:
    print(pow(kaijo(m), 2, MOD)*2%MOD)


Measured memory_bytes: 3060
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def bfs(start):
        dist = [f_inf] * n
        dist[start] = 0
        que = deque([start])
        while que:
            v = que.popleft()
            for u in edge[v]:
                if dist[u] == f_inf:
                    dist[u] = dist[v] + 1
                    que.append(u)
        return dist

    n, u, v = map(int, input().split())
    edge = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b = map(int, input().split())
        edge[a - 1].append(b - 1)
        edge[b - 1].append(a - 1)

    distA = bfs(u - 1)
    distT = bfs(v - 1)

    res = 0
    for i in range(n):
        if distA[i] < distT[i]:
            res = max(res, distT[i])
    print(res - 1)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 33844
#include<bits/stdc++.h>
#define rep(i, n) for(i = 0; i < (n); ++i)
#define PI 3.14159265359
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
 
int main(){
  double a, b, x;
  cin >> a >> b >> x;
  
  double S, height;
  double ans, theta;
  S = x / a;
  if(S > a*b/2){
    S = a*b - S;
    height = S/a*2;
    theta = height/a;
    ans = atan(theta);
    ans = ans * 180 / PI;
  } else {
    height = S/b*2;
    theta = height/b;
    ans = atan(theta);
    ans = ans * 180 / PI;
    ans = 90 - ans;
  }
  
  
  printf("%.8f\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() { 


	int n; cin >> n;
	long long a[n]; for(int i = 0;i<n;i++) cin >> a[i];

	long long height = 0;

	for(int i = 1;i<n;i++)
	{
		if(a[i] < a[i-1])
		{
			height = height + a[i-1] - a[i];
			a[i] = a[i-1];
		}

	}

	cout << height << endl;
		
		
  return 0; 
}

Measured memory_bytes: 5188
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


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


int main(){
	int n;
	cin >> n;
	int a = n / 111;
	int ans = (n % 111 == 0)? n:(a+1)*111;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
int n;
template<typename I>inline void read(I&ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();}
	while(ch>='0' && ch<='9'){x=10*x+ch-'0'; ch=getchar();}
	ot=x*f;}
template<typename I,typename... U>inline void read(I&x,U&... y){read(x); read(y...);}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n);
	printf("Christmas ");
	for(int i=24;i>=n;i--)
	{
		printf("Eve ");
	}
//	fclose(stdin); fclose(stdout);
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll A, B, C;
  cin >> A >> B >> C;
  ll ans = min(B / A, C);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const long long MOD = 1e9+7;
long long M, N;

// a^n modを計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin >> M >> N;
    cout << modpow(M, N, MOD) << endl;
}


Measured memory_bytes: 3112
import sys
x,n = map(int,input().split())
p = list(map(int,input().split()))

if not p:
    print(x)
    sys.exit()
    
for i in range(n+1):
    if x-i not in p:
        print(x-i)
        break
    elif x+i not in p:
        print(x+i)
        break
    else:
        continue
        

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

int main() {
  i64 H, W, A, B;
  cin >> H >> W >> A >> B;
  swap(A, B);
  rep(i,0,H) {
    rep(j,0,W) {
      if(i < A && j < B) {
        cout << 0;
      }
      else if(i >= A && j >= B) {
        cout << 0;
      }
      else {
        cout << 1;
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 1280
n,m = map(int,input().split())
ai = [int(i) for i in input().split()]

for i in range(n):
    ai[i] = ai[i]%m

a = [0]*(n+1)
tmp = 0

for i in range(n):
    tmp += ai[i]
    tmp %= m
    a[i+1] = tmp
    
ans = 0

#li = [0]*(m)

d = dict()

for i in range(n+1):
    if a[i] in d:
        ans += d[a[i]]
        d[a[i]] += 1
    else:
        d[a[i]] = 1
    #print(ans,d)

print(ans)


Measured memory_bytes: 62576
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;
const long LINF = 1e13;
const long LLINF = 1e18;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}



int main() {

  long n;
  cin >> n;
  vector<long> a(n);//長くて100こ

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

  sort(a.begin(), a.end()); //昇順にソート

  // long medi1,medi2;//
  // medi1 = (a[n/2 -1 ] + a[n/2] ) /2;
  // medi2 = medi1 + 1;


  // long cost1;
  // for (int i = 0; i < n; ++i){
  //   cost1 += (a[i] - medi1)*(a[i] - medi1);
  // }

  // long cost2;
  // for (int i = 0; i < n; ++i){
  //   cost2 += (a[i] - medi2)*(a[i] - medi2);
  // }
  long ans = LINF;


  for (long k = -100; k <= 100 ; ++k) {
    long cost = 0;

    for (int i = 0; i < n; ++i) {
      cost += pow(a[i] - k,2);//(a[i] - k) * (a[i] - k);
    }

    ans = min(ans,cost);
  }



  // long ans = min(cost1, cost2);


  cout << ans;




}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll n = N / 1000;
    if (n == 0)
        cout << "ABC";
    else
        cout << "ABD";
    return 0;
}

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

using ll = long long;
using namespace std;

int main() {
  ll N, K;
  string S;
  cin >> N >> K >> S;

  ll len = 0;
  vector<ll> lv;
  if (S[0] == '0') lv.push_back(0);
  for (ll i = 0; i < N; i++) {
    len++;
    if (i == N - 1 || S[i] != S[i + 1]) {
      lv.push_back(len);
      len = 0;
    }
  }
  if (S.back() == '0') lv.push_back(0);
  //for (ll v : lv) cerr << " " << v;
  //cerr << endl;
  ll sum = lv[0];
  ll mx = lv[0];
  ll ed = -K * 2;
  for (ll i = 2; i < lv.size(); i += 2) {
    if (ed >= 0) sum -= lv[ed] + lv[ed + 1];
    sum += lv[i - 1] + lv[i];
    //cerr << sum << endl;
    mx = max(mx, sum);
    ed += 2;
  }
  cout << mx << endl;
  return 0;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define hii cout << "hii" << endl
#define int ll
#define endl '\n'
#define all(s) s.begin(), s.end()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
 
const int N = 3e5 + 5;
const int MAXN = 1e5 + 5;
const int M = 1e5;
const int mod = 998244353;
const int MOD = 998244353;
const int INF = 1e15;
const int LG = 21;

int arr[N];
int query = 1;
int n;


void solve() 
{
	string input;
	cin >> input;
	if(input == "ARC")
	{
		cout << "ABC" << endl;
	}
	else
	{
		cout << "ARC" << endl;
	}
}



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

	    int t = 1;
	    // cin >> t;
	while(t--)solve();
	return 0;
}


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

int main() {
	ll n, x, prev = -1, ans = 0;	scanf("%lld", &n);
	
	for(int i=0; i<n; i++) {
		scanf("%lld", &x);
		
		if(x < prev) ans += (prev - x);
		prev = max(prev, x);
	}
	
	printf("%lld\n", ans);
	return 0;
}

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

int main() {
    string s, t;
    cin >> s >> t;
    int sum=0;
    for (int i=0; i<s.size(); i++)
        if (s[i] == t[i])
            sum++;  
    cout << sum;    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		String str=sc.nextLine();
		char[] c=str.toCharArray();
		String str1="abcdefghijklmnopqrstuvwxyz";
		char[] c1=str1.toCharArray();
		String str2="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		char[] c2=str2.toCharArray();
		for(int i=0;i<c.length;i++){
			for(int j=0;j<c1.length;j++){
				if(c[i]==c1[j]){
					System.out.print(c2[j]);
					break;
				}else if(j==c1.length-1){
					System.out.print(c[i]);
				}
			}
		}
		System.out.println();
	}
}

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

const int N = 200005;
const int inf = 1e9 + 10;

int n;
int x[N], y[N];
int l[N * 2], r[N * 2];
int MIN, MAX;
long long ans = 1LL * inf * inf;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	MIN = inf, MAX = -inf;
	for (int i = 1; i <= n; ++i) {
		cin >> x[i] >> y[i];
		MIN = min(MIN, min(x[i], y[i]));
		MAX = max(MAX, max(x[i], y[i]));
	}

	// (MAX-?) (L) * (?-MIN) (R)
	int minL = inf, maxR = -inf;
	for (int i = 1; i <= n; ++i) {
		if (x[i] > y[i]) minL = min(minL, x[i]), maxR = max(maxR, y[i]);
		else minL = min(minL, y[i]), maxR = max(maxR, x[i]);
	}
	ans = min(ans, 1LL * (MAX-minL) * (maxR-MIN));


	// (MAX-MIN) * (?-?)
	vector<int> a;
	vector<int> z; // for compression
	int lim = inf; // cannot choose an element greater than lim as min of the second group
	for (int i = 1; i <= n; ++i) if (x[i] > y[i]) swap(x[i], y[i]); // (x,y) with x <= y
	for (int i = 1; i <= n; ++i) a.push_back(i);
	sort(a.begin(), a.end(), [&](int i, int j) {
		return x[i] < x[j] || (x[i] == x[j] && y[i] < y[j]); // according to x
	});
	for (int i = 1; i <= n; ++i) {
		z.push_back(x[i]), z.push_back(y[i]);
		lim = min(lim, y[i]);
	}
	sort(z.begin(), z.end()); // compress
	
	int ptr = 0;
	for (int i = 0; i < z.size(); ++i) l[i] = r[i] = -inf;
	for (int i = 0; i < z.size(); ++i) {
		while(ptr < n && x[a[ptr]] < z[i]) l[i] = max(l[i], y[a[ptr]]), ++ptr; // x must be in the first group
		if (i > 0) l[i] = max(l[i], l[i-1]); 
	}
	ptr = n - 1;
	for (int i = (int)z.size()-1; i >= 0; --i) {
		while(ptr >= 0 && x[a[ptr]] >= z[i]) r[i] = max(r[i], x[a[ptr]]), --ptr; // x can be freely assigned to any group
		if (i < (int)z.size()-1) r[i] = max(r[i], r[i+1]);
	}
	for (int i = 0; i < z.size(); ++i) {
		if (z[i] > lim) break;
		ans = min(ans, 1LL * (max(l[i], r[i]) - z[i]) * (MAX - MIN));
	}
	cout << ans << endl;
}

Measured memory_bytes: 7408
a=int(input())
ct=0
list1=[0]*a
list1=list(map(int,input().split()))
list2=sorted(list1)
for i in range(a):
    if list1[i]!=list2[i]:
        ct+=1
if (ct==2)or(ct==0):
    print('YES')
else:
    print('NO')

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[105];

int main()
{
    int N;
    cin >> N;
    REP(i, N)
    {
        cin >> A[i];
    }

    ll ans = 0;
    FOR(i, N, 1)
    {
        if (A[i] == A[i - 1])
        {
            ans++;
            A[i] = INF;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> grid(n, vector<int>(m, 0));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> grid[i][j];
        }
    }
    vector<string> cmd;
    for(int i = 0; i < n-1; i++) {
        for(int j = 0; j < m; j++) {
            if(grid[i][j] % 2) {
                string s = to_string(i+1) + " " + to_string(j+1);
                s += " " + to_string(i+2) + " " + to_string(j+1);
                cmd.push_back(s);
                grid[i][j] -= 1;
                grid[i+1][j] += 1;
            }
        }
    }
    for(int j = 0; j < m-1; j++) {
        if (grid[n-1][j] % 2) {
            string s = to_string(n) + " " + to_string(j+1);
            s += " " + to_string(n) + " " + to_string(j+2);
            grid[n-1][j] -= 1;
            grid[n-1][j+1] += 1;
            cmd.push_back(s);
        }
    }
    cout << cmd.size() << endl;;
    for(auto& s: cmd)
        cout << s << endl;
    return 0;
}



Measured memory_bytes: 11636
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
t = 0
for i in range(n):
    t += a[i]
    if t > x:
        print(i)
        break
else:
    if sum(a) == x:
        print(n)
    else:
        print(n-1)

Measured memory_bytes: 3316
def rotate(v, a)
  [
    Math::cos(a)*v[0] - Math::sin(a)*v[1],
    Math::sin(a)*v[0] + Math::cos(a)*v[1],
  ]
end

Pi=Math::PI
A,B,H,M=gets.split.map(&:to_f)

h=rotate([0,A], -2*Pi/12*H - 2*Pi/12/60*M)
m=rotate([0,B], -2*Pi/60*M)

p Math::hypot(h[0]-m[0], h[1]-m[1])


Measured memory_bytes: 14740
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010;
int a[maxn],b[maxn],c[maxn];
int dp[maxn][10];
int main()
{
	int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    dp[1][1]=a[1];
    dp[1][2]=b[1];
    dp[1][3]=c[1];
    for(int i=2;i<=n;i++)
    {
        dp[i][1]+=max(dp[i-1][2],dp[i-1][3])+a[i];
        dp[i][2]+=max(dp[i-1][1],dp[i-1][3])+b[i];
        dp[i][3]+=max(dp[i-1][1],dp[i-1][2])+c[i];
    }
    cout<<max(dp[n][3],max(dp[n][1],dp[n][2]));
    return 0;
}

Measured memory_bytes: 8580
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int dp[1001][10001]; //dp[i][j]: i+1番目(1番が最初)までのダメージの合計がj以上になるように選んだ時の魔力の総和の最小値
int main(){
    int h,n,a[10000],b[10000];
    
    cin >> h >> n;
    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i];
    }

    for(int i=0; i<n+1; i++){
        for(int j=1; j<=h; j++){
            if(i==0){
                dp[i][j]= 100000001;
            }else if(j < a[i-1]){
                dp[i][j] = min(dp[i-1][j],b[i-1]);
            }else{
                dp[i][j] = min(dp[i-1][j], dp[i][j-a[i-1]] + b[i-1]);
            }
        }
    }

    // //テスト用
    // for(int i=0; i<n+1; i++){
    //     for(int j=0; j<h+1; j++){
    //         cout << right << setw(3) << dp[i][j] << ' ';
    //     }
    //     cout << endl;
    // }

    cout << dp[n][h];


}

Measured memory_bytes: 42672
#include "bits/stdc++.h"

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;
const long double PI = (acos(-1));
const ull MOD = 1000000007;


struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    vector<ll> A_f, A_l;
    for(int i = 0; i < N; i++){
        if(i % 2) A_l.push_back(A[i]);
        else A_f.push_back(A[i]);
    }
    if(N % 2){
        reverse(all(A_f));
        for(int a : A_f) cout << a << ' ';
        for(int a : A_l) cout << a << ' ';
    }else{
        reverse(all(A_l));
        for(int a : A_l) cout << a << ' ';
        for(int a : A_f) cout << a << ' ';
    }
}

Measured memory_bytes: 5484
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var inputList = Console.ReadLine().Split(' ');

			if(inputList.Where(value => value == "5").Count() == 2 && inputList.Where(value => value == "7").Count() == 1)
			{
				Console.WriteLine("YES");
				return;
			}

			Console.WriteLine("NO");
		}
	}
}


Measured memory_bytes: 11220
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello
{
    public static void Main()
    {
        //入力を保持する
        var input = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray();
        //鶴のカウントとして控えておく
        var c = input[0];
        var legs = input[1];
        //亀は0匹スタートとする
        int t = 0;
        for (var n = 0; n <= input[0]; n++)
        {
            if (4 * t + 2 * c == legs)
            {
                Console.WriteLine("Yes");
                return;
            }
            c -= 1;
            t += 1;
        }
        Console.WriteLine("No");
    }
}




Measured memory_bytes: 28204
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
#include <set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator
const int MXN = 1e5+1;
ll a[MXN], b[MXN], c[MXN], n, dp[MXN][3];

void solve() {
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) cin>>b[i];
    for(int i=1;i<=n;i++) cin>>c[i];
    sort(a+1, a+n+1);
    sort(b+1, b+n+1);
    sort(c+1, c+n+1);
    for(int i=1;i<=n;i++) dp[i][0] = i;
    for(int i=1;i<=n;i++) {
        auto it = lower_bound(a+1, a+n+1, b[i]);
        dp[i][1] = dp[i-1][1] + dp[it-a-1][0];
    }
    for(int i=1;i<=n;i++) {
        auto it = lower_bound(b+1, b+n+1, c[i]);
        dp[i][2] = dp[i-1][2] + dp[it-b-1][1];
    }
    cout<< dp[n][2] << endl;    
}

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

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const long long INF = 1LL << 60;
const ll C = 1000000000+7;

int main() {
    set<string> substr;
    string s;
    int K;
    cin >> s >> K;

    for(int begin=0; begin<s.size(); begin++) {
        for(int end = 1; end<=K; end++) {
            string t = s.substr(begin, end);
            substr.insert(t);
        }
    }
    int cnt = 0;
    for(auto s:substr) {
        cnt++;
        if(cnt == K) cout << s << endl;
    }
}

Measured memory_bytes: 4740
/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

long long cnt;

// 挿入ソート
// in/out 配列
// in 配列サイズ
// in 挿入ソートを行う感覚
void insertionSort(int* A, int n, int g){
	int j, v;
	for (int i=g; i<n; ++i){
		v = A[i];
		j = i - g;
		while ((j >= 0) && (A[j] > v)){ // intArray[j] > v だと降順 < だと昇順
			A[j+g] = A[j];
			j = j - g;
			++cnt;
		}
		A[j+g] = v;
	}
}

void shellSort(int *A, int n){
	vector<int> G;
	for(int h=1;;){
		if (h > n){
			break;
		}
		G.push_back(h);
		h = 3*h + 1;
	}

	cout << G.size() << endl;

	for(int i = G.size()-1; i>=0; --i){
		if(i < G.size()-1){
			cout << " ";
		}
		cout << G[i];
		insertionSort(A, n, G[i]);
	}
	cout << endl;
}


int main(){
	cnt = 0;
	int A[1000000] = {0};
	int n;
	cin >> n;
	for(int i =0; i<n; ++i){
		cin >> A[i];
	}
	shellSort(A, n);
	cout << cnt << endl;
	for(int i=0; i<n; ++i){
		cout << A[i] << endl;
	}

	return 0;
}



Measured memory_bytes: 7068