akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define ranger(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define repr(i, b) for (int i = (b)-1; i >= 0; i--)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S>& p) {
	os << '(' << p.first << ',' << p.second << ')';
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

const int M = 1000000007;

vector<vector<int>> dp;
signed main() {
	int n, k;
	cin >> n >> k;

	vector<int> a(n);
	cin >> a;

	dp = vectors(n + 1, 1000005, 0LL);

	dp[0][0] = 1;
	rep(i, n) {
		rep(j, k + 1) {
			(dp[i + 1][j + 0] += dp[i][j]) %= M;
			auto& p = dp[i + 1][min(100004ll, j + a[i] + 1)];
			p = (p % M - dp[i][j] % M) + M;
			p %= M;
		}
		rep(j, k) { (dp[i + 1][j + 1] += dp[i + 1][j]) %= M; }
	}
	cout << dp[n][k] % M << endl;
}


Measured memory_bytes: 797568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x;cin >> x;
	ll ans;
	if(x%11==0) ans=x/11*2;
	else{
		if(x%11<=6) ans=x/11*2+1;
		else ans=x/11*2+2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    N = int(input())
    P = [int(i) for i in input().split()]
    dif = abs(sum(P))
    for n, i in enumerate(P):
        if dif > abs(sum(P[n:]) - sum(P[:n])):
            dif = abs(sum(P[n:]) - sum(P[:n]))

    print(dif)


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;

class Program {
    static void Main( string[] args )
    {
        string[] suit = new string[ 4 ] { "S ", "H ", "C ", "D " };

        List<string> deck = new List<string>( 52 );

        for ( int i = 0; i < 4; ++i ) {
            for ( int j = 1; j < 14; ++j ) {
                deck.Add( suit[ i ] + j );
            }
        }

        int n = int.Parse( Console.ReadLine() );

        for ( int i = 0; i < n; ++i ) {
            deck.Remove( Console.ReadLine() );
        }

        for ( int i = 0; i < deck.Count; ++i ) {
            Console.WriteLine( deck[ i ] );
        }
    }
}

Measured memory_bytes: 9256
N=int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
  S=str(input())
  if S == 'AC':
    AC+=1
  elif S == 'WA':
    WA+=1
  elif S == 'TLE':
    TLE+=1
  else:
    RE+=1
print('AC x '+str(AC))
print('WA x '+str(WA))
print('TLE x '+str(TLE))
print('RE x '+str(RE))

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

int main()
{
    int n;
    cin >> n;
    int a[n] = {};
    int dp[n+2] = {};
    for(int i=0; i<n; i++){
        cin >> a[i];
        dp[i] = 4e9;
    }
    dp[0] = 0;
    for(int i=0; i<n; i++){
        dp[i+1] = min(dp[i] + abs(a[i+1]-a[i]), dp[i+1]);
        dp[i+2] = min(dp[i] + abs(a[i+2]-a[i]), dp[i+2]);
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n, k;
  cin >> n >> k;
  vector<ll> l(n);
  REP(i, n) cin >> l[i];
  sort(ALLr(l));
  int ans = 0;
  REP(i, k) ans += l[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class ABC_127_D
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int M = int.Parse(input[1]);

        int[] A = new int[N];
        int[] newA = new int[N];


        string[] input2 = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++)
        {
            A[i] = int.Parse(input2[i]);
            newA[i] = 0;
        }

        List<Pair> list = new List<Pair>();

        for (int i = 0; i < M; i++)
        {
            string[] input3 = Console.ReadLine().Split(' ');
            int b = int.Parse(input3[0]);
            int c = int.Parse(input3[1]);

            list.Add(new Pair(b, c));
        }

        Array.Sort(A);
        list.Sort((a, b) => b.C - a.C);


        int cnt = 0;
        for (int i = 0; i < list.Count && cnt < N; i++)
        {
            Pair p = list[i];
            for (int j = 0; j < p.B && cnt < N; j++)
            {
                newA[cnt] = p.C;
                cnt++;
            }
        }

        for (int i = 0; i < N; i++)
        {
            A[i] = Math.Max(A[i], newA[i]);
        }

        long sum = 0;
        for (int i = 0; i < N; i++)
        {
            sum += A[i];
        }

        Console.WriteLine(sum);
    }

    class Pair
    {
        public Pair(int b, int c)
        {
            B = b;
            C = c;
        }
        public int B;
        public int C;
    }
}

Measured memory_bytes: 31296
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  char a;
  cin >> a;
  if (a - 'A' < 32) cout << 'A' << endl;
  else cout << 'a' << endl;
  return 0;
}

Measured memory_bytes: 3636
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                long N = sc.nextLong(), x = sc.nextLong();
                long[] a = new long[(int)N];
                for (int i = 0; i < N ; i++) {
                        a[i] = sc.nextLong();
                }
                long ans = 1L << 60;
                long[] amemo = new long[(int)N];
                for (int i = 0; i < N; i++) {
                        amemo[i] = 1L << 60;
                }
                for (long i = 0; i < N; i++) {
                        long memo = i * x;
                        for (long j = 0; j < N; j++) {
                                amemo[(int)j] = Math.min(amemo[(int)j], a[(int)((j - i + N) % N)]);
                                memo += amemo[(int)j];
                        }
                        ans = Math.min(ans, memo);
                }
                System.out.println(ans);
        }
}

Measured memory_bytes: 13708
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 1e4 + 100;
int n;
long long x[maxn], y[maxn];
long long Abs(long long x) { return x < 0 ? -x : x;}
int main()
{
    cin>>n;
    int k = 0;
    for(int i = 1; i <= n; i++){
        cin>>x[i]>>y[i];
        long long ax = Abs(x[i]), ay = Abs(y[i]);
        //cout<<ax<<" "<<ay<<endl;
        if(i == 1) k = (ax + ay) & 1;
        else {
            if(k != ((ax + ay)&1)) { cout<<-1<<endl; return 0; }
        }
    }
    if(k == 1){
        cout<<31<<endl;
        for(int i = 30; i >= 0; i--) cout<<(1<<i)<<" "; cout<<endl;
    } else {
        cout<<32<<endl<<1<<" ";
        for(int i = 30; i >= 0; i--) cout<<(1<<i)<<" "; cout<<endl;
        for(int i = 1; i <= n; i++) x[i]--;
    }
    for(int i = 1; i <= n; i++){
        if(k == 0) cout<<"R";
        int nx = 0, ny = 0;
        for(int j = 30; j >= 0; j--){
            int d = (1<<j);
            if(Abs(nx-d-x[i]) + Abs(ny-y[i]) < d) cout<<"L", nx -= d;
            else if(Abs(nx+d-x[i]) + Abs(ny-y[i]) < d) cout<<"R", nx += d;
            else if(Abs(nx-x[i]) + Abs(ny-d-y[i]) < d) cout<<"D", ny -= d;
            else cout<<"U", ny += d;
        }
        //cout<<nx<<" "<<ny<<endl;
        cout<<endl;
    }
    return 0;
}


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

int main()
{
  double n;
  double t, y, x;
  while(cin >> n){
    t = n / 9.8;
    y = 4.9 * t * t;
    x = (y + 5) / 5;
    
    if(x > ceil(x) - 1){
      cout << ceil(x) << endl;
    }
    else{
      cout << x << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  int n, k; cin >> n >> k;
  double res = 0;

  for (int i = 1; i < n + 1; i++) {
    int j = i, count = 0;
    while (j < k) {
      j *= 2;
      ++count;
    }
    res += pow(0.5, (double)count) / (double)n;
  }


  cout << setprecision(13) << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n,a,b;
	cin>>n>>a>>b;
	ll ans=0;
	FOR(i,1,n+1){
		string now=to_string(i);
		int cnt=0;
		rep(j,now.size()){
			cnt+=int(now[j]-'0');
		}
		if(a<=cnt && cnt<=b) ans+=i;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        double sum = 0;
        double ans = 0;

        for(int i=0; i<N; i++){
            sum = sum + 1/(double)sc.nextInt();
        }
        ans =1/sum;
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
/**
 *　　　　　　  　　┏┓　　 　┏┓
 * 　　　　　  　　┏┛┗━━━━━━━┛┗━━━┓
 * 　　　　　  　　┃　　　　　　　┃ 　
 * 　　　　　  　　┃　　　━　　 　┃
 * 　　　　　  　　┃　＞　　　＜　┃
 * 　　　　　  　　┃　　　　　　　┃
 * 　　　　　  　　┃...　⌒　... 　┃
 * 　　　　　　  　┃              ┃
 * 　　　　　　  　┗━┓          ┏━┛
 * 　　　　　　　　　┃          ┃　Code is far away from bug with the animal protecting　　　　　　　　　　
 * 　　　　　　　　　┃          ┃   神兽保佑,代码无bug
 * 　　　　　　　　　┃          ┃　　　　　　　　　　　
 * 　　　　　　　　　┃          ┃  　　　　　　
 * 　　　　　　　　　┃          ┃
 * 　　　　　　　　　┃          ┃　　　　　　　　　　　
 * 　　　　　　　　　┃          ┗━━━┓
 * 　　　　　　　　　┃              ┣┓
 * 　　　　　　　　　┃              ┏┛
 * 　　　　　　　　　┗┓┓┏━━━━━━━━┳┓┏┛
 * 　　　　　　　　　　┃┫┫       ┃┫┫
 * 　　　　　　　　　　┗┻┛       ┗┻┛
 */ 
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define inf 1000000000
#define maxn 100000+5
#define maxm 100005
#define eps 1e-10
#define for0(i,maxn) for(int i=1;i<=(maxn);++i)
#define for1(i,maxn) for(int i=1;i<=(maxn);++i)
#define for2(i,x,y) for(int i=(x);i<=(y);++i)
#define for3(i,x,y) for(int i=(x);i>=(y);--i)
#define mod 1000000007
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=10*x+ch-'0';ch=getchar();}
    return x*f;
}
int main()
{
    string s;
    cin>>s;
    int l=s.length();
    if(s[0]!='A') puts("WA");
    else
    {
        int ansc=0;
        for(int i=2;i<l-1;++i) 
        {
            if(s[i]=='C') ansc++;
        }
        if(ansc!=1) puts("WA");
        else
        {
            int flag=1;
            for(int i=0;i<l;++i)
            {
                if(s[i]!='A'&&s[i]!='C'&&s[i]>'A'&&s[i]<='Z') flag=0; 
            }
            if(!flag) puts("WA");
            else puts("AC");
        }
        
    }
 }


Measured memory_bytes: 256
#!/usr/bin/env python3


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    N = int(input())
    A = [int(_) for _ in input().split()]
    ans="APPROVED"
    for a in A:
        if a % 2 == 0 and (a % 3 != 0 and a % 5 != 0):
            ans="DENIED"
    print(ans)

if __name__ == '__main__':
    main()

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

typedef long long int ll;

int main() {
    ll  N, L;
    cin >> N >> L;
    vector<ll> v(N);
    for (auto& i : v) cin >> i;
    bool ans = false;
    int pos;
    for (int i = 0; i < N-1; i++) {
        if (v[i]+v[i+1] >= L) ans = true, pos = i;
    }

    if (ans) cout << "Possible" << endl;
    else cout << "Impossible" << endl;

    if (ans) {
        for (int i = 0; i < pos; i++) {
            cout << i+1 << endl;
        }
        for (int i = N-2; i > pos; i--) {
            cout << i+1 << endl;
        }
        cout << pos+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int const INF = 1001001001;


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

int n;
cin >> n;
vi D(n);
rep(i,n) cin >> D[i];
int m;
cin >> m;
vi T(m);
rep(i,m) cin >> T[i];

unordered_map<int , int> mp1, mp2;
rep(i,n) mp1[D[i]]++;
rep(i,m) mp2[T[i]]++;

for(auto x : mp2){
    if(mp1[x.first] < x.second) {
        cout << "NO" << endl;
        return 0;
    }
}

cout << "YES" << endl;

return 0;
}

Measured memory_bytes: 18376
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int mod = 1e9 + 7;
const int maxn = 3000 + 5;

ll qpow(ll x, ll n) {
    ll r = 1;
    while (n > 0) {
        if (n & 1) r = r * x % mod;
        n >>= 1; x = x * x % mod;
    }
    return r;
}
ll inv(ll x) { return qpow(x, mod - 2); }

int n, q, a[maxn];
ll f[maxn][maxn];

int main() {
    scanf("%d%d", &n, &q);
    for (int i = 1; i <= n; i++) scanf("%d", a + i);
    for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (a[i] > a[j]) f[i][j] = 1;
    ll inv2 = inv(2);
    for (int i = 1, x, y; i <= q; i++) {
        scanf("%d%d", &x, &y);
        f[x][y] = f[y][x] = (f[x][y] + f[y][x]) * inv2 % mod;
        for (int j = 1; j <= n; j++) if (j != x && j != y) {
            f[x][j] = f[y][j] = (f[x][j] + f[y][j]) * inv2 % mod;
            f[j][x] = f[j][y] = (f[j][x] + f[j][y]) * inv2 % mod;
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) {
        ans += f[i][j]; if (ans >= mod) ans -= mod;
    }
    cout << ans * qpow(2, q) % mod << endl;
    return 0;
}

Measured memory_bytes: 70656
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <math.h>
#include <iomanip>
#include <queue>
#include <map>
#include <list>
#include <set>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX 50
#define LARGENUM 1000000007
#define INF 9223372036854775807
#define ull unsigned long long 
typedef pair <int, int> P;

int main(){
    int N, Q, A, B, C;
    ull S = 0;
    cin >> N;
    map<int, int> M;
    map<int, int>::iterator it, it2;
    rep(i, N){
        cin >> A;
        it = M.find(A);
        if (it == M.end()){
            M.insert(P(A, 1));
        }
        else it->second += 1;
    }
    for (auto it = M.begin(); it != M.end(); it++){
            S += it->first * it->second;
        }
    cin >> Q;
    rep(i, Q){
        cin >> B >> C;
        it = M.find(B);
        if (it != M.end()){
            it2 = M.find(C);
            if (it2 == M.end()){
                M.insert(P(C, it->second));
            }
            else {
                it2->second += it->second;
            }
            S += (C - it->first) * it->second;
            M.erase(it);
        }
        cout << S << endl;
    }
    return 0;
}


Measured memory_bytes: 6008
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void) {
	
	int N1;
	cin >> N1;

	int* A = new int[N1];

	for (int i = 0; i < N1; i++) {
		cin >> A[i];
	}
	int N2;
	cin >> N2;

	int* B = new int[N2];

	for (int i = 0; i < N2; i++) {
		cin >> B[i];
	}
	int c = 0;
	for (int i = 0; i < N2; i++) {
		for (int j = 0; j < N1; j++) {
			if (B[i] == A[j]){
				c++;
				break;
			}
		}
	}

	cout << c <<"\n";
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=100010;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,a[maxn],b[maxn],len,at,sum,ans;
bool h0,h1;
int main(){
	n=read();
	FOR(i,1,n){
		a[i]=read();
		if(a[i]>0) h0=true;
		if(a[i]<0) h1=true;
	}
	if(h0 && h1){
		FOR(i,1,n) sum+=abs(a[i]);
		printf("%d\n",sum);
		FOR(i,1,n) if(a[i]>0) b[++len]=a[i];
		at=len+1;
		FOR(i,1,n) if(a[i]<=0) b[++len]=a[i];
	}
	else if(h0){
		int mnid=0;
		FOR(i,1,n) if(!mnid || a[i]<a[mnid]) mnid=i;
		FOR(i,1,n) if(i!=mnid) b[++len]=a[i],sum+=a[i];
		at=len+1;
		b[++len]=a[mnid];
		sum-=a[mnid];
		printf("%d\n",sum);
	}
	else if(h1){
		int mxid=0;
		FOR(i,1,n) if(!mxid || a[i]>a[mxid]) mxid=i;
		sum=b[++len]=a[mxid];
		at=len+1;
		FOR(i,1,n) if(i!=mxid) b[++len]=a[i],sum-=a[i];
		printf("%d\n",sum);
	}
	else{
		puts("0");
		FOR(i,1,n-1) puts("0 0");
		return 0;
	}
	if(at==2){
		int s=b[1];
		FOR(i,2,n) printf("%d %d\n",s,b[i]),s-=b[i];
	}
	else{
		int s=b[at]-b[1];
		printf("%d %d\n",b[at],b[1]);
		FOR(i,2,at-2) printf("%d %d\n",s,b[i]),s-=b[i];
		printf("%d %d\n",b[at-1],s);
		s=b[at-1]-s;
		FOR(i,at+1,n) printf("%d %d\n",s,b[i]),s-=b[i];
	}
}

Measured memory_bytes: 2688
#include <iostream>
#include <stdint.h>

int main(){
  int64_t N,X;
  std::cin>>N>>X;
  int64_t cost=N;
  int64_t a=X,b=N-X;
  if(a>b) std::swap(a,b);
  while(b%a){
    cost+=b/a*2*a;
    b%=a;
    std::swap(a,b);
  }
  cost+=2*(b-a)+a;
  std::cout<<cost<<std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, s, n) for(int i = s; i < n; i++)
#define repr(i, n) for(int i = n-1; i >= 0; i--)
using namespace std;

int main(){
  int n, m, Q;
  cin >> n >> m >> Q;
  vector<vector<int>> sum(n+1, vector<int>(n+1, 0));
  int l, r;
  rep(i, m){
    cin >> l >> r;
    sum[l][r]++;
  }
  rep(i, n)rep2(j, i, n) sum[i+1][j+1] += sum[i+1][j];
  repr(i, n)rep2(j, i, n) sum[i+1][j+1] += sum[(i+2)%(n+1)][j+1];
  
  int p, q;
  rep(i, Q){
    cin >> p >> q;
    cout << sum[p][q] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int h, w, D; cin >> h >> w >> D;
    int n = h * w;
    vi x(n);
    vi y(n);

    rep(i, h){
        rep(j, w){
            int A; cin >> A; A--;
            x[A] = j;
            y[A] = i;
        }
    }

    vi memo(n + D + 1);
    rrep(i, n - D){
        int ni = i + D;
        memo[i] = memo[ni] + abs(x[ni] - x[i]) + abs(y[ni] - y[i]);
    }

    int Q; cin >> Q;
    rep(_, Q){
        int l, r; cin >> l >> r;
        l--, r--;
        cout << memo[l] - memo[r] << endl;
    }

    return 0;
}


Measured memory_bytes: 2176
a,b=map(int,input().split())
if b < 0:
    if (b-a+1) % 2 == 0:
        ans = 'Positive'
    elif (b-a+1) % 2 == 1:
        ans = 'Negative'
elif a > 0:
 ans='Positive'
else:
 ans='Zero'
  
print(ans)

Measured memory_bytes: 2940
_500_num = gets.to_i
_100_num = gets.to_i
_50_num = gets.to_i
total = gets.to_i

count = 0

(0.._500_num).each do |i|
  (0.._100_num).each do |j|
    (0.._50_num).each do |k|
  	  if 500 * i + 100 * j + 50 * k == total
        count += 1
      end
    end
  end
end
  
p count




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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES\n")
#define Yes puts("Yes\n")
#define NO  puts("NO\n")
#define No  puts("No\n")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }




using Graph = vector<vector<int> >;

// トポロジカルソートする
void rec(int v, const Graph& G, vector<bool>& seen, vector<int>& order) {
	seen[v] = true;
	for (auto next : G[v]) {
		if (seen[next]) continue; // 既に訪問済みなら探索しない
		rec(next, G, seen, order);
	}
	order.push_back(v);
}

int N;
int v(int a, int b) {
	if (a > b) swap(a, b);
	return a * N + b;
}

P ab(int v) {
	return P(v / N, v % N);
}

signed main() {

	cin >> N;

	int V = N * (N - 1);
	Graph G(V);

	int a[1234][1234-1];
	rep(i, N) {
		rep(j, N - 1) {
			cin >> a[i][j];
			a[i][j]--;
		}
		rep(j, N - 1) {
			if (j != 0) {
				G[v(i, a[i][j - 1])].push_back(v(i, a[i][j]));
			}
		}
	}

	// 探索
	vector<bool> seen(V, 0); // 初期状態では全ノードが未訪問
	vector<int> order; // トポロジカルソート順
	for (int v = 0; v < V; ++v) {
		P p = ab(v);
		if (p.first >= p.second) continue;

		if (seen[v]) continue; // 既に訪問済みなら探索しない
		rec(v, G, seen, order);
	}
	reverse(order.begin(), order.end()); // 逆順に

/*
	cerr << endl;
	for (int v : order) {
		P p = ab(v);
		if (p.first >= p.second) continue;
		cerr << p.first+1 << " " << p.second+1 << endl;
	}
	cerr << endl;
*/

	int ans = 0;
	vector<int> day(V);
	rep(i, V) day[i] = 0;

	int daytotal[1001][1001] = { 0 };

	for (int v : order) {
		P p = ab(v);
		if (p.first >= p.second) continue;
		int man1 = p.first;
		int man2 = p.second;

		int daymax = max(day[man1], day[man2]);
		day[man1] = daymax + 1;
		day[man2] = daymax + 1;

		ans = max(ans, daymax + 1);

		// man1とman2がdaymax+1にやる
		daytotal[man1][man2] = daymax + 1;
		daytotal[man2][man1] = daymax + 1;
	}
	// 入力を満たしているかチェック
	rep(i, N) {
		rep(j, N - 1) {
			if (j != 0) {
				if (daytotal[i][a[i][j - 1]] >= daytotal[i][a[i][j]]) {
					cout << -1 << endl;
					return 0;
				}
			}
		}
	}


	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 70508
#include <iostream>
#include <vector>

int main() {
	int i, x;
	std::cin >> i;
	std::vector<int> ls(i);

	while (i != 0 && std::cin >> x) {
		ls[ls.size() - i] = x;
		i--;
	}
	for (int k = 1; k < ls.size(); k++) {
		int key = ls[k], j = k - 1;
		for (int i = 0; i < ls.size(); i++)
			i == ls.size() - 1 ?
			std::cout << ls[i] << "\n" :
			std::cout << ls[i] << " ";
		while (j >= 0 && ls[j] > key) {
			ls[j + 1] = ls[j];
			j--;
		}
		ls[j + 1] = key;
	}
	for (int i = 0; i < ls.size(); i++)
		i == ls.size() - 1 ?
		std::cout << ls[i] << "\n" :
		std::cout << ls[i] << " ";
	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    vector<ll> A(N), B(N);
    rep(i,N) {
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    B = A;
    deque<ll> Q;
    int i = 0, j = N-1;
    Q.push_front(A[i++]);
    while (i<=j) {
        if (i <= j) Q.push_front(A[j--]);
        if (i <= j) Q.push_back(A[j--]);
        if (i <= j) Q.push_front(A[i++]);
        if (i <= j) Q.push_back(A[i++]);
    }
    rep(i,N) {A[i] = Q.front(); Q.pop_front();}
    Q.clear();
    i = 0; j = N-1;
    Q.push_front(B[j--]);
    while (i<=j) {
        if (i <= j) Q.push_front(B[i++]);
        if (i <= j) Q.push_back(B[i++]);
        if (i <= j) Q.push_front(B[j--]);
        if (i <= j) Q.push_back(B[j--]);
    }
    rep(i,N) {B[i] = Q.front(); Q.pop_front();}
    ll sum = 0, su2 = 0;
    rep(i,N-1) {
        sum += abs(A[i+1] - A[i]); 
    }
    rep(i,N-1) {
        su2 += abs(B[i+1] - B[i]);
    }
    cout << max(sum,su2) << endl;
}


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

int main() {
    ios_base::sync_with_stdio(false);	
    cin.tie(0);
	int k, ans[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	cin >> k;
	cout << ans[k - 1] << "\n";
	return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever while (true)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
using namespace std;
// clang-format on

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(const int &s = 0, const int &d = 0, const Weight &w = 0) : src(s), dst(d), weight(w) {}
};

using Edges = std::vector<Edge>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

class Graph {
  std::vector<Edges> g;

public:
  Graph(const int &size = 0) : g(size) {}

  void addArc(const int &src, const int &dst, const Weight &w = 1) { g[src].emplace_back(src, dst, w); }

  void addEdge(const int &node1, const int &node2, const Weight &w = 1) {
    addArc(node1, node2, w);
    addArc(node2, node1, w);
  }

  const Edges &operator[](const int &i) const { return g[i]; }
};

main {
  int n, m;
  cin >> n >> m;
  Graph g(n);
  while (m--) {
    int a, b;
    cin >> a >> b;
    g.addArc(--a, --b);
  }
  for (auto &e : g[0]) {
    for (auto &f : g[e.dst]) {
      if (f.dst == n - 1) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
}


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

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

    std::vector<long long> H(N);
    for (int i = 0; i < N; i++)
        std::cin >> H[i];

    // ソート
    std::sort(H.begin(), H.end(), std::greater<long long>());

    long long cnt = 0;
    for (int i = 0; i < N; i++)
    {
        if (K > 0)
        {
            K--;
        }
        else
        {
            cnt += H[i];
        }
    }
    std::cout << cnt << std::endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    if(a == b && b != c) {
        out("Yes");
    }
    else if(b == c && c != a) {
        out("Yes");
    }
    else if(c == a && a != b) {
        out("Yes");
    }
    else {
        out("No");
    }

    re0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,l,r;
  cin >> a >> b >> c >> d;
  l=a+b;
  r=c+d;
  if(l>r){
    cout << "Left" << endl;
  }
  else if(l==r){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 3636
import scala.collection.mutable.ListBuffer
import scala.io.StdIn

object Main extends App {
  var continue = true
  var result = ListBuffer.empty[String]
  while(continue){
    val Array(x, y) = StdIn.readLine().trim.split(' ').map(_.toInt)
    continue = if(x == 0 && y == 0) {
      false
    } else {
      result += (if(x > y) f"$y $x%n" else f"$x $y%n")
      true
    }
  }
  
  print(result.map(p => p).mkString(""))
}


Measured memory_bytes: 52476
fn main() {
    let a: usize = read();
    let b: usize = read();
    if a % 2 == 1 && b % 2 == 1 {
        println!("Odd");
    } else {
        println!("Even");
    }
}

// 以下関数

use std::io::*;
use std::str::FromStr;
pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub const MOD: u64 = 10e9 as u64 + 7;

pub fn is_prime(n: i32) -> bool {
    if n < 2 {
        return false;
    } else if n == 2 {
        return true;
    }
    let mut i = 2;
    while i * i < n {
        if n % i == 0 {
            return false;
        } else {
            i += 1;
            continue;
        }
    }
    true
}

pub fn lcm(mut n: i32, mut m: i32) -> i32 {
    n = if n > m { m } else { n };
    m = if n > m { n } else { m };
    let mut i = n;
    while i % m != 0 {
        i += n;
    }
    i
}


Measured memory_bytes: 4352
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

import bisect
N = int(readline())
A = sorted(list(map(int,readline().rstrip().split())))
B = sorted(list(map(int,readline().rstrip().split())))
C = sorted(list(map(int,readline().rstrip().split())))
cnt = 0
for i in range(N):
    j = bisect.bisect_left(A,B[i])
    k = bisect.bisect_right(C,B[i])
    cnt += j*(N-k)
print(cnt)

Measured memory_bytes: 22720
c1 = list(map(int,input().split()))
c2 = list(map(int,input().split()))
c3 = list(map(int,input().split()))

if (c1[2]-c1[1]== c2[2]-c2[1] and c2[2]-c2[1]== c3[2]-c3[1] and c2[1]-c2[0]== c3[1]-c3[0] and c2[1]-c2[0]== c1[1]-c1[0]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61920
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        string s;
        getline(cin, s);
        if(s == "0")
            return 0;

        istringstream iss(s);
        int ret = 0;
        int num1 = 0;
        for(;;){
            int a;
            if(!(iss >> a))
                break;
            if(a > 10)
                a = 10;
            if(a == 1){
                ++ num1;
                a = 11;
            }
            ret += a;
            while(ret > 21 && num1 > 0){
                ret -= 10;
                -- num1;
            }
        }

        if(ret > 21)
            ret = 0;
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);

		char[] data = sc.nextLine().toCharArray();

//		System.out.println(data);
//		System.out.println(data[0]);
//		System.out.println(data[1]);
//		System.out.println(data[2]);
//		System.out.println(data[3]);
//		System.out.println(data[4]);

		for (int i=0; i < data.length; i++) {
			if ( Character.isUpperCase(data[i]) ) {
				data[i] = Character.toLowerCase(data[i]);
			} else if ( Character.isLowerCase(data[i]) ) {
				data[i] = Character.toUpperCase(data[i]);
			}
		}

		System.out.println(data);
	}

}

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

using namespace std;

const int MAXN = 410;

long long dp[MAXN][MAXN];
long long sp[MAXN];
int main() {
    #ifdef BLAT
        freopen("input", "r", stdin);
    #endif

    int n;
    cin >> n;

    for(int i = 1; i <= n; ++i) {
    	int x;
    	cin >> x;
    	sp[i] = sp[i-1] + x;
    } 
   	for(int i = 1; i <= n; ++i) for(int j = 1; j <= n; ++j) dp[i][j] = 1e18*(i != j);
    for(int len = 2; len <= n; ++len) {
    	for(int i = 1, j = i + len - 1; j <= n; ++i, ++j) {
    		for(int k = i; k < j; ++k) {
    			dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + sp[j] - sp[i-1]);
    		}
    	}
    }

    cout << dp[1][n] << '\n';
}   	

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

ll mpow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a;
    a=a*a;
    n>>=1;
  }
  return res;
}

int main() {
  ll X;
  cin >> X;
  vector<ll> k;
  ll max_a = 1e18;
  int m = 0;
  while (1) {
    ll a = mpow(m, 5);
    if(a==X){
      cout << m <<" "<< 0 << endl;
      return 0;
    }
    k.push_back(a);
    if (k[m] > max_a) {
      break;
    }
    m++;
  }
  for (int i = 0; i < (int)k.size(); i++) {
    for (int j = 0; j < (int)k.size(); j++) {
      if (k[i] - k[j] == X) {
        cout << i << " " << j << endl;
        return 0;
      } else if (k[i] + k[j] == X) {
        cout << i << " " << (j*-1) << endl;
        return 0;
      }
    }
  }

    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>

#include <algorithm>

using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
const ll INF = 1ll << 60;

ll MOD = 1e9 + 7;

int main()
{

    string s, t;
    cin >> s;
    cin >> t;

    int ans = 0;

    REP(i, s.length())
    if (s[i] == t[i])
        ans++;

    cout << ans << endl;

    return 0;
}

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

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

	int length = k;
	int ans = 1;
	while (length < n) {
		length += k - 1;
		ans++;
	}
	cout << ans << endl;










	return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline


N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))

A.sort()
l = -1
r = N
while r - l > 1:
    m = (l+r)//2
    if m+1+P > N:
        r = m
        continue
    if V <= m+P:
        if A[m]+M >= A[-P]:
            r = m
        else:
            l = m
        continue
    if A[m]+M < A[-P]:
        l = m
        continue
    limit = A[m] + M
    can = 0
    for i in range(m+1, N-P+1):
        can += limit-A[i]
    if can >= (V-P-m)*M:
        r = m
    else:
        l = m

print(N-r)

Measured memory_bytes: 58736
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
bool toll[100]= {false};
int main() {
	int n,m,x,val;
	cin>>n>>m>>x;
	for(int i=0;i<m;i++){
		cin>>val;
		toll[val] = true;
	}
	int minCost = INT_MAX, cost=0;
	for(int i=x+1;i<n;i++){
		if(toll[i]) cost++;
	}
	minCost = min(minCost,cost), cost = 0;
	for(int i=x-1;i>0;i--){
		if(toll[i]) cost++;
	}
	minCost = min(minCost,cost);
	
	printf("%d\n",minCost);
	return 0;
}

Measured memory_bytes: 256
from collections import deque

S = deque(input())
Q = int(input())
reverse_mode = False #反転毎に全体を反転しているとTLEする
reversed_count = 0
 
for i in range(Q):
    query = [str(e) for e in input().split()]
    if len(query)==1:
        reversed_count += 1
        #反転のモードを切り替える
        if reverse_mode == False:
            reverse_mode = True
        elif reverse_mode == True:
            reverse_mode = False
    
    else:
        if reverse_mode == False:
            if query[1]=="1":
            #先頭に追加
                S.appendleft(query[2])
            else:
            #末尾に追加
                S.append(query[2])
        elif reverse_mode == True:
            if query[1]=="1":
            #反転した先頭に追加＝末尾に追加
                S.append(query[2])
            else:
            #反転した末尾に追加＝先頭に追加
                S.appendleft(query[2])

#終了時に反転回数に応じて逆転orそのままにする
if reversed_count%2 != 0:
    S.reverse()
    
#print(S)
print(''.join(map(str,S)))

Measured memory_bytes: 8612
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

ll factorial(ll a, ll b) {
    ll ret = 1;
    while(1) {
        if (b == 0) break;
        ret = ret * a % mod;
        --a;
        --b;
    }
    return ret;
}

ll expo(ll a, ll b) {
    ll ret = 1;
    while(1) {
        if (b == 0) break;
        if (b&1LL) ret = ret * a % mod;
        a = a * a % mod;
        b >>= 1LL;
    }
    return ret;
}

ll inv(ll a) {
    return expo(a, mod-2);
}

ll comb(ll a, ll b) {
    //cout << factorial(a, b) << " " << factorial(b, b) << " " << inv(factorial(b,b)) << endl;
    return factorial(a, b) * inv(factorial(b,b)) % mod;
}

int main() {
    ll n, k;
    cin >> n >> k;
    for (ll i = 1; i <= k; ++i) {
        //cout << n-k+1 << " " << i << endl;
        if (i == 1 || i == k) {
            cout << comb(n-k+1, i) << endl;
        }
        else {
            cout << comb(n-k+1, i) * comb(k-1, i-1) % mod << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int x;
  int y;
  int r;

  scanf("%d",&x);
  scanf("%d",&y);
  while(y != 0){
    r = x % y;
    x = y;
    y = r;
  }
  printf("%d\n",x);
  return 0;
}



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

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007
#define EPS ((ld)(1e-9))

#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, x) for (int i = 1, _##i = (x); i <= _##i; i++)
#define repr(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)

#define L(x) ((x)*2)
#define R(x) ((x)*2+1)

using namespace std;

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

template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    os << pai.first << ' ' << pai.second;
	return os;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    rep(i, sz(v)) cout << v[i] << ' ';
    return os;
}

template<typename T, typename V>
istream &operator>>(istream &is, pair<T, V> &pai) {
	is >> pai.first >> pai.second;
	return is;
}

int N, M;
int par[100001];
int edges[100001];
int maxv[100001];
ll sumv[100001];

pair<int, pii> edge[100001];

int find(int x) {
	return x == par[x] ? x : par[x] = find(par[x]);
}

int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

	cin >> N >> M;
	repp(i, N) {
		cin >> sumv[i];
		par[i] = i;
	}
	rep(i, M) {
		int a, b, c; cin >> a >> b >> c;
		edge[i] = mp(c, mp(a, b));
	}


	sort(edge, edge+M);
	int res = 0;

	rep(i, M) {
		int g1 = find(edge[i].se.fi);
		int g2 = find(edge[i].se.se);
		int we = edge[i].fi;

		if (g1 == g2) {
			if (sumv[g1] >= we) res++;
			else edges[g1]++;
		} else {
			par[g2] = g1;
			maxv[g1] = we;
			edges[g1] += edges[g2]+1;
			sumv[g1] += sumv[g2];
			if (sumv[g1] >= maxv[g1]) {
				res += edges[g1];
				edges[g1] = 0;
			}
		}
	}

	cout << M-res;
}

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

using namespace std;
const int Mod = 1e9 + 7;

int n;
char s[200005];
int sum[30];

inline long long fsp(long long x, long long p) {
    long long res = 1;
    while (p) {
        if (p & 1) (res *= x) %= Mod;
        (x *= x) %= Mod;
        p >>= 1;
    }
    return res;
}

int main() {
    cin >> n;
    scanf("%s", s + 1);
    long long ans = 1;
    for (int i = 1; i <= n; ++i)
        sum[s[i] - 'a']++;
    for (int i = 0; i < 26; ++i)
        (ans *= sum[i] + 1) %= Mod;
    cout << ans - 1 << endl;
    return 0;
}


Measured memory_bytes: 384
//package hiougyf;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		 Scanner sc =new Scanner(System.in);
		 int t=sc.nextInt();
		   int ans=t+(t*t)+(t*t*t);
		   System.out.println(ans);
		}
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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(a>b){a=b;return 1;}return 0;}
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

signed main(){

  string s;
  cin>>s;

  string s1,s2;
  s1 = s.substr(0,s.size()/2);
  s2 = s.substr(s.size()/2+(s.size()&1?1:0));
  reverse(s2.begin(),s2.end());

  int ans=0;
  rep(i,s1.size())if(s1[i]!=s2[i])ans++;
  cout<<(ans)<<endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  char s[101],p[101];
  int i,j,sn=0,pn=0,t;

  scanf("%s %s",s,p);

//文字数カウント
  while(s[sn] != '\0') sn++;
  while(p[pn] != '\0') pn++;

  for(i=0;i<sn;i++){
    t=1;
    for(j=0;j<pn;j++)
      if(s[(i+j)%sn] != p[j]) t=0;
    if(t) break;
  }

  if( t )
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

int main() {
  int N; cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];

  vector<int> ans(N, 0);
  int cnt = 0;

  for (int k = N-1; k >= 0; k--) {
    int i = k + 1;
    int mul = N / i;
    if (mul == 1) {
      ans[k] = a[k];
      if (a[k] == 1) cnt++;
      continue;
    }

    int tmp = 0;
    while (mul > 1) {
      tmp += ans[i*mul-1];
      mul--;
    }
    if (tmp % 2 != a[k]) {
      ans[k] = 1;
      cnt++;
    }
  }

  cout << cnt << endl;
  rep(i, N) {
    if (ans[i] == 1) {
      cout << i + 1 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main(){
	string s;
	cin>>s;
	int n= s.size();
	int prev[n] = {0};
	for(int i=0;i<n;i++){
		if(s[i] == 'A' || s[i] == 'T'|| s[i] == 'C' || s[i] == 'G'){
			prev[i] = (i>0 ? prev[i-1]:0) + 1;  
		}
		else{
			prev[i] = 0; 
		}
	}
	cout<<*max_element(prev,prev+n);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll i,j,k,l,m,n,o,p,q,r,t;
    ll ans=0;
    string s;
    char a;
    cin>>a;
    m=a;
    if(m>=65&&m<=91)
    cout<<'A'<<endl;
    else 
    cout<<'a'<<endl;
    return 0;
}

Measured memory_bytes: 3620