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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

const ll mod = 1000000007;

template<typename T>
static inline void chmin(T & ref, const T  value) {
	if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
	if (ref < value) ref = value;
}


vector<ll> pow3() {
	vector<ll> ans;
	ll b = 1;
	for (int i = 0; i <= 15; i++) {
		ans.push_back(b);
		b *= 3;
	}
	return ans;
}

inline int pop3(ll j) {
	int a = 0;
	while (j) {
		if (j % 3) a++;
		j /= 3;
	}
	return a;
}

ll n, m;
//dp...各ノードが黒の場合の組み合わせ数
vector<ll> dp;
vector<vector<int>> graph;

ll dfs(int c, int p) {
	ll s = 1;
	for (auto e : graph[c]) {
		if (e == p) continue;
		ll v = dfs(e, c) + 1;
		s *= v;
		s %= m;
	}
	dp[c] = s;
	return dp[c];
}

void dfs2(int c, int p, ll r) {

	//親の組み合わせ分だけかける
	dp[c] *= r + 1;
	dp[c] %= m;

	//dpには親以外の全組み合わせの積が入っている
	//親のdp[p]=r
	//foreach 子の dpを取得
	int edges = graph[c].size();
	vector<ll> pos(edges, 0);
	vector<ll> neg(edges, 0);
	//全ノードの現在の組み合わせ数を取得
	for (int i = 0; i < edges; i++) {
		if (graph[c][i] == p) {
			pos[i] = neg[i] = (r + 1) % m;
		}
		else {
			pos[i] = neg[i] = dp[graph[c][i]] + 1;
		}
	}
	//累積積を計算
	for (int i = 0; i < edges-1; i++) {
		(pos[i + 1] *= pos[i]) %= m;
		(neg[edges - i - 2] *= neg[edges - i - 1]) %= m;
	}

	for (int i = 0; i < edges; i++) {
		if (graph[c][i] == p) continue;
		ll cr = 1;
		if (i > 0) cr *= pos[i - 1];
		if (i < edges - 1) cr *= neg[i + 1];
		cr %= m;
		dfs2(graph[c][i], c, cr);
	}
}

int main() {
	cin >> n >> m;
	graph.resize(n);
	rep(i, n - 1) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		graph[x].push_back(y);
		graph[y].push_back(x);
	}
	dp.resize(n, 0);
	dfs(0, -1);
	dfs2(0, -1, 0);
	rep(i, n) {
		cout << dp[i] << endl;
	}
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 21;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 59;

ll n,q,a,b;
ll x[e5];
ll dp[e3][e3];
ll ans = INF;
ll c;

template<class T>
class segment_tree {
private:
  ll n;
  T d;
  vector<T>* v;
  T _query(ll a,ll b,ll k,ll l,ll r){
    if(r <= a || b <= l) return d;
    if(a <= l && r <= b) return this->v->at(k);
    else {
      T vl = _query(a,b,k*2+1,l,(l+r)/2);
      T vr = _query(a,b,k*2+2,(l+r)/2,r);
      return func(vl,vr);
    }
  }
public:
  segment_tree (){}
  segment_tree(ll n,T d = INT_MAX){
    this->n = 1;
    while(n > this->n) this->n <<= 1;
    v = new vector<T>(this->n*2,d);
    this->d = d;
  }
  void update(ll i,T x){
    i += n-1;
    this->v->at(i) = x;
    while(i > 0){
      i = (i-1)/2;
      this->v->at(i) = func(this->v->at(i*2+1),this->v->at(i*2+2));
    }
  }
  T query(ll a,ll b){
    return _query(a,b,0,0,n);
  }
  T func(T a,T b){
    return min(a,b);
  }
};

segment_tree<ll> seg(e5);
segment_tree<ll> ges(e5);

int main(){
  cin >> n >> q >> a >> b;
  for(ll i = 1;i <= q;i++) cin >> x[i];
  x[0] = b;
  for(ll i = 1;i <= n;i++){
    seg.update(i,INF);
    ges.update(i,INF);
  }
  seg.update(a,0+a);
  ges.update(a,0-a);
  for(ll i = 1;i <= q;i++){
    ll mem = seg.query(x[i],n+1)-x[i];
    mem = min(mem,ges.query(1,x[i])+x[i]);
    ll j = x[i-1];
    ll hoge = seg.query(j,j+1)-j;
    ll egoh = ges.query(j,j+1)+j;
    seg.update(j,min(hoge,mem-abs(x[i]-x[i-1]))+j);
    ges.update(j,min(egoh,mem-abs(x[i]-x[i-1]))-j);
    c += abs(x[i]-x[i-1]);


    // cerr << mem << endl;
    // c += abs(x[i]-x[i-1]);
    // mem -= abs(x[i]-x[i-1]);
    // ll d = seg.query(x[i-1],x[i-1]+1)-x[i-1];
    // d = min(d,mem);
    // cerr <<c << " "<< d << endl;
    // seg.update(x[i-1],d+x[i-1]);
    // ges.update(x[i-1],d-x[i-1]);
  }
  for(ll i = 1;i <= n;i++){
    // cerr << seg.query(i,i+1)<< " " << ges.query(i,i+1) << endl;
    ans = min(ans,seg.query(i,i+1)-i+c);
  }
  cout << ans << endl;
}


Measured memory_bytes: 68352
import math
n,m=map(int,input().split())
if abs(n-m)>1:
    print(0)
else:
    if m==n:
        print((2*((math.factorial(max(m,n))%(10**9+7))**2))%(10**9+7))
    else:
        print(((math.factorial(max(m,n))%(10**9+7))*(math.factorial(min(m,n))%(10**9+7)))%(10**9+7))

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

int main() {
  int N , x;
  cin >> N;
  x = 1;
  
  for (int i= 0; i < N; i++) {
    string S ,Four , Three , Y;
    cin >> S;
    
    if (S == "Y") {
      x *=2;
    }
    
    else {
      x *=1;
    }
   
  }
  
  if (x <= 1) {
    cout << "Three" << endl;
  }
  
  else {
    cout << "Four" << endl; 
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;

#ifdef DEBUG
     #define debug(args...)            {dbg,args; cerr<<endl;}
#else
    #define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;
ld p[2][6];
ld go(ld d0) {
	ld d1=1-d0;
	ld ans=0;
	for (ll i=0;i<6;i++) {
		ld f0=d0*p[0][i];
		ld f1=d1*p[1][i];
		ld adder=max(f0,f1);
		ans+=adder;
	}
	return ans;
}
int main() 
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	cout<<fixed<<setprecision(10);
	for (ll k=0;k<2;k++) for (ll i=0;i<6;i++) {
		ll x; scanf("%lld",&x);
		p[k][i]=(ld)x/(ld)100.0;
	}
	//cout<<go(0.5)<<endl;
	//return 0;
	ld imin=0,imax=1;
	for (ll k=0;k<300;k++) {
		ld imid=(imin+imax)/2;
		if (go(imid)>go(imid+1e-9)) {
			imin=imid;
		}
		else imax=imid;
	}
	//cout<<"imin"<<imin<<endl;
	cout<<go(imin)<<endl;
}



Measured memory_bytes: 256
// Problem : D - Knapsack 1
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define MX 100005
#define N 102

//Solution

int n,W;
int w[N],v[N];
int dp[N][MX];

void solve(){
    cin>>n>>W;
    for(int i=1;i<=n;i++) cin>>w[i]>>v[i];
    for(int i=1;i<=n;i++){
        for(int j=0;j<=W;j++){
            dp[i][j] = dp[i-1][j];
            if(j >= w[i]) dp[i][j] = max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
        }
    }
    int ans = 0;
    for(int i=0;i<=W;i++) ans = max(ans,dp[n][i]);
    cout<<ans;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 81664
#include <cstdio>
#include <iostream>
#include <vector>
#include <cassert>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <cstdlib>
#include <string>
#include <unordered_map>
#include <map>
#include <sstream>
#include <bitset>
#include <random>
#include <tuple>
#include <array>
#include <tgmath.h>
#include <functional>
#include <climits>
#include <complex>
#include <unistd.h>
using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;
typedef pair<lli, lli> plli;
typedef unsigned char byte;
typedef unsigned int uint;
typedef unsigned long long int ulli;

int arr[100100];

int main() {
    int s = 0, n, t, c = 0;
    scanf("%d", &n);
    int i;
    for (i=1; i<=n; ++i) {
        scanf("%d", &t);
        if (t == i) ++c;
        else {
            s += -~c/2;
            c = 0;
        }
    }
    printf("%d\n", s + -~c/2);
    return 0;
}


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

using namespace std;

int main()
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a > b && a > c)
  printf("%d\n", b + c);
else if (b > a && b > c)
  printf("%d\n", a + c);
else
  printf("%d\n", a + b);
return 0;
}

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

using namespace std;

#define MOD 1000000007

const int INF = 1e9;

typedef long long ll;
typedef pair<int, int> pii;
int n,h;
ll dp[(ll)2e4+1];


int main() {
    // oh hi mark
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // memset(dp, -1, sizeof dp);

    cin >> h >> n;
    int a[n];
    int b[n];
    for(int i = 0; i <= (int)2e4; i++) dp[i] = 1LL<<30;
    dp[0] = 0;
    for(int i = 0;i < n; i++) {
        cin >> a[i] >> b[i];
        for(int j = 0; j < h; j++) dp[j + a[i]] = min(dp[j + a[i]], dp[j] + b[i]);
    }

    ll mi = 1LL<<30;
    for(int i = h; i <= (int)2e4; i++) mi = min(mi, dp[i]);

    cout << mi << endl;
   // cout << f(0, h);
    
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleAppTest
{
    class DivGame
    {
        static void Main(string[] args)
        {
            ulong num = ulong.Parse(Console.ReadLine());
            ulong checkNum = (ulong)Math.Sqrt(num);
            int methodNum = 0;

            if (num < 2)
            {
                Console.WriteLine(methodNum);
            }
            else
            {
                for (ulong i = 2; i <= checkNum; i += (1 + i % 2))
                {
                    int powCnt = 0;
                    int popCnt = 1;

                    while (num % i == 0)
                    {
                        powCnt++;
                        num /= i;

                        if (powCnt == popCnt)
                        {
                            methodNum++;
                            popCnt++;
                            powCnt = 0;
                        }
                    }
                }

                if(num > checkNum)
                {
                    methodNum++;
                }
                Console.WriteLine(methodNum);
            }
        }
    }
}

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

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

    vector<long long> A(N);
    set<long long> s;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        s.insert(A[i]);
    }
    map<long long, int> m;
    int idx = 0;
    for (auto x : s)
    {
        m[x] = idx;
        idx++;
    }

    for (int i = 0; i < N; i++)
    {
        A[i] = m[A[i]];
    }
    // for (long long a : A)
    // {
    //     cout << a << " ";
    // }
    // cout << endl;

    vector<int> q(1, 1000000);
    for (int i = 0; i < N; i++)
    {
        if (A[i] <= q.back())
        {
            q.push_back(A[i]);
            continue;
        }
        int l = 0;
        int r = q.size() - 1;
        while (r - l > 1)
        {
            int c = (l + r) / 2;
            if (A[i] > q[c])
            {
                r = c;
            }
            else
            {
                l = c;
            }
        }
        q[r] = A[i];
    }
    cout << q.size() - 1 << endl;
    // for (int x : q)
    // {
    //     cout << x << " ";
    // }
    // cout << endl;
}


Measured memory_bytes: 12416
#include<stdio.h>
#define M 1000000000
int r,h[600]={-M};
int main(){
  int ta[25]={0};
  int to[500],ne[500],co[500];
  int a,b,c,d,e,i,j,k,l,n,m,mi;
  scanf("%d %d",&n,&m);
  n++;
  for(i=1;i<=m*2;i++){
    scanf("%d,%d,%d,%d",&a,&b,&c,&d);
    ne[i]=ta[a];
    to[i]=b;
    co[i]=c;
    ta[a]=i++;
    ne[i]=ta[b];
    to[i]=a;
    co[i]=d;
    ta[b]=i;
  }
  scanf("%d,%d,%d,%d",&e,&b,&c,&d);
  c-=d;
  a=e;
  for(l=0;l<2;l++){
    int u[30];
    for(i=r=1;i<600;i++)h[i]=M;
    for(i=0;i<n;i++)u[i]=M;
    h[u[a]=0]=-M;
    while(1){
      for(j=ta[a];j;j=ne[j]){
	if(u[to[j]]>u[a]+co[j]){
	  u[to[j]]=u[a]+co[j];
	  for(k=r++;h[k/2]>u[to[j]]*30+to[j];k/=2)h[k]=h[k/2];
	  h[k]=u[to[j]]*30+to[j];
	}
      }
      a=h[j=1]%30;
      d=h[--r];
      for(h[r]=M;d>h[j];j=mi){
	h[j]=h[mi=j*2];
	if(h[j]>h[j*2+1])h[j]=h[mi=j*2+1];
      }
      if(r==1)break;
      h[j/2]=d;
    }
    c-=u[b];
    a=b;
    b=e;
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 604
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

bool f(int i, vector<int>& v) {
    return true;
}

int main() {
    string s, t; cin >> s >> t;
    map<char, vector<int> > mp;
    rep(i,(int)s.size()) {
        mp[s[i]].push_back(i);
    }

    ll cnt = 0;
    int last = -1;
    rep(i,(int)t.size()) {
        if (mp[t[i]].empty()) {
            cout << "-1" << endl;
            return 0;
        }
        
        if (last >= mp[t[i]].back()) {
            ++cnt;
            last = mp[t[i]][0];
        }
        else {
            int lb = -1;
            int ub = (int)mp[t[i]].size()-1;
            while (ub-lb>1) {
                int mid = (lb+ub)/2;
                if (last >= mp[t[i]][mid]) lb = mid;
                else ub = mid;
            }     
            last = mp[t[i]][ub];
        }
        //cout << "ti: " << t[i] << " last: " << last << endl;
    }
    ll ans = cnt * (ll)s.size() + last + 1;
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 1216
import bisect


def main():
    N, M, K = list(map(int, input().split(' ')))
    A = list(map(int, input().split(' ')))
    B = list(map(int, input().split(' ')))
    cumsum_A = [0] * (N + 1)
    for i, a in enumerate(A):
        cumsum_A[i + 1] = a + cumsum_A[i]
    cumsum_B = [0] * (M + 1)
    for i, b in enumerate(B):
        cumsum_B[i + 1] = b + cumsum_B[i]
    # Aの本をn冊読むとする
    ans = 0
    for n in range(N + 1):
        if cumsum_A[n] > K:
            break
        m = bisect.bisect_right(cumsum_B, K - cumsum_A[n])
        m -= 1
        if m < 0:
            continue
        ans = max(ans, m + n)
    print(ans)


if __name__ == '__main__':
    main()

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

int main(){

    int n;
    cin >> n;
    long long a[300010];
    for(int i = 0 ; i < n * 3; ++ i) cin >> a[i];
    sort(a, a+n*3);
    long long ans = 0;
    for(int i = 0; i < n * 2; ++ i){
        if(i % 2 == 0)
            ans += a[n + i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>

using namespace std;


int main(int argc, const char * argv[]) {

    int s, w;
    
    cin >>s >> w;
    
    if(s<=w) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    
    
    return 0;
    
}


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

int main(){
  int n,m;
  cin>>n>>m;
  int low=-100010,high=100010;
  rep(i,m){
    int L,R;
    cin>>L>>R;
    low = max(low,L);
    high = min(high,R);
  }
  if(high-low+1>=0){
  cout<<high-low+1<<endl;}
  else cout << 0<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
  
using namespace std;
  
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
  
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())
 
typedef unsigned long long ull;
const int INF = (int)1e8;
 
int main(){
    int n;
    while(cin>>n,n){
        int a=0,b=0;
        FOR(i,n){
            int x,y; cin>>x>>y;
            if(x>y) a+=x+y;
            else if(x<y) b+=x+y;
            else a+=x,b+=y;
        }
        printf("%d %d\n",a,b);
    }
    return 0;
}

Measured memory_bytes: 1136
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<ctime>
#include<vector>
#include<stack>
#include<map>
using namespace std;

int num[100005], red[100005];

int main(){
  int n, m; cin >> n >> m;
  for(int i = 1 ; i <= n ; i++){
    num[i] = 1;
  }
  red[1] = 1;
  for(int i =  1 ; i <= m ; i++){
    int x, y; cin >> x >> y;
    if(red[x]) red[y] = 1;
    num[x]--;
    num[y]++;
    if(num[x]==0){
      red[x] = 0;
    }
  }
  int cnt = 0;
  for(int i = 1 ; i <= n ; i++){
    cnt += red[i];
  }
  cout << cnt;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
using namespace std;

#define loop(i,first,end) for(int i=(first);i<(end);i++)
#define uint unsigned int
#define ull unsigned long long
#define ll long long
#define vint vector<int>
#define vuint vector<unsigned int>
#define vull vector<ULL>
#define vll vector<LL>
#define mod 1000000007

int main(void){
	int n;
	cin >> n;
	vint a(n);
	loop(i, 0, n)cin >> a[i];

	vint b(n, 0);
	int count = 0;
	for (int i = n; i > 0; i--){
		for (int j = 2 * i; j <= n; j += i)if (b[j - 1] == 1)b[i - 1] = !b[i - 1];
		if (b[i - 1] == a[i - 1])b[i - 1] = 0;
		else b[i - 1] = 1;
		if (b[i - 1])count++;
	}
	cout << count << endl;
	loop(i, 0, n)if (b[i])cout << i + 1 << ' ';
	cout << endl;

	return 0;
}

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

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

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

using ull = unsigned long long;

#define MAX_N 100000

int N;
vector<int> graph[MAX_N];

ull base = 100000007; //base for rolling hash
map<ull, int> mp;

ull dfs(int v, int p) {
  ull res = 1;
  for(int u : graph[v]) {
    if(u == p) continue;
    res += dfs(u, v)*base;
  }
  mp[res]++;
  return res;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N;
  rep(i, N-1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  dfs(0, -1);
  int ans = 0;
  for(auto p : mp) {
    ans += p.second*(p.second-1) / 2;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 21176
h,w = (int(i) for i in input().split())
ans = 99999999999999999
for i in range(0,h):
  sa = i*w
  #上下分断
  h2 = (h-i)//2
  sb = h2*w
  sc = (h-i-h2)*w
  judgema = max([sa,sb,sc])
  judgemi = min([sa,sb,sc])
  ans = min(ans,(judgema-judgemi))
  #左右分断
  w2 = (w//2)
  sb = (h-i)*w2
  sc = (h-i)*(w-w2)
  judgema = max([sa,sb,sc])
  judgemi = min([sa,sb,sc])
  ans = min(ans,(judgema-judgemi))

tmp1 = h
tmp2 = w
w =tmp1
h =tmp2
for i in range(0,h):
  sa = i*w
  #上下分断
  h2 = (h-i)//2
  sb = h2*w
  sc = (h-i-h2)*w
  judgema = max([sa,sb,sc])
  judgemi = min([sa,sb,sc])
  ans = min(ans,(judgema-judgemi))
  #左右分断
  w2 = (w//2)
  sb = (h-i)*w2
  sc = (h-i)*(w-w2)
  judgema = max([sa,sb,sc])
  judgemi = min([sa,sb,sc])
  ans = min(ans,(judgema-judgemi))
  
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll INFL = 1e18;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////

int main(){
    long long x, y;
    cin >> x >> y;
    long long res = 1e18;
    for (int i = 1;i < x;i++){
        long long a = (x - i) * y;
        long long b = i * (y / 2);
        long long c = x * y - a - b;
        res = min(res, max(a, max(b, c)) - min(a, min(b, c)));
        a = i * y;
        b = (x - i) / 2 * y;
        c = x * y - a - b;
        res = min(res, max(a, max(b, c)) - min(a, min(b, c)));
    }
    for (int i = 1;i < y;i++){
        long long a = (y - i) * x;
        long long b = i * (x / 2);
        long long c = x * y - a - b;
        res = min(res, max(a, max(b, c)) - min(a, min(b, c)));
        a = i * x;
        b = (y - i) / 2 * x;
        c = x * y - a -b;
        res = min(res, max(a, max(b, c)) - min(a, min(b, c)));
    }
    cout << res << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define Q int t,q; cin>>t ;for(q=1;q<=t;q++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main()
{
    ll i,n,a=0;
    cin>>n;
    for(i=1;;i++)
    {
        a+=i;
        if(a>=n)break;
    }
    cout<<i;
}


Measured memory_bytes: 3600
h, w = map(int, input().split())

if h == 1 or w == 1:
    print(1)
else:
    # H = (h+1)//2
    # W = (w+1)//2
    #
    # print(H*W + (h-H)*(w-W))

    print(((h*w+1)//2))

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
using namespace std;
int main(){
  while(1){
    int n;
    cin >> n;
    if(n == 0)break;
    vector<int> array(n,0);
    int max_a = 0;
    int min_a = 10000;

    for(int i = 0;i < n;i++){
      int tmp;
      cin >> tmp;
      array[i] = tmp;
      max_a = max(max_a,tmp);
      min_a = min(min_a,tmp);

    }

    int sum = -1*(max_a + min_a);
    for(int i = 0; i < n;i++){
	sum += array[i];
    }
    cout << (int)(sum / (n-2)) << endl;
  }
  return 0;
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	int n;
	std::cin >> n;
	std::vector<int> v(30,0);
	string str;
	std::cin >> str;
	for (size_t i = 0; i < str.size(); i++) {
		v[str[i] - 'a']++;
	}

	for (size_t i = 1; i < n; i++) {
		std::cin >> str;
		std::vector<int> t(30,0);
		for (size_t j = 0; j < str.size(); j++) {
			t[str[j] - 'a']++;
		}
		for (size_t j = 0; j < v.size(); j++) {
			v[j] = min(v[j],t[j]);
		}
	}

	string ans;
	for (size_t i = 0; i < v.size(); i++) {
		for (size_t j = 0; j < v[i]; j++) {
			ans += ('a' + i);
		}
	}

	std::cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=100005,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
inline void read(int &x){
	x=0;char ch=getchar(),rev=0;
	while(ch>'9'||ch<'0') rev=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=rev?-x:x;
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,m,pw[20],dp[1<<15],cnt[20][1<<15];
bool g[20][20];

int solve(int mask){
	if((mask&1)^(mask>>1&1)) return 0;
	if(mask==3) return 1;
	if(~dp[mask]) return dp[mask];
	int ans=0;
	for(int i=mask-1;i;i=(i-1)&mask){
		int res=solve(i);
		for(int j=0;j<n;j++)
			if(i&(1<<j)) res=(ll)res*(pw[cnt[j][mask^i]]-1)%mod;
		i^=mask;
		for(int j=0;j<n;j++)
			if(i&(1<<j)) res=(ll)res*pw[cnt[j][mask^i]]%mod;
		i^=mask;ch(ans,res);
//		printf("%d %d\n",i,res);
	}
	ch(ans,1);
	return dp[mask]=ans;
}

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	pw[0]=1;
	for(int i=1;i<=20;i++) pw[i]=pw[i-1]*2;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y;scanf("%d%d",&x,&y);
		x--;y--;
		g[x][y]=1;
	}
	clr(dp,-1);
	for(int i=0;i<n;i++)
		for(int mask=0;mask<(1<<n);mask++){
			if(mask&(1<<i)) continue;
			for(int j=0;j<n;j++)
				if((mask&(1<<j))&&g[i][j]) cnt[i][mask]++;
		}
	printf("%d\n",(exp(2,m)-solve((1<<n)-1)+mod)%mod);
	return 0;
}

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

int main(void) {
    int c1,c5,c10,c50,c100,c500;
    cin>>c1>>c5>>c10>>c50>>c100>>c500;
    if (c1+c5*5+c10*10+c50*50+c100*100+c500*500>=1000) {
        cout<<1<<endl;
    } else {
        cout<<0<<endl;
    }
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
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);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    if(N==0){
        cout << 0 << endl;
        return 0;
    }
    vector<ll> Binary;
    ll bina = N;
    while(bina != 0){
        ll amari = ((bina%2)+2)%2;
        Binary.push_back(amari);
        bina = (bina-(amari))/(-2);
    }

    reverse(Binary.begin(), Binary.end());
    
    for(auto v:Binary){
        cout << v;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using pi = pair<int32, int32>;
using pll = pair<int64, int64>;
using vi = vector<int32>;
using vvi = vector< vector<int32> >;
using vll = vector<int64>;
using ll = int64;
using ull = uint64;
constexpr int32 INF = 1<<30;
constexpr ll INFLL = 1LL<<62;
#define all(x) x.begin(),x.end()
#define LB(V,x) lower_bound(all(V),x)-V.begin()
#define uint uint32
void Main(){
    int N,M,Cost[10] = {0,2,5,5,4,5,6,3,7,6};
    cin >> N >> M;
    vi P(8,0);
    while(M--){
        int32 a;
        cin >> a;
        P[Cost[a]] = max(a, P[Cost[a]]);
    }
    vi U;
    for(int i=2;i<8;i++) if(P[i]!=0) U.push_back(i);
    vvi dp(N+1, vi(8,-1));
    dp[0] = vi(8,0);
    vi H = U;
    for(auto &h:H) h = P[h];
    sort(all(H), greater<int>());
    for(auto &h:H) h = Cost[h];
    for(int i=2;i<=N;i++){
        for(auto u:U){
            if((u<=i)&&(dp[i-u][0]!=-1)){
                vi temp = dp[i-u];
                temp[u]++;
                int tempS = accumulate(all(temp), 0);
                int dpS = accumulate(all(dp[i]), 0);
                if(tempS > dpS) dp[i] = temp;
                else if(tempS == dpS){
                    for(auto h:H) if(temp[h] > dp[i][h]) dp[i] = temp;
                    else if(temp[h] < dp[i][h]) break;
                    else if(temp[h] == dp[i][h]) continue;
                }
            }
        }
    }
    vi Ans(accumulate(all(dp[N]), 0));
    int j=0;
    for(int i=2;i<8;i++){
        while(dp[N][i]--) Ans[j++] = P[i];
    }
    sort(all(Ans), greater<int32>());
    for(auto ans:Ans) cout << ans;
    cout << endl;
}
int main(){cin.tie(0);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 1280
n,m=map(int,input().split())
list=[]
for i in range(0,n):
  x,y=input().split()
  list.append((int(x),int(y)))
  
list=sorted(list,key=lambda x:x[0])
ans=0
for j in range(n):
  if list[j][1]<m:
    ans+=list[j][0]*list[j][1]
    m-=list[j][1]
  else:
    ans+=list[j][0]*m
    break
    
print(ans)    
  

Measured memory_bytes: 18852
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int k, q;
  cin >> k >> q;
  vector<long long> d(k);
  for (int i = 0; i < k; i++) cin >> d[i];
  while (q--) {
    long long n, x, m;
    cin >> n >> x >> m;
    long long tot = 0;
    x %= m;
    long long last = x;
    for (int i = 0; i < k; i++) {
      long long cnt = (n - 1) / k + ((n - 1) % k > i);
      if (d[i] % m == 0) {
        tot += cnt;
      }
      last += (d[i] % m) * cnt;
    }
    tot += last / m - x / m;
    cout << n - 1 - tot << '\n';
  }
  return 0;
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

ll D = 61;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n; cin >> n;
    ll cnt0[D], cnt1[D];
    memset(cnt0, 0LL, sizeof cnt0);
    memset(cnt1, 0LL, sizeof cnt1);
    for(ll i=0;i<n;i++){
        ll a; cin >> a;
        for(ll j=0;j<D;j++){
            if(a % 2 == 0) cnt0[j]++;
            else cnt1[j]++;
            a /= 2;
        }
    }
    ll b = 1, sum = 0;
    for(ll j=0;j<D;j++){
        sum = (sum + (((cnt0[j] * cnt1[j]) %MOD) * b) %MOD) %MOD;
        b = (b*2) %MOD;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
program sample
	implicit none
    integer(8) :: x,y,count
    
    read(*,*) x,y
    
    if (x==1) then
    	count =count+300000
    else if (x==2) then
    	count = count+200000
    else if (x==3) then
    	count = count + 100000
    end if
    if (y==1) then
    	count =count+300000
    else if (y==2) then
    	count = count+200000
    else if (y==3) then
    	count = count + 100000
    end if
    if (x==1 .and. y==1) then
    	count = count + 400000
    end if

	write(*,*) count

	stop
end program sample


Measured memory_bytes: 2856
L = gets.to_i
A = gets.to_i
B = gets.to_i
C = gets.to_i
D = gets.to_i

res = 0
kokugo = 0
sansu = 0
done = false
L.times do |l|
    if kokugo >= A && sansu >= B then
        done = true
    else
        if kokugo < A then
            kokugo += C
        end
        if sansu < B then
            sansu += D
        end
        done = false
    end
    if done then
        res += 1
    end
end
puts res


Measured memory_bytes: 6868
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x) - 1 * 100);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>

using namespace std;

int n;
int main(void) {
	map<int, int> m;
	cin >> n;
	int t;
	rep(i, n) {
		cin >> t;
		m[t]++;
	}
	int ans=0;
	for (auto kv : m) {
		if (m[kv.first] % 2 != 0) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
#include <vector>
#include <iostream>
#include <queue>

using namespace std;

const long long INF = (1LL <<31) -1 ;


// beging_idx: スタートの頂点のインデックス
// n頂点数
// graph: 隣接グラフとその重みなどを記録する配列。
vector<long long> dijkstra(long long begin_idx, long long n, const vector<vector< vector<long long> > >& graph)
{
    //最短経路としてどの頂点が確定済みかをチェックする配列
    vector<bool> confirmed(n, false);

    //それぞれの頂点へ最短経路距離を保存する配列
    //始点0 ,その他はINF
    vector<long long>  dist(n, INF); dist[begin_idx] = 0;
    //P確定済みの頂点の集合から伸びる辺を伝ってたどり着く頂点の始点からの距離を短い順に保存するPriority queue
    //要するにどこの頂点を付き捜索するのかを決める

    //昇順の場合はgreater
    //pairの比較は一つ目の要素→二つ目の要素の優先順位
    priority_queue< vector<long long>, 
                    vector<vector<long long > >, 
                    greater<vector<long long > > > que;

    //始点を入れる
    //今回 idx0が始点からそこまで行くのにかかる距離,idx1が頂点インデックス, 
    que.push({dist[begin_idx], begin_idx});

    //要素がすべて確定するまで頂点を小さい順方見ていく
    while(!que.empty()){
        vector<long long> cur_node = que.top();
        que.pop();

        //すでにその頂点への最短距離が確定済みの場合は飛ばす
        if(confirmed[cur_node[1]]) continue;

        confirmed[cur_node[1]] = true;

        //その確定済みの頂点から伸びる辺の情報をとってくる(参照の方が速い)、lは辺の本数
        //next_candidatesは頂点(idx1)と、その頂点にcurから行くのにかかるコスト(idx0)が入ってる
        const auto& next_candidates = graph[cur_node[1]];

        for(auto next_node : next_candidates){
            //確認済みなら更新しない
            if(confirmed[next_node[1]] == true) continue;
            //辺の重みを更新
            if( dist[cur_node[1]] + next_node[0] < dist[next_node[1]] ){
                dist[next_node[1]] = dist[cur_node[1]] + next_node[0];
                //更新した場合はその頂点が(確定済みでない頂点の中で)最短距離になる可能性があるのでmincandに挿入
                que.push( {dist[next_node[1]], next_node[1]} );
            }
        }
    }
    
    return dist;
}

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

    vector<vector<vector<long long> > > graph(V);
    for(int i=0; i<E; ++i){
        int s, t, d;
        cin >> s >> t >> d;
        graph[s].push_back({d, t});
        //graph[t].push_back({d, s});
    }

    vector<long long> ans = dijkstra(r, V, graph);

    for(long long i : ans){
        if(i == INF){
            cout << "INF" << endl;
        }else{
            cout << i << endl;
        }
    }
}


Measured memory_bytes: 42772
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int IMF = 1'000'000'000; //1e9
const int MIL = -1;
const long long LIMF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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







int main(){
    int H, A; std::cin >> H >> A;
    std::cout << (H+A-1)/A << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<sstream>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
const int L=-100000;
const int R=-999999;
int stoi(string x){
	stringstream ss;
	ss<<x;
	int now;
	ss>>now;
	return now;
}
vector<int>G[10000];
int n,h;
string s;
int main(){
cin>>n;
rep(iii,n){
cin>>s;
stack<int>sta;
string now="";
for(int i=0;i<s.size();i++){

	if(s[i]=='['){
		sta.push(L);
	}

	else if(s[i]==']'){
		vector<int>a(0);
		int length=0,sum=0,nnow;
		nnow=stoi(now);
		if(!now.empty()){
			sta.push(nnow/2+1);
			now="";
		}
		//cout<<sta.top()<<endl;
		while(sta.top()!=L){

			a.push_back(sta.top());
			sta.pop();
		}
		sta.pop();//[を抜く
		length=a.size();
		sort(a.begin(),a.end());
		for(int j=0;j<length/2+1;j++)sum+=a[j];
		sta.push(sum);
		//cout<<sum<<" "<<length<<endl;
	}
	else{
		now.push_back(s[i]);
	}
}
int ans=sta.top();
sta.pop();
cout<<ans<<endl;
}


	return 0;
}


Measured memory_bytes: 3460
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

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

int main() {
	ll H, W, N;
	cin >> H >> W >> N;
	ll sx, sy;
	cin >> sy >> sx;
	sx--;
	sy--;
	string S, T;
	cin >> S >> T;
	struct I {
		ll l;
		ll r;
		ll u;
		ll d;
	};
	I is_no = {};
	T.pop_back();
	ll n = S.size()+T.size();
	rep(i,0,n) {
		if (i % 2 == 0) {
			char c = S.back();
			S.pop_back();
			if (c == 'L') {
				is_no.l++;
			} else if (c == 'R') {
				is_no.r++;
			} else if (c == 'U') {
				is_no.u++;
			} else {
				is_no.d++;
			}
		} else {
			char c = T.back();
			T.pop_back();
			if (c == 'L') {
				is_no.r--;
			} else if (c == 'R') {
				is_no.l--;
			} else if (c == 'U') {
				is_no.d--;
			} else {
				is_no.u--;
			}
		}
		is_no.l = max((ll)0, min(W, is_no.l));
		is_no.r = max((ll)0, min(W, is_no.r));
		is_no.u = max((ll)0, min(H, is_no.u));
		is_no.d = max((ll)0, min(H, is_no.d));
		if (is_no.l + is_no.r >= W || is_no.u + is_no.d >= H) {
			cout << "NO" << endl;
			return 0;
		}
		// cout << i << ": " << is_no.l << " " << is_no.r << " " << is_no.u << " " << is_no.d << endl;
	}
	if (sx < is_no.l || sy < is_no.u || W-sx-1 < is_no.r || H-sy-1 < is_no.d) {
		cout << "NO" << endl;
	} else {
		cout << "YES" << endl;
	}
}


Measured memory_bytes: 1020
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int num = sc.nextInt();

        int[] input = new int[num];

        for(int i = 0; i < num; i++)
            input[i] = sc.nextInt();

        System.out.print(input[num - 1]);
        for(int i = 2; i <= num; i++)
            System.out.print(" " + input[num - i]);
        System.out.println("");
        sc.close();
    }
}



Measured memory_bytes: 26432
def d_smallmultiple(K):
    import collections
    q = collections.deque()
    q.append(1)
    
    dp = [float('Inf') for _ in range(K)]
    dp[1] = 0
    
    while q:
        u = q.popleft()
        if dp[(u*10)%K] > dp[u]:
           dp[(u*10)%K] = dp[u]
           q.appendleft((u*10)%K)
        if dp[(u+1)%K] > dp[u] + 1:
            dp[(u+1)%K] = dp[u] + 1
            q.append((u+1)%K)
            
    return dp[0]+1

K = int(input())
print(d_smallmultiple(K))

Measured memory_bytes: 8388
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long 
#define int long long 
#define vll vector<long long>
#define pii pair<long long ,long long > 
#define vvi vector< vector<long long > > 
#define vpii vector<pair<int,int>> 
#define pll  pair<long long ,long long > 
#define pb  push_back
#define ff  first 
#define sec second  
#define SORT(a) sort(a.begin(),a.end())
#define SORTR(a) sort(a.rbegin(),a.rend()) 
#define m_p make_pair
#define all(x) (x.begin(),x.end()) 
#define sz(v) ((int)(v.size()))
#define endl '\n'
typedef vector< long long > vi ;
const int MOD=1e9 +7 ;
int size=10000000; 
const int INF=1e18L+5 ; 
int32_t main(){
  fast; 
/*  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif */
	
  int T=1; //cin>>T; 
  while(T--){

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

  	vector< vi >  dp(n+1,vi(n+1,0)); 


  	for(int L=n-1;L>=0;L--){
  		for(int R=L;R<n;R++){

  			if(L==R) dp[L][R]=0;
  			else{

  				dp[L][R]=INF; 
  				int temp=0; 
  				for(int j=L;j<=R;j++) temp+=a[j]; 

  				for(int i=L;i<=R-1;i++){
  					dp[L][R]=min(dp[L][R],dp[L][i]+dp[i+1][R]+temp);
  				}

  			} 



  		}
  	}



  	cout<<dp[0][n-1]<<endl;






  }
    


  return 0; 
} 


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() 
{
    ll int a, b, tempa, tempb, ans=0;
    cin>> a >> b;
	
    if((a-1)%4==0)
    {
    	tempa = a-1;
	}
	else if((a-1)%4==1)
	{
		tempa = 1;
	}
	else if((a-1)%4==2)
	{
		tempa = a;
	}
	else if((a-1)%4==3)
	{
		tempa = 0;
	}
	
	if(b%4==0)
    {
    	tempb = b;
	}
	else if(b%4==1)
	{
		tempb = 1;
	}
	else if(b%4==2)
	{
		tempb = b+1;
	}
	else if(b%4==3)
	{
		tempb = 0;
	}
	ans = tempa^tempb;
	
   	cout << ans;
	
	
	
	
	
	return 0;
}


Measured memory_bytes: 256
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    auto no1 = [&](void)
    {
        puts("Impossible");
        return 0;
    };
    auto yes1 = [&](void)
    {
        puts("Possible");
        return 0;
    };
    # define no no1()
    # define yes yes1()
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    static int s[1 << 20];
    fi>>n;
    if (n == 2) return yes;
    for (int i = 1;i <= n;++i) fi>>s[i];
    int mn = *min_element(s + 1,s + 1 + n);
    int cnt = 0;
    for (int i = 1;i <= n;++i)
        cnt += s[i] == mn;
    if (mn == 1 && cnt != 1) return no;
    if (mn != 1 && cnt > 2) return no;
    int mx = *max_element(s + 1,s + 1 + n);
    if (mx > mn + mn - (cnt == 2)) return no;
    static int w[1 << 20];
    for (int i = 1;i <= n;++i) w[s[i]] = 1;
    for (int i = mn;i <= mx;++i)
        if (!w[i]) return no;
    return yes;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.begin(), v.end(), greater<int>);
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge{
    int to, cost;
};


// dijikstra
/* int V;
vector<edge> G[10];
int d[10];

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

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

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


Measured memory_bytes: 256