akhauriyash/Code-Regression huggingface dataset:
from heapq import heapify, heappop, heappush
from collections import deque

n = int(input())
a = list(map(int, input().split()))

L = a[:n]
sum_l = [sum(L)]
heapify(L)

ML = a[n:2 * n]
ML = deque(ML)

R = list(map(lambda x: (-1) * x, a[2 * n:]))
sum_r = [sum(R)]  # あとでReverseする
heapify(R)

MR = list(map(lambda x: (-1) * x, a[n:2 * n]))
MR = deque(MR)

for i in range(n):
    add_to_l = ML.popleft()
    heappush(L, add_to_l)
    subtract_to_l = heappop(L)

    t = sum_l[-1] + add_to_l - subtract_to_l
    sum_l.append(t)

# print(sum_l)

for i in range(n):
    add_to_r = MR.pop()
    heappush(R, add_to_r)
    subtract_to_r = heappop(R)

    t = sum_r[-1] + add_to_r - subtract_to_r
    sum_r.append(t)

# print(sum_r)

sum_r = sum_r[::-1]

ans = sum_l[0] + sum_r[0]
for i in range(1, n + 1):
    t = sum_l[i] + sum_r[i]
    ans = max(ans, t)

print(ans)

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

using namespace std;

int main() {
  int n,k,tmp,cnt=0; scanf("%d%d",&n,&k);
  for (int i=1; i<=n; i++) {
    scanf("%d",&tmp);
    if (tmp>=k) cnt++;
  }
  printf("%d",cnt);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}
int main()
{
  ll X,N;
  ll ans=10000000;
  ll dif=100000;
  cin>>X>>N;
  vector<ll> A(102);
  rep(i,102){
    A.at(i)=1;
  }
  rep(i,N){
    ll d;
    cin>>d;
    A.at(d)=0;
  }
  rep(i,102){
    if(A.at(i)==1){
      if(abs(i-X)<dif){
        dif=abs(i-X);
        ans=i;
      }
    }
  }
  cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
ll a[25];
vector<pll> dp[25][21];

void dfs(int l,int r){
    if(dp[l][r].size()>0)return;
    if(l==r){
        dp[l][r].push_back(pll(0,0));
        return;
    }
    FOR(i,l,r){
        dfs(l,i);
        dfs(i+1,r);
        for(pll P : dp[l][i])for(pll Q : dp[i+1][r]){
            ll sum = P.second + a[i] + Q.first;
            dp[l][r].push_back(pll(P.first+sum, sum+Q.second));
        }
    }
    sort(ALL(dp[l][r]));
    vector<pll> ret;
    for(pll P : dp[l][r]){
        if(ret.size()==0){
            ret.push_back(P); continue;
        }
        if(ret.back().first == P.first)continue;
        if(ret.back().second <= P.second)continue;
        ret.push_back(P);
    }
    sort(ALL(ret), [&](pll a, pll b){return a.first+a.second < b.first+b.second;});
    // const int W = 128;
    // if(ret.size()>W)ret.resize(W);
    dp[l][r] = ret;
}

int main(){
    cin>>n;
    REP(i,n)cin>>a[i];
    dfs(1,n-1);
    ll ans = 1ll<<60;
    for(pll P : dp[1][n-1]){
        CHMIN(ans, a[0]+a[n-1]+P.first+P.second);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1408
import sys
mod = pow(10, 9) + 7
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0: return 1
    elif y == 1	 : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else: return power(x, (y-1)//2)**2 * x % mod
    
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, power(b, mod-2))
def div2(a, b):
    return mul(a, modinv(b))

def modinv(a):
    b, u, v = mod, 1, 0
    while b:
        t = a//b
        a, u = a-t*b, u-t*v
        a, b, u, v = b, a, v, u
    u %= mod
    return u

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NNN = (10**6)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, K = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
mn = 0
for i in range(N):
    mn += mul(cmb(N-i-1, K-1, mod), X[i])
    mn %= mod
mx = 0
for i in range(N-1, -1, -1):
    mx += mul(cmb(i, K-1, mod), X[i])
    mx %= mod
print((mx-mn)%mod)


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

int main() {

  int N;
  cin >> N;

  set<string> S;
  
  for (int i = 0; i < N; i++){
    string keihin;
    cin >> keihin;
    S.insert(keihin);
  }

  cout << S.size() << endl;
}

Measured memory_bytes: 19232
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N;
  cin>>N;
  ll two=1, two1=0, two2=0;
  for(int i=0;i<40;++i) {
    if(i%2==0) two1 += two;
    else two2 -= two;
    two *= 2;
  }
  vector<int> ans(40);
  for(int i=0;i<40;++i) {
    two /= 2;
    if(i%2==0) {
      if(two2<=N && N<two2+two) {
        ans[i] = 1;
        N += two;
      }
      else ans[i] = 0;
      two2 += two;
    }
    else {
      if(two1-two<N && N<=two1) {
        ans[i] = 1;
        N -= two;
      }
      else ans[i] = 0;
      two1 -= two;
    }
  }
  bool zero = true;
  for(int i=0;i<40;++i) {
    if(zero) {
      if(ans[i]==1) {
        zero = false;
        cout<<ans[i];
      }
    }
    else cout<<ans[i];
  }
  if(zero) cout<<0;
  cout<<endl;
}


Measured memory_bytes: 3592
const int N = 405949; // 405949 is my favorite number, but it's less than 5e5
const int LG = 20;
const int MOD = 1e9 + 7;
const int INF = 1e9;

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); x.resize(unique(all(x)) - (x).begin());

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll inv(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(N);
    __ufact.resize(N);
    __rev.resize(N);
    __rev[1] = 1;
    for (int i = 2; i < N; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < N; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int n, k;
ll ans = 0;
ll a[N];

signed main()
{
    #ifdef ONLINE_JUDGE
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // ONLINE_JUDGE
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    ans = 1e18;
    for (int i = 0; i + k - 1 < n; i++)
    {
        int L = a[i], R = a[i + k - 1];
        if (L <= 0 && R <= 0) ans = min(ans, 1LL * -L);
        if (L >= 0 && R >= 0) ans = min(ans, 1LL * R);
        L = abs(L), R = abs(R);
        ans = min(ans, min(2ll * L + R, 2ll * R + L));
    }
    cout << ans;
}

/* Note:
Check constants at the beginning of the code.
Check corner cases.
*/


Measured memory_bytes: 1024
import itertools
import math

N = int(input())
XY = []
for _ in range(N):
    XY.append(list(map(int,input().split(' '))))

SUM = 0
cnt = 0
for v in itertools.permutations(XY, N):
    cnt += 1
    sx = v[0][0]
    sy = v[0][1]
    for i in v[::]:
        SUM += math.sqrt((sx - i[0])**2 + (sy - i[1])**2)
        sx , sy = i[0] ,i[1]

print(SUM/cnt)

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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);


// ABC088C - Takahashi's Information
int main(){
  VECTOR_DIM2(int, c, 3, 3, 0);
  int check = 0;
  rep(i,3) {
    rep(j,3) {
      cin >> c[i][j];
      check += c[i][j];
    }
  }
  // 全部の数字の合計は、3(a1+..+b3)なので3の倍数の必要がある
  if (check % 3 != 0) {
    cout << "No" << endl;
    return 0;
  }

  // sum = a1 + a2 + a3 + b1 + b2 + b3
  const int sum = check / 3;
  const int c11 = c[0][0];
  for (int a1 = 0; a1 <= c11; ++a1) {
    const int b1 = c11 - a1;
    const int b1b2b3 = c[0][0] + c[0][1] + c[0][2] - 3 * a1;
    const int rowa2 = c[1][0] + c[1][1] + c[1][2];
    if ((rowa2 >= b1b2b3) && ((rowa2 - b1b2b3) % 3 != 0)) {
      continue;
    }
    const int a2 = (rowa2 - b1b2b3) / 3;
    const int rowa3 = c[2][0] + c[2][1] + c[2][2];
    if ((rowa3 >= b1b2b3) && ((rowa3 - b1b2b3) % 3 != 0)) {
      continue;
    }
    const int a3 = (rowa3 - b1b2b3) / 3;
    // ここまででa1,a2,a3,b1が確定
    const int a1a2a3 = a1 + a2 + a3;
    const int rowb1 = c[0][0] + c[1][0] + c[2][0];
    if ((rowb1 >= a1a2a3) && ((rowb1 - a1a2a3) % 3 != 0)) {
      continue;
    }
    if ((rowb1 - a1a2a3) / 3 != b1) {
      continue;
    }
    const int rowb2 = c[0][1] + c[1][1] + c[2][1];
    if ((rowb2 >= a1a2a3) && ((rowb2 - a1a2a3) % 3 != 0)) {
      continue;
    }
    const int b2 = (rowb2 - a1a2a3) / 3;
    const int rowb3 = c[0][2] + c[1][2] + c[2][2];
    if ((rowb3 >= a1a2a3) && ((rowb3 - a1a2a3) % 3 != 0)) {
      continue;
    }
    const int b3 = (rowb3 - a1a2a3) / 3;
    if (sum == (a1a2a3 + b1b2b3)) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << 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);
    long N = sc.nextLong();
    long M = sc.nextLong();
    long ans;
    if (N == 1 && M == 1) {
      ans = 1;
    } else if (N == 1 || M == 1) {
      ans = Math.max(N,M) - 2;
    } else {
      ans = (N-2) * (M-2);
    }
    System.out.println(ans);
  }
} 

Measured memory_bytes: 35664
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)

int max(int a,int b){return (a<b)? b:a;}
int min(int a,int b){return (a!=0 && a<b)? a:b;}
int main (){
	int NN,MM,tempa,tempb,ans=1;
	cin >> NN >> MM;
	int tt[100005]={0};
	// 一番狭い区間のデータだけとっておきたいので、終端をメモる配置に適当にでかい値を予め入れておく
	rep(i,MM){
		cin >> tempa >> tempb;
		tt[min(tempa,tempb)] = min(tt[min(tempa,tempb)],max(tempb,tempa));
	}
	vector <pair <int ,int > > ttt;
	rep(i,NN)if(tt[i]!=0)ttt.push_back(make_pair(i,tt[i]));
	int ff = ttt[0].first;
	int fb = ttt[0].second;
	rep(i,ttt.size()){
		if( fb <= ttt[i].first ){ff = ttt[i].first;fb = ttt[i].second;ans ++;}
		if( fb > ttt[i].second ){fb = ttt[i].second;}
	}
	cout << ans << endl;
	return 0;

}


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

int main()
{
    int a,b,c,d,e,f;
    cin>>a>>b>>c;
    d = a*100;
    e = b * 10;
    f = d + e + c;

    if(f%4==0)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;

}


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

int main() {
	int a,b;
  	cin>>a>>b;
  	
  	vector<int> l(a);
  	for (int i=0;i<a;i++){
    	cin>>l.at(i);
    }
  
  	sort(l.begin(),l.end());
  
  	int mysum=0;
  	for (int i=0;i<b;i++){
    	mysum+=l.at(a-1-i);
    }
  	cout<<mysum<<endl;
  	
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;
public class Main{

    static long M=(long)1e9+7;
    
    public static void main(String[] args) {
        FastReader fs=new FastReader();
        int h=fs.nextInt();
        int a=fs.nextInt();
        int ans=0;
        if(a>=h){
            ans=1;
        }
        else{
            int quo=h/a;
            int mod=h%a;
            if(mod==0){
                ans=quo;
            }
            else{
                ans=quo+1;
            }
        }
        System.out.println(ans);
    }
    
    public static long min(long a, long mod){
        return pow(a, mod-2,mod);
    }
    public static long mul(long a,long b,long mod){
        long res=0;
        while(b!=0){
            if ((b & 1) == 1){ res = (res + a) % mod;}
            a = (a + a) % mod;
            b >>= 1;
        }
        return res;
    }
    
    public static long pow(long a, long n, long mod){
        long res=1;
        while(n != 0){
            if ((n & 1) == 1) res = mul(res, a, mod)%mod;
            a = mul(a , a, mod)%mod;
            n >>= 1;
        }
        return res;
    }
    
    public static long gcd(long a, long b){
        if(a == 0) return b;
        return b == 0 ? a: gcd(b, a % b);
    }

    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
}

Measured memory_bytes: 21204
#include<stdio.h>


int search(int A[], int n, int key){
	int i = 0;
	A[n]= key;
	while(A[i] != key)i++;
	return i != n;
}

int main(){
	int i, n, A[10000+1], q, key, sum = 0;
	
	scanf("%d",&n);
	for(i = 0; i < n; i++)scanf("%d",&A[i]);
	
	scanf("%d", &q);
	for(i = 0; i < q; i++){
	scanf("%d",&key);
		if(search(A, n, key))sum++;
	}
	printf("%d\n",sum);
	
	return 0;
	
}



Measured memory_bytes: 2112
// abc177_f
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;


int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int H, W;
    cin >> H >> W;
    vector<int> A(H), B(H);
    REP(i, H) {
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }

    set<P> st;
    REP(i, W) st.emplace(i, i);

    multiset<int> diff;
    REP(i, W) diff.insert(0);

    REP(i, H){

        auto it = st.lower_bound(P(A[i], 0));
        int mx = -1;
        while (it != st.end() && it->first <= B[i]+1){
            diff.erase(diff.lower_bound(it->first - it->second));
            mx = max(mx, it->second);
            st.erase(it++);
        }

        if (mx != -1 && B[i] != W-1){
            st.emplace(B[i]+1, mx);
            diff.emplace(B[i]+1-mx);
        }

        if (st.empty()){
            print(-1);
            continue;
        }

        int ans = *diff.begin() + i+1;

        print(ans);
    }

    return 0;
}


Measured memory_bytes: 23476
from itertools import product
l=input()
a,b,c,d=int(l[0]),int(l[1]),int(l[2]),int(l[3])
p=list(product(range(2),repeat=3))
for i in range(8):
    t=a
    if p[i][0]==1:
        t+=b
    else:
        t-=b
    if p[i][1]==1:
        t+=c
    else:
        t-=c
    if p[i][2]==1:
        t+=d
    else:
        t-=d
    if t==7:
        A=p[i]
        break
print("{}{}{}{}{}{}{}=7".format(a,"+" if A[0]==1 else "-",b,"+" if A[1]==1 else "-",c,"+" if A[2]==1 else "-",d))

Measured memory_bytes: 3064
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

s = input()[:-1]

po = 0

for i in range(len(s)):
    if s[i] == "p":
        po += 1
    

print(len(s)//2 - po)



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin>>n>>q;
	string s; cin>>s;
	vector<int> table(n, 0);
	int pos=-2;
	while((pos = s.find("AC", pos+2))!=string::npos){
		table[pos+1] = 1;
	}
	rep(i, n-1){
		table[i+1] += table[i];
	}
	rep(i, q){
		int l, r; cin>>l>>r;
		cout << table[r-1]-table[l-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1488
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
using namespace std;
int main(){
    int N;
    cin >> N;
    int A[N];
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A,A+N);
    int ans = 0;
    ans = A[N/2]-A[(N/2)-1];
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
  int N, Q;
  string S;
  cin >> N >> Q;
  cin >> S;
  vector<int> cache(N, 0);
  for (int i = 2;i<=N;i++) {
    cache[i] = cache[i-1];
    if (S[i-2] == 'A' && S[i-1] == 'C') {
      cache[i]++;
    }
  }
  for (int i = 0; i<Q;i++) {
    int l, r;
    cin >> l >> r;
    cout << cache[r] - cache[l] << endl;
  }
}


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

long long MOD = 1e9 + 7;
int a[100];
long long dp[102][100003];
long long solve(int i,int rem, int n) {
    //cout<<i<<", "<<rem<<", "<<n<<"\n";
    if(i==n+1)
        return rem>=0;
    if(rem == 0)
     return 1;
    if(dp[i][rem]!=-1) 
        return dp[i][rem];
    int max_candies = min(a[i], rem);
    int l  = rem - max_candies;
    int r =rem;
    long long ans= 0;
    ans+=solve(i+1, r, n);
    ans%=MOD;                
    if(l-1>=0)
        ans-= solve(i+1, l-1, n), ans = (ans+MOD)%MOD;
    ans+=solve(i, rem-1, n);
    ans%=MOD;
    // for(int candies=0;candies<=max_candies;candies++)
    //     ans+= solve(i+1,rem-candies, n), ans%=MOD;
    return dp[i][rem] = ans;
}
// long long solve2(int i,int rem, int n) {
//     if(i==n+1)
//         return rem==0;
//     if(rem == 0)
//         return 1;
        
//     if(dp2[i][rem]!=-1) 
//         return dp2[i][rem];
//     int max_candies = min(a[i], rem);
//     long long ans= 0;
 
//      for(int candies=0;candies<=max_candies;candies++)
//          ans+= solve2(i+1,rem-candies, n), ans%=MOD;
//     return dp2[i][rem] = ans;
// }

// void print(int n, int k){
//     int i, j;
//     for(i=1;i<=n+1;i++){
//         for(j=0;j<=k;j++) {
//             cout<<"("<<i<<","<<j<<"): "<<solve(i, j, n)<<"   ";
//         }
//         cout<<"\n";
//     }
//     cout<<"\n\n";
//     for(i=1;i<=n+1;i++){
//         for(j=0;j<=k;j++) {
//             cout<<"("<<i<<","<<j<<"): "<<solve2(i, j, n)<<"   ";
//         }
//         cout<<"\n";
//     }
// }
int main() {
	int i, n, k;
	cin>>n>>k;
	for(i=1;i<=n;i++) cin>>a[i];
	for(i=1;i<=n+1;i++)
	    for(int j = 0;j<=k;j++)
	        dp[i][j] = -1;
	long long ans = solve(1, k, n) - solve(1, k-1, n);
	ans = (ans+MOD)%MOD;
	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 86912
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
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(a > b) { a = b; return true; } return false; }
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int H,W,Ch,Cw,Dh,Dw;
string grid[1005];
int clr[1005][1006];
int visited[1005][1006];

void bfs(int ai, int aj, int color){
  queue<ii> q;
  q.emplace(ai,aj);
  while(q.size()) {
    int i = q.front().first, j = q.front().second;
    q.pop();
    int dx[] = {0,1,0,-1};
    int dy[] = {1,0,-1,0};
    rep(k,4) {
      int ni = i+dy[k];
      int nj = j+dx[k];
      if (ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
      if (grid[ni][nj] == '#' || clr[ni][nj] != 0) continue;
      clr[ni][nj] = color;
      q.emplace(ni, nj);
    }
  }
}


int main() {
  cin >> H>>W>>Ch>>Cw>>Dh>>Dw;
  Ch--,Cw--,Dh--,Dw--;
  rep(i,H) cin >> grid[i];

  int color = 1;
  rep(i,H) rep(j,W) {
    if (clr[i][j] != 0) continue;
    if (grid[i][j] == '#') continue;
    clr[i][j] = color;
    bfs(i,j,color);
    color++;
  }
  if (clr[Ch][Cw] == clr[Dh][Dw]) {
    cout << 0 << endl;
    return 0;
  }


  queue<ii> q;
  queue<ii> nx;
  // clr[ai][aj] = -1; 
  vvi dist(H,vi(W,INF));
  dist[Ch][Cw] = 0;
  nx.emplace(Ch,Cw);
  int level = 0;

  while(nx.size()) {
    swap(q,nx);
    while (q.size()) {
      auto [i,j] = q.front();
      q.pop();
      for (int dy=-2;dy<=2; dy++) {
        for (int dx=-2;dx<=2; dx++) {
          int ni = i+dy;
          int nj = j+dx;
          if (ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
          if (grid[ni][nj] == '#') continue;
          if (clr[ni][nj] == clr[i][j]) {
            if(chmin(dist[ni][nj], dist[i][j])) q.emplace(ni, nj);
          } else {
            if (chmin(dist[ni][nj], dist[i][j] + 1)) nx.emplace(ni,nj);
          }
        }
      }
    }
  }

  ll ans = dist[Dh][Dw];
  if (ans == INF) ans =-1;
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 13348
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005


int N,t,a;
int ans;
int min_dist[SIZE];
vector<int> G[SIZE];


void dfs(int node_id,int pre){

	for(int i = 0; i < G[node_id].size(); i++){

		int next = G[node_id][i];
		if(next == pre)continue;

		min_dist[next] = min_dist[node_id]+1;
		dfs(next,node_id);
	}
}


void dfs2(int node_id,int pre,int dist){

	if(min_dist[node_id] <= dist)return;

	ans = max(ans,min_dist[node_id]-1);

	for(int i = 0; i < G[node_id].size(); i++){

		int next = G[node_id][i];
		if(next == pre)continue;

		dfs2(next,node_id,dist+1);
	}
}


int main(){

	scanf("%d %d %d",&N,&t,&a);

	t--;
	a--;

	int from,to;

	for(int i = 0; i < N-1; i++){

		scanf("%d %d",&from,&to);
		from--;
		to--;

		G[from].push_back(to);
		G[to].push_back(from);
	}

	min_dist[a] = 0;

	dfs(a,-1);

	ans = 0;
	dfs2(t,-1,0);

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

	return 0;
}


Measured memory_bytes: 11264
k=int(input())
s=input()
n=len(s)
mod=pow(10,9)+7

# コンビネーション、さらに高速。あらかじめO(N)の計算をすることでのちの計算が早くなる
def cmb(n,r,mod):
  if (r<0 or r>n):
    return 0
  r=min(r,n-r)
  return g1[n]*g2[r]*g2[n-r]%mod
g1=[1,1] 
g2=[1,1] 
inverse=[0,1]
for i in range(2,n+k+1):
  g1.append((g1[-1]*i)%mod)
  inverse.append((-inverse[mod%i]*(mod//i))%mod)
  g2.append((g2[-1]*inverse[-1])%mod)

f=[pow(25,i,mod)*cmb(i+n-1,n-1,mod) for i in range(k+1)]
g=[0]*(k+1)
g[0]=1
for ki in range(1,k+1):
  g[ki]=f[ki]+26*g[ki-1]
  g[ki]%=mod
print(g[k])


Measured memory_bytes: 321996
N, C = map(int, input().split())
R = 10**5
T = [[0] * (R+1) for _ in range(C)]
for _ in range(N):
    s, t, c = map(int, input().split())
    T[c-1][s] += 1
    T[c-1][t] -= 1

A = [0] * (R+1)
ans = 0
for i in range(R):
    for c in range(C):
        A[i] += T[c][i+1] if T[c][i+1] > 0 else 0
        A[i] += T[c][i] if T[c][i] < 0 else 0
    A[i+1] += A[i]
    ans = max(ans, A[i+1])
print(ans)


Measured memory_bytes: 71704
// 8/29 リアルタイム参加
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

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

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
} sieve(1000010);

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

    // setwise coprimeは、全く素因数が被らないので、mapに格納して一個でもダブればpairwise。
    // setwise comprimeは、普通にgcdを計算して1かどうかをみる。

    ll d = gcd(A[0], A[1]);
    map<ll, ll> prime_list;
    
    vector<P> f = sieve.factor(A[0]);
    for (auto p : f) {
        // cout << p.first << " " << p.second << endl;
        prime_list[p.first]++;
    }
    f = sieve.factor(A[1]);
    for (auto p : f) {
        prime_list[p.first]++;
    }

    for (int i = 2; i < N; i++) {
        d = gcd(d, A[i]);
        f = sieve.factor(A[i]);
        for (auto p : f) {
            prime_list[p.first]++;
        }
    }

    bool is_pair = true;
    for (auto pl : prime_list) {
        if (pl.second > 1) is_pair = false;
    }

    if (is_pair) {
        cout << "pairwise coprime" << endl;
    } else if (d == 1) {
        cout << "setwise coprime" << endl;
    } else {
        cout << "not coprime" << endl;
    }

    return 0;
}

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

int main(){
    int H, W;
    while(1){
        cin >> H >> W;
        if (H==0 && W==0) return 0;
        rep(i,H) {
            if (i==0 || i==H-1) {
                rep(j,W) cout << "#";
            }
            else {
                cout << "#";
                rep(j, W-2) cout << ".";
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
    int N; cin >> N;
    map<int, int> A;
    rep(i, N) {
        int a; cin >> a;
        A[a]++;
    }

    int ans = 0;
    for (auto i : A) {
        if (i.second % 2) ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 4992
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n, d, x;
    cin >> n >> d >> x;

    rep(i, n){
        int a;
        cin >> a;

        x += 1 + (d - 1) / a;
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  int A, B; cin >> A >> B;
  if ((A - B) == 0) {
    cout << 0 << endl;
  } else if ((A+B)%2 == 0){
    cout << (A+B)/2 << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input;

        int[] count = new int[26];

        while((input = br.readLine()) != null){
            if(input.equals("")){
                break;
            }
//          ??¨????°????????????????
            input = input.toLowerCase();

//          ????????????????????????????´?
            char[] ch = input.toCharArray();

            for(char alpha : ch ){
                if('a' <= alpha && alpha <= 'z'){
//                  a????????°??????alpha???????????????1?????????a??????????????°=?????????????????????alpha?????°
                    count[alpha - 'a']++;
                }
            }
        }
        for(int i = 0; i < count.length; i++){
            System.out.println((char)('a' + i) + " : " + count[i]);
        }
    }
}

Measured memory_bytes: 24076
W,H,N = map(int,input().split())
c = [0]*N
max_x,min_x = 0,W
max_y,min_y = 0,H
for _ in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    max_x = max(max_x,x)
  elif a == 2:
    min_x = min(min_x,x)
  elif a == 3:
    max_y = max(max_y,y)
  else:
    min_y = min(min_y,y)
  if min_x <= max_x or min_y <= max_y:
      print(0)
      exit()
print((min_x-max_x)*(min_y-max_y))

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

bool dislike[10] = {0};

bool check(int x)
{
    while(x)
    {
        int tmp = x % 10;
        if(dislike[tmp]) return false;
        x = x / 10;
    }
    return true;
}

int main()
{
    int N, K;
    cin >> N >> K;
    int dk;
    for(int i = 0; i < K; ++ i)
    {
        cin >> dk;
        dislike[dk] = true;
    }
    int ans = -1;
    for(int i = N; ; i ++)
        if(check(i))
        {
            ans = i;
            break;
        }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int n,i,a[300005];
  ll ans=0;
  
  cin >> n;
  for (i=0;i<n*3;i++) cin >> a[i];
  
  sort(a,a+n*3,greater<int>());
  
  i=1;
  while (i<n*2){
    ans+=a[i];
    i+=2;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
bool head[200005], tail[200005];
int main() {
    int n, m, x, y;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d%d", &x, &y);
        if (x == 1) head[y] = true;
        if (y == 1) head[x] = true;
        if (x == n) tail[y] = true;
        if (y == n) tail[x] = true;
    }
    for (int i = 2; i < n; i++) {
        if (head[i] && tail[i]) {
            printf("POSSIBLE\n");
            return 0;
        }
    }
    printf("IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 640
cap, m = map(int, input().split())
arr = list(map(int, input().split()))

INF = 1 << 60
dp = [INF] * (cap + 1)
dp[0] = 0

for x in arr:
    for i in range(x, cap + 1):
        dp[i] = min(dp[i], dp[i - x] + 1)

print(dp[cap])


Measured memory_bytes: 7520
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>

using namespace std;

int main()
{
    int N;
    if (scanf("%d", &N) < 1) return 0;

    vector<int> C(N, 0);
    vector<int> S(N, 0);
    vector<int> F(N, 0);

    for (int i = 0; i < N - 1; i++)
    {
        if (scanf("%d%d%d", &C[i], &S[i], &F[i]) < 3) return 0;
    }

    for (int i = 0; i < N - 1; i++)
    {
        int ans = S[i] + C[i];
        for (int j = i + 1; j < N - 1; j++)
        {
            if (S[j] <= ans && ans % F[j] == 0)
            {
                ans += C[j];
            }
            else if (S[j] <= ans)
            {
                ans = F[j] * (ans / F[j] + 1) + C[j];
            }
            else
            {
                ans = S[j] + C[j];
            }
        }
        printf("%d\n", ans);
    }

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


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	while (b) {
		ll r = a % b; a = b; b = r;
	}
	return a;
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}
void solve() {
	ll a, b, c, d; cin >> a >> b >> c >> d;
	ll s1 = b / c - (a - 1) / c;
	ll s2 = b / d - (a - 1) / d;
	ll l = lcm(c, d);
	ll s3 = b / l - (a - 1) / l;
	cout << (b - a + 1) - s1 - s2 + s3 << endl;
}

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

	//cout << fixed << setprecision(10);
	//init();
	solve();
	//stop
	return 0;
}


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

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 1e9
using namespace std;
template <class T = int>
T in()
{
  T x;
  cin >> x;
  return (x);
}

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

#pragma endregion

int main()
{
  static const double pi = 3.141592653589793;
  int a = in(), b = in(), h = in(), m = in();

  double tmp1 = (double)360 * h / 12 + (double)30 * m / 60;
  double tmp2 = (double)360 * m / 60;
  double theta = abs(tmp1 - tmp2);

  double tmp3 = cos(pi * theta / 180);

  double ans = sqrt(a * a + b * b - 2 * a * b * tmp3);

  cout << std::fixed << std::setprecision(10) << ans << endl;
  return 0;
}


Measured memory_bytes: 4160
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    int length = (b-a)*(b-a+1)/2;
    printf("%d\n", length-b);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

int main(){

    int n; cin >> n;

    while(n <= 1000){
        int a = n%10;
        int b = (n/10)%10;
        int c = (n/100)%10;

        if(a == b && b == c){
            cout << n;
            break; 
        }

        n++;
    }

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN

/*
平行四辺形の辺の長さの組の遷移を考える
*/

ll n,x,ans=0;

long long gcd(long long a,long long b){
	if(b==0)return a;
	if(a%b!=0){
		ans+=a/b*2*b;
	}else{
		ans+=(a/b*2-1)*b;
	}
	return gcd(b,a%b);
}

int main(void){
	cin>>n>>x;
	ans+=n;
	gcd(n-x,x);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void swap(int* a, int* b){
	int tmp; tmp = *a;
	*a = *b; *b = tmp;
}
int main(void) {
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if (a > b) swap(&a, &b);
	if (b > c) swap(&b, &c);
	if (a > b) swap(&a, &b);
	printf("%d %d %d\n", a, b, c);
	return 0;
}

Measured memory_bytes: 596
#include<cstdio>
#include<iostream>

using namespace std;

int main(void){

	int n,arr[101];

	cin>>n;

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

	for(int i=n-1;i>=0;i--){
		cout<<arr[i];
		if(i==0) cout<<endl;
		else cout<<" ";
	}

	return 0;
}

Measured memory_bytes: 1160
/*
@author: sharrad99
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define	PI 3.141592653589793238462643383279502884197169399375105820974944592307816406286
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vll vector<ll>
#define vbl vector<bool>
#define vpll vector<pll>
#define pb push_back
#define eb emplace_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(x) x.begin(),x.end()
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define mod 1000000007
#define INF 1000000000000000
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set_pll;
#define ook order_of_key
#define fbo find_by_order
/*  
	Query 1 - order_of_key(k) : Number of items strictly smaller than k.
	Query 2 - find_by_order(k) : K-th element in the set (counting from zero).
	less<ll> means Query 1 will return numbers strictly less than k.
	greater<ll> means Query 1 will return numbers strictly greater than k.
*/
ll powmod(ll x, ll n){
	ll res = 1;
	while(n){
		if(n & 1){
			res *= x;
			res %= mod;
		}
		x *= x;
		x %= mod;
		n >>= 1;
	}
	return res;
}
ll invmod(ll a){
	return powmod(a, mod - 2);
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll a, b;
	cin >> a >> b;
	cout << lcm(a, b);
}

Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys


def get_ints():
    return map(int, sys.stdin.readline().strip().split())


def _main():
    input()
    an = list(get_ints())

    t = 0
    old = 1000000000
    while 1:
        ans = sq(t, an)
        g = sq(t+1, an) - sq(t, an)
        t -= g / abs(g)
        if old > ans:
            old = ans
        else:
            break
    print(int(old))


def sq(t, an):
    ans = 0
    for ai in an:
        ans += pow(ai - t, 2)
    return ans


if __name__ == "__main__":
    _main()


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

using namespace std;

int main()
{
    int n, ans=0, big;
    cin>>n;
    int a[n], b;
    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    big=a[n-1];
    for (int i=0; i<n-1; i++)
    {
        if (ans<=min(big-a[i], a[i]))
        {
            ans=min(big-a[i], a[i]);
            b=a[i];
        }
    }
    cout<<big<<" "<<b<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;


int main() {

    int n;
    cin>>n;
    Vec vec(n);
    for(int i=0;i<n;i++){
        cin>>vec[i];
    }
  int ans=100000000;
     for(int i=0;i<100;i++){
         int sum=0;

     for(int j=0;j<n;j++){
         sum+=(vec[j]-i-1)*(vec[j]-i-1);
         
     } 
     ans=min(sum,ans);
  }
cout<<ans<<endl;
 
}

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

int main(){
  int a, b;
  cin >> a >> b;
  if ( a % 3 == 0 || b % 3 == 0 || ( a + b ) % 3 ==0 )
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
}

Measured memory_bytes: 256