akhauriyash/Code-Regression huggingface dataset:
mod = 10 ** 9 + 7

f = [0 for _ in range(200000)]
f[0] = 1
for i in range(1, 200000):
    f[i] = f[i - 1] * i % mod
inv = [pow(f[i], mod - 2, mod) for i in range(200000)]


def C(n, m):
    if n < m or m < 0: return 0
    return f[n] * inv[m] * inv[n - m] % mod

n = int(input())
a = list(map(lambda x: int(x) - 1, input().split()))
pos = [[] for _ in range(n)]

for idx, x in enumerate(a):
    pos[x].append(idx)

for _ in pos:
    if len(_) == 2:
        l, r = _

for i in range(1, n + 2):
    print(((C(n + 1, i) - C(n + l - r, i - 1)) % mod + mod) % mod)



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

int main() {
  int N,L;cin>>N>>L;
  int ideal_pie;
  for(int i=0;i<N;i++) ideal_pie +=L+i;//L+i-1+1
  vector<int> A(N);
  for(int i=0;i<N;i++) A.at(i)=ideal_pie-(L+i);
  vector<int> B(N);
  for(int i=0;i<N;i++) B.at(i)=abs(ideal_pie-A.at(i));
  int min_B=B.at(0);
  int Bx=0;
  for(int i=1;i<N;i++){
    if(min_B>B.at(i)){
      min_B=B.at(i);
      Bx=i;
    }
  }
  cout<<A.at(Bx)<<endl;
      
}


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

struct Drink {
	llong num;
	llong price;

	bool operator<(const Drink & another) const {
		return price < another.price;
	}
};

void solve() {
	int N, M; cin >> N >> M;
	vector<Drink> drink(N);
	rep(i, N) scanf("%lld%lld", &drink[i].price, &drink[i].num);
	
	sort(drink.begin(), drink.end());

	llong res = 0;
	rep(i, N) {
		if (M <= 0) break;
		if (drink[i].num > M) {
			res += M * drink[i].price;
		}
		else if (drink[i].num <= M) {
			res += drink[i].num * drink[i].price;
		}
		M -= drink[i].num;
	}
	cout << res << endl;
}

int main(void) {
	solve();

	return 0;
}

Measured memory_bytes: 1792
L, R = map(int, input().split())

l = L % 2019
r = R % 2019

ans = 2019*2019

if L // 2019 == R // 2019:
    # print(l,r)
    for i in range(l, r):
        # print('i', i)
        for j in range(l+1,r+1):
            # print('j', j)

            ans = min(ans, (i*j)%2019)
else:
    ans = 0

print(ans)


Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define N_MAX 1000
#define M_MAX 200000
#define INF 10000000
#define MOD 1000000007
#define SMAP(a, b) ((a)!=(b))&&((a)^=((b)^=((a)^= (b))))

typedef unsigned long long ull;
typedef   signed long long dll;

int n, m;
int i, j, k;
int a;

bool h[N_MAX];

typedef struct {
	int in;
	int out;
} twoway;

void deb(){
	return;
}

void fill(int x){
	for (k = 2; x * k <= n; k++) {
		h[x * k - 1] = 0;
	}
	return;
}

int kou(int x){
	int y = n;
	int u = 1;
	while (y /= x) {
		u += y;
	}
	return u;
}

void solve(){
	ull result = 1;
	int prev;

	for (i = 0; i < n; i++) h[i] = !!i;

	for (i = 1; i < n; i++) {
		if (!h[i]) continue;

		prev = kou(i + 1);
		result *= (ull)prev;
		result %= MOD;

		fill(i + 1);
	}

	printf("%d\n", result);
	return;
}

int main (void) {
	scanf("%d", &n);

	solve();
	return 0;
}




Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdint>
#include <utility>
#include <tuple>
#include <map>    
#include <queue> 
#include <set>  
#include <stack> 
#include <deque>  
#include <unordered_map> 
#include <unordered_set> 
#include <bitset>

using namespace std;

int main() {
	int X, A;
	cin >> X >> A;

	if (X < A) {
		cout << "0" << endl;
	}
	else {
		cout << "10" << endl;
	}
}

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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int r, D, x;

signed main() {
    cin >> r >> D >> x;
    for (int i = 1; i <= 10; i++) {
        x = x * r - D;
        cout << x << endl;
    }
}

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

int main(void)
{	
	int sum=0;
	int l, i;
	char s[1001];

	while(1){
		scanf("%s", s);
		if(s[0] == '0')
			break;
		l = strlen(s);
		for(i=0; i<l; i++){
			sum += s[i] - '0';
		}
		printf("%d\n", sum);
		sum = 0;
	}
	return 0;
}

Measured memory_bytes: 536
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n), minimum_cost(n);
    for(int i = 0; i < n; i++)
        cin >> v[i];
    minimum_cost[0] = 0;
    minimum_cost[1] = abs(v[1] - v[0]);
    for(int i = 2; i < n; i++)
        minimum_cost[i] = min(minimum_cost[i - 1] + abs(v[i] - v[i - 1]), minimum_cost[i - 2] + abs(v[i] - v[i - 2]));
                                ///if the frog jumps from i - 1 stone        if the frog jumps from i - 2 stone
    cout << minimum_cost[n - 1];

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> A(N, vector<int>(2));

  for (int i = 0; i < N; i++) {
    cin >> A.at(i).at(0);
    A.at(i).at(1) = i + 1; 
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < N; i++) {
    if (i == N - 1) {
      cout << A.at(i).at(1) << endl;
    }
    else {
      cout << A.at(i).at(1) << " ";
    }
  }


}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 1e3 + 12;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
char a[N][N];
int d[N][N];
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int n, m, xm, ym, tox, toy;

bool can (int x, int y){
    return x >= 1 && x <= n && y >= 1 && y <= m && a[x][y] != '#';
}
bool canMag(int sx, int sy, int x, int y) {
    if(sx == x && sy == y)
        return false;
    if(!can(x, y))
        return 0;
    int dx = abs(sx - x);
    int dy = abs(sy - y);
    // 11 12 13 14 15
    // 21 22 23 24 25
    // 31 32 33 34 35
    // 41 42 43 44 45
    // 51 52 53 54 55
    if(dx >= 0 && dx < 3 && dy >= 0 && dy < 3) {
        return 1;
    }return 0;
}
void solve(){
    cin >> n >> m >> xm >> ym >> tox >> toy;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            cin >> a[i][j],
            d[i][j] = INF;
    

    set <pair <int, pair <int,int> >  > q;
    q.ins({0, {xm, ym}});
    d[xm][ym] = 0;
    while(q.size()) {
        auto it = q.begin();
        
        int cx = it->Y.X;
        int cy = it->Y.Y;
        q.erase(it);
        // cout << cx << " " << cy << '\n';
        for(int i = 0; i < 4; ++i) {
            int nx = cx + dx[i];
            int ny = cy + dy[i];
            // cout << nx << ' ' << ny << ' ' << can(nx, ny) << '\n';
            if(can(nx, ny) && d[nx][ny] > d[cx][cy]){
                q.erase({d[nx][ny], {nx, ny}});
                d[nx][ny] = d[cx][cy];
                q.ins({d[nx][ny], {nx, ny}});
            }
        }
        for(int nx = cx - 5; nx <= cx + 5; ++nx) {
            for(int ny = cy - 5; ny <= cy + 5; ++ny) {
                if(canMag(cx, cy, nx, ny) && d[nx][ny] > d[cx][cy] + 1) {
                    q.erase({d[nx][ny], {nx, ny}});
                    d[nx][ny] = d[cx][cy] + 1;
                    q.ins({d[nx][ny], {nx, ny}});
                }
            }
        }
    }
    cout << (d[tox][toy] == INF ? -1 : d[tox][toy]);
}
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

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

using namespace std;

//ユークリッドの互除法で最大公約数を求める
long gcd(long inA, long inB) {
	long lA = max(inA, inB);
	long lB = min(inA, inB);
	if (lB == 0) {
		return lA;
	}
	else {
		return gcd(lB, lA % lB); 
	}
}

//ユークリッドの互除法で最大公約数を求める
long gcd(vector<long>& v) {
	//配列サイズが1の時は1を返して終了．
	if (long(v.size()) == 1) return(v[0]);
	//配列サイズが2以上のとき，gcd(a,b,c)=gcd(gcd(a,b),c)を用いて計算
	long ans = gcd(v[0],v[1]);
	for (long i = 2; i < long(v.size()); i++) {
		ans = gcd(ans, v[i]);
	}
	return ans;
}


int main() {
	//入力
	long N, X;
	cin >> N >> X;
	vector<long> x(N);
	for (long i = 0; i < N; i++) cin >> x[i];
	//スタート位置からの距離の最大公約数を求めればOK
	vector<long> dist(N);
	for (long i = 0; i < N; i++) dist[i] = abs(x[i]-X);
	long D = gcd(dist);
	cout << D;
	return 0;
}

Measured memory_bytes: 1792
m, n = gets.chomp.split.map(&:to_i)
arr = gets.chomp.split.map(&:to_i)
count = 0
if m == 2
    temp = [0, 0]
    arr.each_with_index{|x, i|
        if i.even?
            temp[0] += 1 if x == 1
        else
            temp[0] += 1 if x == 2
        end
    }
    arr.each_with_index{|x, i|
        if i.even?
            temp[1] += 1 if x == 2
        else
            temp[1] += 1 if x == 1
        end
    }
    count = temp.min
else
    1.upto(n - 1){|i|
        if arr[i - 1] == arr[i]
            count += 1
            arr[i] = 0
        end
    }
end
puts count


Measured memory_bytes: 13952
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int K = scanner.nextInt();

        int sum = 0;
        int count = 0;
        if (A >= K) {
            sum += K;
            System.out.println(sum);
            return;
        }
        sum += A;
        count += A;

        if (count + B >= K) {
            System.out.println(sum);
            return;
        }
        count += B;

        sum -= K - count;
        System.out.println(sum);
    }
}

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

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

    if (a == b && b == c) {
        cout << "No" << endl;
    } else if (a != b && a != c && b != c) {
        cout << "No" << endl;
    } 
    else {
        cout << "Yes" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
  
inline unsigned insertion_sort(unsigned a[], unsigned n, unsigned gap){
  unsigned count = 0;
  for(unsigned i = gap; i < n; i++){
    unsigned v = a[i];
    int j = i - gap;
    while(j >= 0 && a[j] > v){
      a[j+gap] = a[j];
      j -= gap;
      count++;
    }
    a[j+gap] = v;
  }
  return count;
}
  
inline void shell_sort(unsigned a[], unsigned n){
  const unsigned gaps[] = {1,8,23,77,281,1073,4193,16577,65921,262913,1050113};
  // generated from pow(4,i)+3*pow(2,i-1)+1 (prefixed with 1)
  
  unsigned gap_num = 0, count = 0;
  while(gaps[gap_num+1] < n) gap_num++;
  
  for(int i = gap_num; i >= 0; i--) count += insertion_sort(a,n,gaps[i]);
  
  std::cout << (gap_num+1) << '\n';
  
  for(int i = gap_num; i; i--) std::cout << gaps[i] << ' ';
  std::cout << gaps[0] << '\n';
  
  std::cout << count << '\n';
}
  
int main(){
  std::ios::sync_with_stdio(false);
  unsigned n;
  unsigned a[1000000];
  std::cin >> n;
  for(unsigned i = 0; i < n; i++) std::cin >> a[i];
  shell_sort(a,n);
  for(unsigned i = 0; i < n; i++) std::cout << a[i] << '\n';
}
 

Measured memory_bytes: 7084
icase=0
if icase==0:
    x1,y1,x2,y2=map(int,input().split())
    r=((x2-x1)**2+(y2-y1)**2)**0.5
    ix=(x2-x1)/r
    iy=(y2-y1)/r
    jx=-iy
    jy=ix
    x3=int(x2+r*jx)
    y3=int(y2+r*jy)
    x4=int(x3-r*ix)
    y4=int(y3-r*iy)
    print(x3,y3,x4,y4)

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<P>> edges(n);
    for (int i = 0;i < m;++i) {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        u--;v--;
        edges[u].push_back(P(v,w));
        edges[v].push_back(P(u,-w));
    }
    queue<int> que;
    vector<ll> dist(n);
    vector<bool> used(n,false);
    bool ok = true;
    for (int i = 0;i < n;++i) if (!used[i]) {
        que.push(i);
        dist[i] = 0;
        used[i] = true;
        while (!que.empty()) {
            int t = que.front();que.pop();
            for (P& p : edges[t]) {
                if (!used[p.first]) {
                    que.push(p.first);
                    dist[p.first] = dist[t]+p.second;
                    used[p.first] = true;
                } else if (dist[t]+p.second != dist[p.first]) {
                    ok = false;
                    break;
                }
            }
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 9728
#include <stdio.h>

int main(){
  int n,A[100],i,j,temp,c=0;

  scanf("%d",&n);

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

  for(i=0 ; i<n ; i++){
    for(j=n-1; j>i ;j--){
      if(A[j] < A[j-1]){
	temp=A[j];
	A[j]=A[j-1];
	A[j-1]=temp;
	c++;
      }
    }
  }

  for(i=0 ; i<n ; i++){
    printf("%d",A[i]);
    if(i!=n-1) printf(" ");
  }

  printf("\n");
  printf("%d\n",c);
  
  return 0;
}



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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)
int count_div(int n)
{
    int cnt = 0;
    REP1(i , n) {
        if(n % i == 0) cnt ++;
    }
    return cnt;
}

int main(void)
{
    int cnt = 0;
    int n;
    cin >> n;
    for(int i = 1; i <= n; i+=2) {
        if(count_div(i) == 8) {
//            cout << i << ": " << count_div(i) << endl;
            cnt ++;
        }
    }
    cout << cnt << endl;

}


Measured memory_bytes: 384
import fractions as fra
a,b=map(int,input().split())
c=fra.gcd(a,b)
cnt=0
for i in range(2,int(c**0.5)+1):
    if(c%i==0):
        cnt+=1
        while(True):
            c//=i
            if(c%i != 0):
                break
if(c!=1):
    cnt+=1
print(cnt+1)

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

int main(){
  int h, w;
  cin >> h >> w;
  string s;
  
  for(int i = 0; i < h; i++){
    cin >> s;
    cout << s << endl;
    cout << s << endl;
  }
}
  

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)

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

int main(int argc, char **argv) {
    int A, B, C;
    cin >> A >> B >> C;

    int res = INF;
    res = min(res, A + B);
    res = min(res, B + C);
    res = min(res, A + C);

    
    cout << res << endl;
}

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

int main(){
  int n;
  cin>>n;
  bool at=false;
  for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
      if(n==i*j){
        at=true;
      }
    }
  }
  if(at){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}
      

Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
x=int(input())
cnt=0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500*i+100*j+50*k == x:
        cnt+=1
print(cnt)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << (x) << endl
using namespace std;
template <typename Functor>
struct fix_type
{
    Functor functor;
    template <typename... Args>
    decltype(auto) operator()(Args&&... args) const& { return functor(functor, std::forward<Args>(args)...); }
};
template <typename Functor>
fix_type<typename std::decay<Functor>::type> fix(Functor&& functor) { return {std::forward<Functor>(functor)}; }
constexpr int INF = 1 << 30;
int main()
{
    int N, E, Q;
    cin >> N >> E >> Q;
    vector<map<int, int>> c(N);
    auto addEdge = [&](const int u, const int v) -> void { c[u][v] = c[v][u] = 1; };
    auto cutEdge = [&](const int u, const int v) -> void { c[u].erase(v), c[v].erase(u); };
    auto flow = [&](const int s, const int t, const int limit) {
        vector<bool> used(N, false);
        auto dfs = fix([&](auto&& self, const int s, const int t, const int f) -> int {
            if (s == t) { return f; }
            used[s] = true;
            for (auto& e : c[s]) {
                if (used[e.first] or e.second == 0) { continue; }
                const int res = min(f, e.second);
                const int d = self(self, e.first, t, res);
                if (d == 0) { continue; }
                return e.second -= d, c[e.first][s] += d, d;
            }
            return 0;
        });
        for (int flow = 0; flow < limit;) {
            fill(used.begin(), used.end(), false);
            const int f = dfs(s, t, limit - flow);
            if (f == 0) { return flow; }
            flow += f;
        }
        return limit;
    };
    for (int i = 0, F, T; i < E; i++) {
        cin >> F >> T;
        addEdge(F - 1, T - 1);
    }
    int ans = flow(0, N - 1, INF);
    for (int q = 0; q < Q; q++) {
        int M, A, B;
        cin >> M >> A >> B;
        A--, B--;
        if (M == 1) {
            addEdge(A, B);
            ans += flow(0, N - 1, INF);
        } else {
            const int cap = c[A][B];
            cutEdge(A, B);
            if (cap == 2) { swap(A, B); }
            if (cap != 1 and flow(A, B, 1) == 0) { ans--, flow(A, 0, 1), flow(N - 1, B, 1); }
        }
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 5012
#include<iostream>
#include<algorithm>
#include<complex>
#include<iomanip>
using namespace std;
int main(){
	int x;
	int t=90000;
	for(int i=t;i;i--){
		for(int j=i;j;j--){
			if(i+j==2)cin>>x;
		}
	}
	cout<<x*x*x<<endl;
	return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

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

  int c[n];
  bool ok = true;
  for(int i = n - 1; i >= 0; i--){
    int j = b.size() - 1;
    for(; j >= 0; j--){
      if(b[j] == j + 1) break;
    }
    if(j < 0){
      ok = false;
      break;
    }
    c[i] = j + 1;
    b.erase(b.begin() + j);
  }

  if(!ok){
    cout << -1 << endl;
    return 0;
  }

  string buf;
  for(int i = 0; i < n; i++){
    buf += to_string(c[i]) + "\n";
  }

  cout << buf;

  return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] w = {"Sunny", "Cloudy", "Rainy"};
		String s = sc.next();
		String ans = "";
		for(int i=0; i<3; i++)
			if(s.equals(w[i]))
				ans = w[(i+1)%3];
		
		System.out.println(ans);
		
		sc.close();
	}
}


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

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int sum = numeric_limits<int>::max();
    for (int c = 0; c <= max(X, Y); ++c) {
        int tmp = c*2*C + max(0, X-c)*A + max(0, Y-c)*B;
        sum = min(sum, tmp);
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#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;
typedef tree<
pair<long long, long long>,
null_type,
less< pair<long long, long long> >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
const long long INFll=1ll*INF*INF;
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define debug(x) cout << x << endl;
#define sz(a) int((a).size())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
long long genrand(long long L,long long R)
{
	return uniform_int_distribution<long long>(L, R)(rng);
}
//use brackets before operations if taking MOD
//use map only when necessary
//give long long to arrays and variables properly
int mul(int a, int b,int mod = MOD) {
	return int(a * 1ll * b % mod);
}
int norm(int a,int mod = MOD) {
	while(a >= mod) a -= mod;
	while(a < 0) a += mod;
	//a = (a%mod+mod)%mod;
	return a;
}
int powmod(int x,int y,int mod = MOD){
	int res = 1;
	while(y>0)
	{
		if(y&1)
			res = mul(res,x,mod);
		x = mul(x,x,mod);
		y=y>>1;
	}
	return res;
}
int inv(int a,int mod = MOD) {
	return powmod(a, mod - 2);
}
int BIT[200005];
int idx;
int query(int x){
	int res = 0;
	for(; x>0; x -= (x & (-x))){
		res+=BIT[x];
	}
	return res;
}
void update(int x){
	for(;x<=idx-1;x += (x & (-x))){
		BIT[x]++;
	}
}
int main() {
	fast();

	long long n, k; cin>>n>>k;
	vector<long long> a(n+1, 0);
	long long ans = 0, sum = 0;
	vector<long long> b;

	for(int i = 1; i<=n; i++){
		cin>>a[i];
		sum += a[i];
		a[i] = sum - i*k;
		b.pb(a[i]);
	}
	b.pb(0);
	sort(all(b));
	idx = 1;
	unordered_map<long long, long long> index, inv_index;
	for(int i = 0;i<b.size();){
		long long ele = b[i];
		index[b[i]] = idx;
		inv_index[idx] = b[i];
		idx++;
		while(i<b.size() && b[i]==ele){
			i++;
		}
	}


	update(index[0]);
	for(int i = 1;i<=n;i++){
		// cout<<a[i]<<' '<<index[a[i]]<<' '<<query(index[a[i]])<<endl;
		ans += query(index[a[i]]);
		update(index[a[i]]);
	}
	
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 20720
package main

import "fmt"

func main() {
	var A, B, C, X, count int
	fmt.Scan(&A, &B, &C, &X)
	for i := 0; i <= A; i++ {
		for j := 0; j <= B; j++ {
			for k := 0; k <= C; k++ {
				if i*500+j*100+k*50 == X {
					count++
				}
			}
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int main() {
	int a,b,c,d;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	if (abs(a - c) <= d ||(abs(a-b)<=d && abs(b-c)<=d)) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

Measured memory_bytes: 256
n,m=map(int,input().split())

cnt=0
l=[0 for i in range(n)]

for i in range(m):
  p,s=input().split()
  p=int(p)
  p-=1
  if l[p]!=-1:
    if s=='AC':
      cnt+=l[p]
      l[p]=-1
    else:
      l[p]+=1

ac_cnt=l.count(-1)
print(ac_cnt,cnt)

Measured memory_bytes: 3888
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int n, m;
	double h;
	cin >> n >> m;

	h = 1.0 / (4 * double(m));
	int cnt = 0;
	vector<int>a(n);
	int i;
	int b=0;
	for (i = 0; i < n; i++)
	{
		cin >> a.at(i);
		b = b + a.at(i);
	}
	for (i = 0; i < n; i++)
	{
		if (4 * m * a.at(i) >= b)
			cnt++;
	}
	if (cnt >= m)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
} 

Measured memory_bytes: 3612
N,D=map(int,input().split())
L=[list(map(int,input().split())) for i in range(N)]
n=0
for i in range(N):
  for j in range(i):
    DD=0
    for k in range(D):
      DD+=(L[i][k]-L[j][k])**2
    if any(n**2==DD for n in range(1,128)):
      n+=1
print(n)

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[500][500];

int main(){
  char a[100][100],b[100][100];
  cin >> n >> m;
  rep(i,0,n){
    rep(j,0,n){
      cin >> a[i][j];
    }
  }
  rep(i,0,m){
    rep(j,0,m){
      cin >> b[i][j];
    }
  }
  s = "No";
  rep(i,0,n){
    rep(j,0,n){
      l = 0;
      rep(k,0,m){
        rep(h,0,m){
          if(a[i+k][j+h] == b[k][h])l++;
        }
      }
      if(l == m * m)s = "Yes";
    }
  }
  print(s);
  return 0;
}

Measured memory_bytes: 256
import itertools
N=int(input())
l=list(map(int,input().split()))
ctn=0
for c  in itertools.combinations(l, 3):
    if len(c)==len(set(c)):
        if sorted(c)[0]+sorted(c)[1]-sorted(c)[2]>0:
            ctn+=1
print(ctn)

Measured memory_bytes: 9140
/*__ _(_) __ _  ___  ___ _   _  __| | __ _ _   _| |_ ___
 / _` | |/ _` |/ _ \/ __| | | |/ _` |/ _` | | | | __/ _ \
| (_| | | (_| | (_) \__ \ |_| | (_| | (_| | |_| | || (_) |
 \__, |_|\__,_|\___/|___/\__,_|\__,_|\__,_|\__,_|\__\___/
 |___/                                  Accepted Code  */
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef gsdt
    freopen("input.txt","r",stdin);
#endif // gsdt

    int N, T; cin>>N>>T;
    int a[100005];
    int Min=INT_MAX, Max=INT_MIN;
    for(int i=0; i<N; i++) {
        cin>>a[i];
        if(i==0) Min=a[i];
        if(a[i]>Min) Max=max(Max,a[i]-Min);
        Min=min(Min,a[i]);
    }

    map<int,bool> data;
    int cnt=0;
    for(int i=0; i<N; i++){
        data[a[i]]=true;
        if((a[i]>Max) && data[a[i]-Max]) cnt++;
    }

    cout<<cnt;

    return 0;
}



Measured memory_bytes: 9984
n,k = map(int,input().split())
p = list(map(int,input().split()))
ps = [0]
for i in range(len(p)):
         ps.append(((p[i] + 1)/2)+ps[i])
ans = 0
for i in range(n+1-k):
         if ans < (ps[i+k] - ps[i]):
                  ans = (ps[i+k] - ps[i])
print(ans)


Measured memory_bytes: 24804
/**
**	author : Raghav
**	codechef:raghav_456
**	codeforces:raghavramola7
**/
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define endl 			"\n"
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void Raghav()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(1003);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	Raghav();
	string s;
	cin >> s;
	if (s[0] == s[1] && s[1] == s[2])
		cout << "No";
	else
		cout << "Yes";


	return 0;
}

Measured memory_bytes: 3660
#include<iostream>
using namespace std;
#define int long long
signed main(){
    long long n;
    cin >> n;
    int tmp = n;

    int cnt = 0;
    for(int i = 2; i*i <= n; i++){
        if(n%i == 0){
            cnt++;
            while(n%i == 0)n /= i;
        }
    }
    if(n > 1){
        //nが1以上のとき、Nは√Nより大きい素因数をもつ
        cnt++;
    }

    cout << cnt << " ";
    n = tmp;
    cnt = 0;
    for(long long i = 1; i*i <= n; i++){
        if(n%i == 0){ //iはnの約数
            cnt++;
            if(i*i != n)cnt++;//n/iの分もカウントする
        }
    }

    cout << cnt-1 << endl;
}



Measured memory_bytes: 3116
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

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

#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2e5 + 10;

int used[maxn];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n, k;
    cin >> n >> k;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vector<int> t;
    int v = 1;
    while (1) {
        if (used[v]) break;
        used[v] = sz(t) + 1;
        t.push_back(v);
        v = a[v];
    }
    int pos = used[v];
    if (sz(t) > k) {
        cout << t[k];
        return 0;
    }
    k -= pos - 1;
    cout << t[pos - 1 + (k) % (sz(t) - pos + 1)] << "\n";

    return 0;
}

Measured memory_bytes: 8500
# -*- coding: utf-8 -*-
import math

a,b = map(int, input().split())
x = 0

for n in range(25):
  l = (25 * a + n) % 2
  m = 25 * a + n
  if(l == 0):
    if((m/2 - 10 * b) == int(m/2 - 10 * b) and (m/2 - 10 * b) < 10 and (m/2 - 10 * b) >= 0):
      x = int(m/2)
      break
  if(n == 24):
    x = -1
    break
    
print("{}".format(x))

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;
const int MAX = 100;

void solve(bool grid[MAX][MAX], int N, int add) {
	if (N == 0)return;
	int cnt = 0;
	for (int i = 1; i < (MAX / 2) - 2; i += 3) {
		for (int j = 1; j < MAX - 1; j += 2) {
			grid[i + add][j] = !grid[i + add][j];
			if (++cnt >= N)return;
			grid[i + 1 + add][j + 1] = !grid[i + 1 + add][j + 1];
			if (++cnt >= N)return;
		}
	}
}

int main() {
	int A, B;
	bool grid[MAX][MAX] = { {false} };

	cin >> A >> B;

	for (int i = 0; i < MAX / 2; i++) {
		for (int j = 0; j < MAX; j++) {
			grid[i][j] = true;
		}
	}

	solve(grid, A - 1, 0);
	solve(grid, B - 1, MAX / 2);

	cout << MAX << " " << MAX << endl;
	for (int i = 0; i < MAX; i++) {
		for (int j = 0; j < MAX; j++) {
			if (grid[i][j])cout << "#";
			else cout << ".";
		}
		cout << endl;
	}


	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    vector<ll> B;
    rep(i, N) {
        ll a = A[i];
        auto idx = lower_bound(B.begin(), B.end(), a);
        if (idx == B.begin()) {
            B.insert(B.begin(), a);
        } else {
            idx--;
            *idx = a;
        }
    }
    cout << B.size() << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 2168
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long x = sc.nextLong();
    int geta = (a % x == 0) ? 1 : 0;
    System.out.println(b/x-a/x +geta);
  }
}

Measured memory_bytes: 22996
#include <stdio.h>
#include <stdlib.h>

#define N 10000
#define INT(X) \
  ( *((int *)(X)) )

int cmpr (
  const void  * a,
  const void  * b
  )
{
  return ( INT(a) - INT(b) );
}

int main (
  void
  )
{
  for ( ; ; )
  {
    unsigned long long int res;
    int d[ N ], n;
    int i;

    scanf ( "%d", &n );
    if ( !n ) break ;

    for ( i = 0; i < n; ++i )
    {
      scanf ( "%d", d + i );
    }
    qsort ( d, n, sizeof ( int ), cmpr );

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

  return ( 0 );
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    int color;
    set<int> colors;
    rep(0, 3) {
        cin >> color;
        colors.insert(color);
    }

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

    return 0;
}


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();
    long A[] =new long[N];
    long B[] =new long[N];
    for(int i=0;i<N;i++){
      A[i]=sc.nextInt();
      B[i]=sc.nextInt();}
    int n =N/2;
    Arrays.sort(A);
    Arrays.sort(B);
    if(N%2==1){
      System.out.println(B[n]-A[n]+1);}
    else{
      System.out.println(B[n]+B[n-1]-A[n]-A[n-1]+1);}
  }
}

Measured memory_bytes: 63400
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int memo[N];
bool vis[N];
vector<int> g[N];

int dp(int u){
	if(vis[u]) return memo[u];
	int ans=0;
	for(auto v: g[u]){
	    ans=max(ans, dp(v) + 1);
	}
	vis[u]=true;
	return memo[u]=ans;
}

int main() {
    int n,m;
	cin>>n>>m;
	int a,b;
	for(int i=0;i<m;i++){
		cin>>a>>b;
		g[a].push_back(b);
	}
	int res=0;
	for(int i=1;i<=n;i++){
	    res=max(res,dp(i));
	}
	cout<<res<<"\n";
	return 0;
}



Measured memory_bytes: 11524
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <numeric>

//#include <map>

using namespace std;

enum suit{
	S, H, C, D,
};

class card{
public:
	char chSuit;
	int iSuit;
	int num;

	card(char c, int n)
	{
		switch (c)
		{
			case 'S':iSuit = S; break;
			case 'H':iSuit = H; break;
			case 'C':iSuit = C; break;
			case 'D':iSuit = D; break;
			default:break;
		}
		chSuit = c;
		num = n;
	}

	card(int c, int n)
	{
		switch (c)
		{
			case S:chSuit = 'S'; break;
			case H:chSuit = 'H'; break;
			case C:chSuit = 'C'; break;
			case D:chSuit = 'D'; break;
			default:break;
		}
		iSuit = n;
		num = n;
	}
};

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

	vector<card> vCardExt,vCardMissing;

	for (int i = 0; i < n; i++)
	{
		char suit;
		int num;
		cin >> suit >> num;
		card cd(suit,num);
		vCardExt.push_back(cd);
	}

	for (int i = S; i <= D; i++)
	{
		for (int j = 1; j <= 13; j++)
		{
			bool isExist = false;
			for (int k = 0; k < vCardExt.size(); k++)
			{
				if (vCardExt.at(k).iSuit == i && vCardExt.at(k).num == j)
				{
					isExist = true;
					break;
				}
				else
				{
				}
			}
			if (isExist == false)
			{
				card cd(i, j);
				vCardMissing.push_back(cd);
			}
		}
	}

	for (int i = 0; i < vCardMissing.size(); i++)
	{
		cout << vCardMissing.at(i).chSuit << " " << vCardMissing.at(i).num << endl;
	}

	return 0;
}

Measured memory_bytes: 3096
n = gets.to_i
rs = n.times.map{ gets.to_i }

maxv, minv = -(10**10), 10**10

while rs.size > 0
  now = rs.shift
  maxv = maxv < (now-minv) ? (now-minv) : maxv
  minv = now < minv ? now : minv
end
puts maxv


Measured memory_bytes: 9256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

int N;
vector<int> va, vb, vc;
/*==================================================*/
/*==================================================*/

int main() {
    cin>>N;
    int t;
    REP(i,0,3){
        REP(j,0,N){
            cin>>t;
            switch (i) {
                case 0:
                    va.push_back(t);
                    break;
                case 1:
                    vb.push_back(t);
                    break;
                default:
                    vc.push_back(t);
                    break;
            }
        }
    }
    sort(va.begin(), va.end());
    sort(vb.begin(), vb.end());
    sort(vc.begin(), vc.end());

    long long ans = 0;
    REP(i,0,N){
        long long apos = lower_bound(va.begin(), va.end(), vb[i]) - va.begin();
        long long cpos = vc.end() - upper_bound(vc.begin(), vc.end(), vb[i]);
        ans += apos * cpos;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 1912
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 2010;
const int MAXM = 1010;
const int MAXK = 110;
const int MAXQ = 200010;

int n, a[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    sort(a+1, a+n+1);
    ll res = 0;
    FOR(i,1,n-2)
        FOR(j,i+1,n-1) {
            int g = a[i] + a[j];
            int dau = j+1, cuoi = n, mid;
            while (dau <= cuoi) {
                mid = (dau + cuoi) >> 1;
                if (a[mid] >= g) cuoi = mid-1;
                else dau = mid+1;
            }
            if (cuoi >= j+1 && cuoi <= n) {
                res += cuoi - j;
            }
        }

    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int N;cin>>N;
    cout<<N/3<<endl;
}

Measured memory_bytes: 3548
A, B, C, D = map(int, input().split())
 
flg = True
t = False
while(flg):
  C -= B
  if (C <= 0):
    t = True
    break
  A -= D
  if (A <= 0) :
    t = False
    break

if (t):
  print("Yes")
else:
  print("No")
  

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

int main(){
    string s;
    cin>>s;
    if(s[0]!='A' || s.back()=='C' || s[1]=='C'){
        cout<<"WA";
        return 0;
    }
    int c=0;
    for(int i=2;i<s.length();i++){
        if(s[i]=='C')c++;
    }
    if(c!=1){
        cout<<"WA";
        return 0;
    }
    for(int i=1;i<s.length();i++){
        if(s[i]!='C' && isupper(s[i])){
            cout<<"WA";
            return 0;
        }
    }
    cout<<"AC";
}


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

#define int long long

signed main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    int ans = 0;
    for(int i=0; i<n; ++i) {
        int a;
        cin >> a;
        ans += min(a*2, (k-a)*2);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
fun trace(a: IntArray?) = a?.let { println(a.joinToString(separator = " ")) }

fun insertionSort(a: IntArray?) {
    a?.let {
        for (i in 1 until a.size) {
            val v = a[i]
            var j = i - 1
            while (j >= 0 && a[j] > v) {
                a[j + 1] = a[j]
                j--
            }
            a[j + 1] = v
            trace(a)
        }
    }
}

fun main(args: Array<String>) {
    readLine()
    val a = readLine()
            ?.split(regex = "\\s+".toRegex())
            ?.map { it.toInt() }
            ?.toIntArray()
    trace(a)
    insertionSort(a)
}


Measured memory_bytes: 35552
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N=300;
ll a[N];
ll b[N];
int32_t main(){
    ll n;
    cin >> n;
    ll l=0,r=n;
    cout << flush << l << endl;
    string t;
    cin >> t;
    ll p1=0;
    if (t=="Female"){
        p1=1;
    }
    while(r-l>1){
        ll mid=(r+l)/2;
        cout << flush << mid << endl;
        string s;
        cin >> s;
        ll p2=0;
        if (s=="Vacant"){
            return 0;
        }
        if (s=="Female"){
            p2=1;
        }
        if ((mid-l)%2==1 && p2==p1){
            r=mid;
            continue;
        }
        if ((mid-l)%2==0 && p2!=p1){
            r=mid;
            continue;
        }
        l=mid;
        p1=p2;
    }

}


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


int main()
{
    vll vec;
    REP(i, 5) {
        ll a;
        cin >> a;
        vec.push_back(a);
    }
    ll k;
    cin >> k;
    sort(ALL(vec));
    if (vec.back() - vec.front() > k) {
        cout << ":(" << endl;
        return 0;
    } else {
        cout << "Yay!" << endl;
    }

}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int n;
		int ans;
		
		while(scan.hasNextInt()){
			n = scan.nextInt();
			ans = 0;
			for(int a = 0;a < 10; a++){
				for(int b = 0;b < 10; b++){
					for(int c = 0;c < 10; c++){
						for(int d = 0;d < 10; d++){
							if(a + b + c + d == n)ans++;
						}	
					}	
				}	
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 26684
import sys

def solve(w, a, b):
    ans = 0

    if w + b < a:
        ans = a - (b + w)
    elif (a <= b + w) and (b <= a + w):
        ans = 0
    else:
        return b - (a + w)
    return ans

def main():
    line = sys.stdin.readline()
    w, a, b = [ int(s) for s in line.split()]

    ans = solve(w, a, b)
    print(ans)
    return 0

if __name__ == '__main__':
    sys.exit(main())


Measured memory_bytes: 3064
using System;

class Atcoder67
{
    public static void Main()
    {
        string number = Console.ReadLine();
        char thou = number[0];
        char hund = number[1];
        char ten = number[2];
        char one = number[3];

        if (thou == hund && thou == ten)
            Console.WriteLine("Yes");
        else if (hund == ten && hund == one)
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
    }
}

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

using namespace std;

int h, w, k;
string grid[7];

int cnt(int maskI, int maskJ) {
    int c = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (grid[i][j] == '#' && ((maskI >> i) & 1) != 0 && ((maskJ >> j) & 1) != 0) {
                c++;
            }
        }
    }
    return c;
}

int main() {
    cin >> h >> w >> k;
    for (int i = 0; i < h; i++) {
        cin >> grid[i];
    }

    int ans = 0;
    for (int maskI = 0; maskI < (1 << h); maskI++) {
        for (int maskJ = 0; maskJ < (1 << w); maskJ++) {
            if (cnt(maskI, maskJ) == k) {
                ans++;
            }
        }
    }

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

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

int main(){
	int n, a; cin >> n >> a;
	int x[n + 1];
	for(int i = 1; i <= n; ++i){
		cin >> x[i];
	}
	long long dp[2][51][2501];
	for(int i = 0; i < 2; ++i){
		for(int j = 0; j < n + 1; ++j){
			for(int k = 0; k <= 2500; ++k){
				if(!j && !k) dp[i][j][k] = 1;
				else dp[i][j][k] = 0;
			}
		}
	}
	for(int i = 1; i <= n; ++i){
		for(int j = 0; j <= i; ++j){
			for(int k = 0; k <= 2500; ++k){
				dp[1][j][k] = dp[0][j][k] + (j >= 1 && k - x[i] >= 0 ? dp[0][j - 1][k - x[i]] : 0);
			}
		}
		for(int j = 0; j <= i; ++j){
			for(int k = 0; k <= 2500; ++k){
				dp[0][j][k] = dp[1][j][k];
			}
		}
	}
	long long ans = 0;
	for(int i = 1; i <= n; ++i){
		ans += dp[1][i][i * a];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cmath> 
#include <cctype>

using namespace std;

int main() {
    int N, M, X;
    int count_low = 0;
    int count_high = 0;
    cin >> N >> M >> X;
    vector<int> A(M);
    for (int i = 0; i < M; i++) {
        cin >> A.at(i);
    }
    for (int i = 0; i < M; i++) {
        if (A.at(i) < X) {
            count_low++;
        } else {
            count_high++;
        }
    }

    cout << min(count_low, count_high) << endl;
    return 0;
}

Measured memory_bytes: 256