akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{	
	int i, N, Q, A[100001];
	scanf("%d %d", &N, &Q);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	
	int q, l[2], r[2], m, X, L, R, M;
	long long sum[2][100002] = {};
	for (i = N, sum[0][N+1] = 0; i > N / 2; i--) sum[0][i] = sum[0][i+1] + A[i];
	for (i = 3, sum[1][1] = A[1]; i <= N; i += 2) sum[1][i] = sum[1][i-2] + A[i];
	for (i = 2, sum[1][0] = 0; i <= N; i += 2) sum[1][i] = sum[1][i-2] + A[i];
	for (q = 1; q <= Q; q++) {
		scanf("%d", &X);
		if (X <= A[1]) {
			printf("%lld\n", sum[0][N/2+1]);
			continue;
		} else if (X >= A[N-1]) {
			printf("%lld\n", sum[1][N]);
			continue;
		}
		
		L = 0;
		R = (X - A[1] < A[N-1] - X)? A[N-1] - X: X - A[1];
		while (L < R) {
			M = (L + R) / 2;
			
			l[0] = 0;
			r[0] = N;
			while (l[0] < r[0]) {
				m = (l[0] + r[0] + 1) / 2;
				if (A[m] < X - M) l[0] = m;
				else r[0] = m - 1;
			}
			l[1] = l[0];
			r[1] = N;
			while (l[1] < r[1]) {
				m = (l[1] + r[1] + 1) / 2;
				if (A[m] > X + M) r[1] = m - 1;
				else l[1] = m;
			}
			
			if (r[1] - l[0] == N - r[1]) break;
			else if (r[1] - l[0] == N - r[1] - 1) {
				l[0]--;
				break;
			} else if (r[1] - l[0] == N - r[1] + 1 && A[l[0]+1] == X - M && A[r[1]] == X + M) {
				l[0]--;
				r[1]--;
				break;
			} else if (r[1] - l[0] < N - r[1]) L = M + 1;
			else R = M;
		}
		
		if (L == R) {
			l[0] = 0;
			r[0] = N;
			while (l[0] < r[0]) {
				m = (l[0] + r[0] + 1) / 2;
				if (A[m] < X - L) l[0] = m;
				else r[0] = m - 1;
			}
			l[1] = l[0];
			r[1] = N;
			while (l[1] < r[1]) {
				m = (l[1] + r[1] + 1) / 2;
				if (A[m] > X + L) r[1] = m - 1;
				else l[1] = m;
			}
			if (r[1] - l[0] == N - r[1] - 1) l[0]--;
			else if (r[1] - l[0] == N - r[1] + 1 && A[l[0]+1] == X - L && A[r[1]] == X + L) {
				l[0]--;
				r[1]--;
			}
		}

		if (l[0] < 0) l[0] = 0;
		printf("%lld\n", sum[0][r[1]+1] + sum[1][l[0]]);
	}
	
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3776
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>

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

using namespace std;

int main(){

ll int X;
ll int N;
cin >> X >> N;

ll int unko = 0;
vector<ll int> p(N);
rep(i,N){
	cin >> p[i];
        if(p[i] == X){
		unko = 1;
	}
}
if(unko == 0){
	cout << X;
	return 0;
}


ll int unko2 = 0;

for(int i =1;;i++){
	unko = 0;
	unko2 = 0;
	rep(j,N){
		if(p[j]==X+i){
			unko =1;
		
			/*
		  if(p[i]==X-i){
		  }
		  else{
		  cout << X-i;
		  return 0;
		  }
		*/
		}
		else if(p[j]==X-i){
			unko2 = 1;
			/*
		 if(p[i]==X+i){
		 }
		 else{
		 cout << X+1;
		 return 0;
		 }
*/
		}
		else{
		
			/*
			cout << X-i;
			return 0;
			*/
			
		}
	
	}
	//cout << unko << unko2 << endl;
	if(unko2 == 0){
			cout << X-i;
			return 0;
		}
		else if(unko == 0){
			cout << X+i;
			return 0;
		}
		else{}

}









	return 0;

}



Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        if(A == 1 || B == 1){
            if(A==1 && B==1){
                System.out.println("Draw");
            }else if(A==1){
                System.out.println("Alice");
            }else if(B==1){
                System.out.println("Bob");
            }
            return;
        }
        if(A > B){
            System.out.println("Alice");
        }else if(A < B){
            System.out.println("Bob");
        }else if(A == B){
            System.out.println("Draw");
        }
    }
}


Measured memory_bytes: 35620
import java.util.Scanner;

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

        Integer intX = scan.nextInt();
        scan.close();

        for(long i = -120; i <= 120; i++){
            for(long j = -120; j <= 120; j++){
                if(intX == i*i*i*i*i - j*j*j*j*j){
                    System.out.println(i + " " + j);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 38732
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;
typedef long long ll;
typedef std::pair<int, ll> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

int main() {
   int n, m;
   cin >> n >> m;
   vector<ipair> AB;
   ll a, b;
   for (int i = 0; i < n; i++) {
      cin >> a >> b;
      AB.push_back(ipair(b, a));
   }
   sort(AB.begin(), AB.end(), lessPair);

   ll ans = 0;
   int rest = m;
   ll tmp;
   for (auto it = AB.begin(); it != AB.end(); ++it) {
      tmp = it->second;
      tmp *= min(rest, it->first);
      ans += tmp;
      rest -= min(rest, it->first);
      if (rest == 0) break;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 2420
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

vector<vector<int>> neighbor;

void dfs(int node, int d, vector<int>& dist, vector<bool>& isVisited)
{
    isVisited[node] = true;
    dist[node] = d;

    for (int ch : neighbor[node]) {
        if (!isVisited[ch]) {
            dfs(ch, d + 1, dist, isVisited);
        }
    }
}

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

    neighbor.resize(n);
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        neighbor[a].push_back(b);
        neighbor[b].push_back(a);
    }

    vector<int> dist(n);
    vector<bool> isVisited(n, false);
    dfs(0, 0, dist, isVisited);
    int d = 0, v = 0;
    rep(i, n)
    {
        if (d < dist[i]) {
            d = dist[i];
            v = i;
        }
    }

    fill(isVisited.begin(), isVisited.end(), false);
    dfs(v, 0, dist, isVisited);
    int diameter = 0;
    rep(i, n)
    {
        diameter = max(diameter, dist[i]);
    }

    if ((diameter + 1) % 3 == 2) {
        cout << "Second" << endl;
    } else {
        cout << "First" << endl;
    }

    return 0;
}

Measured memory_bytes: 21376
#include <bits/stdc++.h>
 
using namespace std;
#define LL long long
 
const int MAXN = 212345;
 
LL a[MAXN], b[MAXN];
 
int main () {
 
	int n;
	scanf("%d", &n);
 
	for (int i = 0; i < n + 1; ++i)
		scanf("%lld", &a[i]);
	for (int i = 0; i < n; ++i)
		scanf("%lld", &b[i]);
 
 
	LL ans = 0;
 
	for (int i = 0; i < n + 1; ++i) {
		ans += min(a[i], b[i]);
		b[i+1] += max (0LL, min(a[i+1], b[i] - a[i]));
	}
 
	printf("%lld\n", ans);
 
 
 
 
 
 
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
S = input()

R = set([v for v,i in enumerate(S) if i == 'R'])
G = set([v for v,i in enumerate(S) if i == 'G'])
B = set([v for v,i in enumerate(S) if i == 'B'])
t = len(B)
c = 0
for i in R:
    for j in G:
        d = [2* i -j,2 * j - i,(i+j)/2]
        for a,s in enumerate(d):
            if s in B:
                c -= 1
        c += t

print(c)

Measured memory_bytes: 9392
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>
#include <limits>

using namespace std;

#define ll int
#define f0(i,n)for(i=0;i<n;i++)
#define f1(i,n)for(i=1;i<=n;i++)
#define fc(i,c,n)for(i=c;i<=n;i++)
#define f0r(i,n)for(i=n-1;i>=0;i--)
#define f1r(i,n)for(i=n;i>0;i--)
#define fcr(i,c,n)for(i=n;i>=c;i--)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef list<ll> LST;
typedef vector<ll> VEC;
typedef map<ll, ll> MAP;

long long i, j, q;

int main() {
	IO;
	//ifstream cin("In.txt");
	ll n, a, b,t,ans;
	cin >> a >> b >> t;
	ans = (t / a)*b;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k, x, y;
  ll res = 0;
  cin >> n >> k >> x >> y;
  for (int i = 1; i <= n; i++) {
    if(i <= k) res += x;
    else res += y;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
#include <iostream>
#include <ctime>
#include <unistd.h>

using namespace std;

#define TRACE(x) cerr << #x <<  " = " << x << endl
#define _ << " " <<
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)

#define X first
#define Y second

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

const int MAX = 1<<19;

int col[MAX];
vector <int> V[MAX];

int dfs(int node, int cl, int &cnt1, int &cnt2) {
  if (col[node] != -1) {
    return col[node] == cl;
  }

  col[node] = cl;
  if (cl) cnt1++;
  else cnt2++;

  int ret = 1;
  for (auto it : V[node]) {
    if (!dfs(it, 1^cl, cnt1, cnt2)) ret = 0;
  }

  return ret;
}

int main()
{
  int n, m;
  scanf("%d%d", &n, &m);
  REP(i, m) {
    int a, b;
    scanf("%d%d", &a, &b); a--; b--;
    V[a].push_back(b);
    V[b].push_back(a);
  }

  ll ret = 0;
  memset(col, -1, sizeof col);

  REP(i, n) {
    if (col[i] == -1) {
      int a=0, b=0;
      if (dfs(i, 0, a, b)) {
	ret += (ll) a * b;
      }
      else
	ret += (ll) (a + b) * (a + b - 1) / 2;
    }
  }

  printf("%lld\n", ret-m);

  return 0;
}


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

using namespace std;

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

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const long MOD = 1000000007;

long dp[1000000];
long dp_sum;

int main(){
    long n;
    cin >> n;
    dp[0] = n;
    dp[1] = (n*n)%MOD;
    dp_sum = 0;
    for(int i = 2; i <= n-1; i++){
        dp[i] = dp[i-1]+dp_sum+(n-1)*(n-1)+(n-(i-1));
        dp[i] %= MOD;
        dp_sum += dp[i-2];
        dp_sum %= MOD;
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 8064
N=int(input())
S=list(input())
i=0
c=0
while i<N-2:
  if S[i]=='A':
    if S[i+1]=='B':
      if S[i+2]=='C':
        c+=1
        i+=1
      else:
        c+=0
        i+=1
    else:
      c+=0
      i+=1
  else:
    c+=0
    i+=1
else:
  print(c)

Measured memory_bytes: 3060
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        if (a - b >= 0) {
            System.out.println("delicious");
        } else if (a - b < 0 && Math.abs(a - b) <= x ) {
            System.out.println("safe");
        } else {
            System.out.println("dangerous");
        }
    }
}


Measured memory_bytes: 21972
using System;

class Test{
  public static void Main(){
    int x = int.Parse(Console.ReadLine());
    var nums = Console.ReadLine().Split(' ');
    string check = "APPROVED";
    for(int i=0;i<x;i++){
      int num = int.Parse(nums[i]);
      if(num%2 == 0){
      	if(!(num%3 == 0||num%5 == 0)){
     	 	check="DENIED";
    	  }
      }
    }
    Console.Write(check);
  }
}

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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define ALL(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(ALL(c)); c.erase(unique(ALL(c)), c.end()); }
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class K, class V> void cout_v(map<K, V>& m)
{ for(auto it=m.begin();it!=m.end();it++)cout<<it->first<<":"<<it->second<<endl;}
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
template<class T> inline bool is_overlap(const T& a, const T& b, const T& p, const T& q)
{ return p <=b && a <= q; }

#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}


template<class T> void sort3a(T& a,T& b,T& c) {if (a>b) swap(a,b); if (b>c) swap(b,c); if (a>b) swap(a,b);}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N; cin >> N;
    int odd_nums = 0;
    rep(i, N) {
        int A; cin >> A;
        if (A%2) odd_nums++;
    }
    YES(N == 1 || odd_nums % 2 == 0);
}


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

using namespace std;

using ll = long long;

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

    int n, h, w, cnt = 0;
    cin >> n >> h >> w;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        if (h <= a && w <= b) ++cnt;
    }

    cout << cnt << endl;

    return 0;
}


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

int main(){

    int i,j;
    string s,p,sp,temp;
    cin>>s>>p;
    p+=p;

    for(i=0; i<p.size(); i++){
        temp="";
        for(j=i; j<p.size(); j++){
            temp+=p[j];
            if(temp.size()==s.size())break;
        }
        if(temp==s){
            cout<<"Yes"<<endl;
            return 0;
        }
        if(temp.size()<s.size())break;
    }
    cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
import math as m

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

z = a ** 2 * b

if z / 2 >= x:
  ap = x * 2 / a / b
  at = m.degrees(m.atan(b/ap))
  print(at)
else:
  bp = b - x / (a ** 2)
  bt = m.degrees(m.atan(bp*2/a))
  print(bt)

Measured memory_bytes: 3060
def count(num,d):
    bite=0
    date=1
    while date<=d:
        bite+=1
        date+=num
    return bite

n=int(input()) #人数
d,x=map(int,input().split()) #日数、のこった数
ans=x
for i in range(n):
    num=int(input())
    ans+=count(num,d)
print(ans)

Measured memory_bytes: 3060
#include<iostream>
using  namespace std;
int main()
{
	int N;
	while (true)
	{
		cin >> N;
		if (N == 0)break;
		int*k = new int[N];
		for (int i = 0; i < N; i++)
		{
			cin >> k[i];
		}
		int max;
		int min = 0;
		for (int i = 0; i < N; i++)
		{
			if (i == 0)
			{
				max = k[i];
				if (k[i] == 0)min = min + 1;
			}
			else
			{
				if (max < k[i])max = k[i];
				if (k[i] == 0)min = min + 1;
			}
		}
		if (max < 2)
		{
			cout << "NA" << endl;
		}
		else
		{
			cout << N + 1-min << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3288
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define in long long int
int main() {
	in n,cap;
	cin>>n>>cap;
	in dp[n+1][cap+1];
	for(int i=0;i<n+1;i++)
	{
	    for(int j=0;j<cap+1;j++)
	    {
	        if(i==0||j==0)
	            dp[i][j]=0;
	    }
	}
	vector<in>w(n),v(n);
	for(in i=0;i<n;i++)
	{
	    cin>>w[i];
	    cin>>v[i];
	}
	for(int i=1;i<n+1;i++)
	{
	    for(int j=1;j<cap+1;j++)
	    {
	        if(w[i-1]<=j)
	            dp[i][j]=max(v[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
	       else
	        dp[i][j]=dp[i-1][j];
	    }
	}
	cout<<dp[n][cap];
	return 0;
}

Measured memory_bytes: 82424
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define rep(i,n) for(int i=0;i<(int) (n);i++)
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;}
using namespace std;
bool check(int a,int b,int c,int d){
  c-=b;
  if(c<=0)return true;
  a-=d;
  if(a<=0)return false;

  return check(a,b,c,d);
}
int main(){
  int a,b,c,d,flag=0;
  cin>>a>>b>>c>>d;
  bool f;
  f=check(a,b,c,d);
  if(f==true)cout<<"Yes";
  else cout<<"No";

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<ll> plus;
  vector<ll> minus;
  vector<ll> a(n);
  ll sum = 0;
  ll plus_sum = 0;
  ll minus_sum = 0;
  rep(i, n){
    ll num;
    cin >> num;
    a[i] = num;
    sum += abs(num);
    if(num >= 0){
      plus.push_back(num);
      plus_sum += num;
    }else{
      minus.push_back(num);
      minus_sum += num;
    }
  }
  if(n == 2){
    cout << max(a[0], a[1]) - min(a[0], a[1]) << endl;
    cout << max(a[0], a[1]) << " " << min(a[0], a[1]) << endl;
    return 0;
  }
  sort(ALL(plus));
  sort(ALL(minus));
  if (plus.size() == n){
    ll num = plus_sum - 2 * plus[0];
    cout << num << endl;
    ll tmp = plus[0] - plus[plus.size() -1];
    rep(i, n-1){
      if(i == 0){
        cout << plus[0] << " " << plus[plus.size() - 1] << endl;
      }else if(i != n-2){
        cout << tmp << " " << plus[plus.size() - 1 - i] << endl;
        tmp -= plus[plus.size() - 1 - i];
      }else{
        cout << plus[1] << " " << tmp << endl;
      }
    }
    return 0;
  }
  if(minus.size() == n){
    ll num = abs(minus_sum) - 2 * abs(minus[minus.size() -1]);
    cout << num << endl;
    ll tmp = minus[minus.size() - 1]- minus[0];
    rep(i, n-1){
      if(i == 0){
        cout << minus[minus.size() - 1] << " " << minus[0] << endl;
      }else{
        cout << tmp << " " << minus[i] << endl;
        tmp -= minus[i];
      }
    }
    return 0;
  }
  cout << sum << endl;
  int mn = min(plus.size(), minus.size());
  ll tmp1 = plus[mn - 1];
  ll tmp2 = minus[mn -1];
  rep(i, n-1){
    if(plus.size() <= minus.size()){
      if(i < mn-1){
        cout << minus[i] << " " << plus[i] << endl;
        minus.push_back(minus[i] - plus[i]);
      }else{
        if(i == mn-1){
          cout << plus[mn - 1] << " " << minus[i] << endl;
        }else{
          cout << tmp1 << " " << minus[i] << endl;
        }
        tmp1 -= minus[i];
      }
    }else{
      if(i < mn-1){
        cout << plus[i] << " " << minus[i] << endl;
        plus.push_back(plus[i] - minus[i]);
      }else if(i >= mn -1 && i != n-2){
        cout << tmp2 << " " << plus[i] << endl;
        tmp2 -= plus[i];
      }else{
        cout << plus[i] << " " << tmp2 << endl;
      }
    }
  }
}


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

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int64_t a, b, c, d;
    cin >> a >> b >> c >> d;
    int64_t e = c * d / gcd(c, d);
    cout << (b-a+1) - ((b/c-(a-1)/c) + (b/d-(a-1)/d) - (b/e-(a-1)/e)) << endl;
    
    return 0;
}

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

int main (void)
{
    char s[11];
    int i, len, c = 0;

    gets(s);

    if (s[0] != 'A') {
        puts("WA");
        return 0;
    }
    if (s[1] < 'a' || s[1] > 'z') {
        puts("WA");
        return 0;
    }

    len = strlen(s);
    for (i = 2; i < len -1; i++) {
        if (s[i] == 'C') c++;
        else if (s[i] < 'a' || s[i] > 'z') {
            puts("WA");
            return 0;
        }
    }
    if (c != 1) {
        puts("WA");
        return 0;
    }
    if (s[len - 1] < 'a' || s[len  - 1] > 'z') {
        puts("WA");
        return 0;
    }
    puts("AC");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
signed main()
{
int a,b;
  cin>>a>>b;
  if(a==b){
    cout<<"Draw\n";
  }else if(a>b){
    if(a==13 && b==1){
    cout<<"Bob\n";
    }else{
      cout<<"Alice\n";
    }
  }
  else{
    if(a==1 && b==13){
    cout<<"Alice\n";
    }else{
      cout<<"Bob\n";
    }
  }
}

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

int main() {
	int a, b, ans;
	char o;
	do {
	cin >> a >> o >> b;
	if (o == '?') break;
	if (o == '+')
		cout << a + b << endl;
	else if (o == '-')
		cout << a - b << endl;
	else if (o == '*')
		cout << a * b << endl;
	else if (o == '/') {
		if (b == 0)
			return 0;
		cout << a / b << endl;
	}
    } while (true);
	return 0;
}


Measured memory_bytes: 3120
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int mem[][] = new int[n+1][n+1];
		for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) {
			mem[i][j] = sc.nextInt() + mem[i][j-1] + mem[i-1][j] - mem[i-1][j-1];
		}
		int max = mem[1][1];
		for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int k=i;k<=n;k++) for(int l=j;l<=n;l++) 
			max = Math.max(max, mem[k][l] + mem[i-1][j-1] - mem[i-1][l] - mem[k][j-1]);
		System.out.println(max);
	}
}

Measured memory_bytes: 37600
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <numeric>
#include <iomanip>
#include <bitset>
#define FI first
#define SE second
#define EB emplace_back
#define MP make_pair
#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 1100000000
#define LLINF 1100000000000000000LL
#define Decimal fixed << setprecision(20)
#define ALL(c) c.begin(),c.end()
#define SHOWVEC(v, sz) for(int i = 0; i < sz; i++) cerr << v[i] << ' '; cerr << endl;
#define SHOWX(x) cerr << #x << ": " << x << endl;
#define SHOWP(p) cerr << "[" << p.first << ',' << p.second << "]";
#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int one(ll b, int i) {
  return (b >> i) & 1;
}

ll pow2(int n) {
  return (1LL << n) % MOD;
}

// c[i][j] := A[0]~A[i]のうちjビット目が1であるような個数
int c[310000][60];
int N;
vector<ll> A;
void make_c() {
  REP(j, 60) c[0][j] = one(A[0], j);
  for (int i = 1; i < N; i++) {
    REP(j, 60) {
      c[i][j] = c[i-1][j] + one(A[i], j);
    }
  }
}

void showbit(ll b) {
  REP(i, 60) {
    cout << ((b >> (59-i)) & 1);
  }
  cout << endl;
}

int main()
{
  REP(i, 310000) REP(j, 60) c[i][j] = 0;
  cin >> N;
  A.resize(N);
  REP(i, N) cin >> A[i];

  //REP(i, N) {
  //  showbit(A[i]);
  //}
  make_c();

  ll ans = 0;
  for (int i = 1; i < N; i++) {
    REP(j, 60) {
      int cnt_one = c[i][j];
      int cnt_zero = (i+1) - cnt_one;
      //cerr << i << '-' << j << ":" << cnt_zero << ' ' << cnt_one << endl;
      if (one(A[i], j)) {
        ans += (cnt_zero * pow2(j)) % MOD;
        ans %= MOD;
      } else {
        ans += (cnt_one * pow2(j)) % MOD;
        ans %= MOD;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 75264
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i = 0;i < n; i++)
#define REP(i,n) for(int i = 1;i <= n; i++)
// ----GCC ONLY---- //
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// ----        ---- //
#define ll long long
#define MOD 10000007
#define PB push_back
 
using namespace std;

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

    int c = n*a;

    if(c >= b){
        cout << b <<"\n";
    }else{
        cout << c <<"\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N; cin >> N;
  ll cnt = 0;
  for(ll i = 1; i <= N; i++) {
    string s = to_string(i);
    int j = s.size();
    if(j % 2 == 1) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3760
#include <iostream>
#include <unordered_map>

using namespace std;

int main(){
    int n;
    cin >> n;
    unordered_map<int, int> s;
    for(int i=0; i<n; ++i){
        int a;
        cin >> a;
        if(s.find(a)==s.end()){
            s[a]=1;
        } else{
            ++s[a];
        }
    }
    int res=0;
    for(auto& p : s){
        int d=p.second-p.first;
        if(d<0) res+=p.second;
        else res+=d;
    }
    cout << res << endl;
    return 0;
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  string ans;
  if ((A == B && B != C) || (A == C && B != C) || (B == C && A != B))
    ans = "Yes";
  else
    ans = "No";
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }

void main() {
  auto S = readln.chomp;

  string solve() {
    return S == "AAA" || S == "BBB" ? "No" : "Yes";
  }

  solve().writeln;
}


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

int main() {
  int N; 
  cin >> N;
  vector<string> vec(N);
  for (int i = 0; i < N; i++) {
  	cin >> vec.at(i);
  }
  
  // P, W, G, Y
  vector<int> flags(4, 0);
  for (int i = 0; i < N; i++) {
  	if (vec.at(i) == "P") flags.at(0) = 1;
    else if (vec.at(i) == "W") flags.at(1) = 1;
    else if (vec.at(i) == "G") flags.at(2) = 1;
    else if (vec.at(i) == "Y") flags.at(3) = 1;
  }
  int count = 0;
  for (int i = 0; i < 4; i++) {
  	count += flags.at(i);
  }
  
  if (count == 4) cout << "Four";
  else cout << "Three";
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int         long long
#define ull 	    unsigned long long
#define ll 	    long long
#define N	    100005
#define M 	    1000000007
#define pb 	    push_back
#define p_q 	    priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp 	    make_pair
#define lb 	    lower_bound
#define ub	    upper_bound
#define F           first
#define S           second
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ini(a,n,b)	for(ll int i=0;i<n;i++) a[i]=0;
#define cset(a)		__builtin_popcountll(a)
#define hell 		(ull)1e9
#define re 		resize


signed main(void)
{ios
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
	{
		int n;
		cin>>n;
		int arr[n];
		rep(i,0,n) cin>>arr[i];
		int dp[n+1];
		dp[1]=0;
		dp[2]=abs(arr[1]-arr[0]);
		rep(i,3,n+1)
		{
			dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i-2]),dp[i-2]+abs(arr[i-1]-arr[i-3]));
		}
		//rep(i,1,n+1)
		cout<<dp[n]<<endl;

	}
	
}

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

int main(){
    int N,M;cin>>N>>M;
    vector<vector<int>> s(M,vector<int>(0)); 
    for (int i = 0; i < M; i++)
    {
        int k;cin>>k;
        for (int j = 0; j < k; j++)
        {
            int a;cin>>a;
            a--;
            s[i].push_back(a);
        }
    }
    vector<int> p(M);
    for (int i = 0; i < M; i++)cin>>p[i];
    
    long long cnt=0;
    for (int i = 0; i < (1<<N); i++)
    {
         bool ok=true;
        for (int j = 0; j < M; j++)
        {
            int on=0;
            for (int v:s[j])
            {
                if(i&(1<<v))on++;
            }
            if(on%2!=p[j])ok=false;
        }
        if(ok)cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3648
#include<stdio.h>



int main(void)

{
   
	int w,h,x,y,r;


   

	scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);


   

	if(0<=x-r && 0<=y-r && x+r<=w && y+r<=h)

 
 		printf("Yes\n");


  
	 else
   
 
		 printf("No\n");


  

	 return 0;


}




Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define sosu 998244353
#define i_5 sosu-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll sosu;

ll hpow(ll x,ll y){
    ll ans=1;
    ll i=x;
    if(y==0)return 1;
    while(y>0){
        if(y%2==1){
            ans=(ans*i)%sosu;
        }
        i=(i*i)%sosu;
        y=y/2;
        
    }
    return ans;
}

ll memop[2000000];
ll mkai(ll i){
    if(i==0){
        return 1;
    }
    if(memop[i]!=0){
        return memop[i];
    }else{
        ll ans=(mkai(i-1)*hpow(i,sosu-2))%sosu;
        memop[i]=ans;
        return ans;
    }
}

ll memok[2000000];
ll kai(ll i){
    if(i==0){
        return 1;
    }
    if(memok[i]!=0){
        return memok[i];
    }else{
        ll ans=(kai(i-1)*i)%sosu;
        memok[i]=ans;
        return ans;
    }
}

ll comb(ll n,ll k){
    ll ans=(kai(n)*mkai(k))%sosu;
    ans=(ans*mkai(n-k))%sosu;
    return ans;
}

int main(){fastio
    sosu=998244353;
    ll n,m,k;cin>>n>>m>>k;
    ll now=1;
    ll ans=0;
    now=comb(n-1,n-k-1);
    rep(i,n-k-1,n-1){
        ans=(((ans+((now*m)%sosu)*hpow(m-1,i)))%sosu+sosu)%sosu;
        //cout<<now<<endl;
        now=(now*(n-i-1))%sosu;
        now=(now*hpow(i+1,sosu-2))%sosu;
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
     
    
    return 0;
}





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

int main() {
  int n;cin>>n;
  ll ans=1,x=1e18;
  bool ng=false;
  rep(i,n){
    ll a;cin>>a;
    if(a==0){
      cout<<0<<endl;
      return 0;
    }
    if(ng||x/ans<a)ng=true;
    ans*=a;
  }
  if(ng)cout<<-1<<endl;
  else cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100;
int N;
int A[MAX_N];
int B[MAX_N];

int main() {

  cin >> N;
  rep(i, N-1) cin >> B[i];

  A[0] = B[0];
  for (int i = 1; i < N-1; ++i) {
    A[i] = min(B[i-1], B[i]);
  }
  A[N-1] = B[N-2];

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

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
from itertools import combinations_with_replacement
from collections import defaultdict


def main():
    n, m, q = map(int, input().split())
    abcd = [list(map(int, input().split())) for _ in range(q)]

    ll = list(combinations_with_replacement(range(1, m+1), n))

    ans = 0
    for l in ll:
        tmp = 0
        for data in abcd:
            if l[data[1]-1] - l[data[0]-1] == data[2]:
                tmp += data[3]
        if tmp > ans:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 21904
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//ll dp[1004][100004];
ll ks(ll v[],ll wt[],ll w,ll n){
	ll dp[n+1][w+1];
	// initialization
	for(int i=0;i<=w;i++){
		dp[0][i]=0;
	}
	
	for(int i=0;i<=n;i++){
		dp[i][0]=0;
	}
	
	
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=w;j++){
			if(wt[i-1]<=j){
				dp[i][j]=max(v[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
			}
			else{
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	

	return dp[n][w];
}


int main(){
//	memset(dp,-1,sizeof(dp));
	ll n,w;
	cin>>n>>w;
	ll wt[n],v[n];
	for(ll i=0;i<n;i++){
		cin>>wt[i]>>v[i];
	}
	cout<<ks(v,wt,w,n);
}

Measured memory_bytes: 79104
n, m = gets.chomp.split(" ").map(&:to_i)
a = []
b = []
list = {}
m.times do |i|
  x, y = gets.chomp.split(" ").map(&:to_i)
  list[x] = [] if list[x].nil?
  list[y] = [] if list[y].nil?
  list[x].push(y)
  list[y].push(x)
end

dist = Array.new(n+1, -1)
que = []

dist[1] = 0
que.push(1)

while !que.empty? do
  v = que.first
  # p que
  que.shift
  # p list[v]
  list[v].each do |nv|
    next if dist[nv] != -1
    dist[nv] = v
    que.push(nv)
  end
end
dist = dist.drop(2)
if dist.include?(-1)
  puts "No"
else
  puts "Yes"
  puts dist
end

Measured memory_bytes: 33772
#include<stdio.h>
int main() {
	int n,max=-1000001,min=1000001,d[10005];
	long long sum = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &d[i]);
	for (int i = 0; i < n; i++) {
		sum += d[i];
		if (max < d[i])
			max = d[i];
		if (min > d[i])
			min = d[i];
	}
	printf("%d %d %lld\n", min, max, sum);
	return 0;
}

Measured memory_bytes: 2756
from decimal import Decimal, getcontext
W, H, x, y = map(int, input().split())
getcontext().prec = 10

gpoint = [W/2, H/2]
res = [0,0]

if gpoint[0] == x and gpoint[1] == y:
    res[1] = 1
else:
    res[1] = 0

res[0] = Decimal(W) * Decimal(H) / Decimal(2)
res[0] = float(res[0])
# print(res)

for i in res:
    print(i, end=" ")

Measured memory_bytes: 5332
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
/* END OF TEMPLATE */

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n, q;
    cin >> n >> q;
    vll s(n), t(n), x(n);
    multiset<tuple<ll, ll, ll>> dat;
    rep(i, n){
        cin >> s[i] >> t[i] >> x[i];
        dat.emplace(s[i]-x[i], 1, x[i]);
        dat.emplace(t[i]-x[i], 0, x[i]);
    }
    vector<tuple<ll, ll>> dat2;
    multiset<ll> ms;
    ms.emplace(INF);
    for(auto itr = dat.begin(); itr != dat.end(); ++itr){
        ll d0 = get<0>(*itr);
        ll d1 = get<1>(*itr);
        ll d2 = get<2>(*itr);
        if(d1){
            ms.emplace(d2);
        }else{
            ms.erase(ms.find(d2));
        }
        dat2.emplace_back(d0, *ms.begin());
    }
    vll d(q);
    rep(i, q){
        cin >> d[i];
        auto itr = upper_bound(ALL(dat2), make_tuple(d[i], INF));
        itr--;
        ll ans = (get<1>(*itr) == INF ? -1 : get<1>(*itr));
        cout << ans << "\n";
    }
    sort(ALL(d));
    
    return 0;
}

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

using namespace std;

double dp[3005];
int main()
{
    //freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    dp[0]=1;
    for (int i=0;i<n;i++)
    {
        double pr;
        cin >> pr;
        for (int j=i+1;j>=0;j--)
        {
            dp[j]=(j==0 ? 0 : pr*dp[j-1])+dp[j]*(1.0-pr);
        }
    }

    double ans=0;
    for (int i=0;i<=n;i++)
    {
        int t=n-i;
        if (i>t)
            ans+=dp[i];
    }

    cout << fixed << setprecision(10) << ans;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);

  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());


  int Alice= 0, Bob= 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) Alice += a.at(i);
    else Bob += a.at(i);
  }
  int ans = Alice - Bob;
  cout << ans << endl;
  
}

Measured memory_bytes: 256
N = input()
l = len(N)
N = int(N)
if l == 1:
    print(N)
elif l == 2:
    print(9)
elif l == 3:
    print(9 + (N - 99))
elif l == 4:
    print(9 + 900)
elif l == 5:
    print(9 + 900 + (N - 9999))
else:
    print(9 + 900 + 90000)

Measured memory_bytes: 3060
import math


def main():
    N = int(input())
    L = list(map(int, input().split()))

    cnt = 0

    for i in range(N):
        for j in range(i + 1, N):
            for k in range(j + 1, N):
                if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
                    continue
                sum_ = L[i] + L[j] + L[k]
                max_ = max(L[i], L[j], L[k])

                if max_ < sum_ - max_:
                    cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000000
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
int getbit(int s, int i)
{ return (s >> i) & 1; }
int cntbit(int s)
{ return __builtin_popcountll(s); }
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}

int main()
{
     fast;
     ll x;
    cin>>x;
    for(ll i=0;i<3980;i++)
    {
         for(ll j=0;j<=3980;j++)
         {
              ll p1=pow(i,5);
              ll p2=pow(j,5);
              if(p1-p2==x)
              {
                   cout<<i<<" "<<j;
                   return 0;
              }
              else if(p2%2==1&&p1+p2==x)
              {
                   cout<<i<<" -"<<j;
                   return 0;
              }
         }

    }
}


Measured memory_bytes: 4184
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
 
int main() {
	int N;
	cin >> N;
	vector<int> x(N), y(N), h(N);
	for (int i = 0; i < N; i++)
	{
		cin >> x[i] >> y[i] >> h[i];
	}
 
	//[0, 100]に座標があるのでMAXを定義すると楽
	int MAX = 100;
 
	for (int posY = 0; posY <= MAX; posY++)
	{
		for (int posX = 0; posX <= MAX; posX++)
		{
			//頂上がどれくらいの高さであってほしいか。
			//-1はまだ良く分からない時。0以上は確定してるとき
			//-2はダメだって分かった時
			int needH = -1;
 
			for (int i = 0; i < N; i++)
			{
				if (h[i] > 0) {
					//この頂点から見て、頂上がposY,posXの時に、
					//どれくらいの高さがあってほしいかを求める
					int tmp = h[i] + abs(posY - y[i]) + abs(posX - x[i]);
					if (needH == -1) {
						needH = tmp;
					}
					else {
						if (needH != tmp) {
							needH = -2;
							break;
						}
					}
				}
			}
			//ダメだったら別の場所を探す。
			if (needH == -2) continue;
 
			for (int i = 0; i < N; i++)
			{
				//高さが0の場合に矛盾してないか調べる
				if (h[i] == 0) {
					int dist = abs(posY - y[i]) + abs(posX - x[i]);
					if (needH > dist) {
						needH = -2;
						break;
					}
				}
			}
 
			if (needH == -2) continue;
 
			//見つけられたら答えをそのまま返す。
			cout << posX << " " << posY << " " << needH << endl;
			return 0;
		}
	}
 
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>
#include <set>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N;
  cin >> N;

  cout << (N/11) * 2 + ((5 + N%11) / 6) << endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include<cmath>
using namespace std;
#define int long long int
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define pii pair<int,int>
#define piii pair< int,pair<int,int> >
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define endl '\n'
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define N 2005
#define mod 1000000007
#define inf 1e17
#define pf push_front
#define pob pop_back
#define pof pop_front
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
int n,W;
int w[101],v[101];
int dp[100001][101];
int knapsack(int remw,int numitem)
{
    if(remw==0||numitem==0)
    {
        return 0;
        }
if(dp[remw][numitem]!=-1)
{
    return dp[remw][numitem];
}
if(w[numitem-1]<=remw)
{
    return dp[remw][numitem]=max(v[numitem-1]+knapsack(remw-w[numitem-1],numitem-1),knapsack(remw,numitem-1));
}
else if(w[numitem-1]>remw)
{
    return dp[remw][numitem]=knapsack(remw,numitem-1);
}
}
int32_t main()
{
   // boost
    int t=1;
   // cin>>t;
    while(t--)
    {
        
        cin>>n>>W;
        memset(dp,-1,sizeof(dp));

        for(int i=0;i<n;i++)
        {
            cin>>w[i]>>v[i];
        }
        cout<<knapsack(W,n);


        
    }


    

}

Measured memory_bytes: 79232
#include <cstdio>
#include <queue>
#define R(i, n) for(int i = 0;i < n;i++)
#define RR(i, n) for(int i = n;i >= 0;i--)
#define F(i, m, n) for(int i = m;i < n;i++)
#define FR(i, m, n) for(int i = m; i >= n; i--)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define P(a) printf("%d", a)
using namespace std;


int N, K;

int main() {
	priority_queue<int> pque;
	S2(N, K);
	R(i, N) {
		int hp;
		scanf("%d", &hp);
		pque.push(hp);
	}
	if (K > N) K = N;
	R(i, K) {
		pque.pop();
	}
	long long ans = 0;
	while (!pque.empty()) {
		ans += pque.top();
		pque.pop();
	}
	printf("%lld", ans);
}

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n;
int v[N];
LL m;
LL x[N];
LL s[N], rs[N];

int main()
{
	scanf("%d%lld", &n, &m);
	for (int i = 1; i <= n; i ++ ) scanf("%lld%d", &x[i], &v[i]);
	
	for (int i = 1; i <= n; i ++ ) s[i] = s[i - 1] + v[i];
	for (int i = n; i >= 1; i -- ) rs[i] = rs[i + 1] + v[i];
	for (int i = 1; i <= n; i ++ )
	{
		s[i] = max(0LL, s[i] - x[i]);
		s[i] = max(s[i], s[i - 1]);
	}
	for (int i = n; i >= 1; i -- )
	{
		rs[i] = max(0LL, rs[i] - (m - x[i]));
		rs[i] = max(rs[i], rs[i + 1]);
	}
	
	LL res = 0;
	for (int i = 1; i <= n; i ++ ) res = max(res, s[i] + max(0LL, rs[i + 1] - x[i]));
	for (int i = n; i >= 1; i -- ) res = max(res, rs[i] + max(0LL, s[i - 1] - (m - x[i])));
	printf("%lld\n", res);
	return 0;
}

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

int main(){
	int n,a,b;
	long suma=0,sumb=0;
	cin >> n;
	while(n!=0){
		for(int i=0;i<n;i++){
			cin >> a >> b;
			if(a>b) suma+=a+b;
			else if(a<b) sumb+=a+b;
			else{suma+=a;sumb+=b;}
		}
		printf("%ld %ld\n",suma,sumb);
		cin >> n;
		suma = sumb = 0;
	}
	return 0;
}

Measured memory_bytes: 1148
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
	#define SAY(X) cout << (X) << '\n';
#else
	#define DBG(X)
	#define SAY(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

const int MAXN = 307 * 307;

int H, W, D;
int X[MAXN], Y[MAXN];

vector<int> pref[MAXN];
int sz[MAXN];

void solve() {
	cin >> H >> W >> D;

	for(int i = 0; i < H; ++i) {
		for(int j = 0; j < W; ++j) {
			int val = fetch<int>() - 1;

			X[val] = i;
			Y[val] = j;
		}
	}

	for(int rem = 0; rem < D; ++rem) {
		for(int i = rem; i < H * W; i += D) {
			++sz[rem];
		}

		pref[rem].resize(sz[rem], 0);

		for(int i = rem; i < H * W; i += D) {
			int j = (i - rem) / D;

			if(j == 0) {
				continue;
			}

			pref[rem][j] = pref[rem][j - 1] + abs(X[i] - X[i - D]) + abs(Y[i] - Y[i - D]);
		}

#ifdef __LOCAL
		cout << "@rem=" << rem << '\n';
		cout << "@pref=";

		for(int i = 0; i < sz[rem]; ++i) {
			cout << pref[rem][i] << ' ';
		}

		cout << '\n';
#endif
	}

	int q = fetch<int>();

	while(q--) {
		int L = fetch<int>() - 1;
		int R = fetch<int>() - 1;

		int rem = L % D;
		L -= rem, R -= rem;
		L /= D, R /= D;

		if(L <= R) {
			cout << pref[rem][R] - pref[rem][L] << '\n';
		} else {
			cout << pref[rem][sz[rem] - 1] - pref[rem][R] + pref[rem][L] << '\n';
		}
	}
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 6528