akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 2e5+23;

int h[N];

void solve() {
  int n; scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int a; scanf("%d", &a);
    ++h[--a];
  }
  for (int i = 0; i < n; ++i) {
    printf("%d\n", h[i]);
  }
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 4620
lt = int(input())
times = [int(i) for i in input().split(' ')]
ld = int(input())
for drink in range(0, ld):
  i, t = [int(j) for j in input().split(' ')]
  i -= 1
  tmp = times[i]
  times[i] = t
  print(sum(times))
  times[i] = tmp

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
double  p[3005], dp[3005], ans;
ll n;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	for (ll i = 1; i<= n; i++)cin >> p[i];
	dp[0] = 1;
	for (ll i= 1; i <= n; i++){
		for (ll j = i; j >= 0; j--){
			if (j == 0)dp[j] = dp[j]*((double)1-p[i]);
			else dp[j] = dp[j]*((double)1-p[i]) + dp[j-1]*(p[i]);
		}
	}//dp[i] stores the probability of having i heads up till this point
	for (ll i = 0; i <= n; i++){
		ll tails = n-i;
		if (i > tails)ans += dp[i];
	}
	cout << setprecision(20) << ans;
	//~ for (ll i= 0; i <= n; i++)cout << dp[i] << ' ';
	//~ cout << dp[n/2+1];
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ar array
#define db double
#define filename "SUBKGCD"
#define pow pw
const db pi = 3.14159265358979323846;
int pw(int a,int b){
	int ans=1;
	while(b){
	if (b%2) ans*=a;
	a*=a;
	b/=2;
	}
	return(ans);
}
const int mxn=2e5+3,INF=1e18;
int n,q;
struct BST
{
    int mx;
} st[4*mxn];
void upd(int i,int v,int x=1,int l2=0,int r2=n-1)
{
    if (l2==r2)
    {
        st[x].mx=v;
        return;
    }
    int m=(l2+r2)/2;
    if (i<=m) upd(i,v,2*x,l2,m);
    else upd(i,v,2*x+1,m+1,r2);
    st[x].mx=max(st[2*x].mx,st[2*x+1].mx);
}
int que(int l,int r,int x=1,int l2=0,int r2=n-1)
{
    if (r2<l||l2>r) return(-INF);
    if (l<=l2&&r2<=r) return(st[x].mx);
    int m=(l2+r2)/2;
    return(max(que(l,r,2*x,l2,m),que(l,r,2*x+1,m+1,r2)));
}
int que2(int k,int l,int x=1,int l2=0,int r2=n-1)
{
    if (st[x].mx<k) return(n);
    if (r2<l) return(n);
    if (l2==r2) return(l2);
    int m=(l2+r2)/2;
    int res=que2(k,l,2*x,l2,m);
    if (res==n) res=que2(k,l,2*x+1,m+1,r2);
    return(res);
}
signed main()
{
    //freopen(filename".inp","r",stdin);
    //freopen(filename".out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    cin>>n>>q;
    for (int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        upd(i,x);
    }
    while(q--)
    {
        int qu,a,b;
        cin>>qu>>a>>b;
        if (qu==1)
        {
            upd(a-1,b);
        }
        else if (qu==2)
        {
            cout<<que(a-1,b-1)<<"\n";
        }
        else
        {
            cout<<que2(b,a-1)+1<<"\n";
        }
    }
	return 0;
}


Measured memory_bytes: 7764
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main()
{
    int v[1000001], i = 1;
    cin >> v[0];
    set<int> s;
    s.insert(v[0]);
    while(1){
        if(v[i-1] % 2 == 0) v[i] = v[i-1] / 2;
        else v[i] = v[i-1] * 3 + 1;
        if(s.find(v[i]) == s.end()) s.insert(v[i]);
        else break;
        i++;
    }
    cout << i + 1 << endl;
}


Measured memory_bytes: 256
s = int(input())

count = 1

x = [0] * 1000000
x[s] = 1
while True:
    if s % 2 == 0:
        s = s / 2
    else:
        s = 3 * s + 1
    count += 1
    if x[int(s)] == 1:
        print(count)
        break
    else:
        x[int(s)] = 1


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

#ifdef LOCAL
#define DEBUG(...) cerr << #__VA_ARGS__ << ": ", debug(__VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename T, size_t N> ostream& operator << (ostream &os, const array<T, N> &a) {os << "("; for (int i=0; i<(int)N; i++) {if (i) os << ", "; os << a[i];} return os << ")";}
template<typename T> ostream& operator << (ostream &os, const vector<T> &v) {os << "["; for (int i=0; i<(int)v.size(); i++) {if (i) os << ", "; os << v[i];} return os << "]";}
void debug() {cerr << "\n";} template<typename T, typename... Args> void debug(T x, Args... args) {cerr << x << "; "; debug(args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

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

    cout << (a == b && a != c || a == c && a != b || b == c && a != b ? "Yes" : "No") << "\n";

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

const int o = 4280;

int main()
{
    int w;

    while (scanf("%d", &w), w != -1) {
        int ans = 1150;
        w -= 10;

        if (w > 0) {
            int mul = w >= 10 ? 10 : w;

            ans += mul * 125;
            w -= 10;
        }

        if (w > 0) {
            int mul = w >= 10 ? 10 : w;

            ans += mul * 140;
            w -= 10;
        }

        if (w > 0) {
            int mul = w;

            ans += mul * 160;
        }

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

    return 0;
}



Measured memory_bytes: 2572
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
  class Program
  {
    static void Main(string[] args)
    {
      int input = int.Parse(Console.ReadLine());
      double PI = 3.1415926535897931;
      
      double result = (input * 2 * PI);
      
      Console.WriteLine(result);
    }
  }
}

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

using namespace std;

#define TEMP_T template<typename T>
TEMP_T void sort(T& v){ sort(v.begin(), v.end()); }
TEMP_T void revs(T& v){ reverse(v.begin(), v.end()); }
TEMP_T void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end())); }
TEMP_T void show(T& v, char delim=' ', char end='\n'){ for(int i=0; i<v.size()-1; i++) cout << v[i] << delim; cout << v[v.size()-1] << end; }
TEMP_T T    cums(T& v){ T r; r.push_back(v[0]); for(int i=1; i<v.size(); i++) r.push_back(r[i-1] + v[i]); return r; }
TEMP_T void maxe(T& v, T m){ v = max(v, m); }
TEMP_T void mine(T& v, T m){ v = min(v, m); }

static inline int in(){ int x; scanf("%d", &x); return x; }

struct Solver {
  int mini;
  vector<int> vs;
  Solver(vector<int> vs) : vs(vs), mini(INT_MAX) {}
  void solve(int it=0, int a=0, int b=0){
    if (it == vs.size()){
      mine(mini, abs(a - b));
      return;
    }
    solve(it + 1, a + vs[it], b);
    solve(it + 1, a, b + vs[it]);
  }
  int get_min(){ return mini; }
};
int main()
{
  int n;
  while (n = in()){
    vector<int> vs;
    for (int i = 0; i < n; i++){
      vs.push_back(in());
    }
    Solver solver(vs);
    solver.solve();
    printf("%d\n", solver.get_min());
  }

  return 0;
}

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

int main(){
  string s;
  cin >> s;
  if((s[1] == s[2]) && (s[0] == s[1] || s[3] == s[1])){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl; 
  }
}

Measured memory_bytes: 256
package main
 
import(
  "fmt"
	"bufio"
	"os"
	"strings"
	"log"
	"strconv"
)
 
var sc = bufio.NewScanner(os.Stdin)
 
func Rr() []string {
  sc.Scan()
  slice := strings.Split(sc.Text(), " ")
  return slice
}
 
func abc148b(N int, S string,T string){
	for i := 0; i < N; i++{
		fmt.Printf("%c%c",S[i],T[i])
	}
	fmt.Println("")
}
 
func main(){
	N := 0
	S := ""
	T := ""
	fmt.Scan(&N)
	fmt.Scan(&S)
	fmt.Scan(&T)
	abc148b(N,S,T)
}

//入力関係ライブラリ(Atcoder:yamanobori_oldさんのもの)
func make_liner(maxByte int) *bufio.Scanner {
  liner := bufio.NewScanner(os.Stdin)
  liner.Buffer(make([]uint8, 0, 8192), maxByte)
  return liner
}
func word_spliter() *bufio.Scanner {
  words := make_liner(8192) 
  words.Split(bufio.ScanWords)
  return words
}

func eGetLine(r *bufio.Scanner) string {
  if r.Scan() {
    return r.Text()
  }
  err := r.Err()
  if err != nil {
    log.Fatal(err)
  }
  // EOF
  return ""
}

func eGetInt(r *bufio.Scanner) int {
  line := eGetLine(r)
  return eAtoi(line)
}

func eAtoi(s string) int {
  n, err := strconv.Atoi(s)
  if err != nil {
    log.Fatal(err)
  }
  return n
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    if(n == 1 && m == 1) cout << 1 << endl;
    else 
    {
        n -= 2, m -= 2;
        cout << abs(n * m) << endl;
    }
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

long int gcd(long int a,long int b){
  if(b==0)return a;
  return gcd(b,a%b);
}

int main(){
  int n;
  cin >> n;
  vector<long int> v;
  for(int i = 0; i < n; ++i){
    int a;
    cin >> a;
    v.push_back(a);
  }

  vector<long int> r,l;
  r.push_back(v[n-1]);
  l.push_back(v[0]);
  for(int i = 1; i < n;++i){
    r.insert(r.begin(),gcd(r[0],v[n-1-i]));
    l.push_back(gcd(l[l.size() - 1],v[i]));
  }


  long int max = r[1];
  if(max < l[n - 2])
    max = l[n - 2];

  for(int i = 1;i < n - 1;++i){
    if(max < gcd(l[i-1],r[i+1]))
      max = gcd(l[i-1],r[i+1]);
  }

  cout << max  << endl;
}


Measured memory_bytes: 3444
import numpy as np
from collections import deque
from itertools import product

H, W = map(int, input().split())
S = np.full((H, W), 'x', dtype='U1')
for i in range(H):
    S[i] = list(input())

def bfs(x, y):
    dist = np.full((H, W), -1, dtype='i8')
    que = deque()

    dist[x, y] = 0
    que.append((x, y))

    while que:
        h, w = que.popleft()
        d = dist[h, w]
        for dx, dy in ((0, -1), (-1, 0), (1, 0), (0, 1)):
            hh, ww = h + dx, w + dy
            if hh < 0 or H <= hh or ww < 0 or W <= ww or S[hh, ww] == '#' or dist[hh, ww] != -1:
                continue
            dist[hh, ww] = d + 1
            que.append((hh, ww))

    return d

res = 0
for i, k in product(range(H), range(W)):
    if S[i, k] == '#':
        continue
    d = bfs(i, k)
    if d > res:
        res = d
print(res)


Measured memory_bytes: 21232
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static int[] hs;
        static long ans;
        static void Main(string[] args)
        {
            long[] nx = ReadLine().Split(' ').Select(long.Parse).ToArray();
            long n = nx[0];
            long x = nx[1];
            long[] s = ReadLine().Split(' ').Select(long.Parse).ToArray();

            var ls = new List<long>();
            ls.AddRange(s);
            ls.Add(x);
            ls.Sort();
            var SaLs = new List<long>();
            for (int i = 0; i < ls.Count-1; i++)
            {
                SaLs.Add(ls[i + 1] - ls[i]);
            }

            
            if (n > 1)
            {
                long tmp = Gcd(SaLs[0], SaLs[1]);
                for (int i = 2; i < n; i++)
                {
                    tmp = Gcd(tmp, SaLs[i]);
                }
                WriteLine(tmp);
            }
            else WriteLine(Abs(s[0]-x));
        }

        static long Gcd(long a, long b)
        {
            var v = new[] { a, b };
            while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
            return v[0];
        }

    }
}



Measured memory_bytes: 29152
#include <iostream>
#include <vector>
using namespace std;
constexpr int INF = 1e9;

struct Edge {
    int to, cap, rev;
    Edge(int t, int c, int r) : to(t), cap(c), rev(r){}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;



class Flow {
    public:
        Flow(int v){
            mGraph.resize(v);
            mUsed.assign(v,false);
            mVert = v;
        }
        void add_edge(int from, int to, int cap){
            mGraph[from].emplace_back(to,cap,mGraph[to].size()); // directed
            mGraph[to].emplace_back(from,0,mGraph[from].size()-1);
        }
        // ford-fulkerson
        int dfs(int v, int t, int f){
            if(v==t) return f;
            mUsed[v] = true;
            for(auto &e : mGraph[v]){
                if(!mUsed[e.to] && e.cap > 0){
                    int d = dfs(e.to,t,min(f,e.cap));
                    if(d > 0){
                        e.cap -= d;
                        mGraph[e.to][e.rev].cap += d;
                        return d;
                    }
                }
            }
            return 0;
        }

        int max_flow(int s,int t){
            int flow = 0;
            while(true){
                mUsed.assign(mVert,false);
                int f = dfs(s,t,INF);
                if(f==0) break;
                flow += f;
            }
            return flow;
        }


    private:
        Graph mGraph;
        vector<bool> mUsed;
        int mVert;

};

int main(){
    int V,E,u,v,c;
    cin >> V >> E;
    Flow f(V);
    for(int i=0; i < E; ++i){
        cin >> u >> v >> c;
        f.add_edge(u,v,c);
    }
    cout << f.max_flow(0,V-1) << '\n';
    return 0;
}




Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int sum=0,m=0;
	for(int i=0;i<n;i++){
		int z;
		cin>>z;
		sum+=z;
		m=max(m,z);
	}
	cout<<sum-m/2<<endl;
	
	return 0;
}

Measured memory_bytes: 256
from collections import deque
S = deque(input())
Q = int(input())
querry = [list(map(str, input().split())) for i in range(Q)]
reverse = False
for i in range(Q):
    if querry[i][0] == '1':
        reverse = not reverse
    elif querry[i][0] == '2':
        if querry[i][1] == '1':
            if reverse:
                S.append(querry[i][2])
            else:
                S.appendleft(querry[i][2])
        elif querry[i][1] == '2':
            if reverse:
                S.appendleft(querry[i][2])
            else:
                S.append(querry[i][2])

ans=list(S)

if reverse:
    print("".join(reversed(ans)))
else:
    print("".join(ans))


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

typedef long long int ll;
ll powk(ll a, ll n){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}

int main()
{
    ll n;
    cin >> n;
    vector<ll> p(n);
    for(ll i = 0;i < n;i++){
        cin >> p[i];
    }
    ll m = p[0];
    ll ans = 0;
    for(ll i = 0;i < n;i++){
        if(p[i] <= m){
            ans++;
        }
        m = min(m, p[i]);
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 1792
// kartikay26
#include <bits/stdc++.h>
using namespace std;
#define debug(x...) 
#ifdef LOCAL
#include "prettyprint.hpp"
#endif
typedef long long int ll; typedef double db; typedef vector<ll> vi; typedef pair<ll, ll> pii;
#define int ll
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define clr(x) memset(x, 0, sizeof(x))
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
void print(){cout << endl;} void prints(){}
template<typename T> void get(T* x, int n){for (int i = 0; i < n; ++i) { cin >> x[i]; }}
template<typename T> void get(T& x, int n){for (int i = 0; i < n; ++i) { cin >> x[i]; }}
template<typename T, typename... A> void print(T x,A... r){cout << x << " ";print(r...);}
template<typename T, typename... A> void prints(T x,A... r){cout << x << " ";prints(r...);}

const int mod = 1e9+7;
const int N = 1e6+1;

int dp[2001];

int solve(int n){
	if (n < 3) {
		return dp[n] = 0;
	} else {
		int ans = 1;
		for (int i = 3; i <= n-3; ++i) {
			ans += dp[i];
			ans %= mod;
		}
		return dp[n] = ans;
	}
}

int32_t main(){
	fast_io();

	int s;
	cin >> s;
	for (int i = 0; i <= s; ++i) {
		solve(i);
	}
	print(dp[s]);

	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include<iomanip>
using namespace std;

long long A, B, K;

int main() {
    cin >> A >> B >> K;
    if (K > A + B) {
        A = 0;
        B = 0;
    } else if (K > A) {
        B -= K - A;
        A = 0;
    } else {
        A -= K;
    }
    cout << A << ' ' << B << endl;
}


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

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define INF (1 << 29)

static const int MAX = 3000;

using namespace std;

int main(){
	int n; cin >> n; 
	long dp[MAX][MAX];
	vector<pair<int, int> > A;

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

	sort(A.begin(), A.end());
	reverse(A.begin(), A.end());

	long m = 0;	

	for(long i = 0; i <= n; i++)
		for(long j = 0; j <= n; j++)
			dp[i][j] = 0; 

	for(long l = 0; l <= n; l++){
		for(long r = 0; r <= n; r++){
			if(l + r == n){
				m = max(m, dp[l][r]);
				break;
			}

			long act = A[l + r].first, idx = A[l + r].second;

			dp[l + 1][r] = max(dp[l + 1][r], 
					dp[l][r] + act * abs(idx - l));
			dp[l][r + 1] = max(dp[l][r + 1], 
					dp[l][r] + act * abs(idx - (n - 1 - r)));
		}
	}

	/*for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 42948
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
ll mod = 1000000007;
ll INF = 100000000099;

int n;
vector<vector<pair<ll,ll>>> v;
vector<int> g;

void dfs(ll x, ll p){//閉路グラフなら親ノードを持てば無限ループしない
    for(int i=0;i < (ll)v.at(x).size();i++)
    {
        if(v.at(x).at(i).fi==p) continue;

        if(v.at(x).at(i).se%2==0){
            g.at(v.at(x).at(i).fi)=g.at(x);
        }else{
            g.at(v.at(x).at(i).fi) = (1-g.at(x));//こうすれば1→0.0→1にできる
        }
        dfs(v.at(x).at(i).fi,x);
    }
}

signed main(){
    cin>>n;
    g.resize(n,0);
    v.resize(n,vector<pair<ll,ll>>());

    for(int i=0;i < n-1;i++)
    {
        ll u,w,z;
        cin>>u>>w>>z;
        
        v.at(u-1).pb({w-1,z});
        v.at(w-1).pb({u-1,z});
    }

    dfs(0ll,-1ll);
    
    for(int i : g)//範囲for文
    {
        cout << i<< endl;
    }
}

Measured memory_bytes: 10496
N, M, C = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]
A = [0 for _ in range(N)]
ans = 0
for i in range(N):
    A[i] = [int(n) for n in input().split()]
    result = sum([a*b for a, b in zip(A[i], B)]) + C
    if(result > 0):
        ans += 1
print(ans)


Measured memory_bytes: 38512
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<end
 
ll d[510][510];
ll dd[510][510];
ll ddd[510][510];
 
int main(void) {
	clr(d,0);
	clr(dd,0);
	ll n,m,q;
	cin>>n>>m>>q;
	rep(i,0,m){
		ll a,b;
		cin>>a>>b;
		a--;b--;
		d[a][b]++;
	}
	vector<pair<ll,ll> > vp;
	rep(i,0,q){
		ll a,b;
		cin>>a>>b;
		a--;b--;
		vp.pb(mp(a,b));
	}
	rep(i,0,n){
		rep(j,i,n){
			ll c = 0;
			rep(k,i,j+1){
				c += d[i][k];
			}
			dd[i][j] = c;
		}
	}
	rep(i,0,n){
		rep(j,i,n){
			ll c = 0;
			rep(k,i,j+1){
				c += dd[k][j];
			}
			ddd[i][j] = c;
		}
	}
	rep(i,0,vp.sz){
		ll l = vp[i].fi;
		ll r = vp[i].se;
		cout << ddd[l][r] << endl;
	}
	return 0;
}

Measured memory_bytes: 8688
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N, L;
  vector<string> S;
  cin >> N >> L;
  for (int i = 0; i < N; i++) {
    string tmp;
    cin >> tmp;
    S.push_back(tmp);
  }
  sort(S.begin(), S.end());
  string ans = "";
  for (auto s : S) ans += s;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 888
import math

a, b, h, m = list(map(int,input().split()))

h_deg = (60*h + m) * (math.pi*2 / 720)
m_deg = m * (math.pi*2 / 60)

cos = math.cos(abs(h_deg - m_deg))
 
print(math.sqrt((a*a) + (b*b) - (2*a*b*cos)))

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

int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int temp;
		cin>>temp;
		if(temp%2==1)
		{
			cout<<"first"<<endl;
	 		return 0;
	 	}
	 } 
	 cout<<"second"<<endl;
	return 0;
} 

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

using namespace std;

struct Dinic {
    using F = int;
    const F INF = 0x3f3f3f3f; 
    struct Edge {
        int v, bro; F cap;
        Edge() {}
        Edge(int _v, int _bro, F _cap) : v(_v), bro(_bro), cap(_cap) {}
    };
    vector<Edge> e;
    vector<int> pos, cur;
    int n, s, t, m;
    Dinic(int _n, int _s, int _t) : n(_n), s(_s), t(_t), m(0) {
        pos.assign(n, -1);
        cur.resize(n);
        d.resize(n);
        e.reserve(1e5);
    }
    void add(int u, int v, F c) {
        assert(u < n && v < n);
        e.emplace_back(v, pos[u], c); pos[u] = m++;
        e.emplace_back(u, pos[v], 0); pos[v] = m++;
    }
    vector<int> d;
    bool bfs() {
        fill(d.begin(), d.end(), -1);
        d[s] = 0;
        queue<int> q; q.push(s);
        while (!q.empty()) {
            int u = q.front(); q.pop();
            for (int i = cur[u] = pos[u]; i != -1; i = e[i].bro) {
                int v = e[i].v;
                if (d[v] == -1 && e[i].cap != 0) {
                    d[v] = d[u] + 1;
                    q.push(v);
                }
            }
        }
        return d[t] != -1;
    }
    F dfs(int u, F lim) {
        if (u == t) return lim;
        F tot = 0;
        for (int& i = cur[u]; i != -1; i = e[i].bro) {
            int v = e[i].v;
            if (e[i].cap != 0 && d[v] == d[u] + 1) {
                int flow = dfs(v, min(e[i].cap, lim-tot));
                tot += flow;
                e[i].cap -= flow;
                e[i^1].cap += flow;
                if (tot == lim) return lim;
            }
        }
        return tot;
    }
    F flow() {
        F res = 0;
        while (bfs()) {
            res += dfs(s, INF);
        }
        return res;
    }
};

void solve() {
    int n,m;
    cin >> n >> m;
    vector<string> s(n);    
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    pair<int, int> Sp, Tp;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i][j] == 'S') Sp ={i,j};
            if (s[i][j] == 'T') Tp ={i,j};
        }
    }
    if (Sp.first == Tp.first || Sp.second == Tp.second) {
        cout << -1; return;
    }

    int S = 0, T = n+m+1;
    Dinic mc(T+1, S, T);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i][j]=='o') {
                mc.add(i+1, n+j+1, 1);
                mc.add(n+j+1, i+1, 1);
            }
            if (s[i][j]=='S') {
                mc.add(S, i+1, mc.INF);
                mc.add(i+1, S, mc.INF);
                mc.add(S, n+j+1, mc.INF);
                mc.add(n+j+1, S, mc.INF);
            }
            if (s[i][j]=='T') {
                mc.add(T, i+1, mc.INF);
                mc.add(i+1, T, mc.INF);
                mc.add(T, n+j+1, mc.INF);
                mc.add(n+j+1, T, mc.INF);
            }
        }
    }

    int res = mc.flow();
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

template <typename _tp> inline void read(_tp&x) {
	char ch=getchar(),ob=0;x=0;
	while(ch!='-'&&!isdigit(ch))ch=getchar();if(ch=='-')ch=getchar(),ob=1;
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();if(ob)x=-x;
}

const int N = 607, p = 1e9+7;
int f[N][N], g[N][N];
int a[N], b[N], n, ct;

inline void pls(int&x, const int y) {x = x+y < p ? x+y : x+y-p;}

int main() {
	read(n);
	for(int i=1,x,y;i<=n;++i) {
		read(x), read(y);
		if((~x) and (~y)) {b[x] = b[y] = 2; continue;}
		if(~x) {b[x] = 1; continue;}
		if(~y) {b[y] = 1; continue;}
		++ct;
	}
	int nn = 0;
	for(int i=1;i<=n+n;++i)
		if(b[i] != 2)
			a[++nn] = b[i];
	
	swap(n,nn);
	nn = min(n, nn);
	g[0][0] = 1;
	for(int i=n;i;--i) {
		swap(f, g);
		for(int j=0;j<=nn;++j)
		for(int k=0;k<=nn;++k)
			g[j][k] = 0;
		
		if(a[i])
			for(int j=0;j<=nn;++j)
			for(int k=0;k<=nn;++k) {
				pls(g[j][k+1], f[j][k]);
				if(j) pls(g[j-1][k], f[j][k]);
			}
		else
			for(int j=0;j<=nn;++j)
			for(int k=0;k<=nn;++k) {
				pls(g[j+1][k], f[j][k]);
				if(j) pls(g[j-1][k], f[j][k]);
				if(k) pls(g[j][k-1], (ll)f[j][k] * k%p);
			}
	}

	int ans = g[0][0];
	for(int i=1;i<=ct;++i)
		ans = (ll)ans * i%p;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3072
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    if(10%p == 0){
        ll ans = 0;
        rep(r,n){
            if((s[r] - '0') % p == 0){
                ans += r + 1;
            }
        }
        cout << ans << endl;
        return 0;
    }
    vector<int> d(n+1, 0);
    int ten = 1;
    for(int i = n-1; i >= 0; --i){
        int a = (s[i] - '0') * ten % p;
        d[i] = (d[i+1] + a) % p;
        ten *= 10;
        ten %= p;
    }
    vector<int> cnt(p);
    ll ans = 0;
    for(int i = n; i >= 0; --i){
        ans += cnt[d[i]]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1428
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(int n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=n;p++){
		if(prime[p]){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(int p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		ll n;
		cin>>n;
		ll ma=0;
		ll ans=0;
		for(int i=0;i<n;i++){
			ll z;
			cin>>z;
			if(z<ma){
				ans+=(ma-z);
			}
			ma=max(ma,z);
		}
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 3556
#include <cstdio>
#include <vector>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int H, W; char c[1009][1009];
int main() {
	while (scanf("%d%d", &W, &H), W) {
		for (int i = 0; i < H; i++) scanf("%s", &c[i]);
		vector<vector<pair<int, int> > > v(7);
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (c[i][j] == '.') continue;
				if (c[i][j] == 'S') v[0].push_back(make_pair(i, j));
				else if (c[i][j] == 'G') v[6].push_back(make_pair(i, j));
				else v[c[i][j] - 48].push_back(make_pair(i, j));
			}
		}
		int ret = 999999999, p = -1;
		for (int i = 0; i < 5; i++) {
			vector<int> r = { 0 };
			for (int j = 1; j < 5; j++) r.push_back((i + j) % 5 + 1);
			r.push_back(6);
			vector<vector<int> > dp(6); dp[0] = { 0 };
			for (int j = 1; j < 6; j++) {
				dp[j].resize(v[r[j]].size());
				for (int k = 0; k < dp[j].size(); k++) {
					dp[j][k] = 999999999;
					for (int l = 0; l < dp[j - 1].size(); l++) {
						int dist = abs(v[r[j]][k].first - v[r[j - 1]][l].first) + abs(v[r[j]][k].second - v[r[j - 1]][l].second);
						dp[j][k] = min(dp[j][k], dp[j - 1][l] + dist);
					}
				}
			}
			if (ret > dp[5][0]) {
				ret = dp[5][0];
				p = i + 1;
			}
		}
		if (ret == 999999999) puts("NA");
		else printf("%d %d\n", p, ret);
	}
	return 0;
}

Measured memory_bytes: 3564
#include <iostream>
using namespace std;
int main(void)
{
	int n;
	cin >> n;
	
	int b,f,r,v;
	int a[4][3][10] = {};
	int i;
	
	for( i = 0; i < n; i++){
		cin >> b >> f >> r >> v;
		a[b-1][f-1][r-1] += v;
	}
	
	int j,k;
	for( i = 0; i < 4; i++){
		for( j = 0; j < 3; j++){
			for( k = 0; k < 10; k++){
				cout << " " << a[i][j][k];
			}
			cout << endl;
		}
		if(i != 3){
			cout << "####################" << endl;
		}
	}
	return 0;
}

		

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

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

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

  int max = 0;
  for (int i = 0; i < N; i++)
  {
    chmax(max, A[i]);
  }
  int max_cnt = 0;
  for (int i = 0; i < N; i++)
  {
    if (max == A[i])
      max_cnt++;
  }

  if (max_cnt >= 2)
  {
    for (int i = 0; i < N; i++)
    {
      cout << max << endl;
    }
  }
  else
  {
    int second_max = 0;
    for (int i = 0; i < N; i++)
    {
      if (A[i] != max)
        chmax(second_max, A[i]);
    }

    for (int i = 0; i < N; i++)
    {
      if (A[i] == max)
        cout << second_max << endl;
      else
        cout << max << endl;
    }
  }
}

Measured memory_bytes: 2432
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef pair<ll, ll> lpair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (200000 + 2)

void exec(){
  int n;
  ll a[MAX_N], sum = 0, ans = 0;
  cin >> n;

  for (int i = 0; i < n; i++){
    scanf("%lld", &a[i]);
    sum = (sum + a[i]) % MOD;
  }

  for (int i = 0; i < n-1; i++){
    sum -= a[i];
    if (sum < 0) {
      sum += MOD;
    }
    ans = (ans + (a[i] * sum % MOD)) % MOD;
  }

  cout << ans << endl;

}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

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


Measured memory_bytes: 5240
#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 H, W;
    cin >> H >> W;

    ll N = 10;
    vector<vector<ll>> d(N, vector<ll>(N, INF));

    rep (i, N) {
        rep (j, N) {
            ll c;
            cin >> c;
            d[i][j] = c;
        }
    }

    vector<vector<ll>> A(H, vector<ll>(W, 0));
    rep (i, H) {
        rep (j, W) {
            ll a;
            cin >> a;
            A[i][j] = a;
        }
    }

    rep (k, N) {
        rep (i, N) {
            rep (j, N) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    ll ans = 0;
    rep (i, H) {
        rep (j, W) {
            if (A[i][j] == -1 || A[i][j] == 1) {
                continue;
            } else {
                ans += d[A[i][j]][1];
            }
        }
    }

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

Measured memory_bytes: 640
using namespace std;

#include<bits/stdc++.h>

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

#define getBit(x,i) (x&(1<<i))
#define setBit(x,i) (x|(1<<i))
#define mem(A,N) memset(A,N,sizeof(A))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define rep(i, x, y)  for(int i = x; i < y; ++i)
#define Rep(i, x, y)  for(int i = x; i <= y; ++i)
#define srep(i, x, y) for(int i = x; i > y; --i)
#define sRep(i, x, y) for(int i = x; i >= y; --i)
#define All(v) v.begin(),v.end()
#define sortA(a) sort(a, a+n)
#define sortArr(a, i, n) sort(a+i, a+n)
#define SortArr(a, i, n) sort(a+i, a+n+1)
#define Sort(x) sort(x.begin(), x.end())
#define f1(i,n) for (int i=1; i<=n; i++)
#define f0(i,n) for (int i=0; i<n; i++)
#define sz(x) ((int)(x).size())
#define len(x) ((int)(x).length())
#define fi first
#define se second
#define concatenate(a, b) std::copy(b.begin(), b.end(), std::back_inserter(a));
// #define concatenate(a, b) a.insert(b.end(), b.begin(), b.end());
// std::move(b.begin(), b.end(), std::back_inserter(a)); "Undefined behaviour if a actually is b (which is OK if you know that can never happen - but worth being aware of in general purpose code)"
#define makeUnique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define inRange(x, a, b) (a <= x && x < b)

#define linf 0x7FFFFFFFFFFFFFFF
#define inf 0x7FFFFFFF
#define mod 1000000007
#define eps 1e-9
#define Pi 3.14159265358979323846

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define write(x) cerr << #x << " = " << (x) << ", ";
#define writeI0 cerr << "i = " << 0 << ", ";
#define dumpI0 cerr << "i = " << 0 << endl;
#define printSet(s) for(auto it = s.begin(); it!=s.end(); it++) (it==s.begin())? cout << *it : cout << ' ' << *it; cout << endl;
#define printMap(m) for(auto it = m.begin(); it!=m.end(); it++) (it==m.begin())? cout << '(' << it->first << ", " << it->second << ')' : cout << " (" << it->first << ", " << it->second << ')'; cout << endl;
#define printPairSet(s) for(auto it = s.begin(); it!=s.end(); it++) (it==s.begin())? cout << '(' << it->first << ", " << it->second << ')' : cout << " (" << it->first << ", " << it->second << ')'; cout << endl;
#define printVector(x) for(auto it = x.begin(); it!=x.end(); it++) (it==x.begin())? cout << *it : cout << ' ' << *it; cout << endl;
#define printArray(a,x,y) for(auto it = a+x; it != a+y; it++) (it==a+x)? cout << *it : cout << ' ' << *it; cout << endl;
#define PrintArray(a,x,y) for(auto it = a+x; it != a+y+1; it++) (it==a+x)? cout << *it : cout << ' ' << *it; cout << endl;

// ***************** End Of Template ********************



int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	char c;
	cin >> c;
	cout << (char)(c+1) << '\n';
	return 0;
}

Measured memory_bytes: 256
s = input()
should_continue = True

while should_continue:
    should_continue = False
    if len(s) >= 6:
        s6 = s[0:6]
        if s6 == "dreamd" or s6 == "erased" or s6 == "erasee":
            s = s[5:]
            should_continue = True
    if len(s) >= 7:
        if s6 == "eraser":
            s = s[6:]
            should_continue = True
    if len(s) >= 8:
        s8 = s[:8]
        if s8 == "dreamerd" or s8 == "dreamere":
            s = s[7:]
            should_continue = True
        elif s8 == "dreamera":
            s = s[5:]
            should_continue = True

if s == "dream" or s == "dreamer" or s == "erase" or s == "eraser":
    print("YES")
else:
    print("NO")
    

Measured memory_bytes: 9140
#include<bits/stdc++.h>
using namespace std;
 
int main(){
   int a,b;
   cin >> a >>  b;

    int  num = a + b;
    if(num % 2 == 0){
        cout << num / 2; 
    }else{
        cout << num / 2 + 1;
    }

 return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <unordered_set>
using namespace std;
inline long  toInt(string s) {long  v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define long long long
long  pw(long  x, long  y){long  ans = 1;for(long  i = 0; i < y; i++){ans = ans * x;}return ans;}
long  factorial(long  x){long  ans = 1; for(int i = 1 ;i < x+1; i++){ans = ans *i;}return ans;}
long  combination(long  x,long  y){return factorial(x)/factorial(y)/factorial(x-y);}
long  permutation(long  x, long  y){return factorial(x)/factorial(x-y);}
#define TimeCount1    auto chrono_start = std::chrono::system_clock::now();
#define TimeCount2   auto chrono_end = std::chrono::system_clock::now();std::cout << "Elapsed time(C++):" << std::chrono::duration_cast<std::chrono::milliseconds>(chrono_end - chrono_start).count() << "[ms]" << std::endl;

#define MOD 1000000007


int main(){
	vector<int> v(27,0);
	string s;
	cin >> s;
	for(int i = 0; i < s.length(); i++){
		v[s[i] - 'a']++;
	}
	for(int i = 0; i < 27; i++){
		if(v[i] % 2 == 1){
			cout << "No" <<endl;
			return 0;
		}
	}
	cout << "Yes" <<endl;
	return 0;
}



Measured memory_bytes: 256
n = int(input())
res = 0
for i in range(2, int(n**0.5)+1):
    if n%i == 0:
        e = 0
        while n%i == 0:
            n //= i
            e += 1
        tmp = 0
        for i in range(1, e+1):
            if e >= i:
                e -= i
                tmp += 1
        res += tmp
if n > 1: res += 1
print(res)

Measured memory_bytes: 63508
#include <bits/stdc++.h>
#include <stdlib.h>
#include <time.h> 
 
using namespace std;
long long mod = 1e9 + 7;
long long INF = 1e7;
double EPS = 1e-12;
typedef long long int lld;
long double tick(){static clock_t oldt; clock_t newt=clock();
    long double diff=1.0L*(newt-oldt)/CLOCKS_PER_SEC; oldt = newt; return diff; }
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)
inline lld sc() { lld a; scanf("%lld", &a); return a; }
inline int scd() { int a; scanf("%d", &a); return a; }
inline double scf() { double a; scanf("%lf",&a); return a; }
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define all(c) (c).begin(), (c).end()
#define sz(a) ((int)a.size())
#define Error(x...) { cout << "(" << #x << ")" << " = ( "; printIt(x); }
template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); }
#define errorpair(a) cout<<#a<<" = ( "<<((a).first)<<" , "<<((a).second)<<" )\n";
#define mset(a, v) memset(a, v, sizeof(a))
#define popcount __builtin_popcountll

typedef pair<lld,lld> PA;

lld powP(lld x, lld y, lld mod) {
    lld ans = 1, po = x % mod;
    while(y > 0) {
        if(y & 1) ans = ans * po % mod;
        y >>= 1; po = po * po % mod;
    }
    return ans;
}
 
bool bitSet(lld n, lld bit){
    if((n & (1LL << bit)) != 0) return true;
    else return false;
}
 
lld findGcd(lld a, lld b){
    while(a != 0) { lld temp = b % a; b = a; a = temp; }
    return b;
}

#define lim 1000010
#define lim2 200010
#define qqqqqq 210
// Ab :)
// inline lld sqr(lld x) { return x * x; }
// unordered_map<lld,lld>::iterator it;
// std::ios::sync_with_stdio(false);
// priority_queue<PA> Q;
// lld dp[1<<18];

// vector<lld> G[lim];
// string S[lim];
lld A[lim];

int main(){
    A[0] = 0;
    rep(i,1,3e5) {
        lld p = i % popcount(i);
        A[i] = A[p] + 1;
        // Error(i, popcount(i), A[i]);
    }
    lld n = sc();
    string S;
    cin >> S;
    lld numBits = 0;
    for(auto c : S) numBits += (c == '1');
    auto findMod = [](string &S, lld mod){
        if(mod == 0) return 0LL;
        lld ret = 0;
        for(auto c : S) {
            ret = ret * 2;
            if(c == '1') ret++;
            ret %= mod;
        }
        return ret;
    };
    lld less = findMod(S, numBits - 1);
    lld more = findMod(S, numBits + 1);
    rep(i,0,n-1) {
        if(S[i] == '1') {
            if(numBits == 1) printf("0\n");
            else {
                mod = numBits - 1;
                lld rem = (less - powP(2, n - (i + 1), mod) + mod) % mod;
                prL(A[rem] + 1);
            }
        }
        else {
            mod = numBits + 1;
            lld rem = (more + powP(2, n - (i + 1), mod) + mod) % mod;
            prL(A[rem] + 1);
        }
    }
    return 0;
}


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

long long gcd(long long a,long long b){
	if (b == 0) 
        return a; 
    return gcd(b, a % b);  
}

int main() {
	long long n,a=0,b,s=0,max=0;
	cin>>n;
	vector<pair<long long,long long>> v;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		v.push_back(make_pair(b,a));
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++){
		a=v[i].second;
		b=v[i].first;
		if(a>b){
			cout<<"No";
			return 0;
		}
		s+=a;
		if(max<b)
		max=b;
		if(s>max){
			cout<<"No";
			return 0;
		}
	}
//	cout<<max;
	if(s<=max)
	cout<<"Yes";
	else
	cout<<"No";
	
	
	return 0;
}

Measured memory_bytes: 6256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ld PI = 3.1415926535;

int main(){
  int N;cin >> N;
  for(int i=0;i<N;i++){
    int A;cin >> A;
    if(A%2==0){
      if(A%3!=0&&A%5!=0){
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
#!/bin/env ruby

s = STDIN.readlines
n = s[0]
a = s[1].split(" ").map(&:to_i)
b = s[2].split(" ").map(&:to_i)

c = 0

b.each_index do |i|
  if b[i] <= a[i]
    c = c + b[i]
  elsif b[i] > a[i]
    if b[i] < a[i] + a[i+1]
      c = c + b[i]
      a[i+1] = a[i] + a[i+1] - b[i]
    elsif b[i] >= a[i] + a[i+1]
      c = c + a[i] + a[i+1]
      a[i+1] = 0
    end
  end
end

puts c


Measured memory_bytes: 15492
#include <iostream>
#include <string>
using namespace std;
 
string s;
int n, g, p, ans;
 
int main() {
  cin >> s;
  n = s.size();
 
  for (int i = 0; i < n; ++i) {
    if (g == p) {
      if (s[i] == 'g') {
      }
      else ans--;
      g++;
    }
    else {
      if (s[i] == 'g') {
	ans++;
      }
      else {
      }
      p++;
    }
  }
 
  cout << ans << endl;
 
  return 0;
}

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

int main(){
  int n;
  string s;
  cin>>n>>s;
  int ans = 0;
  
  rep(i,1000){
    string p = to_string(i);
    while(p.size()<3) p = '0' + p;
    int j = 0;
    rep(i,s.size()){
      if(s[i] == p[j]) j++;
    }
    if(j == 3) ans++;   
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9+7;
const int INF = 0x3f3f3f3f;
ll max(ll a, ll b){return a > b ? a : b;}
ll min(ll a, ll b){return a < b ? a : b;}

int a[101];


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    if(k==1)
    {
        cout << 0;
        return 0;
    }
    else cout << n-k;
}

//TODO: 56
//come back to 50D, 55D, DP-J


Measured memory_bytes: 256
#include <stdio.h>
#define N 100005
#define NIL -1
 
struct Node{
  int p, left, right;
};
struct Node T[N];
int n;
 
void inorder(int p){
  if(p != NIL) {
    inorder(T[p].left);
    printf(" %d", p);
    inorder(T[p].right);
  }
}
 
void postorder(int p){
if(p != NIL) {
    postorder(T[p].left);
    postorder(T[p].right);
    printf(" %d", p);
  }
}
 
void preorder(int p){
if(p != NIL) {
  printf(" %d", p);
  preorder(T[p].left);
  preorder(T[p].right);
  }
}
 
 
 
main(){
  int i, id;
 
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    T[i].left = T[i].p = T[i].right = NIL;
  }
  for(i = 0; i < n; i++){
    scanf("%d", &id);
    scanf("%d %d", &T[id].left, &T[id].right);
      T[T[id].left].p = id;
      T[T[id].right].p = id;
    }    
 
  printf("Preorder\n");
  for(i = 0; i < n; i++){
    if(T[i].p == NIL){
      preorder(i);
    }
  }
  printf("\nInorder\n");
  for(i = 0; i < n; i++){
    if(T[i].p == NIL){
      inorder(i);
    }
  }
  printf("\nPostorder\n");
  for(i = 0; i < n; i++){
    if(T[i].p == NIL){
      postorder(i);
    }
  }
  printf("\n");
  return 0;
}

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

int main()
{
    int i,j;
    int z,x,c,v;
    scanf("%d %d %d %d",&z,&x,&c,&v);
    if((z-1)/v+1 >= (c-1)/x+1)printf("Yes");
    else printf("No");
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

struct UF
{
	vector<int> par; // 親のインデックスを記憶する配列
	vector<int> sz; // サイズを記憶する。
	vector<int> rank;
	// 初期化
	UF(int n):par(n),sz(n),rank(n){
		for(int i = 0; i < n; i++){
			par[i] = i;sz[i] = 1;rank[i] = 0;
		}
	}
	// 親を求める
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if(rank[x] < rank[y]){
			par[x] = y;
			sz[y] += sz[x];
		}
		else{
			par[y] = x;
			sz[x] += sz[y];
			if(rank[x] == rank[y])rank[x]++;
		}
	}
	// xとyが同じ集合ならtrue
	bool same(int x, int y) { return find(x) == find(y); }
	// 素の集合のサイズを求める
	int size(int n){return sz[find(n)];}
};

vector<pair<int,int>> x;
vector<pair<int,int>> y;
vector<pair<int,pair<int,int>>> seica;

int main(){

	int n;cin >> n;
	REP(i,n){
		int a,b;cin >> a >> b;
		x.PB(MP(a,i));
		y.PB(MP(b,i));
	}

	sort(ALL(x));
	sort(ALL(y));

	REP(i,n-1){
		seica.PB(MP(abs(x[i].FI-x[i+1].FI),MP(x[i].SE,x[i+1].SE)));
		seica.PB(MP(abs(y[i].FI-y[i+1].FI),MP(y[i].SE,y[i+1].SE)));
	}

	sort(ALL(seica));

	UF uf(n);
	ll ans = 0;
	REP(i,seica.size()){
		int a = seica[i].SE.FI;
		int b = seica[i].SE.SE;
		int c = seica[i].FI;
		if(!uf.same(a,b)){
			uf.unite(a,b);
			ans += c;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 7144