akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {return cost < e.cost;}
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans;

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

    rep(i, 1, N) {
        if (A[i]<A[i-1]) {
            ans += A[i-1]-A[i];
            A[i] = A[i-1];
        }
        
    }

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





Measured memory_bytes: 4836
N = int(input())
A = list(map(int,input().split()))
n = 0
for i in A:
  if i %2 == 0:
    if i%3 ==0 or i% 5 == 0:
      n = 0
    else:
      n = 1
      print('DENIED')
      break
if n == 0:
  print('APPROVED') 

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=500005,INF=1<<30,D=1000;
int N,Q;
int A[MAX],cnt[MAX],ans[MAX];
int sum=0,l=-1,r=-1;

struct dat{
    int l;
    int r;
    int id;
};

vector<dat> S;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>Q;
    for(int i=0;i<N;i++) cin>>A[i];
    
    S.resize(Q);
    for(int i=0;i<Q;i++){
        cin>>S[i].l>>S[i].r;
        S[i].id=i;
        S[i].l--;S[i].r--;
    }
    
    sort(all(S),[](auto a,auto b){
        if(a.l/D==b.l/D) return a.r<b.r;
        return a.l/D<b.l/D;
    });
    
    for(int i=0;i<Q;i++){
        while(S[i].r<r){
            cnt[A[r]]--;
            if(cnt[A[r]]==0) sum--;
            r--;
        }
        while(S[i].r>r){
            cnt[A[r+1]]++;
            if(cnt[A[r+1]]==1) sum++;
            r++;
        }
        
        while(S[i].l<l){
            cnt[A[l-1]]++;
            if(cnt[A[l-1]]==1) sum++;
            l--;
        }
        while(S[i].l>l){
            cnt[A[l]]--;
            if(cnt[A[l]]==0) sum--;
            l++;
        }
        
        ans[S[i].id]=sum;
    }
    
    for(int i=0;i<Q;i++) cout<<ans[i]<<"\n";
}


Measured memory_bytes: 15452
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

vector<bool> PrimeNumberBool(int num)
{
	vector<bool> prime_num(num + 1, true);

	prime_num[0] = false;
	prime_num[1] = false;
	for (int i = 2; i <= sqrt(num); i++)
	{
		if (!prime_num[i])
			continue;

		for (int j = i * 2; j <= num; j += i)
		{
			prime_num[j] = false;
		}
	}

	return prime_num;
}

void execute()
{
	int N;
	cin >> N;

	vector<bool> prime_num = PrimeNumberBool(100001);
	vector<int> cum(100002, 0);

	for (int i = 1; i < 100000; i++)
	{
		cum[i + 2] = cum[i] + (prime_num[i + 2] && prime_num[(i + 3) / 2] ? 1 : 0);
	}

	int left, right;
	for (int i = 0; i < N; i++)
	{
		cin >> left >> right;

		cout << cum[right] - cum[max(left - 2, 1)] << endl;
	}
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
int main() {
	int n,w[100]={},s1=0,s2=0,sum=0,min=1000000000;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &w[i]);
		sum+=w[i];
	}
	for (int i = 0; i < n; i++) {
		s1+=w[i];
		s2=sum-s1;
		if(abs(s1-s2)<min){
			min=abs(s1-s2);
		}
	}
	printf("%d\n", min);
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;

const string YES = "Possible";
const string NO = "Impossible";

void solve(long long N, long long L, std::vector<long long> a){
    bool isGood = false;
    ll i0;
    REP(i, N-1){
        if(a[i]+a[i+1]>= L){
            isGood = true;
            i0 = i;
            break;
        }
    }
    if(!isGood){
        cout << NO <<endl; return;
    }
    cout << YES <<endl;
    for(ll i=1; i<=i0; i++){
        cout << i <<endl;
    }
    for(ll i= N-1; i >= i0+2; i--){
        cout << i <<endl;
    }
    cout << i0+1<<endl;


}

int main(){
    long long N;
    scanf("%lld",&N);
    long long L;
    scanf("%lld",&L);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, L, std::move(a));
    return 0;
}


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

int main() {
  int n,d,x;
  cin >> n >> d >> x;
  
  vector<int> a(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  
  for(int i=0; i<n; i++){
    for(int j=0; j<=100; j++){
      if(j*a[i]+1 <= d){
        x++;
      }
      else{
        break;
      }
    }
  }
  
  cout << x << endl;
  
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}


int a,b,c,x,y;

int main(){
	cin>>a>>b>>c>>x>>y;
	if(a+b<=2*c){
		cout<<a*x+b*y<<endl;
		return 0;
	}
	int ans=0;
	if(x>y){
		ans+=2*c*y;
		if(a>=2*c){
			ans+=2*c*(x-y);
		}else{
			ans+=a*(x-y);
		}
	}else{
		ans+=2*c*x;
		if(b>=2*c){
			ans+=2*c*(y-x);
		}else{
			ans+=b*(y-x);
		}
	}
	cout<<ans<<endl;
	return 0;
}
	

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int f(int s){
    if(s % 2 == 0) return s/2;
    else return s*3 + 1;
}

int main(void){
    int N, K; cin >> N >> K;
    //各種類の代表を知りたいのは確か
    //上からK個取ると美味しさは最大化する
    //美味しさを犠牲に種類数を増やしていく
    //2個以上あるものの中で,最も価値の低いものから新たな種類に置き換えていく
    //置き換えていく種類は,より価値の高いものを優先する -> そのまま商品の走査を続ければいい
    vector<pair<ll, int>> A(N);
    rep(i, N){
        int t; ll d; cin >> t >> d; t--;
        A[i] = make_pair(d, t);
    }
    sort(A.begin(), A.end(), greater<pair<ll, int>>());

    ll ans = 0, acc = 0;
    set<int> chose; //既に選んだやつ
    vector<ll> change_list;
    rep(i, K){
        if(chose.count(A[i].second) == 0) chose.insert(A[i].second);
        else change_list.push_back(A[i].first);
        ans += A[i].first;
    }
    ans += chose.size()*chose.size();

    sort(change_list.begin(), change_list.end(), greater<ll>());

    acc = ans;
    for(int i = K; i < N && change_list.size() > 0; i++){
        if(chose.count(A[i].second) == 0){
            int sabun = chose.size()*2 + 1;
            chose.insert(A[i].second);
            acc = acc + sabun - (change_list.back() - A[i].first);
            ans = max(ans, acc);
            change_list.pop_back();
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5116
from collections import Counter
N = int(input())
src = list(map(lambda x: str(bin(int(x)))[2:], input().split()))
c = Counter()
mod = 10**9 + 7
for num in src:
    l = len(num)
    num = num[::-1]
    for i in range(l):
        if num[i] == '1':
            c[2**i] += 1
ans = 0
for i in c:
    ans += i*(N-c[i])*c[i]
    ans %= mod
print(ans)

Measured memory_bytes: 153576
import std.stdio;

void main ()
{
	int a;
	int b;
	while (readf (" %s %s", &a, &b) > 0)
	{
		auto d = (a + 11) % 13 - (b + 11) % 13;
		if (d > 0) writeln ("Alice");
		if (d == 0) writeln ("Draw");
		if (d < 0) writeln ("Bob");
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){

  int n;
  cin>>n;
  vector <int> a(n);
  for(int i=0;i<n;i++) a[i]=i+1;
  do{
    for(int i=0;i<n;i++){
      if(i) cout<<" ";
      cout<<a[i];
    }
    cout<<endl;
  }while(next_permutation(a.begin(),a.end()));

  return 0;

}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

int main(){
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	
	if(a[0]==a[1]&&a[2]!=a[0]){
		cout<<"Yes";
		return 0; 
	}
	else if(a[1]==a[2]&&a[0]!=a[1]){
		cout<<"Yes";
		return 0;
	}
	
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int xx[]={0,1,0,-1},yy[]={1,0,-1,0};

int main() {
	int h,w;
	string com;
	int x,y;
	while(w=in(),h=in()){
		x=y=1;
		int n;
		int dir=0;
		while(1){
			cin>>com;
//cout<<"x "<<x<<" y "<<y<<" com "<<com<<endl;
			if(com=="FORWARD"){
				cin>>n;
				x+=xx[dir]*n;
				y+=yy[dir]*n;
				if(x<=0)x=1;
				if(x>w)x=w;
				if(y<=0)y=1;
				if(y>h)y=h;
			}else if(com=="BACKWARD"){
				cin>>n;
				x-=xx[dir]*n;
				y-=yy[dir]*n;
				if(x<=0)x=1;
				if(x>w)x=w;
				if(y<=0)y=1;
				if(y>h)y=h;
			}else if(com=="RIGHT"){
				dir=(dir+1)%4;
			}else if(com=="LEFT"){
				dir=(dir+3)%4;
			}else{
				break;
			}
		}
		cout<<x<<" "<<y<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#define INF 1000000000
#define N 101

int n;

int matrixChainOrder(int p[]){
  int i,j,k,l;
  int q;
  int m[n+1][n+1];
  
  for(i=1;i<=n;i++){
    m[i][i] = 0;
  }
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i+l-1;
      m[i][j] = INF;
      for(k=i;k<=j-1;k++){
	q = m[i][k] + m[k+1][j] + (p[i-1]*p[k]*p[j]);
	if(m[i][j]>q) m[i][j] = q;
      }
    }
  }

  /*for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      if(i<=j) printf("m[%d][%d] = %d\n",i,j,m[i][j]);
    }
    }*/


  return m[1][n];
}

int main(){

  int i;
  
  scanf("%d",&n);

  int x,p[N];
  
  for(i=0;i<n;i++){
    if(i==0) scanf("%d%d",&p[0],&p[1]);
    else scanf("%d%d",&x,&p[i+1]);
  }

  x = matrixChainOrder(p);
  
  printf("%d\n",x);
  
  return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int f(int n)
{
    if (n == 1)
    {
        return 300000;
    }
    else if (n == 2)
    {
        return 200000;
    }
    else if (n == 3)
    {
        return 100000;
    }
    return 0;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y;
    cin >> x >> y;
    int ans = 0;
    ans += f(x) + f(y);
    if (x == y && x == 1)
    {
        ans += 400000;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int re[4];
int main()
{
	
	int n;
	cin>>n;
	string s;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		if(s=="AC")
		re[0]+=1;
		else if(s=="WA")
		re[1]+=1;
		else if(s=="TLE")
		re[2]+=1;
		else if(s=="RE")
		re[3]+=1;
	}
	cout<<"AC x "<<re[0]<<endl;
	cout<<"WA x "<<re[1]<<endl;
	cout<<"TLE x "<<re[2]<<endl;
	cout<<"RE x "<<re[3];
	return 0;
}

Measured memory_bytes: 3224
// 6/26 解き直し → 6/30
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;
const int INF = 1000000007;

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;}

ll get_undividable_num(ll p, ll q, ll X) {
    ll ans = X;
    ans -= X / p;
    ans -= X / q;
    ans += X / lcm(p, q);
    return ans;
}

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

    cout << get_undividable_num(C, D, B) - get_undividable_num(C, D, A - 1) << endl;

}

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

int main() {
  
  int N;
  cin >> N;// 先にＮを入力しないと次の行がエラーになる
  vector<int> a(N); 
  for(int i=0; i<N; i++){
    cin >> a.at(i); 
  }
  //cout << "a.at(N-1):"<< a.at(N-1) << endl;
  
  vector<int>b(N);// (N)を書かないとエラーになる
  b.at(0) = a.at(0);
  for(int j=1; j<N; j++){
    b.at(j) = a.at(b.at(j-1)-1);
  }
  //cout << b.at(0) << b.at(1) << b.at(2) << endl;
 
  int count = 0;
  for(int i=0; i<N; i++){
    if(b.at(i) == 2){
      cout << count + 1 << endl;
      break;//
    }
     if(b.at(i) != 2){
      count++;
    }
  } 
  
  //cout << "count" << count << endl;
  if(count == N){
    cout << "-1" << endl;  
  }
  
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int h, w, x, y;
    cin >> h >> w >> x >> y;
    cout << min(h, w) + min(x, y) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
    int N,K;
    cin>>N>>K;
    int ret = 0;
    while(N)
    {
        N = N / K;
        ret ++;
    }
    cout<<ret<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
     int N, sum = 0;
     cin>>N;
     int arr[N];
     for(int i=0; i<N; i++){
        cin>>arr[i];
     }

while(N--)
    for(int j=0; j<N; j++){
        sum += arr[j] * arr[N];
     }

     cout<<sum;

}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

A1, A2 = {}, {}
for i, a in enumerate(A):
    key1 = str(-a-i)
    if key1 in A1:
        A1[key1] = (key1 in A1) * A1[key1] + 1
    else:
        A1[key1] = 1
    key2 = str(a-i)
    if key2 in A2:
        A2[key2] += 1
    else:
        A2[key2] = 1

cnt = 0
for key, value in A1.items():
    if key in A2:
        cnt += value * A2[key]

print(cnt)


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

using namespace std;

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

    int a, b;
    cin >> a >> b;

    int flag=0;
    for(int i=a; i<=b; i++){
        if(i%k == 0){
            flag = 1;
            break;
        }
    }
    if(flag==1){
        cout << "OK" << endl;
    }
    else{
        cout << "NG" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>

using namespace std;

struct ListNode {
    int val;
    ListNode *next;
    ListNode *prev;
};

set <int> s;

const int MAX_N = 200000;


int  retsize(vector<int> numbers) {

    int size = numbers.size();
    
for (int i = 0; i < numbers.size(); i++) {
    s.insert(numbers[i]);
}

return s.size();

}

int main() {

    int N;

    cin >> N;

    vector<int> A(N);

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


    int before_size = A.size();
    int after_size = retsize(A);

    if (before_size != after_size) {
        printf("NO\n");
    } else printf("YES\n");

    return 0;

}

Measured memory_bytes: 11136
from fractions import gcd
def main():

    N = int(input())
    a_list = list(map(int, input().split()))

    MOD = 10**9 + 7

    a_lcm = a_list[0]
    for a in a_list[1:]:
        a_lcm *= a // gcd(a_lcm,a)

    res = 0
    for a in a_list:
        res += a_lcm // a
    print(res%MOD)

if __name__ == "__main__":
    main()


Measured memory_bytes: 6112
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.append(X)
A.sort()
distances = {}

for i in range(N):
    dist = A[i+1] - A[i]
    distances[dist] = None

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

distances = list(distances.keys())
gcd_calc = distances[0]

if N > 1:
    for dist in distances[1:]:
        gcd_calc = gcd(gcd_calc, dist)
        if gcd_calc == 1:
            break

print(gcd_calc)


Measured memory_bytes: 14224
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
using namespace std;
int main()
{
	queue<char> aa,bb,cc;
	string a,b,c;cin>>a>>b>>c;
	for(int i=0;i<a.size();i++)aa.push(a[i]);
	for(int i=0;i<b.size();i++)bb.push(b[i]);
	for(int i=0;i<c.size();i++)cc.push(c[i]);
	char t=aa.front();
	aa.pop();
	for(;;)
	{
		if(t=='a')
		{
			if(aa.empty())
			{
				cout<<"A"<<endl;
				return 0;
			}
			t=aa.front();
			aa.pop();
		}
		else if(t=='b')
		{
			if(bb.empty())
			{
				cout<<"B"<<endl;
				return 0;
			}
			t=bb.front();
			bb.pop();
		}
		else
		{
			if(cc.empty())
			{
				cout<<"C"<<endl;
				return 0;
			}
			t=cc.front();
			cc.pop();
		}
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

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

    int min = std::abs(k - a[n - 1] + a[0]);
    for (int i = 0; i < n - 1; i++) {
        min = std::max(min, std::abs(a[i] - a[i + 1]));
    }

    std::cout << k - min << std::endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	map<int, int>mp;
	rep(i, 0, 3) {
		int a; cin >> a;
		mp[a]++;
	}
	cout << mp.size() << "\n";

	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
using namespace std;
const int N = 200050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f;
const ll mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME_END - TIME_START) / CLOCKS_PER_SEC);
    system("pause");
#endif
}
int n, m;
ll k;
ll a[N], b[N];
ll suma[N], sumb[N];
int ans;

void solve()
{
    cin >> n >> m >> k;
    for (int i = 1; i <= n; ++i)
        cin >> a[i], suma[i] = suma[i - 1] + a[i];
    for (int i = 1; i <= m; ++i)
        cin >> b[i], sumb[i] = sumb[i - 1] + b[i];
    sumb[m + 1] = llinf;
    for (int i = 0; i <= n; ++i)
    {
        if (suma[i] > k)
            break;
        int pos = upper_bound(sumb + 1, sumb + m + 1, k - suma[i]) - sumb - 1;
        ans = max(ans, pos + i);
    }
    cout << ans << endl;
}

int main()
{
    TIME_START = clock();
    int Test = 1;
    // cin >> Test;
    while (Test--)
        solve();
    TIME_END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 9884
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    vi v={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll n;cin>>n;
    out(v[n-1]);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define _USE_MATH_DEFINES
#include <cmath>

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

using namespace std;
typedef long long ll;

const int MAXN = 200100;
const int INF  = 2e9;

int A[MAXN];
ll  cnt = 0;

ll merge(int head, int mid, int tail) {
   int n1 = mid - head;
   int n2 = tail - mid;
   ll  ans = 0;
   int cur = n1;
   int L[n1 + 1], R[n2 + 1];

   rep(i, n1) L[i] = A[head + i];
   rep(i, n2) R[i] = A[mid + i];
   L[n1] = R[n2] = INF;
   int l = 0;
   int r = 0;
   for (int i = 0; i < tail - head; i++) {
      if (L[l] <= R[r]) {
         A[head + i] = L[l];
         l++;
         cur--;
      }
      else{
         A[head + i] = R[r];
         r++;
         ans += cur;
      }
   }
   return(ans);
}

void mergeSort(int head, int tail) {
   int mid = (head + tail) / 2;

   if (head + 1 < tail) {
      mergeSort(head, mid);
      mergeSort(mid, tail);
      cnt += merge(head, mid, tail);
   }
}

int main() {
   int n;

   cin >> n;
   rep(i, n) scanf("%d", &A[i]);
   mergeSort(0, n);
   cout << cnt << endl;
   return(0);
}



Measured memory_bytes: 4696
g(){int x;scanf("%d",&x);x?x:exit(0);}
main(m,v,x){
  for(;;){double s=0,t=0,z=.01745329,e=.000001;
    scanf("%d",&m);if(!m)return 0;
    for(v=360;--m;s+=sin(x*z))v-=(x=g());s+=sin(v*z);
    scanf("%d",&m);
    for(v=360;--m;t+=sin(x*z))v-=(x=g());t+=sin(v*z);
    puts(s>t+e?"1":s+e<t?"2":"0");
  }
}

Measured memory_bytes: 0
import numpy as np

S = input()

S = [int(i) for i in S]
#print(s_zero[0])

count = 0

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        count = count +1
        if S[i+1] == 1:
            S[i+1] = 0
        else:
            S[i+1] = 1

print(count)


Measured memory_bytes: 13796
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int x,sum=0,ma=0;
  rep(i,5){
    cin>>x;
    sum+=(x+9)/10*10;
    ma=max(ma,(1000-x)%10);
  }
  
  cout<<sum-ma<<endl;
    
  return 0;
}

Measured memory_bytes: 3608
N, M, *L = map(int, open(0).read().split())
dic = [[] for i in range(N+1)]
for a,b in zip(*[iter(L)]*2):
  dic[a] += [b]
  dic[b] += [a]

log = set([1])
pre = [1]
p = 1
while True:
  for v in dic[p]:
    if v not in log:
      break
  else:
    break
  p = v
  pre.append(v)
  log.add(v)
log = set(pre)
ans = pre[::-1]
p = 1
while True:
  for v in dic[p]:
    if v not in log:
      break
  else:
    break
  p = v
  ans.append(v)
  log.add(v)
print(len(ans))
print(*ans)

Measured memory_bytes: 34388
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n,m;cin>>n>>m;
    vint imos(n+1,0);
    rep(i,m){
        int l,r;cin>>l>>r; l--;
        imos[l]++; imos[r]--;
    }
    rep(i,n)imos[i+1]+=imos[i];
    int res=0;
    rep(i,n+1)if(imos[i]==m)res++;
    //rep(i,n+1) cout<<imos[i]<<endl;
    cout<<res<<endl;

}

Measured memory_bytes: 3976
#include<bits/stdc++.h>
#include<bitset>
#include<random>
#include<time.h>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code

int main()
{
  int n;
  cin>>n;
  cout<<(48-n)<<endl;
}


Measured memory_bytes: 256
import numpy as np
I = [int(_) for _ in open(0).read().split()]
N, T = I[:2]
A, B = I[2::2], I[3::2]
dp = np.array([-1] * 6001, dtype=np.int64)
dp[0] = 0
for a, b in sorted(zip(A, B)):
    dp_new = dp[:]
    dp_new[a:a + T] = np.maximum(dp[a:a + T], dp[:T] + b)
    dp = dp_new
print(max(dp))


Measured memory_bytes: 12900
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  vector<string> S = {
    "SUN",
    "MON",
    "TUE",
    "WED",
    "THU",
    "FRI",
    "SAT",
    "SUN"
  };
  string t; cin >> t;
  auto it = std::find(S.begin(), S.end(), t);
  auto nextSun = S.end() - 1;
  auto ans = std::distance(it, nextSun);
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
struct _IO { _IO() { ios::sync_with_stdio(0); cin.tie(0); } } _io;
typedef long long ll; typedef long double db;

ll exgcd(ll a, ll b, ll& x, ll& y)
{
	if (!b)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll d = exgcd(b, a % b, x, y);
	ll t = x;
	x = y;
	y = t - (a / b) * y;
	return d;
}
ll getInv(ll a, ll mod)
{
	ll x, y;
	return exgcd(a, mod, x, y) == 1 ? (x % mod + mod) % mod : -1;
}

int main()
{
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a * c, max(a * d, max(b * c, b * d))) << endl;
	return 0;
}

Measured memory_bytes: 3644
/**
 * @author Finn Lidbetter
 */
import java.util.*;
import java.io.*;
import java.awt.geom.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();

    String[] s = br.readLine().split(" ");
    long q = Long.parseLong(s[0]);
    long h = Long.parseLong(s[1]);
    long w = Long.parseLong(s[2]);
    long d = Long.parseLong(s[3]);
    long n = Long.parseLong(br.readLine());

    long cost1 = w;
    if (4*q<cost1) {
      cost1 = 4*q;
    }
    if (2*h<cost1) {
      cost1 = 2*h;
    }
    long cost = Long.MAX_VALUE;
    if (n%2==0) {
      cost = Math.min((n/2)*d, n*cost1);
    } else {
      cost = Math.min((n/2)*d + cost1, n*cost1);
    }
    System.out.println(cost);
  }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,a,b) for(int i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1<<30;
//typedef long double ld;
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 dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
int main(){
  int n;  cin >> n;
  vector<ll> a(n), b(n);
  rep(i,0,n){
    cin >> a[i] >> b[i];
  }
  ll mi = INF;
  if(n==1){
    cout << 1 << endl;
    return 0;
  }
  rep(i,0,n)rep(j,0,n){
    if(i==j) continue;
    ll dx = a[i]-a[j], dy = b[i] - b[j];
    ll res = 0;
    rep(i2,0,n)rep(j2,0,n){
      if(i2==j2) continue;
      if(dx==a[i2]-a[j2] && dy==b[i2]-b[j2]) res++;
    }
    chmin(mi, n-res);
  }
  cout << mi << endl;
  return 0;
}


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

#define int long long
#define x first
#define y second
#define PII pair<int,int>
#define LL long long
#define pb push_back
#define pqp priority_queue<PII,vector<PII>,greater<PII>>
#define pqi priority_queue<int,vector<int>,greater<int>>
#define PSS pair<string,string>
#define in insert
#define line inline
#define sort(s) sort(s.begin(),s.end());
#define reverse(s) reverse(s.begin(),s.end());
#define V vector<int>
#define VV vector<V>
#define PDD pair<double,double>

using namespace std;

const int N = 1000010;

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

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<<1) + (x<<3) + (ch^48);
        ch = getchar();
    }
    return x * f;
}

void solve()
{
    int n; cin >> n;
    cout << (1000 - n % 1000) % 1000 << endl;


}
signed main()
{
    //int _; cin >> _ ;while(_ --)
    solve();

    return 0;
}


Measured memory_bytes: 3584
S = input()
if S == "SUN":
    print(7)
if S == "MON":
    print(6)
if S == "TUE":
    print(5)
if S == "WED":
    print(4)
if S == "THU":
    print(3)
if S == "FRI":
    print(2)
if S == "SAT":
    print(1)

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

int p[1002],sum[1002];
int t0[1002][1002], t1[1002][1002];

void paintZero(int x,int h,int w){
	int i = h - 1;
	int j = x - 1;

	while(i >= 0){
		if(t0[i][j] == 0){
			i--;
		}
		else if(t0[i][j] == 1){
			t0[i][j] = x;
			i--;
			j++;
		}
		else if(t0[i][j] == -1){
			t0[i][j] = -x;
			i--;
			j--;
		}
	}
}

void paintOne(int x,int h,int w){
	int i = 0;
	int j = x - 1;

	while(i < h){
		if(t1[i][j] == 0){
			i++;
		}
		else if(t1[i][j] == 1){
			t1[i][j] = x;
			i++;
			j++;
		}
		else if(t1[i][j] == -1){
			t1[i][j] = -x;
			i++;
			j--;
		}
	}
}

int main(void){
	int i,j;
	int n,m,h,k,a,b;
	int sumAll,ans,tmp;

	while(scanf("%d%d%d%d",&n,&m,&h,&k) && (n||m||h||k)){
		for(i=0;i<n;i++){
			scanf("%d",&p[i]);
		}

		memset(t0,0,sizeof(t0));
		memset(t1,0,sizeof(t1));
		for(i=0;i<m;i++){
			scanf("%d%d",&a,&b);
			t0[b-1][a-1] = t1[b-1][a-1] = 1;
			t0[b-1][a] = t1[b-1][a] = -1;
		}

		for(i=0;i<n;i++){
			paintZero(i+1,h,n);
			paintOne(i+1,h,n);
		}

		sumAll = 0;
		for(j=0;j<k;j++){
			for(i=0;i<h && t0[i][j]==0;i++);

			if(i == h)
				sum[j] = p[j];
			else if(t0[i][j] < 0)
				sum[j] = p[abs(t0[i][j-1])-1];
			else
				sum[j] = p[abs(t0[i][j+1])-1];

			sumAll += sum[j];
		}

		ans = sumAll;
		for(i=0;i<h;i++){
			for(j=0;j<n;j++){
				if(t0[i][j] > 0){
					tmp = sumAll;

					if(t1[i][j] <= k){
						tmp -= sum[t1[i][j]-1];
						tmp += p[t0[i][j]-1];
					}
					if(t1[i][j+1] >= -k){
						tmp -= sum[abs(t1[i][j+1])-1];
						tmp += p[abs(t0[i][j+1])-1];
					}

					if(ans > tmp) ans = tmp;
				}
			}
		}

		printf("%d\n",ans);
	}

	return 0;
}

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

#define int long long
#define double long double

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;
using P = pair<int, int>;
using ll = long long;
using ld = double;

using bint = boost::multiprecision::cpp_int;

constexpr int MOD = 1e9 + 7;

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, popcnt = 0;
    string s;
    cin >> n >> s;
    vector<int> memo(200001);
    memo[0] = 0;
    rep(i, 1, 200001) {
        if (i < n + 1 && s[i - 1] == '1') popcnt++;
        memo[i] = memo[i % __builtin_popcountll(i)] + 1;
    }
    int p1 = popcnt + 1, p2 = popcnt - 1;
    int b1 = 0, b2 = 0;
    vector<int> m1(n), m2(n);
    m1[0] = 1 % p1;
    if (p2) m2[0] = 1 % p2;
    b1 = (s[n - 1] - '0') ? m1[0] : 0;
    if (p2) b2 = (s[n - 1] - '0') ? m2[0] : 0;
    rep(i, 1, n) {
        m1[i] = m1[i - 1] * 2 % p1;
        if (p2) m2[i] = m2[i - 1] * 2 % p2;
        b1 += (s[n - i - 1] - '0') ? m1[i] : 0;
        if (p2) b2 += (s[n - i - 1] - '0') ? m2[i] : 0;
        b1 %= p1;
        if (p2) b2 %= p2;
    }
    rep(i, n) {
        if (s[i] - '0') {
            if (p2)
            cout << memo[(b2 + p2 - m2[n - i - 1]) % p2] + 1 << endl;
            else
                cout << 0 << endl;
        }
        else {
                cout << memo[(b1 + m1[n - i - 1]) % p1] + 1 << endl;
            
        }
    }
}


Measured memory_bytes: 8316
#include<iostream>
#include<vector>
#include<cstring>
#include<cstdio>
#define N 100002
using namespace std;
int is[N];
vector<int>G[N];
int n,m;
int h[N];
int main()
{
	memset(is,-1,sizeof(is));
	int i;
	cin>>n>>m;
	for(i=1;i<=n;i++) scanf("%d",h+i);
	for(i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(i=1;i<=n;i++)
	{
		if(is[i]==-1)
		{
			bool flag=1;
			for(auto j:G[i])
			{
				if(h[j]>=h[i]) flag=0;
				else is[j]=0;
			}
			if(flag) is[i]=1;
			else is[i]=0;
		}
	}
	int ans=0;
	for(i=1;i<=n;i++)
	{
		if(is[i]==1||G[i].size()==0) ans++;
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 9164
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define qwq(x) cerr<<" #"<<#x<<" = "<<x<<endl;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=100005;
char s[N];

int main(){
	scanf("%s",s);
	int n=strlen(s);
	int N=0,W=0,S=0,E=0;
	REP(i,n){
		N|=(s[i]=='N');
		W|=(s[i]=='W');
		S|=(s[i]=='S');
		E|=(s[i]=='E');
	}
	if(N!=S||W!=E)puts("No");
	else puts("Yes");
	return 0;
}


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

typedef long long ll;

ll N, K;
double R;

int main() {
  cin >> N >> K;
  for (ll i = 1; i <= N; ++i) {
    double p = 1. / N;
    for (ll x = i; x < K; x *= 2, p /= 2)
      ;
    R += p;
  }
  cout << setprecision(15) << R << endl;
  return 0;
}


Measured memory_bytes: 256
/** author: __nishad__ **/
//#pragma GCC optimize(2)
//#pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>
using namespace std;


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a,b) for(ll i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    int a, b, c;
    cin>>a>>b>>c;

    a = a - c;

    cout<<a/(b+c);




}





























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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int MAXN = 1e5 + 1;
const int MOD = 1e9 + 7;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define FAIL0 {printf("0\n"); return 0;}
#define FAIL1 {printf("-1\n"); return 0;}
#define FAILNO {printf("NO\n"); return 0;}

int N;
int M;
pii bridges[MAXN];
int parent[MAXN];
int size[MAXN];
LL ans[MAXN];

int Find(int x) {
    if (parent[x] != x) 
        parent[x] = Find(parent[x]);

    return parent[x];
}

void Union(int x, int y) {
    int xRoot = Find(x);
    int yRoot = Find(y);

    if (xRoot == yRoot) return;

    if (size[xRoot] < size[yRoot])
        swap(xRoot, yRoot);

    parent[yRoot] = xRoot;
    size[xRoot] += size[yRoot];
}


int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    scanf("%d", &N);
    scanf("%d", &M);
    for (int i = 0; i < M; i++) {
        int u,v;
        scanf("%d %d", &u, &v);
        u--; v--;

        bridges[i] = {u,v};
    }

    for (int i = 0; i < N; i++) {
        parent[i] = i;
        size[i] = 1;
    }

    ans[M-1] = 1LL*N*(N-1)/2;
    for (int i = M-1; i > 0; i--) {
        int u = bridges[i].fi;
        int v = bridges[i].se;

        int su = Find(u);
        int sv = Find(v);

        if (su == sv) {
            ans[i-1] = ans[i];
        } else {
            ans[i-1] = ans[i] - 1LL*size[su]*size[sv];
            Union(u,v);
        }
    }

    for (int i = 0; i < M; i++) printf("%lld\n", ans[i]);

    //printf("\n");
	return 0;
}


Measured memory_bytes: 3712
from collections import deque

def bfs(s):
    visit[i] = 1
    q = deque()
    q.append(s)
    while q:
        p = q.popleft()
        for j in G[p]:
            if not visit[j]:
                visit[j] = 1
                q.append(j)
    return

n, m = map(int, input().split())
G = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
visit = [0] * (n + 1)
ans = -1
for i in range(1, n + 1):
    if not visit[i]:
        bfs(i)
        ans += 1
print(ans)

Measured memory_bytes: 81756
while True:
    try:
        n = int(raw_input())
    except EOFError:
        break

    for i in range(n):
        base = [False,False,False] # first, second, third
        point = 0
        out = 0
        while out <3:
            order = raw_input()
            if order =='HIT':
                base.insert(0,True)
                if base[-1]:
                    base.pop()
                    point += 1
                else:
                    base.pop()
            elif order == 'OUT':
                out += 1
            elif order == 'HOMERUN':
                point += sum(base) + 1
                base = [False,False,False]
        else:
            print point

Measured memory_bytes: 4220
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,d,dem;long double x,y;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>d;
    while(n--)
    {
        cin>>x>>y;
        if(sqrt(x*x+y*y)<=d)
            dem++;
    }
    cout<<dem;
}



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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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

int main(){
    bool flag=false;
    ll ans=0,sum=LINF;

    int n,m;
    cin >>n;

    rep(i,n){
        int pi;
        cin>>pi;
        if(chmin(sum,pi))++ans;
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<ans<<endl;
    //if(m==n)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256