akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
int main() {
int A,B,C,D,n,k;
std::cin >> A >> B >> C >> D;
if(A-B>=0)
n=B;
else { 
	if(A-B<=0)
	n=A;
	else { 
		n=A;
	}
}
		

	if(C-D>=0)
	k=D;
	else {
		if(C-D<=0)
		k=C;
		else {
			k=C;
		}
	}
		std::cout << n+k << std::endl;
	


			return 0;
		}
		


			
	


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;
constexpr ll INF = 1LL<<60;
vector<vector<pair<ll,ll>>> edge;
ll n;
vector<ll> dijkstra(ll start) {
  vector<ll> dist(n,INF);
  dist[start]=0;
  priority_queue<pair<ll,ll>,
    vector<pair<ll,ll>>,
    greater<pair<ll,ll>>> pq;
  pq.push({dist[start],start});

  while(!pq.empty()) {
    auto p = pq.top();
    pq.pop();
    ll d=p.first,from=p.second;
    if(dist[from]<d) continue;
    for(const auto& next: edge[from]) 
    {
      ll to=next.first,cost=next.second;
      if (dist[to]>dist[from]+cost) {
        dist[to]=dist[from]+cost;
        pq.push({dist[to],to});
      }
    }
  }
  return dist;
}


int main()
{
  cin>>n;
  edge.resize(n);
  for (int i = 0; i < n-1; ++i)
  {
    ll u,v,w;
    cin>>u>>v>>w;
    u--;v--;
    edge[u].push_back({v,w});
    edge[v].push_back({u,w});
  }
  vector<ll> dist=dijkstra(0);
  for(auto&& e: dist) 
  {
    cout<<(e%2)<<endl;
  }

}

Measured memory_bytes: 11288
#include<stdio.h>

int main( )
{	
    int n;
    int maxProfit = 1-1000000000;
    int Rj, Ri, t, i;
   
    scanf( "%d", &n );
    
    scanf( "%d", &Ri );
    for( i=1; i<n; i++ ) {
    	scanf( "%d", &Rj );
    	t = Rj - Ri;
    	if( maxProfit < t ) {
       		maxProfit = t;
       	}
       	if( Rj < Ri ) {
    		Ri = Rj;
    	}
    }
    printf( "%d\n", maxProfit );
	
	return 0;
}

Measured memory_bytes: 596
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int n; ll X;
ll x[MAXN]; int v[MAXN];

ll a[MAXN],aa[MAXN];
ll b[MAXN],bb[MAXN];

void run() {
	scanf("%d%lld",&n,&X); REP(i,n) scanf("%lld%d",&x[i],&v[i]);

	ll ret=0;
	REP(rep,2) {
		a[0]=v[0]-x[0]; FOR(i,1,n) a[i]=a[i-1]+v[i]-(x[i]-x[i-1]);
		b[n-1]=v[n-1]-2*(X-x[n-1]); for(int i=n-2;i>=0;--i) b[i]=b[i+1]+v[i]-2*(x[i+1]-x[i]);
		REP(i,n) ret=max(ret,a[i]);
		aa[0]=a[0]; FOR(i,1,n) aa[i]=max(aa[i-1],a[i]); bb[n-1]=b[n-1]; for(int i=n-2;i>=0;--i) bb[i]=max(b[i],bb[i+1]);
		REP(i,n-1) ret=max(ret,aa[i]+bb[i+1]);
		//printf("a :"); REP(i,n) printf(" %lld",a[i]); puts("");
		//printf("b :"); REP(i,n) printf(" %lld",b[i]); puts("");
		REP(i,n) x[i]=X-x[i];
		reverse(x,x+n); reverse(v,v+n);
	}
	printf("%lld\n",ret);
}

int main() {
	run();
	return 0;
}


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

#define int long long
#define fi first
#define se second
#define pb push_back

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

int n, a[1 << 18], maxi;
iiii ans[1 << 18];

signed main(){
	ios_base::sync_with_stdio(0);
	cin >> n;
	for(int i = 0; i < (1 << n); i++) cin >> a[i];
	for(int i = 0; i < (1 << n); i++){
		ans[i] = {{a[i], i}, {0, -1}};
		for(int j = 0; j < n; j++){
			if(!(i & (1 << j))) continue;
			if(ans[i - (1 << j)].fi.fi > ans[i].fi.fi){
				ans[i].se = ans[i].fi;
				ans[i].fi = ans[i - (1 << j)].fi;
			}
			else if(ans[i - (1 << j)].fi.fi > ans[i].se.fi && (ans[i - (1 << j)].fi != ans[i].fi)) ans[i].se = ans[i - (1 << j)].fi;
			if(ans[i - (1 << j)].se.fi > ans[i].se.fi) ans[i].se = ans[i - (1 << j)].se;
		}
		if(i){
			maxi = max(maxi, ans[i].fi.fi + ans[i].se.fi);
			cout << maxi << "\n";
		}
	}
}


Measured memory_bytes: 13880
#include<iostream>
using namespace std;
int main()
{
    int N,R;
    cin >> N >> R;

    int ans;

    if (N >= 10) {
        ans = R;
    } else {
        ans = R + 100 * (10 - N);
    }
    


    cout << ans << endl;


    
    return 0;
}

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

int main(){
    int h,w;
    cin>>h>>w;
    int a[h+2][w+2]={0};
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            char x;
            cin>>x;
            if(x=='#')a[i][j]=1;
        }
    }
    //trick is to add borders 
    int f=0;
    for(int i=0;i<h+2;i++){
        for(int j=0;j<w+2;j++){
            if(a[i][j]==1){
                if(a[i-1][j]==1 || a[i+1][j]==1 || a[i][j-1]==1 || a[i][j+1]==1)continue;
                else {f=1;break;}
            }
        }
    }
    if(f==1)cout<<"No";
    else cout<<"Yes";
}


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

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

  sort(b,b+n);

  int ma = b[n-1];
  int next = b[n-2];

  for(int i=0; i<n; i++) {
    if(a[i]==ma) cout<<next<<endl;
    else cout<<ma<<endl;
  }



  return 0;
}

Measured memory_bytes: 5156
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<int> h(n+1);
    int ans=0;
    repi(i,1,n+1){
        cin>>h[i];
        if(h[i-1]<h[i]) ans+=h[i]-h[i-1];
    }
    cout<<ans;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std; 
int main(){
  int n;
  cin >> n;
  vector<int> vec(n);
  int i,sum=0;
  for(i=0;i<n;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  for(i=1;i<n;i++){
    sum+=vec.at(i);
  }
  sum+=vec.at(0)/2;
  cout << sum;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
typedef pair<ll  ,ll > pll;

const ll maxn =2e6;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
//#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

int n , m;
int mark[maxn];
int wtf[maxn];
int ac = 0 , wa = 0;

int main(){
    migmig
    cin >> n >> m;
    for (int i = 0 ; i < m ; i ++){
        int inp ;
        string s;
        cin >> inp >> s;
        if(!mark[inp]){
            if(s == "AC"){
                wa+=wtf[inp];
                ac++;
                mark[inp] = 1;
            }
            else{
                wtf[inp]++;
            }
        }
        else{
            continue;
        }
    }
    cout << ac << ' ' << wa;

    return(0);
}


//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


Measured memory_bytes: 4736
#include <stdio.h>
#define N 100000
#define NIL -1

struct Node
{int p;
  int l;
  int r;
};

struct Node T[N];
int n,D[N],H[N];

int setDepth(int u, int p){
  if (u==NIL) return 0;
  D[u]=p;
  setDepth(T[u].l, p+1);
  setDepth(T[u].r, p+1);
}

int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].l!=NIL)
    h1=setHeight(T[u].l)+1;
  if(T[u].r!=NIL)
    h2=setHeight(T[u].r)+1;
  return H[u]=(h1>h2?h1:h2);
}

int getSibling(int u){
  if(T[u].p==NIL) return NIL;
  if(T[T[u].p].l!=u && T[T[u].p].l!=NIL)
    return T[T[u].p].l;
  if(T[T[u].p].r!=u && T[T[u].p].r!=NIL)
    return T[T[u].p].r;
  return NIL;
}

void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("sibling = %d, ",getSibling(u));
  int deg=0;
  if (T[u].l!=NIL) deg++;
  if (T[u].r!=NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);
  
  if(T[u].p==NIL) printf("root\n");
  else if (T[u].l==NIL && T[u].r==NIL) printf("leaf\n");
  else printf("internal node\n");
}

int main(){
  int i,v,l,r,root=0;
  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].p=NIL;

  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].l=l;
    T[v].r=r;
    if(l!=NIL) T[l].p=v;
    if(r!=NIL) T[r].p=v;
  }

  for(i=0;i<n;i++) if(T[i].p==NIL) root=i;

  setDepth(root, 0);
  setHeight(root);

  for(i=0;i<n;i++) print(i);
    
  return 0;
}



Measured memory_bytes: 2088
import java.lang.*;
import java.util.*;
  
class Main{
   public static void main(String[] args){
     Scanner stdId = new Scanner(System.in);
     int S = stdId.nextInt(); 
     System.out.println("" + S/3600 + ":" + S%3600/60 + ":" + S%60);
  }
}

Measured memory_bytes: 17304
/* warshall_floyd.cpp
    ワーシャルフロイド法を用いて、全点間最短路を求める。

    初期化：dis[i][j] = iからjへの距離(辺がなければINF) (i≠j)
            dist[i][i] = 0
            prev[i][j] = i

    負閉路の検出：dis[i][i] < 0 となる i が存在するか

    verified:
        http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_C&lang=ja
*/

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17;

/* warshall_floyd(dist,prev)
    入力：初期化した dist, prev
    計算量：O(|V|^3)
    副作用：dis[i][j]にiからjへの最短路のコストを格納、prev[i][j]にiからjへの最短路でのjの1つ前の点を格納
*/
void warshall_floyd(vector<vector<long long>> &dist, vector<vector<long long>> &prev) {
    int V = dist.size();
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                if (dist[i][k] + dist[k][j] < dist[i][j]) {
                    dist[i][j] = dist[i][k] + dist[k][j];
                    prev[i][j] = prev[k][j];
                }
            }
        }
    }
}

/* get_path(prev, s, t)
    入力：warshall_floyd で得た prev, スタート s, ゴール t
    出力：s から t への最短路のパス
*/
vector<int> get_path(const vector<vector<long long>> &prev, int s, int t) {
    vector<int> path;
    for (int cur = t; cur != s; cur = prev[s][cur]) {
        path.push_back(cur);
    }
    path.push_back(s);
    reverse(path.begin(), path.end());
    return path;
}

/* is_negative(dist)
    入力：warshall_floyd で得た dist
    出力：負の有向路を含むかどうか
*/
bool is_negative(const vector<vector<long long>> &dist) {
    int V = dist.size();
    for (int i = 0; i < V; i++) {
        if (dist[i][i] < 0) {
            return true;
        }
    }
    return false;
}

int main() {
    int V, E;
    cin >> V >> E;

    // initialization
    vector<vector<long long>> dist(V, vector<long long>(V, INF));
    vector<vector<long long>> prev(V);
    for (int i = 0; i < V; ++i) {
        dist[i][i] = 0;
        prev[i] = vector<long long>(V, i);
    }

    // input
    for (int i = 0; i < E; i++) {
        long long s, t, c;
        cin >> s >> t >> c;
        dist[s][t] = c;
        // dist[t][s] = c;
    }

    warshall_floyd(dist, prev);

    if (is_negative(dist)) {
        cout << "NEGATIVE CYCLE" << endl;
    } else {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                if (dist[i][j] >= INF / 2) {
                    cout << "INF";
                } else {
                    cout << dist[i][j];
                }
                if (j != V - 1) {
                    cout << " ";
                }
            }
            cout << endl;
        }
    }

    return 0;
}



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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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 ll MRINF = 5000000000000000;

int main() {

  ll N, H, W;
  cin >> N >> H >> W;
  vector<ll> A(N), B(N);

  REP(i, N){
    cin >> A[i] >> B[i];
  }
  ll ans = 0;
  REP(i, N){
    if(A[i]>=H && B[i]>=W)ans++;
  }

  cout << ans << endl;



}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3604
'''
productでrepeatすればいいよ、
0,1リスト生成
minでとれたね
enumerateは手前がindex,valueの順

'''
N, M, X = map(int, input().split())

C_list = [list(map(int, input().split())) for i in range(N)]
import itertools

#print(targets)
answer = 10 ** 9
for i in range(0,1 << N):
    result = [0] * (M + 1)
    for j in range(N):
        if (i >> j) % 2 == 1:
            for k in range(M + 1):
                result[k] += C_list[j][k]
        #print(result)
    if min(result[1:]) >= X:
        #print(result)
        answer = min(answer,result[0])
if answer == 10 ** 9:
    print(-1)
else:
    print(answer)


Measured memory_bytes: 9164
#include<cstdio>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
const int N = 100005;
map<ll,ll> M;
ll a[N];
int main() {
    int n;
    ll sum = 0;
    scanf("%d",&n);
    for(int i = 1; i <= n; ++i) {
        scanf("%lld",&a[i]);
        sum += a[i], ++M[a[i]];
    }
    int q;
    ll a, b;
    scanf("%d",&q);
    while(q--) {
        scanf("%lld%lld",&a,&b);
        sum += M[a] * (b-a);
        M[b] += M[a], M[a] = 0;
        printf("%lld\n",sum);
    }
}

Measured memory_bytes: 10460
import sys
readline = sys.stdin.readline

N, A, B = map(int, readline().split())
*P, = map(int, readline().split())
Q = [0]*N
for i, p in enumerate(P):
    Q[p-1] = i

INF = 10**18
dp = [[INF]*(N+1) for i in range(N+1)]
dp[0][0] = 0
for i in range(N):
    qi = Q[i]
    for j in range(N):
        v = dp[i][j]
        dp[i+1][j] = min(dp[i+1][j], v + (A if qi < j else B))
        dp[i][j+1] = min(dp[i][j+1], v)
        if Q[i] == j:
            dp[i+1][j+1] = min(dp[i+1][j+1], v)
for i in range(N):
    dp[i+1][N] = min(dp[i+1][N], dp[i][N] + A)
for j in range(N):
    dp[N][j+1] = min(dp[N][j+1], dp[N][j])
sys.stdout.write("%d\n" % dp[N][N])

Measured memory_bytes: 231176
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';
ll num=1, ans=0, cnt=0, sum=0;

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

  ll n, m, k;
  cin >> n >> m;
  
  pl alc;
  vector<pl> ans;
  if(n%2==1) {   
    rep2(i, n/2) {
      alc.first = i;
      alc.second = n-i;
      ans.push_back(alc);
    }
    
  }else if(n%4==2){
    k = n/4;
    rep2(i, k) {
      alc.first = 2*k+2+i;
      alc.second = 4*k+3-i;
      ans.push_back(alc);
    }
    rep2(i, k) {
      alc.first = i;
      alc.second = 2*k+2-i;
      ans.push_back(alc);
    }
    
  }else if(n%4==0){
    k = n/4;
    rep2(i, k) {
      alc.first = 2*k+i;
      alc.second = 4*k+1-i;
      ans.push_back(alc);
    }
    rep2(i, k-1) {
      alc.first = i;
      alc.second = 2*k-i;
      ans.push_back(alc);
    }
  }
  
  rep(i, m) cout << ans[i].first << " " << ans[i].second << newl;
  return 0;
}

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

void solve(long long N, std::vector<long long> A){
    long long tmp = 1;
    sort(A.begin(), A.end());
    for (long long i = 0; i < N; i++) {
        if (A[i] == 0) {
            cout << 0 << endl;
            return;
        }
        
        if ((double)tmp > (double)1000000000000000000 / (double)A[i]) {
            cout << -1 << endl;
            return;
        }

        if ((double)tmp == (double)1000000000000000000 / (double)A[i]) {
            if (tmp * A[i] > 1000000000000000000) {
                cout << -1 << endl;
                return;
            }
        }
        tmp *= A[i];
    }
    cout << tmp << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 4076
n,m = map(int,input().split())
a = [list(input()) for i in range(n)]
b = [list(input()) for i in range(m)]

c = 0
for i in range(n-m+1):
    for j in range(n-m+1):
        c = 0
        for x in range(m):
            for y in range(m):
                if a[i+x][j+y] == b[x][y]:
                    c += 1
            
        if c == m**2:
            break
    
    if c == m**2:
        break

if c == m**2:
    print('Yes')

else:
    print('No')

Measured memory_bytes: 40304
#include<bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define N 300005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
main()
{
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    ll m=x/d;
    m=min(m,k);
    ll now=x-m*d;
    ll ans=1e18;
    ll baki=k-m;
    //cout<<x<<' '<<d<<' '<<m<<' '<<now<<endl;
    if(baki%2==0)
    {
        ans=min(ans,abs(now));
    }
    else
    {
        ans=min(ans,abs(now-d));
    }

    if(baki>0)
    {
        baki--;
        now-=d;

        if(baki%2==0)
        {
            ans=min(ans,abs(now));
        }
        else
        {
            ans=min(ans,abs(now+d));
        }
    }
    cout<<ans;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define int long long
#define mod 998244353
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/

int n, t[105];
map<double, double>v;
signed main() {
	cin >> n;
	rep(i, n) {
		int a; cin >> a;
		t[i] += a;
		t[i + 1] += t[i];
	}
	rep(i, t[n]) {
		v[i] = inf;
		v[i + 0.5] = inf;
	}
	rep(i, n) {
		double a; cin >> a;
		for (double j = (i ? t[i - 1] : 0); j <= t[i]; j += 0.5) {
			chmin(v[j], a);
		}
	}
	v[0.0] = 0;
	v[t[n]] = 0;
	for (double i = 20000; i > 0.; i -= 0.5) {
		chmin(v[i - 0.5], v[i] + 0.5);
	}
	double ans = 0;
	double st = 0, sttaka = 0;
	int jyotai = 0;
	double now = 0;
	for (double i = 0; i <= t[n]; i += 0.5) {
		now = min(now + 0.5, v[i]);
		if (jyotai == 0 && now >= v[i + 0.5]) {
			ans += (i - st) * sttaka + (i - st) * (now - sttaka) / 2;
			st = i, sttaka = now;
			if (now == v[i + 0.5])jyotai = 1;
			else jyotai = 2;
		}
		if (jyotai == 1 && now != v[i + 0.5]) {
			ans += (i - st) * now;
			st = i, sttaka = now;
			if (now < v[i + 0.5])jyotai = 0;
			else jyotai = 2;
		}
		if (jyotai == 2 && now <= v[i + 0.5]) {
			ans += (i - st) * now + (i - st) * (sttaka - now) / 2;
			st = i; sttaka = now;
			if (now == v[i + 0.5])jyotai = 1;
			else jyotai = 0;
		}
	}
	printf("%.12lf\n", ans);
}


Measured memory_bytes: 2688
//In the Name of God
//Let Our Voices Echo
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define X real()
#define Y imag()
typedef long long ll;
typedef double ld; 
typedef complex<ld> point;
const ld eps=1e-9;
const int MAX=1e5+9,MOD=1e9+7;
vector<int> v;
int n,a[MAX],ans;
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n;
	for (int i=0;i<n;i++) cin>>a[i],v.push_back(a[i]);
	sort(v.begin(),v.end());
	for (int i=0;i<n;i++) a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin();
	for (int i=0;i<n;i++) ans+=abs(a[i]-i)%2;
	cout<<ans/2;
	return 0;
}


Measured memory_bytes: 1148
#include<iostream>

using namespace std;

int main() {

	int b1,b2,b3;
	cin >> b1 >> b2 >> b3;

	if ((b1 == 1 && b2 == 1)||b3 == 1) {
		cout << "Open" << endl;
	} else {
		cout << "Close" << endl;
	}

	return 0;
}

Measured memory_bytes: 1156
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a)
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a)
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll sum(ll n) {
	return (1 + n) * n / 2;
}
//1から整数nまでの合計
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double m = sqrt(a);
	for (int i = 3; i <= m; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定

// ===============================================================

int main(void) {
  string s;cin>>s;
  int n=s.size()/2;
  bool h=true;
  for (int i=0;i<n;i++){
    if (s[i]!=s[n-i-1]) h=false;
  }
  for (int i=n;i<s.size();i++)
    if (s[i]!=s[s.size()-i-1]) h=false;
  if (h) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3680
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 整数の入力
		int n = sc.nextInt();
		int l = sc.nextInt();

		int ans = 0;
		int num = 9999;

		for(int i=0;i<n;i++){
			ans += l+i;
			num = abs(num)>abs(l+i)?l+i:num;
		}
		// 出力
		System.out.println(ans-num);
	}

	static int abs(int n){
		return n<0?-n:n;
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

#define MOD_BIG 1000000007
#define MOD_BIG2 998244353
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using std::vector;

#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

//////////////////////////////////////



//////////////////////////////////////

int main() {
    
    int N, M;
    cin >> N >> M;
    vector<int> k(M), p(M);
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        p[i] = a;
        REP(j, b) {
            int c;
            cin >> c;
            k[i] += 1 << (c-1);
        }
    }
    
    int s = pow(2, N);
    vector<ll> dp(s, 10e9+7);
    dp[0] = 0;
    
    FOR(i, 0, s) {
        FOR(j, 0, M) {
            int n = i | k[j];
            dp[n] = std::min(dp[n], dp[i] + p[j]);
            //cerr << n << " " << dp[n] << endl;
        }
    }
    if (dp[s-1] == 10e9+7) {
        cout << -1 << endl;
    } else {
        cout << dp[s-1] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
s = input()
count = 0
for si,ss in enumerate(s):
    if si%2 == 1 and ss not in ['L','U','D']:
        count += 1
    if si%2 == 0 and ss not in ['R','U','D']:
        count += 1
if count == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
coins=[1]
n=int(input())
for i in range(20):
    coins.append(6**i)
for i in range(20):
    coins.append(9**i)
dp=[10**9]*(n+1)
dp[0]=0 
for c in coins:
    for j in range(n+1):
        if c<=j:
            dp[j]=min(dp[j],dp[j-c]+1)
print(dp[n])

Measured memory_bytes: 43356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=50005,INF=1<<30;
struct dat{
    int space;
    string A;
    string B;
};
string X;
vector<dat> T;
map<string,set<string>> G;

void bunkai(string S){
    int space=0,i=0;
    string A,B;
    while(i<si(S)&&S[i]==' '){
        i++;
        space++;
    }
    while(i<si(S)&&S[i]!=':'){
        A+=S[i];
        i++;
    }
    i+=2;
    while(i<si(S)){
        B+=S[i];
        i++;
    }
    
    T.push_back({space,A,B});
}

void DFS(int u,int p){
    if(p!=-1){
        G[T[p].A].insert(T[u].A);
    }
    if(si(T[u].B)){
        G[T[u].A].insert(T[u].B);
        return;
    }
    
    int d=T[u+1].space;
    if(d<=T[u].space) return;
    
    for(int k=u+1;k<si(T);k++){
        if(T[k].space==d){
            DFS(k,u);
        }else if(T[k].space<=T[u].space) return;
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    getline(cin,X);
    
    T.push_back({-1,"",""});
    while(1){
        string x;
        getline(cin,x);
        if(x=="") break;
        bunkai(x);
    }
    
    DFS(0,-1);
    
    int i=0;
    string now="";
    
    bool ok=true;
    
    while(i<si(X)){
        if(X[i]=='.') i++;
        string S;
        while(i<si(X)&&X[i]!='.'){
            S+=X[i];
            i++;
        }
        
        if(G[now].count(S)){
            now=S;
        }else{
            ok=false;
            break;
        }
    }
    if(!ok){
        cout<<"no such property"<<endl;
    }else{
        if(si(G[now])==1){
            string to=*G[now].begin();
            if(si(G[to])) cout<<"object"<<endl;
            else cout<<"string "<<'"'<<*G[now].begin()<<'"'<<endl;
        }else if(si(G[now])) cout<<"object"<<endl;
        else cout<<"no such property"<<endl;
    }
}



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

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void){
    int n, k; cin >> n >> k;
    vector<vi> b(k);

    rep(i, k){
        int m; cin >> m;
        while(m --){ int usa; cin >> usa; b[i].pb(usa); }
    }

    int r; cin >> r;
    set<int> cnt;
    
    while(r --){
        int p, q; cin >> p >> q;
       rep(i, k) if(find(ALL(b[i]), p) != b[i].end() && find(ALL(b[i]), q) != b[i].end()) cnt.insert(p), cnt.insert(q);
    }

    cout << cnt.size() << endl;

    return 0;
}

Measured memory_bytes: 1220
/**
   Solution by Abil
**/
# include <bits/stdc++.h>

# define fr first
# define sc second
# define pb push_back
# define mk make_pair
# define sz(s) s.size()
# define all(s) s.begin(),s.end()
# define int long long

using namespace std;

const long long N = (1e6 + 10);
const long long mod = (1e9 + 7);
const long long inf = (1e9 + 7);

double a[N];
double dp[4000][4000];
main()
{
    int n;
    cin >> n;
    for(int i = 1;i <= n; i++){
        cin >> a[i];
    }
    dp[1][1] = a[1];
    dp[1][0] = 1 - a[1];
    for(int i = 2;i <= n; i++){
        for(int j = 0;j <= n; j++){
            if(j == 0){
                dp[i][j] = dp[i - 1][j] * (1 - a[i]);
            }
            else{
                dp[i][j] = dp[i - 1][j] * (1 - a[i]) + dp[i - 1][j - 1] * a[i];
            }
        }
    }
    double ans = 0;
    for(int i = (n + 1) / 2; i <= n; i++){
        ans += dp[n][i];
    }

    cout << fixed << setprecision(9) << ans;
}


Measured memory_bytes: 96256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define f first
#define s second

ll dp[100100];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.in", "r", stdin);
        //freopen("output.out", "w", stdout);
	int n, w;
	cin >> n >> w;	
	int a[n], b[n];
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
	}
	for(int i = 0; i < n; i++){
		for(int j = w - a[i]; j >= 0; j--){
			dp[j + a[i]] = max(dp[j] + b[i], dp[j + a[i]]);
		}
	}
	cout << dp[w] << endl;	
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int a[200001];
int main(){
    int n;
    cin>>n;
    rep(i,n) cin>>a[i];
    if(a[0]!=0){
        cout<<-1<<endl;
        return 0;
    }
    ll cnt=0;
    FOR(i,1,n){
        if(a[i]>a[i-1]+1){
            cout<<-1<<endl;
            return 0;
        }
        else if(a[i]==a[i-1]+1){
            ++cnt;
        }
        else cnt+=a[i];
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 1532
// D - Worst Case

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	vector<ll> ans;
	for (int i=0; i<Q; i++) {
		ll A, B;
		cin >> A >> B;

		if (A == B) {
			ans.push_back(2*A - 2);
			continue;
		}

		ll r = sqrt(A * B);
		ll r1 = r;
		ll r2 = r;

		if (r1 * r2 == A * B) {
			r1--;
			r2--;
			if (A <= r1) r1--;
			if (B <= r2) r2--;
			ans.push_back(r1 + r2);
		} else if ((r1 + 1) * r2 < A * B) {
			if (A <= r1) r1--;
			if (B <= r2) r2--;
			ans.push_back(r1 + r2);
		} else {
			r1--;
			r2--;
			if (A <= r1) r1--;
			if (B <= r2) r2--;
			if (r != A && r != B) ans.push_back(r1 + r2 + 1);
			else ans.push_back(r1 + r2);
		}
	}

	for (ll a : ans) {
		cout << a << endl;
	}

	return 0;
}

Measured memory_bytes: 3704
N = int(input())
a = list(map(int, input().split()))

# 絶対値が最大の要素a_jをすべての要素に加算する。
# その後、
# a_j >= 0 ならば a_1 に a_j を加算し、a_i に a_{i - 1} を加算
# a_j < 0 ならば a_N に a_j を加算し、a_i に a_{i + 1} を加算
i = max(range(N), key=lambda j: abs(a[j])) + 1
ans = '{}\n{}'.format(
    2 * N,
    '\n'.join(
        [
            '{} {}'.format(i, j)
            for j in range(1, N + 1)
            if j != i
        ] +
        [
            '{} {}'.format(i, i)
        ] +
        (
            [
                '{} {}'.format(i, 1)
            ] +
            [
                '{} {}' .format(j, j + 1)
                for j in range(1, N)
            ] if a[i - 1] >= 0 else
            [
                '{} {}'.format(i, N)
            ] +
            [
                '{} {}'.format(j + 1, j)
                for j in reversed(range(1, N))
            ]
        )
    )
)

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
	ll a, b, c, k;
	cin>>a>>b>>c>>k;
	while(b<=a)
	{
		if(k==0)
			break;
		b*=2;
		k--;
	}
	while(c<=b)
	{
		if(k==0)
			break;
		c*=2;
		k--;
	}
	if(c>b&&b>a)
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3796
//daddy's back in town, back to rolling the damn hash yoooo babeeeeees//
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
#define L nod<<1
#define R ((nod<<1)|1)
const ll mod = 998244353;
#define int ll
int n, m, ans, cnt[200010];

int32_t main(){
	ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	cin>>n;
	cnt[0]=1;
	for(int i=1, x; i<=n; i++){
		cin>>x;
		if(cnt[x-1]) cnt[x]=1;
	}
	for(int i=n; i>=1; i--) if(cnt[i]) return cout<<n-i, 0;
	cout<<-1<<endl;
}

Measured memory_bytes: 1920
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e15;

int main(){
    ll w,h,n;
    cin >> w >> h >> n;
    ll le=0,ri=w,up=h,lo=0;
    rep(i,n){
        ll x,y,a;
        cin >> x >> y >>a;
        if(a==1){
            le=max(le,x);
        }
        if(a==2){
            ri=min(ri,x);
        }
        if(a==3){
            lo=max(lo,y);
        }
        if(a==4){
            up=min(up,y);
        }
    }
    cout << max(ri-le,0LL)*max(up-lo,0LL) << endl;
    return 0;
}


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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.1415926535897932384626

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int n, cnt;

int main(){
	scanf("%d", &n);
	FI(i, 1, n){
		int x;
		scanf("%d", &x);
		cnt += (x & 1);
	}
	if(cnt & 1) printf("NO\n");
	else printf("YES\n");
	return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
	string tgt, input;
	int ans = 0;

	cin >> tgt;

	for (;;) {
		cin >> input;
		if (input == "END_OF_TEXT") break;
		transform(input.begin(), input.end(), input.begin(), ::tolower);
		if (input == tgt) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3216
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")



#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include <ext/rope>
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define Find order_of_key
// #define at find_by_order
#define x first
#define y second
#define ll long long
#define lll __int128
#define ull unsigned long long
#define ulll unsigned __int128
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#define gu getchar_unlocked()
#define pu putchar_unlocked()
#define all(x) x.begin(),x.end()
#define endl '\n'

const int mx=200010;
vector<int> g[mx];
ll cnt[mx];
int n,m;
void dfs(int u,int par,int val){
	ll a=cnt[u];
	cnt[u]+=val;
	for(auto v:g[u]){
		if(v!=par){
			dfs(v,u,val+a);
		}
	}
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	for(int i=0;i<m;i++){
		int p,x;
		cin>>p>>x;
		cnt[p]+=x;
	}
	dfs(1,-1,0);
	for(int i=1;i<=n;i++)cout<<cnt[i]<<" \n"[i==n];
	return 0;
}

Measured memory_bytes: 25468
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {
    r:usize,d:usize,x:usize,
     }

    let mut prev = x;
    for _ in 0..10 {
        prev = r * prev - d;
        println!("{}", prev);
    }
}


Measured memory_bytes: 2144
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;

int main(void)
{
    //string a,b;
    int a,b,c,d;
    //char a,b,c;
    int i=0,sum=700;
    //char a,b='.';
    cin>>a>>b>>c;
    cout<<max(max(a,b),c)-min(min(a,b),c);
    return 0;
}



Measured memory_bytes: 256
def main():
    s = input().strip()

    dp = [0] * 13
    dp[0] = 1

    power = 1
    mod = 10 ** 9 + 7
    for c in reversed(s):
        ndp = [0] * 13
        for rem in range(13):
            candidate = range(10) if c == '?' else [int(c)]
            for digit in candidate:
                nrem = (rem + digit * power) % 13
                ndp[nrem] = (ndp[nrem] + dp[rem]) % mod
        dp = ndp
        power = (power * 10) % 13
    print(dp[5])


if __name__ == '__main__':
    main()

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

using namespace std;
#define N 200010
#define ll long long
#define ld long double

struct line
{
    ll a,b;
};

vector<line>dq;

ld giaoX(line u,line v)
{
    return (ld)(v.b-u.b)/(u.a-v.a);
}

ll vall(line u,ll x)
{
    return u.a*x+u.b;
}

void update(line u)
{
    while(dq.size()>=2&&giaoX(dq[dq.size()-1],u)<=giaoX(dq[dq.size()-2],u))dq.pop_back();
    dq.push_back(u);
}

ll tktp(ll x)
{
    int l=0,r=dq.size()-1;
    while(l<r)
    {
        int mid=(l+r)/2;
        if(vall(dq[mid],x)>vall(dq[mid+1],x))l=mid+1;else r=mid;
    }
    return vall(dq[l],x);
}

ll h[N],dp[N],C;
int n;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cin>>n>>C;
    for(int i=1;i<=n;i++)cin>>h[i];
    dq.push_back({-2*h[1],dp[1]+h[1]*h[1]});
    for(int i=2;i<=n;i++)
    {
        ll u=tktp(h[i]);
        dp[i]=u+h[i]*h[i]+C;
        update({-2*h[i],dp[i]+h[i]*h[i]});
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 10536
#include <stdio.h>

#define H_MAX 1000
#define W_MAX 1000

int main(void){
  int i, j;

  int h, w;
  scanf("%d%d", &h, &w);

  char c;
  int board[H_MAX][W_MAX] = {}, black_num = 0;
  for(i = 0; i < h; i++){
    for(j = 0; j < w; j++){
      scanf(" %c", &c);
      if(c == '.') board[i][j] = -1;
      else black_num++;
    }
  }

  if(black_num == 1){
    int max_h, max_w;
    for(i = 0; i < h; i++){
      for(j = 0; j < w; j++){
        if(board[i][j] == 0){
          if(i > h-i-1) max_h = i;
          else max_h = h-i-1;
          if(j > w-j-1) max_w = j;
          else max_w = w-j-1;
          printf("%d\n", max_h+max_w);
          return 0;
        }
      }
    }
  }

  int cnt = 0, flag;
  while(1){
    flag = 0;
    for(i = 0; i < h; i++){
      for(j = 0; j < w; j++){
        if(board[i][j] == cnt){
          if(i != 0 && board[i-1][j] == -1){
            board[i-1][j] = cnt+1;
            flag = 1;
          }
          if(i != h-1 && board[i+1][j] == -1){
            board[i+1][j] = cnt+1;
            flag = 1;
          }
          if(j != 0 && board[i][j-1] == -1){
            board[i][j-1] = cnt+1;
            flag = 1;
          }
          if(j != w-1 && board[i][j+1] == -1){
            board[i][j+1] = cnt+1;
            flag = 1;
          }
        }
      }
    }
    if(flag == 0) break;
    cnt++;
  }

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

  return 0;
}


Measured memory_bytes: 4096
from math import ceil
N, K, S = map(int,input().split())

fill = 10**9
if S == 10**9: fill-=2
if N == K:
  for i in range(K): print(S,end=" ")
elif S == 1:    
  for i in range(K): print(1,end=" ")
  for i in range(N-K): print(fill,end=" ")  
else:
  for i in range(ceil(K/2)): 
    print(S-1,end=" ")
    print(1,end=" ")
  if K%2 == 0: 
    print(S-1,end=" ")  
    for i in range(N-ceil(K/2)*2-1):
      print(fill,end=" ")
  else:
    for i in range(N-ceil(K/2)*2):
      print(fill,end=" ")

Measured memory_bytes: 48472
import math
from itertools import permutations

n = int(input())

verts = []

for _ in range(n):
	x, y = map(int, input().split())
	verts.append((x, y))

def get_dist(x0, y0, x1, y1):
	return math.sqrt(pow(x1 - x0, 2) + pow(y1 - y0, 2))

avg_dist = 0
den = 0
for permutation in permutations(verts, n):
	dist = 0
	# print(permutation)
	for i in range(1, len(permutation)):
		x1, y1 = permutation[i]
		x0, y0 = permutation[i-1]
		dist += get_dist(x0, y0, x1, y1)
	avg_dist += dist
	den += 1
print('%.10f'%(avg_dist/den))

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

int main(){
	int a, b, ans;
	cin >> a >> b;
	if(a >= 1 && a <= 9 && b >= 1 && b <= 9){
		ans = a*b;
	}else{
		ans = -1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;

/* typedef */
typedef long long ll;

/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;

/* global variables */

/* function */

/* main */
int main(){

    int n; cin >> n;
    // 1 ============================
    int upper = pow(2, n);

    for (int i = 0; i < upper; i++) {
        bitset<18> bs(i);
        printf("%d:", i);
        for (int j = 0; j < n; j++) {
            if ((bs>>j)[0]) printf(" %d", j);
        } 
        printf("\n");
    }
    /*
    // 2 ===========================
    for (int b = 0;b < (1 << n); b++) {
        printf("%d:", b);
        for (int i = 0; i < n;i++)
            if( (b >> i) & 1)
                printf(" %d", i);
    cout<<"\n";
    }
    */

}



Measured memory_bytes: 3336
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 == 0) continue;
        if (i % 5 == 0) continue;
        if (i % 15 == 0) continue;
        ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
import java.util.*;

public class Main{

public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int[] mountains = new int[10];

for(int i=0; i<10; i++){
mountains[i] = sc.nextInt();
}

Arrays.sort(mountains);
System.out.println(mountains[9]);
System.out.println(mountains[8]);
System.out.println(mountains[7]);
}


}

Measured memory_bytes: 26348
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

bool isMM(ll s) { return 1 <= s && s <= 12; }

void solve(long long S) {
  ll first = S / 100;
  ll second = S % 100;

  if (isMM(first) && isMM(second)) {
    print("AMBIGUOUS");
  } else if (isMM(first) && !isMM(second)) {
    print("MMYY");
  } else if (!isMM(first) && isMM(second)) {
    print("YYMM");
  } else {
    print("NA");
  }
}

int main() {
  long long S;
  scanf("%lld", &S);
  solve(S);
  return 0;
}


Measured memory_bytes: 256