akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <stdlib.h>
#include <list>
#include <map>
#include <utility>
#include <set>
#include <bitset>
#include <vector>
#define pi acos(-1.0)
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fLL
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
int min3(int a,int b,int c)
{
    return min(min(a,b),c);
}
int max3(int a,int b,int c)
{
    return max(max(a,b),c);
}
int gcd(int x, int y)
{
    if(y==0)return x;
    return gcd(y, x%y);
}
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
string s;
string s1="keyence";
ll a[maxn];
ll b[maxn];
ll c[maxn];
ll d[maxn];
int main()
{
    int n;
    ll sum1=0;
    ll sum2=0;
    scanf("%d",&n);
    for(int i=0; i<n; i++)scanf("%lld",&a[i]),sum1+=a[i];
    for(int i=0; i<n; i++)scanf("%lld",&b[i]),sum2+=b[i];
    //printf("aaa\n");
    if(sum1<sum2)return 0*printf("-1\n");

    ll t=0;
    int flag=1;

    for(int i=0; i<n; i++)c[i]=b[i]-a[i];

    sort(c,c+n);
    int j = 0;
    ll ans = 0;
    for(int i=n-1; i>=0&&c[i]>0; i--)
    {
        while(j<i && t<c[i])
            t -= c[j++],ans++;
        t -= c[i];
        ans++;
    }

    printf("%lld\n",ans);




    return 0;
}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

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

int main()
{
    ll a,b,ans=0;
    cin >> a >> b;
    for(ll i=a;i<=b;i++){
        if(i/10000 == i%10 && (i/1000)%10 == (i/10)%10)ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
string s;
ll dp[100005][15];
int main(){
    ios::sync_with_stdio(false);
    cin>>s;int n = s.length();s="*"+s;
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        if(s[i]=='?'){
            for(int j=0;j<13;j++){
                for(int k=0;k<=9;k++){
                    (dp[i][(j*10+k)%13]+=dp[i-1][j])%=mod;
                }
            }
        }else{
            int p = s[i]-'0';
            for(int j=0;j<13;j++){
                dp[i][(j*10+p)%13]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][5]<<endl;
}

Measured memory_bytes: 12140
//----------------------------------------------------
//HEADER
#include<bits/stdc++.h>

//NAMESPACE
using namespace std;

//CONSTANT
const int64_t INF=INT64_MAX;

//FAST I/O
void init(){cin.tie(0);ios::sync_with_stdio(false);}
//----------------------------------------------------

int main(){
  init();

  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      cout << i << "x" << j << "=" << i*j << endl;
    }
  }

  return 0;
}

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

using namespace std;

bool dislike[10];

int main() {
	int n, k;
	cin >> n >> k;
	memset(dislike, 0, sizeof(dislike));
	for (int i = 0; i < k; ++i) {
		int d;
		cin >> d;
		dislike[d] = true;
	}
	for (int i = n; i <= 100000; ++i) {
		bool flag = true;
		for (int x = i; x; x /= 10)
			if (dislike[x%10]) {
				flag = false;
				break;
			}
		if (flag) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	list<int> a;
	auto c = a.begin();

	for (int i = 0; i < n; i++)
	{
		int q;
		cin >> q;

		int x;

		switch (q)
		{
			case 0:
				cin >> x;
				c = a.insert(c, x);
				break;

			case 1:
				cin >> x;

				if (x > 0)
				{
					for (int j = x; j > 0; j--)
					{
						c++;
					}
				}
				else
				{
					for (int j = x; j < 0; j++)
					{
						c--;
					}
				}
				break;

			case 2:
				c = a.erase(c);
				break;
		}
	}

	for (auto it = a.begin(); it != a.end(); it++)
	{
		println(*it);
	}
}




Measured memory_bytes: 18640
N, M, C = map(int,input().split())
B = list(map(int,input().split()))
A = []
for p in range(N):
    A.append(list(map(int,input().split())))
#checking
result = 0
for i in range(N):
    sum = 0
    for j in range(M):
        sum += A[i][j] * B[j]
    if sum + C > 0:
        result += 1
print(result)

Measured memory_bytes: 9128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

int W,a,b;
cin >> W >> a >> b;
cout << max(0,abs(a-b) - W) << endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	int a, b;
	cin >> a >> b;
	cout << 2 * b - a << endl;
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

class UnionFind{
  int n;
  vector<int> data;
public:
  UnionFind(int _n):n(_n),data(_n,-1){}
  bool link(int a, int b){ //if new link, then true.
    int ra=find_root(a);
    int rb=find_root(b);
    if(ra!=rb){
      if(data[rb]<data[ra]) swap(ra,rb);
      data[ra]+=data[rb];
      data[rb]=ra;
    }
    return (ra!=rb);
  }
  bool check(int a, int b){ //if same set, then true.
    return (find_root(a)==find_root(b));
  }
  int find_root(int a){
    return ((data[a]<0)?a:(data[a]=find_root(data[a])));
  }
};

int main(){
  int N;
  cin >> N;
  vector<pair<int,int>> v;
  rep(i,N){
    int x, y;
    cin >> x >> y;
    v.emplace_back(x,y);
  }

  UnionFind uf(200000);
  rep(i,N){
    int xi = v[i].first;
    int yi = v[i].second + 100000;

    uf.link(xi, yi);
  }

  map<int,vector<pair<int,int>>> memo;
  rep(i,N){
    memo[uf.find_root(v[i].first)].push_back(v[i]);
  }


  ll ret = 0;
  FOR(it,memo){
    vector<pair<int,int>> w = it->second;

    set<int> xx, yy;
    rep(i,w.size()){
      xx.insert(w[i].first);
      yy.insert(w[i].second);
    }
    ll M = xx.size();
    M *= yy.size();

    ret += M - w.size();
  }
  
  cout << ret << endl;

  return 0;
}



Measured memory_bytes: 8052
n = int(input())
s = list(map(int, input().split()))
cnt = 0
SENTINEL = 10e9 + 1
def merge(a, left, mid, right):
    global cnt
    l = a[left: mid] + [SENTINEL]
    r = a[mid: right] + [SENTINEL]
    n1 = mid - left
    i,j = 0,0
    for k in range(left, right):
        if(l[i] < r[j]):
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            cnt += n1 - i
            j += 1

def merge_sort(a, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right)

merge_sort(s, 0, n)
print(cnt)



Measured memory_bytes: 27488
#include <iostream>

bool isRightTriangle(int a, int b, int c);

int main()
{
    int n;
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        int a, b, c;
        std::cin >> a >> b >> c;
        if (isRightTriangle(a, b, c)) {
            std::cout << "YES" << std::endl;
        } else {
            std::cout << "NO" << std::endl;
        }
    }
}

bool isRightTriangle(int a, int b, int c)
{
    if (a > b && a > c) {
        return a * a == b * b + c * c;
    } else if (b > a && b > c) {
        return b * b == c * c + a * a;
    } else {
        return c * c == a * a + b * b;
    }
}

Measured memory_bytes: 2980
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
//#define mp make_pair

int a[] = {5,5,7};
int v[3];

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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

cin >> v[0] >> v[1] >> v[2];
sort(v, v+3);

rep(i, 0, 2){
if(v[i]==a[i])continue;
else return 0*printf("NO");
}
cout << "YES" << endl;

return 0;}


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

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

struct ps {
	string name;
	int time;
};

int main() {
	int n,q,t=0;
	queue<ps> qe;
	cin >> n >> q;
	rep(i,n) {
		ps p;
		cin >> p.name >> p.time;
		qe.push(p);
	}

	while(!qe.empty()) {
		ps p = qe.front();
		qe.pop();
		if (p.time > q) {
			p.time -= q;
			t += q;
			qe.push(p);
		} else {
			t += p.time;
			cout << p.name << " " << t << endl;
		}
	}

	return 0;
}

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

int sx, sy, tx, ty;

int main(){
  cin >> sx >> sy >> tx >> ty;
  rep(i, tx-sx) cout<<"R";
  rep(i, ty-sy) cout<<"U";
  rep(i, tx-sx) cout<<"L";
  rep(i, ty-sy) cout<<"D";
  cout<<"D";
  rep(i,tx-sx+1)  cout<<"R";
  rep(i,ty-sy+1) cout<<"U";
  cout<<"L";
  cout<<"U";
  rep(i, tx-sx+1) cout<<"L";
  rep(i,ty-sy+1) cout<<"D";
  cout<<"R";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		long MOD = 1_000_000_000 + 7;
		long sum = 1;
		for (int i = 1; i <= n; i++) {
			sum *= i;
			sum %= MOD;
		}
		System.out.println(sum);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 22868
import sys
string = input()

excess = len(string)-7

if excess != 0:
        for i in range(8):
                if string[:i] + string[i+excess:] == "keyence":
                        print('YES')
                        sys.exit()
        print('NO')
else:
        if string == "keyence":
                print('YES')
        else:
                print('NO')

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
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<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,k;
string s;

int main(){
	cin>>n>>k>>s;
	char c=(char)('z'+1);
	int m,I=0;
	string s_=s;
	reverse(s_.begin(),s_.end());
	s+=s_+'#';
	for(int i=1;i<=2*n;i++) if(s[i]!=s[i-1]){
		if(s[I]<c) c=s[I],m=i-I;
		else if(s[I]==c&&i-I>m) m=i-I;
		I=i;
	}
	string res;
	res+=(char)('z'+1);
	int M=min(n,(k>=14?n:m*(1<<(k-1))));
	for(int i=0;i<n;i++) if(s.substr(i,m)==string(m,c)){
		string t(M,c);
		for(int j=0;j<n-M;j++) t+=s[i+j+m];
		res=min(res,t);
	}
	cout<<res<<endl;
}


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

using namespace std;

int main(void) {
    long K, ans = 0;
    string S;

    cin >> S;
    cin >> K;

    long tmp = 1;
    for (size_t i = 1; i < S.length(); i++) {
        if (S[i] == S[i-1]) {
            tmp++;
        }
        else {
            ans += floor(tmp/2);
            tmp = 1;
        }
    }
    ans += floor(tmp/2);
    ans *= K;

    bool flag = true;
    for (size_t i = 1; i < S.length(); i++) {
        if (S[i] != S[i-1]) {
            flag = false;
            break;
        }
    }

    if (flag) {
        cout << (long)floor(S.length() * K / 2) << endl;
        return 0;
    }

    if (S[0] == S[S.length()-1]) {
        long a = 1;
        long b = 1;
        for (size_t i = 1; i < S.length(); i++) {
            if (S[i] != S[i-1]) break;
            a++;
        }
        for (size_t i = S.length()-1; i > 0; i--) {
            if (S[i] != S[i-1]) break;
            b++;
        }
        ans -= (long)(floor(a/2) + floor(b/2) - floor((a+b)/2)) * (K-1);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		int lunch, dinner, midnight;
		int kLunch, kDinner, kMidnight;
		int timeBegin[], timeEnd[];
		int a;
		String st;

		n = sc.nextInt();
		while (n != 0) {
			lunch     = 0;
			dinner    = 0;
			midnight  = 0;
			kLunch    = 0;
			kDinner   = 0;
			kMidnight = 0;
			timeBegin = new int[n];
			timeEnd   = new int[n];

			for (int i = 0; i < n; i++) {
				st = sc.next();
				timeBegin[i] = 1000*Integer.parseInt("" + st.charAt(0)) + 100*Integer.parseInt("" + st.charAt(1)) + 10*Integer.parseInt("" + st.charAt(3)) + Integer.parseInt("" + st.charAt(4));
				if (timeBegin[i] < 1000) {
					timeBegin[i] += 2400;
				}
				timeEnd[i]   = sc.nextInt();

				a = timeEnd[i] - (timeBegin[i] % 100);
				if (a < 0) {
					a += 60;
				}

				if (1100 <= timeBegin[i] && timeBegin[i] <= 1459) {
					kLunch++;
					if (a <= 8) {
						lunch++;
					}
				} else if (1800 <= timeBegin[i] && timeBegin[i] <= 2059) {
					kDinner++;
					if (a <= 8) {
						dinner++;
					}
				} else if (2100 <= timeBegin[i] && timeBegin[i] <= 2559) {
					kMidnight++;
					if (a <= 8) {
						midnight++;
					}
				}
			}

			System.out.print("lunch ");
			if (kLunch == 0) {
				System.out.println("no guest");
			} else {
				System.out.println((int)(lunch * 100 / kLunch));
			}
			System.out.print("dinner ");
			if (kDinner == 0) {
				System.out.println("no guest");
			} else {
				System.out.println((int)(dinner * 100 / kDinner));
			}
			System.out.print("midnight ");
			if (kMidnight== 0) {
				System.out.println("no guest");
			} else {
				System.out.println((int)(midnight * 100 / kMidnight));
			}

			n = sc.nextInt();
		}
	}
}

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

long long a, b, c;

int main() {

    cin >> a >> b >> c;

    if (a % c == 0) {
        cout << b / c - a / c + 1 << endl;
    } else {
        cout << b / c - a / c << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
   ll n,i;
   cin>>n;
   ll arr[n];
   for(i=0;i<n;i++)
   {
       cin>>arr[i];
   }
   ll flag=0;
   for(i=0;i<n;i++)
   {

       if(arr[i]==0)
       {

           flag=1;
           break;
       }
   }
   if(flag)
   {
       cout<<0<<endl;
   }
   else
   {
       ll p = 1000000000000000000;
       ll val = arr[0];
       ll flag=0;
       for(i=1;i<n;i++)
       {
           ll x = p/val;

           //cout<<x<<endl;
           if(arr[i]>x)
           {
               flag=1;
               break;
           }
           else
           {
               val = val*arr[i];
           }
       }
       if(flag)
       {
           cout<<"-1"<<endl;
       }
       else
       {
           cout<<val<<endl;
       }
   }
}


Measured memory_bytes: 4416
#include<bits/stdc++.h>
using namespace std;
main(){
int i,j,k,l,m,n,o,p,q;
while(cin>>p>>q){
  int x[10000]={0};
  while(q--){
    cin>>m;
    for(i=0;i<m;i++){cin>>n; x[n]++; }
  }
  m=0;
  for(i=1;i<=p;i++)if(x[i]==0)m++;
  cout<<m<<endl;
} return 0;

}


Measured memory_bytes: 3676
a, b, c, d = map(int, input().split())

max_value = -float('inf')
if max_value < a * c:
    max_value = a * c
if max_value < a * d:
    max_value = a * d
if max_value < b * c:
    max_value = b * c
if max_value < b * d:
    max_value = b * d

print(max_value)

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

int main(){
    size_t N;
    cin >> N;
    vector<vector<size_t>> edge(N);
    for(size_t i = 1, a, b; i < N; ++i){
        cin >> a >> b;
        edge[--a].push_back(--b);
        edge[b].push_back(a);
    }
    size_t K;
    cin >> K;
    vector<unsigned long> ans(N, ~0UL);
    priority_queue<pair<unsigned long, size_t>, deque<pair<unsigned long, size_t>>, greater<>> pq;
    for(size_t i = 0, V, P; i < K; ++i){
        cin >> V >> P;
        pq.emplace(P, --V);
    }
    while(!pq.empty()){
        auto t = pq.top();
        pq.pop();
        if(~ans[t.second]){
            if(ans[t.second] != t.first)return 0 & puts("No");
        }else{
            ans[t.second] = t.first;
            for(auto& i : edge[t.second])if(~ans[i]){if(ans[i] + 1 != t.first)return 0 & puts("No");
            }else pq.emplace(t.first + 1, i);
        }
    }
    puts("Yes");
    copy(ans.begin(), ans.end(), ostream_iterator<unsigned long>(cout, "\n"));
    return 0;
}

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

int main(){
    int x,y,n;
    cin>>n>>x>>y;
    int a[n+1]={0};
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            int elem;
            elem = min(abs(i-j),min(abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i)));
            a[elem]++;
        }
    }
    for(int i=1;i<n;i++)
        cout<<a[i]<<endl;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
x = int(input())

y = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            sum = a * 500 + b * 100 + c * 50
            if sum == x:
                y += 1

print(y)


Measured memory_bytes: 3060
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Runtime.CompilerServices;

class Program
{
    #region Reader
    static string ReadStr => Console.ReadLine();
    static string[] ReadStrs => Console.ReadLine().Split(' ');
    static int ReadInt => Convert.ToInt32(Console.ReadLine().Trim());
    static int[] ReadInts => Console.ReadLine().Trim().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
    static long ReadLong => Convert.ToInt64(Console.ReadLine().Trim());
    static long[] ReadLongs => Console.ReadLine().Trim().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
    static List<int[]> ReadPairs(int N)
    {
        List<int[]> ans = new List<int[]>();
        for (int i = 0; i < N; i++) { ans.Add(ReadInts); }
        return ans;
    }
    static List<long[]> ReadPairsLong(int N)
    {
        List<long[]> ans = new List<long[]>();
        for (int i = 0; i < N; i++) { ans.Add(ReadLongs); }
        return ans;
    }
    #endregion
    #region Method
    const int mod = 1000000007;
    public static int Mod(int a, int mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    public static long Mod(long a, long mod = mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    bool eq<T, U>() => typeof(T).Equals(typeof(U));
    T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
    T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                       : eq<T, long>() ? ct<T, long>(long.Parse(s))
                       : eq<T, double>() ? ct<T, double>(double.Parse(s))
                       : eq<T, char>() ? ct<T, char>(s[0])
                                         : ct<T, string>(s);
    void Multi<T>(out T a) => a = cv<T>(ReadStr);
    void Multi<T, U>(out (T,U) ans)
    {
        var ar = ReadStrs;
        ans =(cv<T>(ar[0]), cv<U>(ar[1]));
    }
    void Multi<T, U, V>(out (T,U,V) ans)
    {
        var ar = ReadStrs; 
        ans =(cv<T>(ar[0]), cv<U>(ar[1]),cv<V>(ar[2]));
    }
    void Multi<T,U>(out T a,out U b)
    {
        var ar = ReadStrs; 
        a = cv<T>(ar[0]);  b = cv<U>(ar[1]);
    }
    void Multi<T, U, V>(out T a,out U b,out V c)
    {
        var ar = ReadStrs;
        a = cv<T>(ar[0]);  b = cv<U>(ar[1]);  c = cv<V>(ar[2]);
    }
    #endregion


    static void Main()
    {
        int N = ReadInt;
        long[] As = ReadLongs;
        long[] Bs = ReadLongs;

        long limit = Bs.Sum() - As.Sum();

        long need_a = 0;
        long need_b = 0;

        for (int i = 0; i < N; i++)
        {
            long a = As[i];
            long b = Bs[i];

            if (a > b)
            {
                need_b += a - b;
            }
            else
            {
                if((b-a)%2 == 0)
                {
                    need_a += (b - a);
                }
                else
                {
                    need_a += 1 + (b - a);
                    need_b++;
                }
            }
        }



        WriteLine(need_a >= 2*need_b?"Yes":"No") ;
    }



}



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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n;
	cin >> n;
	vector< pair<int, int> > a;
	vector< pair<int, int> > b;

	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		a.push_back(make_pair(t, i));
	}

	b = a;
	sort(b.begin(), b.end());

	for(int i=0; i<n; i++){
		a[b[i].second].second = i;
	}

	/*
	puts("############");
	for(int i=0; i<n; i++){
		cout << a[i].second << endl;
	}
	puts("############");
	*/

	long long int ans = 0;
	for(int i=0; i<n; i++){
		if(a[i].second % 2 != i % 2) ans++;
	}

	cout << ans / 2 << endl;

	return 0;
}


Measured memory_bytes: 1908
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <string>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;

#define rep(i, n) for(int i = 0; i < n ; i++ )
#define For(i, a, b) for(int i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

int main(void){
    int A, B, C;
    
    cin >> A >> B >> C;
    
    cout << min(B / A, C) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>

using namespace std;
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int,int> pii;
typedef vector<pii> vp;
typedef vector<vp> vvp;
const int inf=2e9;
#define pb push_back

int main(){
  int n,m;
  cin>>n>>m;
  vvp cost(n);
  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    cost[a].pb(pii(b,c));
  }
  vi used(n);
  vi d(n,inf);
  d[0]=0;
  used[n-1]=true;

  priority_queue<pii>q;
  q.push(pii(0,0));
  while(!q.empty()){
    pii p=q.top();
    q.pop();
    int pos=p.second,cost1=-p.first;
    if(cost1>d[pos])continue;
    rep(i,cost[pos].size()){
      int to=cost[pos][i].first;
      int nowcost=cost[pos][i].second;
      if(d[pos]<=nowcost&&d[to]>nowcost){
	d[to]=nowcost;
	q.push(pii(-d[to],to));
      }
    }
  }
  /*
  while(1){
    int v=-1;
    rep(i,n)if(!used[i]&&(v==-1||d[i]<d[v]))v=i;
    if(v==-1)break;
    used[v]=true;
    rep(i,cost[v].size())if(d[v]<=cost[v][i].second&&d[cost[v][i].first]>cost[v][i].second)d[cost[v][i].first]=cost[v][i].second;
    // rep(i,n-1)rep(j,cost[v][i].size())if(d[v]<=cost[v][i][j]&&d[i]>cost[v][i][j])d[i]=cost[v][i][j];
  }
  */
  int out=-1;
  rep(i,n-1)rep(j,cost[i].size())if(cost[i][j].first==n-1&&d[i]<=cost[i][j].second)out=max(out,cost[i][j].second);
  cout<<out<<endl;
}

Measured memory_bytes: 7232
N, M = map(int, input().split())
xyzs = [list(map(int, input().split())) for i in range(N)]


res = []
for i in range(8):
    sign = [1, 1, 1]
    if i & 1 == 1:
        sign[0] = -1
    if i & 2 == 2:
        sign[1] = -1
    if i & 4 == 4:
        sign[2] = -1

    _xyzs = [[xyz[j]*sign[j] for j in range(3)] for xyz in xyzs]
    p = [sum(_xyz) for _xyz in _xyzs]
    p.sort(reverse=True)
    res.append(sum(p[:M]))

print(max(res))

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
using ll = long long; 
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using pq = priority_queue<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() { // 問題文はしっかり読め!!!
	int n, x;
	cin >> n >> x;
	V a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(all(a));
	int ans = 0;
	rep(i, n) {
		if (a[i] <= x) ans++, x -= a[i];
	}
	if (x != 0 && ans == n) ans--;
	cout << ans << endl;
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int a[n] = {0};
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a,a+n);
  cout << a[n-1] - a[0] << endl;
}



Measured memory_bytes: 256
/**/

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int N, M, P;
vector<tuple<int, int, long long>> grafo;
long long resp;

void BellmanFord(int inicio)
{
     vector<long long> distancia(N + 1, LONG_LONG_MAX);
     distancia[inicio] = 0;

     //Verifica o looping negativo (não há máximo)
     vector<bool> verifica(N + 1, false);
     verifica[N] = true;

     int primeiro, segundo;
     long long moedas;

     //Verifica o máximo possível, exceto os casos de looping negativo
     for (int i = 1; i < N; i++)
     {
          for (int j = 0; j < M; j++)
          {
               tie(primeiro, segundo, moedas) = grafo[j];

               if (distancia[primeiro] != LONG_LONG_MAX &&
                   distancia[primeiro] + moedas < distancia[segundo])
               {
                    distancia[segundo] = distancia[primeiro] + moedas;
               }

               if(verifica[segundo] == true)
               {
                    verifica[primeiro] = true;
               }
          }
     }

     //Salvando a resposta máxima atual
     resp = max((long long)0, -distancia[N]);

     //Percorrendo o grafo e verificando se há o looping negativo
     for(int i = 0; i < M; i++)
     {
          tie(primeiro, segundo, moedas) = grafo[i];

          if (distancia[primeiro] != LONG_LONG_MAX &&
              distancia[primeiro] + moedas < distancia[segundo] &&
              verifica[segundo] == true)
          {
               //Looping negativo = impossível
               resp = -1;
               break;
          }     
     }
     

}

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

     for (int i = 0; i < M; i++)
     {
          int primeiro, segundo;
          long long moedas;
          cin >> primeiro >> segundo >> moedas;

          grafo.push_back({primeiro, segundo, P - moedas});
     }

     BellmanFord(1);
     cout << resp << endl;

     return 0;
}

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

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

  for (int ix = 0; ix <= n; ix++) {
    for (int iy = 0; iy <= n - ix; iy++) {
      int iz = n - ix - iy;
      if (10000 * ix + 5000 * iy + 1000 * iz == y) {
        printf("%d %d %d\n", ix, iy, iz);
        return 0;
      }
    }
  }

  puts("-1 -1 -1");
  return 0;
}

Measured memory_bytes: 256
lst = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

N = int(input())

for n in range(N):
    buf = input()
    b, f, r, v = map(int, buf.split())
    lst[b-1][f-1][r-1] += v

for i, building in enumerate(lst):
    if i > 0:
        print("####################")
    for floor in building:
        for room in floor:
            print(end=" ")
            print(room, end="")
        print()



Measured memory_bytes: 5632
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc165_a.cpp
 * time   : Sat May  2 21:36:46 2020
 * quest  : A - We Love Golf
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b, k;
  cin >> k >> a >> b;
  cout << (((a % k == 0) || (b % k == 0) || (b - (b % k)) >= a) ? "OK\n" : "NG\n");
  return 0;
}


Measured memory_bytes: 3664
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

using ll = int_fast64_t;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<T>;
using vi = vt<int>;
using vvi = vvt<int>;
using vl = vt<ll>;
using vvl = vvt<ll>;
using pi = pair<int, int>;

constexpr int INF = 1 << 29;
// constexpr ll INFL = 1 << 58;
constexpr int dx[] = {0, 1, 0, -1};
constexpr int dy[] = {1, 0, -1, 0};

// [a, b)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (b)-1; i >= (a); i--)
// [a, b]
#define RANGE(i, a, b) for (int i = (a); i <= (b); i++)
#define RANGER(i, a, b) for (int i = (b); i >= (a); i--)
// [0, n)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) RFOR(i, 0, (n))

#define ALL(i) i.begin(), i.end()

inline int gint() {
  int a;
  cin >> a;
  return a;
}

int main() {
  int D;
  cin >> D;
  cout << "Christmas";
  REP(i, 25 - D) cout << " Eve";
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 100005

// it's swapnil07 ;)

vector<pii> adj[MAXN];

int color[MAXN];
bool vis[MAXN];

void dfs(int node, int weight, int clr){
    if(weight%2==0){
        color[node] = 0;
    }
    else{
        color[node] = 1;
    }
    vis[node] = true;
    for(auto p: adj[node]){
        int n = p.F;
        if(vis[n]){
            continue;
        }
        int wt = weight + p.S;
        dfs(n, wt, color[node]);
    }
}


signed main(){
    fast
    #ifdef SWAPNIL07
        freopen("/home/swapnil/Desktop/c++/input.txt","r",stdin);
        freopen("/home/swapnil/Desktop/c++/output.txt","w",stdout);
    #endif
    int n; cin>>n;
    For(i, 0, n-1){
        int u, v, w;
        cin>>u>>v>>w;
        adj[u].pb({v, w});
        adj[v].pb({u, w});
    }
    dfs(1, 0, 0);
    For(i, 1, n+1){
        cout<<color[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 10240
use std::error::Error;
use std::io;

fn main() {
    if let Err(e) = run() {
        println!("{}", e);
    }

}

fn run() -> Result<(), Box<Error>> {
    io::stdin().read_line(&mut String::new())?;
    let mut s = String::new();
    io::stdin().read_line(&mut s)?;
    let mut a: Vec<u64> = s.trim().split(" ").map(|x| x.parse().expect("")).collect();

    a.sort();
    a.reverse();

    let mut n = 0;
    let mut pre = 0;
    let mut ans = 0;

    for x in a {
        if pre == x {
            n += 1;
            if n== 2 {
                if ans == 0{
                    ans = x;
                } else {
                    println!("{}", ans * x);
                    return Ok(())
                }

                n = 0;
            }
            continue;
        }
        pre = x;
        n = 1;
    }
    if n==2 && ans != 0 {
        println!("{}", ans*pre);
        return Ok(())
    }

    println!("0");
    Ok(())
}


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

int main() {
  ll X;
  ll N=100;
  cin >> X;
  ll cnt=0;
  while(N < X){
    N = N*1.01;
    //cout << N << endl;
    cnt++;
  }
  
  cout << cnt << endl;
  
  return(0);
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;

const int  mod = 1e9+7;
int N, M, Q;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> N >> M >> Q;

  int cnt[501][501];
  rep(i, 501) {
    rep(j, 501) {
      cnt[i][j] = 0;
    }
  }

  rep(i, M) {
    int L, R;
    cin >> L >> R;
    cnt[L][R]++;
  }

  rep(i, 501) {
    for(int j=1; j<=500; j++) {
      cnt[i][j] += cnt[i][j-1];
    }
  }
  
  rep(j, 501) {
    for(int i=500; i>=1; i--) {
      cnt[i-1][j] += cnt[i][j];
    }
  }

  rep(i, Q) {
    int p, q;
    cin >> p >> q;
    cout << cnt[p][q] << '\n';
  }
}


Measured memory_bytes: 1920
n, k = gets.split.map(&:to_i)
d = []
k.times {
  du = gets.to_i
  d << gets.split.map(&:to_i)
}
d = d.uniq.flatten!
ans = 0
1.upto(n) {|i|
  unless d.include?(i) then ans += 1 end 
}
p ans


Measured memory_bytes: 14332
#include <iostream>
using namespace std;
int main(){
	const double REF[]={0.0,0.2,0.6,1.1};
	double l,r;
	int a[4]={0},b[4]={0};
	while(cin>>l>>r){
		for(int i=3;i>=0;--i){
			if(REF[i]<=l){
				a[i]++;
				break;
			}
		}
		for(int i=3;i>=0;--i){
			if(REF[i]<=r){
				b[i]++;
				break;
			}
		}
	}
	for(int i=3;i>=0;--i){
	cout<<a[i]<<" "<<b[i]<<"\n";
	}
	return 0;
}

Measured memory_bytes: 0
from collections import deque
import math

N, D, A = map(int, input().split())
monster = [list(map(int, input().split())) for _ in range(N)]
monster.sort(key=lambda x:x[0])

bomb = deque()
s = 0
ans = 0
for i in range(N):
    x, h = monster[i]
    while len(bomb) > 0 and bomb[0][1] < x:
        s -= bomb.popleft()[2]
    h -= s
    if h > 0:
        cnt = math.ceil(h/A)
        damage = cnt*A
        bomb.append([x, x+2*D, damage])
        s += damage
        ans += cnt
print(ans)

Measured memory_bytes: 108376
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=1e9;
const long long LINF=1e18;
#define int long long
//template
template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
struct UnionFind{
  int n;
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};
//main
signed main(){
  int N,M;cin>>N>>M;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  UnionFind uf(N);
  for(int i=0;i<M;i++){
    int x,y;cin>>x>>y;
    uf.unite(x,y);
  }
  if(M==N-1)fin(0);
  typedef pair<int,int> P;
  map<int,P> m;
  for(int i=0;i<N;i++){
    int f=uf.find(i);
    if(m.count(f)==0)m[f]=P(v[i],i);
    else if(m[f].first>v[i])m[f]=P(v[i],i);
  }
  int ans=0;
  std::vector<int> used(N,0);
  for(auto p:m){
    ans+=p.second.first;
    used[p.second.second]++;
  }
  priority_queue<int,vector<int>,greater<int>> que;
  for(int i=0;i<N;i++)if(!used[i])que.push(v[i]);
  if(que.size()<(N-1-M)*2-m.size())fin("Impossible");
  for(int i=0;i<(N-1-M)*2-m.size();i++)ans+=que.top(),que.pop();
  fin(ans);
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF (1e+9)

vector<int> min_seg_tree;
vector<int> max_seg_tree;
int N;

void min_init(vector<int> &v){
  int n = v.size();
  N = pow(2, ceil(log2(n))); 
  min_seg_tree.resize(2*N-1);

  for(int i=0;i<N;i++) min_seg_tree[N-1+i] = (i>=n?INF:v[i]);
  for(int i=N-2;i>=0;i--) min_seg_tree[i] = min(min_seg_tree[2*i+1], min_seg_tree[2*i+2]);
}

int min_query(int a, int b, int ind, int l, int r){
  if(r <= a || b <= l) return INF;
  if(a <= l && r <= b) return min_seg_tree[ind];
  else return min(min_query(a, b, 2*ind+1, l, (l+r)/2), 
                  min_query(a, b, 2*ind+2, (l+r)/2, r));
}

void max_init(vector<int> &v){
  int n = v.size();
  N = pow(2, ceil(log2(n))); 
  max_seg_tree.resize(2*N-1);

  for(int i=0;i<N;i++) max_seg_tree[N-1+i] = (i>=n?-1:v[i]);
  for(int i=N-2;i>=0;i--) max_seg_tree[i] = max(max_seg_tree[2*i+1], max_seg_tree[2*i+2]);
}

int max_query(int a, int b, int ind, int l, int r){
  if(r <= a || b <= l) return -1;
  if(a <= l && r <= b) return max_seg_tree[ind];
  else return max(max_query(a, b, 2*ind+1, l, (l+r)/2), 
                  max_query(a, b, 2*ind+2, (l+r)/2, r));
}

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> p(n, 0);
    for(int i=0;i<n;i++) cin >> p[i];
    min_init(p);
    max_init(p);
    int cnt = 1;
    int buf = -1;
    int stair = 0;
    bool st = false;
    for(int i=0;i<k;i++){
        if(buf < p[i]){
            stair++;
        }else{
            stair = 1;
        }
        buf = p[i];
    }
    if (stair >= k){
        st = true;
    }
    for(int i = 0; i < n - k; i++){
        // i番目からの連続区間を評価
        // k個以上昇順に並んできているならソートしても元と変化しない
        // この区間の最低値と先頭の値が一致し, この区間の最大値よりこの直後の値が大きければ次のソートしたケースと変わらない
        if(!st){
            if (p[i] != min_query(i, i+k, 0, 0, N) || p[i+k] <= max_query(i, i+k,0,0,N)){
                cnt++;
            }
        }else{
            if (stair < k){
                if (p[i] != min_query(i, i+k, 0, 0, N) || p[i+k] <= max_query(i, i+k,0,0,N)){
                    cnt++;
                }
            }
        }
        if(buf < p[i+k]){
            stair++;
        }else{
            stair = 1;
        }
        buf = p[i+k];
        if (stair >= k){
            st = true;
        }
    }
    if(st){
        bool f = true;
        for(int i=n-k+1;i<n;i++){
            f = f && (p[i-1] < p[i]);
        }
        if(!f) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

inline int xor128() {
    static int x = 123456789;
    static int y = 362436069;
    static int z = 521288629;
    static int w = 88675123;
    int t;
    t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}


const int D = 365;
const int M = 26;
vec<int> C(M);
vvec<int> S(D,vec<int>(M));

using arr = array<int,M>;

struct state{
    vec<int> res;
    int day;
    arr last;
    int score;
    state(){
        last = {};
        score = 0;
        day = 0;
    }
    void add(int type){
        day++;
        score += S[(int) res.size()][type];
        res.push_back(type);
        last[type] = day;
        for(int i=0;i<M;i++) if(i!=type) score -= C[i]*(day-last[i]);
    }

    bool operator<(const state& R)const{
        return score>R.score;
    }
};

const int width = 750;
const int lower = 10000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int d;
    cin >> d;
    for(auto& x:C) cin >> x;
    for(auto& v:S) for(auto& x:v) cin >> x;
    state init;
    vec<state> states;
    states.push_back(init);
    for(int d=0;d<D;d++){
        vec<state> neS;
        for(auto& now:states){
            for(int i=0;i<M;i++) if(S[d][i]>lower){
                state ne = now;
                ne.add(i);
                neS.push_back(ne);
            }
        }
        sort(neS.begin(),neS.end());
        if(neS.size()>width) neS.resize(width);
        states.swap(neS);
    }
    auto ans = states[0].res;
    for(int i=0;i<D;i++) cout << ans[i]+1 << "\n";
}

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

int main(){
    ll N = pow(10,9)+7;
    vector<ll> ans(61,0);
    ll n;
    cin >> n;
    for(int i=0; i<n; i++){
        ll a;
        cin >> a;
        int count=0;
        while(a!=0){
            ans.at(count) += a%2;
            a /= 2;
            count++;
        }
    }
    ll out=0;
    ll keta=1;
    for(int i=0; i<61; i++){
        //cout << "ou" << out << endl;
        //cout << "ke" << keta << endl;
        ll t = (n-ans.at(i))*ans.at(i)%N;
        out = (out+keta*t)%N;
        keta = (keta*2)%N;
        
    }
    cout << out << endl;
}


Measured memory_bytes: 3616
from collections import deque

N,M = map(int,input().split())
H = [0] + [int(i) for i in input().split()]

data = [list(map(int,input().split())) for i in range(M)]

G = {}

for i in range(1,N+1):
    G[i] = []
for i in range(M):
    G[data[i][0]].append(data[i][1])
    G[data[i][1]].append(data[i][0])

ans = 0
for i in range(1,N+1):
    for j in G[i]:
        if H[i] > H[j]:
            continue
        else:
            break
    else:
        ans += 1

print(ans)

Measured memory_bytes: 50136
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int a = in.nextInt();
		int b = in.nextInt();
		long k = a + b;
		if (k % 2 == 0)
			System.out.println(k / 2);
		else
			System.out.println("IMPOSSIBLE");
		in.close();
	}
}


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

using namespace std;

#define ll long long int
#define get(a) ll a; cin >> a;
#define show(a) cout << a << endl;
#define full(p) p.begin(), p.end()
#define sz(a) (ll)(a.size())
#define pb push_back

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout<<fixed;
	////////////////////////////////
	std::vector<int> v;
	for (int i = 0; i < 5; ++i)
		{
			get(ai);
			v.push_back(ai);
		}	
	get(k);

	for(int i = 0 ; i<5 ; i++)
	{
		for(int j = i ; j<5; j++)
		{
			if(i == j)
				continue;
			if(abs(v[i] - v[j]) > k)
			{
				cout << ":(" << endl;
				return 0;
			}
		}
	}
	cout << "Yay!" << endl;

	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

ld dp[301][301][301];
int N;

ld rec(int i, int j, int k) {
    if (dp[i][j][k] >= 0)return dp[i][j][k];
    if(i == 0 and j == 0 and k == 0) return 0.0;
    ld res = 0.0;
    if (i > 0) res += rec(i - 1, j, k) * i;
    if (j > 0) res += rec(i + 1, j - 1, k) * j;
    if (k > 0) res += rec(i, j + 1, k - 1) * k;
    res += N;
    res *= 1.0 / (i + j + k);
    return dp[i][j][k] = res;
}

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

    cin >> N;
    vei a(N); rep(i,N) cin >> a[i];

    int one = 0; int two = 0; int three = 0;
    rep(i,N) {
        if(a[i] == 1) one++;
        if(a[i] == 2) two++;
        if(a[i] == 3) three++;
    }
    memset(dp, -1, sizeof(dp));
    cout << setprecision(15) << rec(one, two, three) << endl;
    return 0;
}



Measured memory_bytes: 426496
a,b,m=map(int,input().split())
ap=list(map(int,input().split()))
bp=list(map(int,input().split()))

ans1=min(ap)+min(bp)
ans=[ans1]
for i in range(m):
    ai,bj,d=map(int,input().split())
    ans2=ap[ai-1]+bp[bj-1]-d
    ans.append(ans2)
    
print(min(ans))

Measured memory_bytes: 18736