akhauriyash/Code-Regression huggingface dataset:
// using no_way as a way
// using no_limitation as a limitation

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = (1e-9);
typedef long long ll;
typedef unsigned long long ull;
#define flush fflush(stdout), cout.flush()
#define all(v) ((v).begin()),((v).end())
#define rall(v) ((v).rbegin()),((v).rend())
#define clr(v,line) memset(v,line,sizeof(v))
#define rep(i,n) for(int(i)=0;(i)<(int)(n);(i)++)
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define RT(x) return cout<<x, 0;
//#define lcm(a,b) (a*(b/__gcd(a,b)))
#define P 1000000007
#define endl '\n'
// const int dx[] = {1,-1,0,0,1,-1,1,-1};
// const int dy[] = {0,0,1,-1,1,-1,-1,1};
// const int dxhorse[] = {-2,-2,-1,-1,1,1,2,2};
// const int dyhorse[] = {1,-1,2,-2,2,-2,1,-1};
 
void file() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void fast()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
}
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());


int main(int argc, char const *argv[])
{
     // file();
    fast();
    
    int n, m; cin>>n>>m;
    vi v(n);
    double total = 0.0;
    for (int i = 0; i < n; ++i)
    {
        cin>>v[i], total+=v[i];
    }
    sort(rall(v));
    for (int i = 0; i < m; ++i)
    {
        if ((1.0 / (4.0 * m) * total) - v[i] > EPS )
        {
            RT("No");
        }
    }
    cout<<"Yes";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define SUM(v) accumulate(v.begin(),v.end(),lli(0))
#define rev(n,d) for(int i=n;i>=d;i--)
#define FOR0(n) for(int i=0;i<n;i++)
#define FOR(a,n) for(int i=a;i<n;i++)
#define FORQ(a,n) for(int i=a;i<=n;i++)
#define inf 1000000009
#define inff 0x3f3f3f3f
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define mem(ar,x) memset(ar,x,sizeof ar)
#define present(container, element) (container.find(element) != container.end())
#define max3(a,b,c) return (lli(a)>lli(b)?(lli(a)>lli(c)?a:c):(lli(b)>lli(c)?b:c))
#define max4(a,b,c,d) return (max3(a,b,c)>lli(d)?(max3(a,b,c)):d)
#define min3(a,b,c) return (lli(a)<lli(b)?(lli(a)<lli(c)?a:c):(lli(b)<lli(c)?b:c))
#define min4(a,b,c,d) return (max3(a,b,c)<lli(d)?(max3(a,b,c)):d)
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<int,pii>ppii;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<pii>vpii;
const int N=100005;
int dr8[]={0,0,1,-1,1,1,-1,-1};
int dc8[]={1,-1,0,0,-1,1,-1,1};
int dr4[]={0,1,-1,0};
int dc4[]={1,0,0,-1};
int main(){
	fast
	int x,y;
	cin>>x>>y;
	int a,b;
	b=(y-(2*x))/2;
	int np=0;
	if((y-2*x)<0) np=1;
	if((y-(2*x))%2) np=1;
	a=(4*x-y)/2;
	if((4*x-y)%2) np=1;
	if((4*x-y)<0) np=1;
	if((a+b)!=x) np=1;
	if(a<0||b<0) np=1;
	if(np) cout<<"No";
	else cout<<"Yes";
}



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

int main() {
    string s, t;
    cin >> s >> t;
    int n = (int)s.size();
    s += s;
    vector<vector<int>> cnt(26, vector<int>());
    for (int i = 0; i < s.size(); i++) {
        cnt[s[i] - 'a'].push_back(i + 1);
    }

    long long res = 0;
    int temp = 0;
    for (char c : t) {
        if (cnt[c - 'a'].empty()) {
            cout << -1 << endl;
            return 0;
        }

        int index = *upper_bound(cnt[c - 'a'].begin(), cnt[c - 'a'].end(), temp);
        temp = index;
        if (temp > n) {
            res += n;
            temp -= n;
        }
    }
    res += temp;

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int n, m;
long long P[100010];
long long Q[100010];
long long R[100010];

long long sum[100010];
int cnt[100010];

void forward() {
	for(int i = 2; i <= n; i++) {
		if(a[i-1] <= a[i]) {
			sum[a[i-1] + 1] += a[i-1];
			sum[a[i] + 1] -= a[i-1];
			cnt[a[i-1] + 1] += 1;
			cnt[a[i] + 1] -= 1;
		}
	}
	long long cursum = 0;
	int cunt = 0;
	for(int i = 1; i <= m; i++) {
		cursum += sum[i];
		cunt += cnt[i];
		P[i] = 1LL * i * cunt - cursum;
		P[i] -= cunt;
	}
}
void backward() {
	memset(sum, 0, sizeof sum);
	memset(cnt, 0, sizeof cnt);
	
	for(int i = 2; i <= n; i++) {
		if(a[i-1] > a[i]) {
			sum[a[i]] += m - a[i-1];
			cnt[a[i]] += 1;
		}
	}
	long long cursum = 0;
	int cunt = 0;
	for(int i = m; i >= 1; i--) {
		cursum += sum[i];
		cunt += cnt[i];
		Q[i] = 1LL * i * cunt + cursum;
		Q[i] -= cunt;
	}
	
	memset(sum, 0, sizeof sum);
	memset(cnt, 0, sizeof cnt);
	for(int i = 2; i <= n; i++) {
		if(a[i-1] > a[i]) {
			sum[a[i - 1] + 1] += a[i - 1];
			cnt[a[i - 1] + 1] += 1;
		}
	}
	cursum = 0;
	cunt = 0;
	for(int i = 1; i <= m; i++) {
		cursum += sum[i];
		cunt += cnt[i];
		R[i] = 1LL * i * cunt - cursum;
		R[i] -= cunt;
	}
}
/*
long long brute(int x) {
	for(int i = 2; i <= n; i++) {
		if(a[i-1] <= a[i]) {
			if(a[i-1] < x && x <= a[i]) ans += 1 + (a[i] - x);
			else ans += a[i] - a[i-1];
		} else {
			ans += 
		}
	}
}
*/

int main (int argc, char const* argv[])
{
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}	
	forward();
	backward();
	
	long long tot = 0;
	for(int i = 2; i <= n; i++) {
		if(a[i-1] <= a[i]) {
			tot += a[i] - a[i-1];
		} else {
			tot += m - a[i-1] + a[i];
		}
	}
	long long ans = tot;
	for(int i = 1; i <= m; i++) {
		long long res = tot - P[i] - Q[i] - R[i];
		ans = min(ans, res);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define pb push_back
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef pair<int, int> P;
const int maxn = 20005;
typedef long long ll;
ll a[maxn], b[maxn], n;
int main() {
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) cin >> b[i];
    ll sum = 0;
    ll op = 0;
    for(int i = 1; i <= n; i++){
        if(b[i] > a[i]){
            sum+=ceil((b[i] - a[i])/2.0);
        }
        op += b[i]-a[i];
    }
    if(sum <= op)puts("Yes");
    else puts("No");
}

Measured memory_bytes: 384
n = int(input())
l = list(map(int, input().split()))
ans = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if l[i] + l[j]>l[k] and l[j]+l[k]>l[i] and l[k]+l[i]>l[j] and l[i] != l[j] and l[j] != l[k] and l[k] != l[i]:
                ans += 1
print(ans)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
const int DX[8]={-1,0,1,0,-1,-1,1,1},DY[8]={0,-1,0,1,-1,1,-1,1};


int main(){;
	while(1){
		int h,w;
		cin>>h>>w;
		if(h==0) break;
		vvi a(h,vi(w));
		for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin>>a[i][j];
		int res=0;
		for(int lx=0;lx<h;lx++) for(int rx=lx+3;rx<=h;rx++) for(int ly=0;ly<w;ly++) for(int ry=ly+3;ry<=w;ry++){
			int mx=inf;
			for(int i=lx;i<rx;i++) for(int j=ly;j<ry;j++) if(i==lx||i==rx-1||j==ly||j==ry-1){
				mx=min(mx,a[i][j]);
			}
			bool B=1;
			for(int i=lx+1;i<rx-1;i++) for(int j=ly+1;j<ry-1;j++) if(a[i][j]>=mx) B=0;
			if(!B) continue;
			int tmp=0;
			for(int i=lx+1;i<rx-1;i++) for(int j=ly+1;j<ry-1;j++) tmp+=mx-a[i][j];
			res=max(res,tmp);
		}
		cout<<res<<endl;
	}
}


Measured memory_bytes: 3160
n = gets.to_i
s1 = []
n.times do
  s1 << gets.chomp.to_s
end
m = gets.to_i
s2 = []
m.times do
  s2 << gets.chomp.to_s
end
s1_cnt = s1.inject(Hash.new(0)){|r, i| r[i] += 1; r}
s2_cnt = s2.inject(Hash.new(0)){|r, i| r[i] += 1; r}
ans = 0
s1_cnt.each do |i|
  if ans < i[1].to_i - s2_cnt[i[0]].to_i
    ans = i[1].to_i - s2_cnt[i[0]].to_i
  end
end
if ans > 0
  puts ans
else
  puts '0'
end


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

int n,a,b,dig,tmp;
long long x,y;
vector<long long> ans;
int main(int argc,char const* argv[])
{
  string s;
  cin >> s;
  s[0]='2';
  s[1]='0';
  s[2]='1';
  s[3]='8';
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>

int main(){
  int K;
  std::cin>>K;
  long long ans=0;
  for(int a=0;a<K;a++){
    
    for(int b=0;b<K;b++){
      
      for(int i=0;i<K;i++){
        int x =std::gcd(a+1,b+1);
        int y =std::gcd(x,i+1);
        ans=ans+y;
      }
    }
  }
  



    std::cout << ans << std::endl;

}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

// ------------------------------------------------------------------------------------------

const int INF = 1e18;

int N, A, B, C;
vec<int> l;

int rec(int idx, int a, int b, int c) {
  if (idx >= N) {
    if (a == 0 or b == 0 or c == 0) return INF;
    return abs(a - A) + abs(b - B) + abs(c - C);
  }

  int ret = INF;

  // A
  chmin(ret, rec(idx + 1, a + l[idx], b, c) + (a > 0 ? 10 : 0));
  // B
  chmin(ret, rec(idx + 1, a, b + l[idx], c) + (b > 0 ? 10 : 0));
  // C
  chmin(ret, rec(idx + 1, a, b, c + l[idx]) + (c > 0 ? 10 : 0));
  // No
  chmin(ret, rec(idx + 1, a, b, c));

  return ret;
}

signed main() {
  cin >> N >> A >> B >> C;
  l.resize(N);
  rep (i, N) {
    cin >> l[i];
  }

  cout << rec(0, 0, 0, 0) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int N,i,cnt=0;
    scanf("%d",&N);
    int P[N+1];
    for(i=1;i<=N;i++){
        scanf("%d",&P[i]);
    }

    int min=P[1];

    for(i=1;i<=N;i++){
        if(P[i]<=min){
        min=P[i];
        cnt++;
        }
    }
    printf("%d\n",cnt);

    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>

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

long long qmi(long long b, long long p){
    //快速幂求 b^p mod 1e9 + 7
    long long res = 1;
    while(p){
        if(p & 1) res = res * b % mod;
        p = p >> 1;
        b = b * b % mod;
    }
    return res % mod;
}

long long inv(long long b){
    //求 x，使得 xb = 1 (mod 1e9 + 7)
    return qmi(b, mod - 2) % mod;
}

long long mfact(long long x){
    //返回的是 x！mod 1e9 + 7
    long long res = 1;
    for(long long i = 1; i <= x; i ++){
        res = res * i % mod;
    }
    return res;
}

long long combine(long long a, long long b){
    //返回的是 aCb mod 1e9 + 7；
    return mfact(a) * inv(mfact(b) * mfact(a - b) % mod) % mod;
}

int main(){
    int x, y;
    cin >> x >> y;
    if ((x + y) % 3 != 0) {
        cout << 0 << endl;
    } else {
        long long m, n;
        m = x - (x + y) / 3; // 解方程
        n = y - (x + y) / 3; 
        if( (m < 0) || (n < 0) ) cout << 0 << endl;
        else cout << combine(m + n, m) << endl;
    }
    return 0;
}


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

using namespace std;

#define ll long long

signed main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0;i < n;i++)
        cin >> a[i];
    /*
    x5 + x1 = a1
    x1 + x2 = a2
    x2 + x3 = a3
    x3 + x4 = a4
    x4 + x5 = a5
    a1 - a2 + a3 - a4 + a5
        = x5 + x1 - x1 - x2 + x2 + x3 - ... + x4 + x5
        = 2 * x5
     */
    /* xnの特定 */
    vector<ll> x(n);
    ll xn = 0;
    for (int i = 0;i < n;i++){
        if (i & 1) // iが奇数だったら
            xn -= a[i];
        else // iが偶数だったら
            xn += a[i];
    }
    xn /= 2;
    x[n - 1] = xn;
    ll x1 = a[0] - xn;
    x[0] = x1;
    for (int i = 1;i < n - 1;i++){
        x[i] = a[i] - x[i - 1];
    }
    for (int i = n - 1;i < 2 * n - 1;i++)
        cout << 2 *x[i % n] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 2944
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b >= c) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (A, B, C) = Slice3<long>();
            if (A == B)
                WriteLine(C);
            else if (B == C)
                WriteLine(A);
            else
                WriteLine(B);
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 27336
#include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xmod 100000007
using namespace std;

int n,m,dp[100005][5],a[100005][5],ans;
int main (){
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i=1;i<=n;i++){
		cin >> a[i][1] >> a[i][2] >> a[i][3];
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=3;j++){
			for (int k=1;k<=3;k++){
				if (j != k)
				dp[i][j]=max(dp[i-1][k],dp[i][j]);
			}
			dp[i][j]+=a[i][j];
		}
	}
	for (int i=1;i<=3;i++){
		ans=max(ans,dp[n][i]);
	}
	cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin>>s;
    while(s!="0"){
        int sum=0;
        for(int i=0;i<s.size();i++)
            sum+=s[i]-'0';
        cout<<sum<<endl;
        cin >>s;
    }
}


Measured memory_bytes: 3204
# import numpy as np
import statistics
while True:
    n = int(input())
    if n == 0:
        break
    list_point = [int(_) for _ in input().split()]
    average = statistics.mean(list_point)
    list_from_ave2 = [(list_point[i] - average)**2 for i in range(n)]
    sigma2 = sum(list_from_ave2) / n
    sigma = sigma2 ** (1 / 2)
    
    print(f"{sigma:.5f}")
    
    


Measured memory_bytes: 7144
import sys
import heapq
from collections import defaultdict
n, m = map(int, sys.stdin.readline().split())
a_b = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
dic = defaultdict(list)
for ele in a_b:
    dic[ele[0]].append(ele[1])

#print(dic)
L =[]
money = 0
for d in range(1, m+1):
    for e in dic[d]:
        heapq.heappush(L, -e)
    if L:
        money +=heapq.heappop(L)
print(-money)

Measured memory_bytes: 48940
#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
	ll A,B,C,K;
	cin>>A>>B>>C>>K;
	if(A>=K) cout<<K<<endl;
	else
	{
		if(K<=A+B) cout<<A<<endl;
		else  cout<<A-(K-A-B)<<endl;
	}
	 
	return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define NIL -2000000001
#define MAX 2000000000

double abs (double a) {
  if (a>0) {
    return a;
  } else {
    return -a;
  }
}

int main() {
  int n, t, a;
  scanf("%d", &n);
  scanf("%d %d", &t, &a);
  int H[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &H[i]);
  }
  double min=MAX;
  int ans;
  for (int i = 0; i < n; i++) {
    if (abs(t-H[i]*0.006-a)<min) {
      min = abs(t-H[i]*0.006-a);
      ans = i+1;
    }
  }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        int includedTax = sc.nextInt();
        int includedTax2 = includedTax + 1;
        int nomineeExcludedTax = (int) (includedTax / 1.08);
        int nomineeExcludedTax2 = (int) (includedTax2 / 1.08);
        int calculatedIncludedTax = (int) (nomineeExcludedTax * 1.08);
        int calculatedIncludedTax2 = (int) (nomineeExcludedTax2 * 1.08);
        System.out.println(includedTax == calculatedIncludedTax ? nomineeExcludedTax : includedTax == calculatedIncludedTax2 ? nomineeExcludedTax2 : ":(");
    }
}


Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <bitset>
using namespace std;

int main() {
  int n;
  cin >> n;
  bool one = false;
  vector<int> a(n);
  for(int i=0;i<n;i++) {
    char c;
    cin >> c;
    a[i] = c - '1';
    if(a[i] == 1) one = true;
  }
  int ans = 0;
  for(int i=0;i<n;i++) {
    if(a[i] % 2 == 0) continue;
    else {
      bool even = false;
      bitset<32> x(n-1);
      bitset<32> y(i);
      for(int j=0;j<32;j++) {
        if(!x.test(j) && y.test(j)) {
          even = true;
          break;
        }
      }
      if(!even) ans ^= 1;
    }
  }
  if(ans == 1) {
    cout << 1 << endl;
    return 0;
  }
  if(one) {
    cout << 0 << endl;
    return 0;
  }
  for(int i=0;i<n;i++) {
    if(a[i] == 0) continue;
    a[i] /= 2;
    bool even = false;
    bitset<32> x(n-1);
    bitset<32> y(i);
    for(int j=0;j<32;j++) {
      if(!x.test(j) && y.test(j)) {
        even = true;
        break;
      }
    }
    if(!even) ans ^= 1;
  }
  cout << ans * 2 << endl;
  return 0;
}


Measured memory_bytes: 4096
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

const int N = 100'009;

int n;
vector<int> g[N];
int pa[N];
int d[N];
int q[N];

int bfs(int from) {
  memset(pa, -1, sizeof pa);
  d[from] = 0;
  q[0] = from;
  for (int qh = 0, qt = 1; qh < qt; ++qh) {
    int x = q[qh];
    for (int y : g[x]) {
      if (y != pa[x]) {
        pa[y] = x;
        d[y] = d[x] + 1;
        q[qt++] = y;
      }
    }
  }
  int res = 0;
  for (int i = 0; i < n; ++i) {
    if (d[i] > d[res]) {
      res = i;
    }
  }
  return res;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    g[i].clear();
  }
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    --x;
    --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  vector<int> path;
  for (int i = bfs(bfs(0)); i != -1; i = pa[i]) {
    path.push_back(i);
  }
  int sum = 0;
  for (int x : path) {
    sum += (int)g[x].size();
  }
  if (sum - (int)path.size() + 1 != n - 1) {
    puts("-1");
    return 0;
  }
  vector<int> ans(n, n);
  for (int s = 0; s < 2; ++s) {
    vector<int> cur;
    int cnt = 0;
    for (int x : path) {
      int deg = (int)g[x].size();
      if (deg >= 3) {
        for (int i = 0; i < deg - 2; ++i) {
          cur.push_back(cnt + i + 1);
        }
      }
      cur.push_back(cnt);
      if (deg >= 3) {
        cnt += deg - 2;
      }
      ++cnt;
    }
    ans = min(ans, cur);
    reverse(path.begin(), path.end());
  }
  for (int i = 0; i < n; ++i) {
    if (i > 0) {
      putchar(' ');
    }
    printf("%d", ans[i] + 1);
  }
  putchar('\n');
}


Measured memory_bytes: 8560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n; string s;
    cin >> n >> s;
    ll r = 0, g = 0, b = 0;
    for(auto c : s){
        if (c == 'R') r++;
        else if (c == 'G') g++;
        else b++;
    }

    ll all = r*b*g;
    ll sub = 0;
    for (int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(s.at(i) == s.at(j)) continue;
        
        int k = j*2 -i;
        if(k >= n || s.at(k) == s.at(i) || s.at(k) == s.at(j))continue;
        sub++;
    }
   
} cout << all - sub << endl;
}

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

int main() {
	// your code goes here
	int n, k, q;
	cin >> n >> k >> q;
	int a[q];
	int p[n] = {0};
	for(int i=0; i<q; i++)
	{
		cin >> a[i];
		p[(a[i] - 1)] += 1;
	}
	
	for(int i=0; i<n; i++)
	{
		p[i] += (k - q);
		if(p[i] > 0)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1408
#include <cstdio>

using namespace std;

typedef long long ll;

ll mod_pow(ll a,ll b,ll m)
{
  if( b == 0 ) return 1;
  ll res = mod_pow(a*a%m,b/2,m);
  if(b&1)res=(a*res)%m;
  return res;
}

int main(void)
{
  ll n,m,k;
  scanf("%lld%lld%lld",&n,&m,&k);
  int a = n%10,b = 1;
  int shu[11] = {};
  int sss[11] = {},sz = 0;
  //for( int i = 0; i < m; i++ ) b = (b*a)%10;
  b = mod_pow(a,m,10);
  for( int i = 0; i < 10; i++ ) {
    if( shu[a] ) break;
    shu[a] = 1;
    sss[sz+1] = sss[sz]+a;
    ++sz;
    a = (a*b)%10;
  }
  //printf("%d\n",sz);
  ll res = 0;
  res += k/sz*sss[sz];
  k %= sz;
  for( int i = 0; i < k; i++ ) {
    res += a;
    a *= b;
    a %= 10;
    //printf("%d\n",a);
  }
  printf("%lld\n",res);
  return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */


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

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

	vector<PLL>anss;

	LL mx = *max_element(ALL(a));
	LL mn = *min_element(ALL(a));
	bool to_plus = abs(mx) > abs(mn);
	int mxid; {
		if (to_plus) {
			mxid = max_element(ALL(a)) - a.begin();
		}
		else {
			mxid = min_element(ALL(a)) - a.begin();
		}
	}
	FOR(i, 0, N) { // 正規化
		if (mxid == i)continue;
		anss.push_back(PLL(mxid, i));
	}
	if (!to_plus) {
		FORR(i, N - 1, 0) {
			anss.push_back(PLL(i, i - 1));
		}
	}
	else {
		FOR(i, 0, N - 1) {
			anss.push_back(PLL(i, i + 1));
		}
	}

	cout << SZ(anss) << endl;
	for (auto it : anss) {
		cout << it.first + 1 << " " << it.second + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
N = int(input())
ac, wa, tle, re = 0, 0, 0, 0
for i in range(N):
    result = input()
    if result == 'AC':
        ac += 1
    elif result == 'WA':
        wa += 1
    elif result == 'TLE':
        tle += 1
    else:
        re += 1
print('AC x %d\nWA x %d\nTLE x %d\nRE x %d' % (ac, wa, tle, re))

Measured memory_bytes: 69832
import java.util.Scanner

import scala.math.BigInt

object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt

  val xs = Vector.fill(n)(sc.nextInt)
  val expects = Range(0, n).zipWithIndex.map { case (a, i) =>
    if (n % 2 == 0)
      if (i % 2 == 0) a + 1 else a
    else if (i % 2 == 0) a else a + 1
  }.toVector

  val ans = if (xs.sorted == expects)
    BigInt(2).modPow(BigInt(n / 2), BigInt("1000000007"))
  else 0

  println(ans)
}


Measured memory_bytes: 61040
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

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

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

// =========ここまでテンプレ============

int main()
{
    ll n;
    cin >> n;
    vector<ll> as(n);
    bool containsZero = false;
    rep(i, n)
    {
        cin >> as[i];
        if (as[i] == 0)
        {
            containsZero = true;
        }
    }
    if (containsZero)
    {
        cout << 0 << endl;
    }
    else
    {
        ll result = 1;
        rep(i, n)
        {
            if (result >= LLONG_MAX / as[i])
            {
                result = -1;
                break;
            }
            result *= as[i];
            if (result > 1000000000000000000 || result < 0)
            {
                result = -1;
                break;
            }
        }
        cout << result << endl;
    }
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;
  vl cols(9, 0);
  ll a;
  rep(i, N){
    cin >> a;

    cols[((a / 400) < 8 ? (a / 400) : 8)]++;
  }

  ll cnt = 0;
  
  rep(i, 8){
    if(cols[i] > 0) cnt++;
  }

  if(cnt == 0){
    cout << 1 << ' ' << cols[8] << endl;
  } else{
    cout << cnt << ' ' << cnt + cols[8] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
program main
    implicit none
    character(3) n
    integer i
    logical :: flag = .false.
    read *, n
    do i=1,3
        if (n(i:i) == '7') then
            flag = .true.
            exit
        endif
    enddo
    if (flag) then
        print *, 'Yes'
    else
        print *, 'No'
    endif
end program main


Measured memory_bytes: 2792
N,M = map(int,input().split())
D = [0]
for _ in range(N):
  D.append(int(input()))

C = [0]
for _ in range(M):
  C.append(int(input()))

INF = float('inf')
dp = [ [INF]*(N+1) for _ in range(M+1) ]
dp[0][0] = 0

# i日目
for i in range(M):
  c = C[i+1]
  # 都市j
  for j in range(min(i+1,N)):
    d = D[j+1]

    dp[i+1][j] = min(dp[i+1][j], dp[i][j])
    dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]+c*d)

res = INF
for i in range(M+1):
  res = min(res, dp[i][-1])

print(res)


Measured memory_bytes: 18668
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)][::-1]

ab.append([0,0])
ans = 0
for i in range(n):
    if ab[i][0] % ab[i][1] == 0:
        pass
    elif ab[i][0] > ab[i][1]:
        ans += ab[i][1] - ab[i][0] % ab[i][1]
    elif ab[i][1]:
        ans += ab[i][1] - ab[i][0]
    ab[i+1][0] += ans

print(ans)

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

int main() {
	int student[31];
	for(int i=0;i<31;i++){
		student[i]=0;
	}
	for(int i=0;i<28;i++){
		int number;
		cin>>number;
		student[number]=1;
	}
	for(int i=1;i<=30;i++){
		if(student[i]==0){
			cout<<i<<endl;
		}
	}
	return 0;
}

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

const int MAXN = 1e5 + 10;

int N, M;
int C[MAXN];

int main()
{
	cin >> N >> M;
	for(int i = 1; i <= M; i++)
	{
		int u, v;
		cin >> u >> v;
		C[u]++, C[v]++;
	}

	for(int i = 1; i <= N; i++)
		if(C[i] & 1)
		{
			cout << "NO" << endl;
			return 0;
		}

	cout << "YES" << endl ;

	return 0;
}



Measured memory_bytes: 640
#include<stdio.h>

int main(void)
{
  int n,i,j,count=0,ans=0;
  scanf("%d",&n);
  for(i=1;i<=n;i+=2)
    {
      for(j=1;j<=i;j++)
	{
	  if(i%j == 0)
	    {
	      count++;
	    }
	}
      if(count == 8)
	{
	  ans++;
	  //printf("%d\n",i);
	}
      count = 0;
    }
  printf("%d\n",ans);
  return 0;
}


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

int main()
{
	string s;

	cin >> s;

	int n = s.size(), ans;
	char basic = s[n / 2];

	if (n % 2 == 0)
	{
		ans = n / 2;

		for (int i = 0; i < n / 2; i++)
		{
			if ((s[n / 2 - 1 - i] != basic) || (s[n / 2 + i] != basic))
			{
				break;
			}
			ans++;
		}
	}

	else
	{
		ans = (n + 1) / 2;

		for (int i = 0; i < (n - 1) / 2; i++)
		{
			if ((s[(n - 1) / 2 - 1 - i] != basic) || (s[(n - 1) / 2 + 1 + i] != basic))
			{
				break;
			}
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 512
#幅優先探索
H,W=map(int,input().split())
sy,sx=0,0
gy,gx=H-1,W-1
MAZE=[0]*H
queue=[]
queue.append([sy,sx])
black=0
for i in range(H):
  MAZE[i]=list(str(input()))
  black+=MAZE[i].count('#')
MAZE[sy][sx]='#'

d=[[100000000]*W for i in range(H)]
d[sy][sx]=0
dx=[1,0,-1,0]
dy=[0,1,0,-1]
goal=0
while len(queue)>0:
  #Qを取り出す
  Q=queue.pop(0)
  move=d[Q[0]][Q[1]]
  #もし取り出したところがゴールなら出力して終了
  if Q==[gy,gx]:
    goal=1
    break
  #4方向をループする
  for j in range(4):
    y=Q[0]+dy[j]
    x=Q[1]+dx[j]
    if 0<=y<H and 0<=x<W and MAZE[y][x] == '.':
      queue.append([y,x])
      MAZE[y][x] = '#'
      d[y][x] = move+1
if goal==1:
    print(H*W-black-move-1)
else:
    print(-1)

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

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

  vector<int> mochi(N);

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

  for (int i = 0; i < N; i++) {
    if (mochi.at(i) != x) {
      x = mochi.at(i);
      num++;
    }
  }
  cout << num << endl;
}

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

using namespace std;

int main() {
	int n;
	string s;
	cin >> n >> s;
	if(n %2 != 0 || n == 1) {
		cout << "No";
		return 0;
	} else {
		int j = s.length()/2;
		for(int i = 0; i < s.length()/2; i++) {
			if(s[i] != s[j]) {
				cout << "No";
				return 0;
			}
			j++;
		}
		cout << "Yes";
	}

	return 0;
}



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

using namespace std;
const int INF = 1e9 + 5;
int main() {
	int n,k;
	cin >> n >> k;
	vector<int> height(n);
	vector<int> sum(n,INF);
	int x;
	for(int i=0; i<n; i++) {
		cin >> x;
		height[i] = x;
	}
	
	sum [0] = 0;
	sum [1] = abs(height[1] - height[0]);
	for(int i=0; i<n; i++) {
		for(int j=i-k; j<i; j++) {
			if(j >= 0) {
				sum[i] = min(
						sum[j] + abs(height[i] - height[j]),
						sum[i]
						);
			}
		}
	} 
	cout << sum[n-1];
	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int solve(int n, vector<int>& p) {
  sort(p.begin(), p.end(), greater<int>());
  int sum = p.front() / 2;
  FOR(i, 1, n) {
    sum += p[i];
  }
  return sum;
}

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  REP(i, n) cin >> p[i];
  cout << solve(n, p) << endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

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

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let a = read::<i64>();
  let b = read::<i64>();
  let c = read::<i64>();

  println!("{}", a + b + c - max(a, max(b, c)))
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define per(i,a,b) for(ll i=(a)-1; i>=(b); i--)
const ll maxn=2e3+5;
ll q[maxn],d[maxn],u[maxn],s,e,c,ans[maxn],n,x,y;
vector<ll> ady[maxn];
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n>>x>>y;
    rep(i,1,n) ady[i].push_back(i+1), ady[i+1].push_back(i);
    ady[x].push_back(y), ady[y].push_back(x);
    rep(i,1,n+1) {
        s=e=0;
        q[e++]=i, d[i]=0, u[i]=++c;
        while(s<e) {
            ll j=q[s++];
            for(ll to: ady[j]) if(u[to]!=c)
                q[e++]=to, d[to]=d[j]+1, u[to]=c;
        }
        rep(j,1,n+1) ans[d[j]]++;
    }
    rep(i,1,n) cout<<ans[i]/2<<"\n";
}

Measured memory_bytes: 384
m=10**9+7
n,a,b=map(int,input().split())

def comb(n,r,m):
    x,y=1,1
    for i in range(r):
        x*=n-i
        y*=i+1
        x%=m
        y%=m
    return int(x * pow(y, m-2, m))
ans = pow(2, n, m)-1-comb(n, a, m) - comb(n, b, m)
print(ans%m)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
	int n;
	int cnt[101];
	int i,j;
	int max;
	
	for(i=1;i<=100;i++){
		cnt[i]=0;
	}
	while(scanf("%d",&n)!=EOF){
		cnt[n]++;
	}
	max=0;
	for(i=1;i<=100;i++){
		if(cnt[i]>max){
			max=cnt[i];
			j=i;
		}
	}
	printf("%d\n",j);
	for(i=j+1;i<=100;i++){
		if(cnt[i]==max){
			printf("%d\n",i);
		}
	}
	return 0;
}

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

using vi = vector<int>;
using vll = vector<long long>;

constexpr long long mod = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];

    long long sum = 0;
    rep(i, n) sum += a[i];

    vll v(n, 0);

    v[0] = sum;
    for (int i = 0; i < n; i++) {
        if (i % 2) {
            v[0] -= 2*a[i];
        }
    }

    for (int i = 0; i < n - 1; i++) {
        v[i + 1] = 2 * a[i] - v[i];
    }

    rep(i, n) {
        cout << v[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 2944
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()



int main(void){
	ll A,B,C,D;
    cin >> A >> B >> C >> D;

    ll a, b, r, x, tmp;
    
    a = C;
    b = D;

    x = a * b;
    if(a<b){
    tmp = a;
    a = b;
    b = tmp;
    }
 

    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }

    ll CD = x/b;


    ll ans,Ac,Bc,Ad,Bd,Acd,Bcd,nc,nd,ncd;

    Ac = A/C;
    if(A%C > 0){
        Ac = Ac + 1;
    }

    Bc = B/C;
    
    Ad = A/D;
    if(A%D > 0){
        Ad = Ad + 1;
    }

    Bd = B/D;

    Acd = A/CD;
    if(A%CD > 0){
        Acd = Acd + 1;
    }

    Bcd = B/CD;

    nc = Bc-Ac + 1;
    nd = Bd-Ad + 1;
    ncd = Bcd - Acd + 1;

    ans = B-A - (nc + nd -ncd) + 1;

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		
		String xi[] = new String[n];
		String bi[] = new String[n];
		String ci[] = new String[n];
		
		int x = scan.nextInt();
		for(int i = 0 ; i < x ; i++) {
			int num = scan.nextInt();
			xi[num-1] = "A";
		}
		int b = scan.nextInt();
		for(int i = 0 ; i < b ;i++) {
			int num = scan.nextInt();
			bi[num-1] = "B";
		}
		int c = scan.nextInt();
		for(int i = 0 ; i < c ;i++) {
			int num = scan.nextInt();
			ci[num-1] = "C";
		}
		
		int count = 0;
		
		for(int i = 0 ; i < n ; i++) {
			if(xi[i] == null && ci[i] == "C") {
				++count;
			}else if(bi[i] == "B" && ci[i] == "C"){
				++count;
			}
		}
		System.out.println(count);
	}
}



Measured memory_bytes: 26572
import collections
n = int(input())
s = [input() for _ in range(n)]
c = collections.Counter(s)
if len(c) == 1:
    print(s[0])
    exit()
a = c.most_common()[0][1]
b = c.most_common()
d = collections.deque()
for i in range(n):
    if b[i][1] == a:
        d.append(b[i][0])
    else:
        break
for i in sorted(list(d)):
    print(i)


Measured memory_bytes: 50884
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
/*
string S_str[H];
cins(S_str, S_str + H);
S_str[i][j];
*/
inline int at(ll x, int k){ return (x >> k) & 1; }
#define rep(i, n) for(ll i = 0; i < n; i++)


int main(){
  ll n, k;
  cin >> n>>k;
  n=n%k;
  if(k-n>n){
    cout << n << endl;
  }
  else{
    cout<<k-n<<endl;
  }

}


Measured memory_bytes: 256
#include <stdio.h>
int main (void){
	char a[101];
	int b[101][101];
	int h,w,i,j,k;
	scanf("%d%d",&h,&w);
	for(i=0;i<h;i++)
	for(j=0;j<w;j++)
	b[i][j]=-1;
	for(i=0;i<h;i++){
		scanf("%s",a);
		for(j=0;a[j]!='\0';j++)
		if(a[j]=='c'){
			b[i][j]=0;
			for(k=0;a[j+k]!='\0';k++)b[i][j+k]=k;
		}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			printf("%d",b[i][j]);
			if(j<w-1)printf(" ");
		}
		printf("\n");
	}
	return 0;
}



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

int main(int argc, char** argv) {
    int N = 0;
    scanf("%d",&N);    
    int arr[N];
    int counter, j, temp, aaa;
    int ppp = 0;
    for(counter=0;counter<N;counter++){
        scanf("%d",&arr[counter]);
    }
    for(counter=0;counter<N;counter++){
        temp = counter;
        for(j=counter;j<N;j++){
            if (arr[j]<arr[temp]){
               temp = j; 
            }
        }
        if(temp != counter){
            aaa = arr[counter];
            arr[counter] = arr[temp];
            arr[temp] = aaa;
            ppp++;
        }
    }
    for(j=0; j<N; j++){
        printf("%d",arr[j]);
        if(j != N-1) printf(" ");
    }
    printf("\n%d\n",ppp);
    return 0;
}


Measured memory_bytes: 2124
n = int(input())
for i in range(n):
    F = set(map(int, input().split()))
    fl = min(F); fr = max(F)
    G = {i for i in range(1, 14)} - F - {7}
    gl = min(G); gr = max(G)

    memo = {}
    def dfs(s, t, u):
        if (s, t, u) in memo:
            return memo[s, t, u]
        T = [G, F][u]
        res = 0
        if s-1 in T:
            if s-1 <= [gl, fl][u] and [gr, fr][u] <= t:
                res = 1
            else:
                res |= dfs(s-1, t, u^1)^1

        if t+1 in T:
            if s <= [gl, fl][u] and [gr, fr][u] <= t+1:
                res = 1
            else:
                res |= dfs(s, t+1, u^1)^1

        if s-1 not in T and t+1 not in T:
            res = dfs(s, t, u^1)^1
        memo[s, t, u] = res
        return res
    print(["no", "yes"][dfs(7, 7, 1)])

Measured memory_bytes: 7796
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;



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

	cin >> M;
	while (M--) {
		cin >> N;
		vector<vector<int>>v(N + 1);
		vector<vector<int>>w(N + 1);
		vector<long long int>vscore(N + 1);
		vector<long long int>wscore(N + 1);
		long long int ans = 0;
		for (int i = 0; i < N; i++) {
			cin >> K >> L >> R;
			if (L >= R) {
				v[K].push_back(L - R);
				ans += R;
			}
			else {
				w[N - K].push_back(R - L);
				ans += L;
			}
		}
		priority_queue<int, vector<int>, greater<int>>PQ;
		long long int cnt = 0;
		for (int i = 1; i <= N; i++) {
			for (auto j : v[i]) {
				PQ.push(j);
				cnt += j;
			}
			while (PQ.size() > i) {
				cnt -= PQ.top();
				PQ.pop();
			}
			vscore[PQ.size()] = cnt;
		}
		cnt = 0;
		while (!PQ.empty())PQ.pop();
		for (int i = 1; i <= N; i++) {
			for (auto j : w[i]) {
				PQ.push(j);
				cnt += j;
			}
			while (PQ.size() > i) {
				cnt -= PQ.top();
				PQ.pop();
			}
			wscore[PQ.size()] = cnt;
		}
		long long int add = 0;
		for (int i = 1; i <= N; i++) {
			vscore[i] = max(vscore[i], vscore[i - 1]);
			wscore[i] = max(wscore[i], wscore[i - 1]);
		}
		for (int i = 0; i <= N; i++) {
	//		cout << i << " " << vscore[i] << " " << wscore[i] << endl;
			add = max(add, vscore[i] + wscore[N - i]);
		}
		cout << ans+add << endl;
	}
}


Measured memory_bytes: 20964
use std::collections::BTreeMap;

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_owned()
}

fn reads<T>() -> Vec<T>
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    read_line()
        .split_whitespace()
        .map(|w| w.parse().unwrap())
        .collect()
}

fn main() {
    let n: i32 = reads()[0];

    let mut m = BTreeMap::<char, i64>::new();
    for _ in 0..n {
        let w = read_line();
        *m.entry(w.chars().nth(0).unwrap()).or_insert(0) += 1;
    }

    let v: Vec<i64> = "MARCH".chars().map(|c| *m.entry(c).or_insert(0)).collect();

    let ans: i64 = (0..1 << 5)
        .filter(|b| (*b as u32).count_ones() == 3)
        .map(|b| -> i64 { (0..5).filter(|i| b & (1 << i) != 0).map(|i| v[i]).product() })
        .sum();

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  string S;
  cin >> S;

  if ( S == "SUN")   
    cout << 7 << endl;
  if ( S == "MON")
    cout << 6 << endl;
  if ( S == "TUE")   
    cout << 5 << endl;
  if ( S == "WED")   
    cout << 4 << endl;
  if ( S == "THU")   
    cout << 3 << endl;
  if ( S == "FRI")   
    cout << 2 << endl;
  if ( S == "SAT")   
    cout << 1 << endl;

  return 0;
}


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

#define int long long int


signed main() {
    int n;
    cin >> n;
    int MOD = 1e9 + 7;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0ll, p = 1ll;
    for(int i = 0; i < 60; i++) {
        int ones = 0ll, zero = 0ll;
        for(int x : a) {
            if(x & (1ll << i))    ones++;
            else    zero++;
        }
        ans = ans % MOD + ((ones * zero) % MOD * p) % MOD;
        p = (p * 2ll) % MOD;
        ans %= MOD;
    }
    cout << ans % MOD << endl;
}

Measured memory_bytes: 5596