akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1000006, INF=1000000009;
long long a[N], b[N], t[N], n, u;
int main(){ ios_base::sync_with_stdio(false);
    cin>>n;n*=2;n--;
    for (int i=1; i<=n; i++)
      	cin>>a[i];
    int l=1, r=n;
    int k=n/2+1;
    while(l<r){
       	int mid=(l+r+1)/2;
    	for (int i=1; i<=n; i++)
     		if(a[i]>=mid)b[i]=1;
      		else 		 b[i]=0;
      	if(b[k]==b[k-1] || b[k]==b[k+1]){
			if(b[k])l=mid;
			else      r=mid-1;
		}
		else{
     		int x=k; while(b[x]!=b[x+1] && x<n)x++;
     		int y=k; while(b[y]!=b[y-1] && y>1)y--;
       		if((b[k]+min(x-k, k-y))%2)l=mid;
       		else r=mid-1;
       	}
    }
    cout<<l;
   	return 0;
}

Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define pll pair<lli,lli>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mp  make_pair
#define ss  second
#define ff  first
#define all(x) x.begin(),x.end()
const lli mod = 1e9+7;
//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    #endif
lli p2(lli n){lli ans=0;while(n>=1){n=n/2;ans++;}return ans;}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli add(lli a,lli b){return(a+b)%mod;}
lli mul(lli a,lli b){return (a*b)%mod;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli lcm(lli a,lli b)
{
    lli ans=(a*b)/(__gcd(a,b));
    return ans;
}

int main()
{
    int n;cin>>n;
    if(n<=0 or n>81)cout<<"No\n";
    else
    {
        for(int i=1;i<=9;i++)
        {
            if(n%i==0 and n/i <= 9)
            {
                cout<<"Yes\n";return 0;
            }
        }
        cout<<"No\n";
    }
}





Measured memory_bytes: 3544
#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define repd(i,x,y) for (int i=x; i>=y; --i)
#define mid ((l+r)>>1)
using namespace std;

const double pi=acos(-1);
int n,xs,ys,xt,yt,stk[200100],top;
struct data
{
    int x,y;
    bool operator<(const data &t) const
    {
        return x<t.x;
    }
} a[200100];

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()));
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

int main()
{
    scanf("%d%d%d%d%d",&xs,&ys,&xt,&yt,&n);
    repu(i,1,n)
        a[i].x=getint(),a[i].y=getint();
    if (xs>xt)
    {
        xs=1e8-xs,xt=1e8-xt;
        repu(i,1,n)
            a[i].x=1e8-a[i].x;
    }
    if (ys>yt)
    {
        ys=1e8-ys,yt=1e8-yt;
        repu(i,1,n)
            a[i].y=1e8-a[i].y;
    }
    repd(i,n,1)
        if (a[i].x<xs || a[i].x>xt || a[i].y<ys || a[i].y>yt)
            a[i]=a[n--];
    sort(a+1,a+1+n);
    repu(i,1,n)
    {
        int l=1,r=top+1;
        while (l<r)
            stk[mid]>a[i].y?r=mid:l=mid+1;
        stk[l]=a[i].y,top=max(top,l);
    }
    double ans=(xt-xs+yt-ys)*100.0+top*(5*pi-20);
    if (top==min(xt-xs,yt-ys)+1)
        ans+=5*pi;
    printf("%.15f\n",ans);
    return 0;
}

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

using namespace std;

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

	double tmp = N / (2.0 * D + 1.0);

	int res = tmp - int(tmp) > 0.0 ? int(tmp) + 1 : int(tmp);

	cout << res << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String s = sc.next();
        int ans = 0;
        for (int i = 0; i < n - 2; i++) {
            if (s.substring(i, i + 3).equals("ABC")) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef long long ll;
typedef long long integer;
//////////////////////////////////////////////////
int main(){
	integer ans = 0;
	int N,M;
	SCD2(N,M);
	static int A[100002] = {};
	static int S[100002] = {};

	REP(i,N){
		SCD(A[i]);
		A[i] = A[i] % M;
	}

	S[0] = A[0];
	if (S[0] == 0) ans++;
	FORq(i,1,N-1){
		S[i] = (A[i] + S[i-1]) % M;
		if (S[i] == 0) ans++;
	}

	sort(S,S+N);

	vector<int> U;	
	int count = 1;
	REP(i,N-1){
		if (S[i] == S[i+1]){
			count++;
		}else{
			U.PB(count);
			count = 1;
		}
	}
	U.PB(count);

	

	REP(i,U.size()){
		integer x = U[i];
		ans += x * (x-1) / 2;
	}

	PRINTLLD(ans);
}	

Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main(void){
	int n;
	int a[1000];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=n;i>=0,i--;){
		cout<<a[i];
		if(i>0){
			cout<<" ";
		}
	}
	cout<<endl;
return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e7+10;
int n;
int tot,flag;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		int x,y;
		cin>>x>>y;
		if(x==y)tot++;
		else tot=0;
		if(tot==3){flag=true;}
	}
	if(!flag)puts("No");
	else puts("Yes");
    return 0;
}

Measured memory_bytes: 3632
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e7 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int p = 7;
   int cur = 1;
   int n;
   cin >> n;
   while(cur <= N){
      p %= n;
      // debug(p);
      if(p == 0){
         cout << cur << '\n';
         return 0;
      }
      cur++;
      p = p*10+7;
   }
   cout << -1;
   return 0;
} 

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
int pwr(int x,int p)
{
    int temp=1;
    while(p>0)
    {
        if(p%2)
        {
            temp*=x;
            temp%=MOD;
            --p;
        }
        else
        {
            x*=x;
            x%=MOD;
            p/=2;
        }
    }
    return temp;
}
signed main()
{
    SPEED;
    int n;
    cin>>n;
    int a[n],b[n],z=0,cnt=0,z1=0,z2=0;
    map<pair<int,int>,int> m;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
        if(a[i]==0 && b[i]==0)
        {
            ++z;
            continue;
        }
        else if(a[i]==0)
        {
            ++z1;
            continue;
        }
        else if(b[i]==0)
        {
            ++z2;
            continue;
        }
        int g=__gcd(a[i],b[i]);
        a[i]/=g;
        b[i]/=g;
        if(b[i]<0)
        {
            a[i]*=-1;
            b[i]*=-1;
        }
        m[{a[i],b[i]}]++;
    }
    cnt=pwr(2,z1)+pwr(2,z2)-1;
    for(int i=0;i<n;i++)
    {
        if(a[i]==0 || b[i]==0 || m[{a[i],b[i]}]==0)
        {
            continue;
        }
        int chk=pwr(2,m[{a[i],b[i]}]);
        m[{a[i],b[i]}]=0;
        if(a[i]<0)
        {
            a[i]*=-1;
            b[i]*=-1;
        }
        chk+=(pwr(2,m[{-b[i],a[i]}]))-1+MOD;
        m[{-b[i],a[i]}]=0;
        chk%=MOD;
        cnt*=chk;
        cnt%=MOD;
    }
    cout<<(cnt+z-1+MOD)%MOD;
}

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

#define PI 4*atan(1)
#define INF 1e9

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

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

int V;
struct edge { int to, cost; };
vector<vector<edge>> G;
vector<int> d;

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P>> que;
  for(int i = 0; i < V; i++)d[i] = INF;
  d[s] = 0;
  que.push(P(0, s));

  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(int i = 0; i < G[v].size(); i++){
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main(){
  int E, r;
  cin >> V >> E >> r;
  G.resize(V);
  d.resize(V);
  for(int i = 0; i < E; i++){
    int s, t, _d;
    cin >> s >> t >> _d;
    edge e; e.to = t; e.cost = _d;
    G[s].push_back(e);
  }
  dijkstra(r);
  for(auto t : d){
    if(t == INF)cout << "INF" << endl;
    else cout << t << endl;
  }
}

Measured memory_bytes: 13008
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
#define repi(i,a,b) for (int i=a;i<(b);i++)
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >> n;
  repi(i,1,10){
    repi(j,1,10){
      if(i*j==n){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, k, n) for(ll i = k; i < (ll)(n); i++)
using ll = long long;

int main(){
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    bool checker = 1;
    rep(i, 0, a){if (s[i] == '-') checker = 0;}
    if (s[a] != '-') checker = 0;
    rep(i, a+1, a+b+1){if (s[i] == '-') checker = 0;}   
    if (checker) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#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>

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

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

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 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; }

void solve(void)
{
  string s; cin >> s;

  if(s[0] == 'A')
  {
    auto s1 = s.substr(2, s.size() - 3);
    auto cnt = std::count_if(s1.begin(), s1.end(), [](auto c){ return c == 'C'; });
    if(cnt == 1)
    {
      ull upper_cnt{};
      for(const auto& c : s)
      {
        uc num = c - 'a';
        if(num > 'z' - 'a')
        {
          ++upper_cnt;
        }
      }
      if(upper_cnt == 2)
      {
        cout << "AC" << CRLF;
        return;
      }
    }
  }

  cout << "WA" << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
n,m,k=map(int,input().split())
par=[-1]*n

# this par & rank are initialized lists
def find(x):
    global par
    if par[x]<0:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
        
def unite(x,y):
    x,y=find(x),find(y)
    global par
    if x==y:return False
    else:
        if par[x]>par[y]:x,y=y,x
        par[x]+=par[y]
        par[y]=x
        return True

def size(x):
    return -par[find(x)]
def same(x,y):
    return find(x)==find(y)
from sys import stdin 
input=stdin.readline
friend=[0]*n
for i in range(m):
    a,s=map(int,input().split())
    a-=1;s-=1
    unite(a,s)
    friend[a]+=1
    friend[s]+=1
anti=[set() for i in range(n)]
for i in range(k):
    a,b=map(int,input().split())
    a-=1;b-=1
    anti[a].add(b)
    anti[b].add(a)

print(*[size(i)-1-sum(same(i,b) for b in anti[i])-friend[i] for i in range(n)],sep=" ")


Measured memory_bytes: 43544
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/


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

	int n;
	cin >> n;
	vector<int> d(n);
	int ma = 0;
	rep(i, n) {
		cin >> d[i];
		ma = max(ma, d[i]);
	}
	int ans = 0;

	sort(allof(d));

	int a = d[n / 2 - 1];
	int b = d[n / 2];

	cout << b - a << endl;

	return 0;
}


Measured memory_bytes: 640
// Author : heyuhhh
// Created Time : 2020/09/13 20:05:49
#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5, MOD = 1e9 + 7;
int qpow(ll a, ll b) {
    ll res = 1;
    while(b) {
        if (b & 1) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}
void run() {
    int n;
    cin >> n;
    int ans = qpow(10, n);
    ans -= ((qpow(9, n) + qpow(9, n) - qpow(8, n)) % MOD + MOD) % MOD;
    ans %= MOD;
    if (ans < 0) ans += MOD;
    cout << ans << '\n';
}
int main() {
#ifdef Local
    freopen("input.in", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

Measured memory_bytes: 3644
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<long long> A(n + 1, 0);
    for (int i = 0; i < n; ++i) {
        cin >> A[i + 1];
    }

    const long long INF = 1LL << 60;
    vector<long long> dp(2, -INF);
    dp[0] = 0;
    auto ndp = dp;
    for (int i = 1; i <= n; ++i) {
        fill(ndp.begin(), ndp.end(), -INF);
        
        for (int j = 0; j < 2; ++j) {
            if (dp[j] <= -INF) {
                continue;
            }
            
            for (int k = 0; k < 2; ++k) {
                long long v = A[i];
                if ((j ^ k)) {
                    v = -v;
                }
                ndp[k] = max(ndp[k], dp[j] + v);
            }
        }

        swap(ndp, dp);
    }

    cout << dp[0] << "\n";

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
    int x,c=0;
    cin>>x;
    int arr[x];
    for(int i=0;i<x;i++){
        cin>>arr[i];
    }
    for(int i=0;i<x;i++){
        if(arr[i]%2!=0&&i%2==0){
            c++;
        }
    }
    cout<<c;
}

Measured memory_bytes: 3500
from heapq import heappush, heappop


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

    jobs.sort(key=lambda x: x[0], reverse=True)

    hq = []
    ans = 0

    for i in range(1, m+1):
        for j in range(len(jobs)-1, -1, -1):
            if jobs[j][0] != i:
                break
            heappush(hq, jobs[j][1]*-1)
            jobs.pop()
        if len(hq) > 0:
            ans += heappop(hq)*-1

    print(ans)


if __name__ == '__main__':
    main()


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

#define lli long long
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define REP(i,n) for (lli i=0;i<(n);i++)
#define rep(i,n) for (lli i=0;i<(n);i++)

#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>

int main(){
  double r;

  cin>>r;
  
  printf("%30.30f %30.30f",M_PI*r*r,2*M_PI*r);
  
  return 0;
}

Measured memory_bytes: 3268
#include <iostream>
using namespace std;
int main(){
	int c1=1,c5=5,c10=10,c50=50,c100=100,c500=500;
	int a,b,c,e,f,g;
	cin>>a>>b>>c>>e>>f>>g;
	int sum;
	sum=c1*a+c5*b+c10*c+c50*e+c100*f+c500*g;
	if(sum>=1000){
	cout<<"1"<<endl;
	}else{
	cout<<"0"<<endl;
	}
}

Measured memory_bytes: 1156
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

double pi = acos(-1);

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  double a, b, x;
  while (cin >> a >> b >> x) {
    double fail = 0, pass = 90;
    auto volume = [&](double theta) {
      double rad = theta * pi / 180;
      double height = b * tan(rad);
      double area;
      if (height <= a) {
        area = b * height / 2;
      } else {
        double bottom = a / tan(rad);
        area = a * b - a * bottom / 2;
      }
      return area * a;
    };
    for (int i = 0; i < 100; i++) {
      double theta = (fail + pass) / 2;
      if (x <= volume(theta)) {
        pass = theta;
      } else {
        fail = theta;
      }
    }
    printf("%.20f\n", 90 - pass);
  }
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;


class Lowlink{
public:
  // {v_from, v_to}
  vector<pair<int,int>> bridge;
  // [v]
  vector<int> articulation_point;
  void construct(const vector<vector<int>>& g){
    const int n = g.size();
    bridge = vector<pair<int, int>>{};
    articulation_point = vector<int>{};

    vector<int> ord(n, -1);
    vector<int> low(n);
    for(int i=0; i<n; i++){
      dfs(g, ord, low, i);
    }
  }

private:
  void dfs(
    const vector<vector<int>>& g, vector<int>& ord, vector<int>& low,
    int cur, int par = -1)
  {
    ord[cur] = par==-1 ? 0 : ord[par] + 1;
    low[cur] = ord[cur];
    int num_children = 0;
    bool is_articulation = false;
    for(auto& nex: g[cur]){
      if(ord[nex] == -1){
        ++num_children;
        dfs(g, ord, low, nex, cur);
        low[cur] = min(low[cur], low[nex]);
        if(ord[cur] <= low[nex] && par!=-1)
          is_articulation = true;
        if(ord[cur] < low[nex])
          bridge.emplace_back(min(cur, nex), max(cur, nex));
      }else if(nex != par){ // back edge
        low[cur] = min(low[cur], ord[nex]);
      }
    }
    if(par == -1 && num_children >= 2)
      is_articulation = true;
    if(is_articulation)
      articulation_point.push_back(cur);
  }

};

int main(){
  int n,e;
  cin >> n >> e;
  vector<vector<int>> g(n);
  for(int i=0; i<e; i++){
    int u,v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  Lowlink lowlink;
  lowlink.construct(g);
  auto b = lowlink.bridge;
  sort(begin(b), end(b));
  for(auto e : b){
    cout << e.first << " " << e.second << endl;
  }
  return 0;
}


Measured memory_bytes: 4448
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
int k,x,a,b;
cin >> k >> x;
a = x-k+1;
b = x+k;
for(int i=a;i<b;i++){
	cout << i << endl;
}

////////////////////////////////////////////////////////
return 0;}

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

using namespace std;

const int N = 110;
const int K = 1e5 + 100;
const int Mod = 1e9 + 7;

int Arr[N];
int Dp[2][K];
int Prefix[2][K];

void CalcPrefix(int row, int k) {
    Prefix[row][0] = Dp[row][0];
    for (int i = 1; i <= k; i++)
        Prefix[row][i] = (Prefix[row][i - 1] + Dp[row][i]) % Mod;
}

int getPrefix(int row, int L, int R) {
    return (Prefix[row][R] - (L ? Prefix[row][L - 1] : 0) + Mod) % Mod;
}

int main()
{
    int n, k;   scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++)
        scanf("%d", Arr + i);

    Dp[n&1][0] = 1;
    for (int child = n - 1; ~child; child--) {
        CalcPrefix((child + 1)&1, k);
        for (int candie = 0; candie <= k; candie++)
            Dp[child&1][candie] = getPrefix((child + 1)&1, max(0, candie - Arr[child]), candie);
    }

    printf("%d\n", Dp[0][k]);
    return 0;
}


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

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int main(){
    string str;
    cin >> str;
    int N = str.size();
    vector<int> S(N);
    for(int i=0; i<N; i++) S[i] = str[i] - '0';
    int K;
    cin >> K;
    int N1 = accumulate(S.begin(), S.end(), 0);
    int N0 = N-N1;
    K = min(K, N1);

    // 0 で区切った時の各エリアの1の個数と、その累積和
    vector<int> one, oneS;
    int len = 0;
    for(int i=0; i<N; i++){
        if(S[i]){
            len++;
        }else{
            one.push_back(len);
            len = 0;
        }
    }
    one.push_back(len);
    oneS = one;
    for(int i=1; i<=N0; i++) oneS[i] += oneS[i-1];

    // エリアi-1まで見て、操作をj回使って、1をk回使った
    static int64_t dp[310][310][310];
    dp[0][0][0] = 1;
    for(int i=0; i<=N0; i++){
        // 元々あった one[i] 個の1を全部は使わないパターン
        // 0～(one[i]-1) 個使って合計k個になるような遷移元を累積和で処理
        for(int j=0; j<=K; j++){
            int64_t s = 0;
            for(int k=0; k<=N1; k++){
                add(s, dp[i][j][k]);
                if(k >= one[i]) add(s, MOD - dp[i][j][k-one[i]]);
                // 使った1の個数が oneS[i] 個以上なら遷移
                if(k >= oneS[i]) add(dp[i+1][j][k], s);
            }
        }
        // 元々あった one[i] 個の1を全部使って、さらに移動してきた1を0個以上使うパターン
        for(int j=0; j<=K; j++) for(int k=0; k<=N1; k++){
            // 移動してきた1を1個使って同じiに遷移
            add(dp[i][j+1][k+1], dp[i][j][k]);
            // one[i] 個の1を使い、使った1の個数が oneS[i] 個以上ならi+1遷移
            if(k+one[i] >= oneS[i]) add(dp[i+1][j][k+one[i]], dp[i][j][k]);

        }
    }

    int64_t ans = 0;
    for(int j=0; j<=K; j++) add(ans, dp[N0+1][j][N1]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 59452
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=10000009;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		ans+=i;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005],dp[100005];
ll n;
ll ans=0;
ll recur(ll i)
{
	if(dp[i]!=-1)
	{	
		return dp[i];
	}	
	if(i==n-1)
	{
		return 0;
	}
	ll q,w=LONG_LONG_MAX;
	q=abs(a[i]-a[i+1])+recur(i+1);
	if(i+2<n)
	w=abs(a[i]-a[i+2])+recur(i+2);
	dp[i]=min(q,w);
	return(min(q,w));
}
int main()
{
for(ll i=0;i<100005;i++)
dp[i]=-1;
cin>>n;	
for(ll i=0;i<n;i++)
cin>>a[i];
cout<<recur(0);
return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  int a;
  cin >> a;
  double sum = 0.00000;
  rep(i,a){
    double b;
    string c;
    cin >> b >> c;
    if(c=="BTC")b *= 380000.0;
    sum += b;
  }
cout << sum;
}


Measured memory_bytes: 3808
#include <algorithm>
#include <map>
#include <iostream>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <iterator>
#include <array>
#include <iomanip>
typedef long long int ll;
using namespace std;
#define maxN 200005
#define mod 1000000007
#define pi 3.14159265358979323846264338327950

void solve()
{
    string a, b;
    cin >> a >> b;
    int ans = 0;
    for (int i = 0; i < a.length(); i++)
    {
        if (a[i] != b[i])
        {
            ans++;
        }
    }
    cout << ans << endl;
}

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

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

using namespace std;

#define il inline
#define re register int
#define Rep(i, s, e) for (re i = s; i <= e; ++i)
#define Dep(i, s, e) for (re i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)

il int read() {
	int x = 0; bool f = true; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = false; c = getchar();}
	while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
	return f ? x : -x;
}

int n, h, s;
int main() {
	h = read(), n = read();
	Rep(i, 1, n) s += read();
	return printf("%s", (s >= h) ? "Yes" : "No") & 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll A, B, C;
    cin >> A >> B >> C;

    ll d = A*100+B*10+C;
    if (d%4) {
        NO;
    } else {
        YES;
    }
    return 0;
}

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

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    vector<int> n = {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};
    int k;
    cin >> k;
    cout << n[k-1] << endl;
}

Measured memory_bytes: 888
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define REP(x,l,u) for(ll x = l;x<u;x++) // for loop
#define RREP(x,l,u) for(ll x = l;x>=u;x--) // reverse for loop

/**
 *  debugging stuff
 */
string to_string(string s) {return s;}
string to_string(char c) {return string(1,c);}
template <typename A, typename B> string to_string(pair<A,B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(vector<A> v) { string s = "("; int first = 1; for (A a : v) { if (!first) { s += ", "; } first = 0; s += to_string(a); } s += ")"; return s; }
template <typename A> string to_string(set<A> v) { string s = "("; int first = 1; for (A a : v) { if (!first) { s += ", "; } first = 0; s += to_string(a); } s += ")"; return s; }

/**
 *  more debugging stuff
 */
void debug_out() {cerr << endl;}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

#ifndef ONLINE_JUDGE
#define debug(...) do { cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__); } while (false)
#else
#define debug(...) do { } while (false)
#endif

typedef long long ll;
typedef double db;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL; 
typedef pair<ll,ll> PLL;
typedef vector<string> VS;

template <typename A, typename B> void in(A & a, B & b) { in(a); in(b); }
template <typename A, typename B, typename C> void in(A & a, B & b, C & c) { in(a); in(b); in(c); }

const ll inf = (ll)1e18 + 5;

VLL stones;
VLL memoize;
ll k;

ll cost(ll index) {

    if (!index) return 0;

    if (index < 0) return inf;

    if (memoize[index] != -1) return memoize[index];

    // if (!index) {
    //     return 0;
    // } else if (index == 1) {
    //     return abs(stones[index] - stones[index - 1]);
    // }

    ll min = inf;

    REP(i,1,k + 1) {

        if (index - i < 0) continue;

        ll current = cost(index - i) + abs(stones[index] - stones[index - i]);

        if (current < min) min = current;
    }

    memoize[index] = min;

    return memoize[index];
}

namespace SOLVE {	
	void main() {
		ll N;

        cin >> N >> k;

        REP(i,0,N) {
            ll stone;
            cin >> stone;

            stones.push_back(stone);
        }

        memoize.resize(N, -1);

        // start from the back
        ll min_cost = cost(N - 1);

        // REP(i,0,N) debug(cost(i));

        cout << min_cost << endl;

	}
}

signed main() {
	ll t;
	t = 1;
    // cin >> t;
	REP(i,0,t) {
		SOLVE::main();
	}

	return 0;
}

Measured memory_bytes: 6644
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace __gnu_pbds;
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define ld long double
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST int testcase;cin>>testcase;while(testcase--)
#define FTEST int testcase;fin>>testcase;while(testcase--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
#define endl "\n"
#define plll pair<ll,pll>
#define plii pair<ll,pii>
#define no {cout<<"no"<<endl;return;}
#define yes {cout<<"yes"<<endl;}
#define rep(i,N) for(int i=0;i<N;i++)
const int maxn=1e6;
const int mod=998244353;
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int n,q,k,c=0;
pii arr[maxn+1];
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>q;
        arr[i].first=q;
        arr[i].second=i;
    }
    sort(arr+1,arr+n+1);
    for(int i=1;i<=n;i++){
        cout<<arr[i].second<<" ";
    }
}
int main(){
    IO
    //TEST
    solve();

    return(0);
}
/*
1
aabce
ace
*/


Measured memory_bytes: 4372
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define gcd __gcd
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define mp make_pair
#define pb push_back
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sbits(a) __builtin_popcount(a)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define nani(x) cerr << #x << " is " << x << endl;
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

typedef long long ll;

const int N = 1e5 + 5;

int A[105];
bool dp[N];

int main()
{
    fast;

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

    int n, k;
    cin >> n >> k;

    for (int i = 0; i < n; i++)
        cin >> A[i];

    for (int i = 0; i <= k; i++) {
        int z = !dp[i];
        for (int x = 0; x < n; x++) {
            if (i + A[x] <= k && !dp[i + A[x]])
                dp[i + A[x]] |= z;
        }
    }

    if (dp[k])
        cout << "First";
    else
        cout << "Second";

    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }

        int res = 0;
        while(true) {
            int max = 0;
            for(int i = 0; i < N; i++) {
                max = Math.max(max, arr[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j < N) {
                if(arr[j] == 0) j++;
                else {
                    res++;
                    while(j < N && arr[j] > 0) {
                        arr[j]--;
                        j++;
                    }
                }
            }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 35912
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int a = Integer.parseInt(s);
    int f = 0;
    for (int i = 0; i < s.length(); i++) {
      f += Character.getNumericValue(s.charAt(i));
    }

    if ((a % f) == 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }
}

Measured memory_bytes: 35392
h,w,m=map(int,input().split())
g=[]
e1=[0]*h
e2=[0]*w
for c in range(m):
    a,b=map(int,input().split())
    g.append([a-1,b-1])
    e1[a-1]+=1
    e2[b-1]+=1
p1=max(e1)
p2=max(e2)
x=[1 if e1[c]==p1 else 0 for c in range(h)]
y=[1 if e2[c]==p2 else 0 for c in range(w)]
r=sum(x)*sum(y)
for i in g:
    if x[i[0]]==1 and y[i[1]]==1:
        r-=1
if r==0:
    print(p1+p2-1)
else:
    print(p1+p2)


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

int main(){
    long long a,b,n;
    cin >> a >> b >> n;
    long long x =n;
    if(n >= b-1)x = b-1;
    long long ans =a*x/b-a*(x/b);
    cout << ans << endl;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
const int MAX_V=500,inf=1e8;
map<int,int> G[MAX_V];
bool used[MAX_V];
void add_edge(int from, int to, int cap){
	G[from][to]=G[to][from]=cap;
}
void erase_edge(int from,int to){
	G[from].erase(to);
	G[to].erase(from);
}
int dfs(int v,int t,int f){
	if(v==t) return f;
	used[v]=true;
	for(auto &e:G[v]){
		if(!used[e.fs] && e.sc>0){
			int d=dfs(e.fs,t,min(f,e.sc));
			if(d>0){
				e.sc-=d;
				G[e.fs][v]+=d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s,int t){
	int flow=0;
	while(true){
		memset(used,0,sizeof(used));
		int f=dfs(s,t,inf);
		if(f==0) return flow;
		flow+=f;
	}
}
int main(){
	int N,E,Q;
	cin>>N>>E>>Q;
	rep(i,E){
		int F,T;
		cin>>F>>T;
		add_edge(F-1,T-1,1);
	}
	int now=max_flow(0,N-1);
	rep(i,Q){
		int m,a,b;
		cin>>m>>a>>b;
		a--,b--;
		if(m==1){
			add_edge(a,b,1);
			now+=max_flow(0,N-1);
		}else{
			int ecap=G[a][b];
			erase_edge(a,b);
			if(ecap==2) swap(a,b);
			if(ecap!=1){
				memset(used,0,sizeof(used));
				int f=dfs(a,b,1);
				if(f==0){
					memset(used,0,sizeof(used));
					dfs(a,0,1);
					memset(used,0,sizeof(used));
					dfs(N-1,b,1);
					now--;
				}
			}
		}
		printf("%d\n",now);
	}
}

Measured memory_bytes: 3160
import math

n,m = map(int,input().split())
if(abs(n-m)>1):
	print("0")
else:
	x = math.factorial(n)
	y = math.factorial(m)
	md = 1000000007
	if(n==m):
		print(((x%md)*(y%md)*2)%md)
	else:
		print(((x%md)*(y%md))%md)

Measured memory_bytes: 4360
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define TIN(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
#define VIND(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem,--_elem
#define OUT(x) cout << x;
#define OUTL(x) cout << x << endl;
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

ll c[114514];

void solve()
{
    Bint n;
    cin >> n;
    IN(x, m);
    vector<ll> v;
    v.push_back(0);
    v.push_back(x);
    c[x] = 1;
    bool loop = false;
    ll ran = (ll)min((Bint)114514, n);
    for(int i = 2; i <= ran; ++i) {
        x = ((x % m) * (x % m)) % m;
        if (c[x] != 0) {
            loop = true;
            break;
        }
        c[x] = i;
        v.push_back(x);
    }
    ll res = 0;
    if (!loop) {
        rep(i, (ll)n+1) {
            res += v[i];
        }
        cout << res << endl;
        return;
    }
    rep(i, c[x]) {
        res += v[i];
    }
    n -= c[x] - 1;
    ll cicle = v.size() - c[x];
    ll sum = 0;
    reps(i, c[x], v.size()) sum += v[i];
    res += (ll)(n / cicle) * sum;
    rep(i, (ll)(n % cicle)) {
        res += v[c[x]+i];
    }
    cout << res << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 4700
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

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

	int n;
	cin>>n;
	for(int i=1000;i<1000000;i+=1000){
		if(i>=n){
			cout<<i-n<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
#include<algorithm>
int main()
{
	int n,x=0,i,j,a[9][9],s,*p,*q,f;
	while(scanf("%d",&n),n)
	{
		p=&i,q=&j;
		for(f=i=j=0,s=1;s<=n*n;++s)
		{
			a[i][j]=s;
			if(f ? *q==n-1 : !*p)std::swap(p,q),++*(f?q:p);
			else--*p,++*q;
			if(s>=n*n/2)++f;
		}
		printf("Case %d:\n",++x);
		for(i=0;i<n;putchar('\n'),++i)for(j=0;j<n;++j)printf("%3d",a[i][j]);
	}
	return 0;
}

Measured memory_bytes: 0
n, k = map(int, input().split())
V = list(map(int, input().split()))

from collections import deque
V = deque(V)

import copy

ans = -10**18
for i in range(k+1):
    for j in range(k+1):
        if i+j > k:
            continue
        if i+j > n:
            continue
        V_ = copy.copy(V)
        temp = []
        for p in range(i):
            temp.append(V_.popleft())
        for q in range(j):
            temp.append(V_.pop())
        temp.sort()
        s = sum(temp)
        l = k-i-j
        for r in range(min(l, len(temp))):
            if temp[r] < 0:
                s -= temp[r]
        ans = max(ans, s)
print(ans)


Measured memory_bytes: 75004
#include<cstdio>
#include<cstring>
//long long
const int len = 1e5 + 5;
int a[len],cnt[5],N;

int main(void)
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i)
	{
		scanf("%d", &a[i]);
		if (a[i] % 4 == 0)
			++cnt[4];
		else if (!(a[i] & 01))
			++cnt[2];
		else
			++ cnt[1];
	}
	if (cnt[2] == 0 && cnt[4] >= cnt[1] - 1)
		printf("Yes");
	else if (cnt[4] >= cnt[1])
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 512
import sys
sys.setrecursionlimit(5000)

H, W = map(int, input().split())
s=[]
for row in range(H):
    s.append(input())
#print(s)



waiting=[]
dx=[1,0,-1,0]
dy=[0,1,0,-1]
def func(xy):
    x, y = xy
    for i in range(4):
        if 0<=y+dy[i]<H and 0<=x+dx[i]<W:
            if walker[y+dy[i]][x+dx[i]] == None and s[y+dy[i]][x+dx[i]]=='.':
                walker[y + dy[i]][x + dx[i]]=walker[y][x]+1
                waiting.append((x+dx[i], y+dy[i]))
    if waiting:
        func(waiting.pop(0))
    else:
        return None

walker=[]
for row in range(H):
    walker.append([None]*W)
#print(walker)
walker[0][0]=0
func((0,0))
#print(walker)
if walker[H-1][W-1] != None:
    minimum=walker[H-1][W-1]

    white_count=0
    for row in range(H):
        white_count += s[row].count('.')
    #print(white_count)
    print(white_count-minimum-1)
else:
    print(-1)



Measured memory_bytes: 5108
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する

int main(){
    int n;
    cin>>n;
    int a,b;
    cin>>a>>b;
    int64_t ans = 0;
    for(int i=1;i<=n;i++){
        string s = to_string(i);
        int64_t sum = 0;
        int l = s.length();
        rep(j,l){
            sum += s[j]-'0';
        }
        if(sum>=a && sum<=b){
            ans += i;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/*@shutoshsuman99*/
#include<bits/stdc++.h>
using namespace std;
#include<cstdio>
#define pi 3.141592653589
#define pb push_back
#define ld long double
#define rem 1000000007
#define rem1 998244353
#define inf 1e18+1e17
#define F first
#define S second
#define pii pair<long long,long long>
#define p_q priority_queue <ll, vector<ll>, greater<ll> >
#define m_sp multiset <pair <ll,ll> > 
#define el "\n"
#define sp " "
typedef long long ll;
ll Pow(ll x,ll y,ll m) 
{ if (y == 0) return 1; ll p = Pow(x, y/2, m) % m; 
p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m; }
int main()
{
	ll i,n,ac,bd,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	string s,ans;
	cin>>s;
	s+="##";
	bool f=false;
	a--,b--,c--,d--;
	for(i=b;i<=d;i++)
	{
		if(s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.')
		f=true;
	}
	ac=a,bd=b;
	for(i=a;i<s.size()-1;i++)
	{
		if(s[i]=='#'&&s[i+1]=='#')
		{
			ac=i-1;
			break;
		}
	}
	for(i=b;i<s.size()-1;i++)
	{
		if(s[i]=='#'&&s[i+1]=='#')
		{
			bd=i-1;
			break;
		}
	}
	if(c<d)
	{
		if(ac>=c&&bd>=d)
		ans="Yes";
		else
		ans="No";
	}
	else
	{
		if(f&&ac>=c&&bd>=d)
		ans="Yes";
		else
		ans="No";
	}
	cout<<ans<<el;
}



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

#define endl "\n"
// g++ b.cpp -o b

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

    int n,k;
    cin >> n >> k;

    int arr[n];

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

    sort(arr, arr+n);

    int result = 0;

    for(int i=0; i<k; i++){
        result += arr[i];
    }

    cout << result << endl;
    

    return 0;
}

Measured memory_bytes: 3640
n = int(input())
h = list(map(int, input().split()))

dp = [10 ** 9] * n
dp[0] = 0

for i in range(1, n):
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[-1])

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

bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}

int main()
{
    int n;
    cin >> n;
    vector<int> t(n, 0);
    int m;
    int t_sum = 0;
    for (size_t i = 0; i < n; i++)
    {
        cin >> t[i];
        t_sum += t[i];
    }
    cin >> m;
    vector<pair<int, int>> vp;
    for (size_t i = 0; i < m; i++)
    {
        int p, x;
        cin >> p >> x;
        vp.push_back({p, x});
        /* code */
    }
    for (size_t i = 0; i < m; i++)
    {
        cout << t_sum - t[vp[i].first - 1] + vp[i].second << endl;
    }

    return 0;
}

Measured memory_bytes: 256