akhauriyash/Code-Regression huggingface dataset:
from itertools import permutations
import heapq
import sys

INF = 2 ** sys.int_info.bits_per_digit

def warshall(N, ABCs):
    dists = [[INF for _ in range(N)] for __ in range(N)]
    for i in range(N):
        dists[i][i] = 0

    for a, b, c in ABCs:
        dists[a - 1][b - 1] = c
        dists[b - 1][a - 1] = c

    for s in range(N):
        for e in range(N):
            for i in range(N):
                dists[s][e] = min(dists[s][e], dists[s][i] + dists[i][e])
    return dists


def dijkstra(s, e, N, ABCs):
    adjlist = [[] for _ in range(N)]
    for a, b, c in ABCs:
        adjlist[a - 1].append((b, c))
        adjlist[b - 1].append((a, c))

    q = [(0, s)]
    while len(q):
        d, i = heapq.heappop(q)
        if i == e:
            return d
        for nexti, nextd in adjlist[i - 1]:
            heapq.heappush(q, (d + nextd, nexti))
    return None


def dense_dijkstra(s, e, N, ABCs):
    distsmap = [[-1 for _ in range(N)] for __ in range(N)]
    for a, b, c in ABCs:
        distsmap[a - 1][b - 1] = c
        distsmap[b - 1][a - 1] = c

    dists = [INF for _ in range(N)]
    visited = [False for _ in range(N)]
    dists[s - 1] = 0

    while True:
        minW, index = min([(dists[i], i) for i in range(N) if not visited[i]])
        visited[index] = True
        if minW == INF:
            return -1
        if index + 1 == e:
            return minW
        for rindex, w in enumerate(distsmap[index]):
            if w == -1:
                continue
            dists[rindex] = min(dists[rindex], minW + w)


# def solve(N, M, R, Rs, ABCs):
#     dists = warshall(N, ABCs)
#     ans = INF
#     for way in permutations(Rs):
#         tans = 0
#         for s, e in zip(way, way[1:]):
#             tans += dists[s - 1][e - 1]
#         ans = min(ans, tans)
#     return ans


def solve(N, M, R, Rs, ABCs):
    dists = [[-1 for _ in range(N)] for __ in range(N)]
    ans = INF
    for way in permutations(Rs):
        tans = 0
        for s, e in zip(way, way[1:]):
            if dists[s - 1][e - 1] == -1:
                d = dense_dijkstra(s, e, N, ABCs)
                dists[s - 1][e - 1] = d
                dists[e - 1][s - 1] = d
            else:
                d = dists[s - 1][e - 1]
            tans += d
        ans = min(ans, tans)

    return ans

if __name__ == "__main__":
    N, M, R = tuple(map(int, input().split(" ")))
    Rs = list(map(int, input().split(" ")))
    ABCs = [tuple(map(int, input().split(" "))) for _ in range(M)]
    print(solve(N, M, R, Rs, ABCs))


Measured memory_bytes: 6052
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a , b , c;
    cin >> a >> b >> c;
    cout << a + b + c - max( { a , b , c } );
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <cmath> //fabs, pow, sqrt, sin, fmod
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int h, w, k;

int main() {
    int ans = 0;
    cin >> h >> w >> k;

    vector<string> c(h);

    rep(i, h) cin >> c.at(i);

    rep(is,1<<h)rep(js,1<<w) {
        int cnt = 0;
        rep(i,h)rep(j,w) {
            if(is>>i&1) continue;
            if(js>>j&1) continue;
            if(c[i][j] == '#') cnt++;
        }
        if(cnt == k) ans++;
    } 

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3488
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, s, n) for(int i = s; i < n; i++)
#define rRep(i, n) for(int i = n - 1; i >= 0; i--)
#define pi pair<int, int>
#define vi vector<int>
#define endl "\n"
const double PI = 3.141592653589793238;

int32_t main() {
    FAST
    int r;
    cin >> r;
    double ans = 2*PI;
    ans = ans*(double)r;
    cout << fixed << setprecision(6) << ans << endl;
}

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

int main(void)
{
    int N,cnt = 0;
    int ans = 1000000;
    string s;
    cin >> N >> s;
    vector<int> e(N,0),w(N,0);

    rep(i,N){
        if(s[i] == 'E'){
            cnt++;
        }
        e[i] = cnt;
    }

    cnt = 0;

    rep(i,N){
        if(s[i] == 'W'){
            cnt++;
        }
        w[i] = cnt;
    }

    rep(i,N){
        ans = min(ans,w[i-1]+e[N-1]-e[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6148
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int fmt(string s)
{
    int ret = 0;
    ret += (s[0] - '0') * 36000;
    ret += (s[1] - '0') * 3600;
    ret += (s[3] - '0') * 600;
    ret += (s[4] - '0') * 60;
    ret += (s[6] - '0') * 10;
    ret += (s[7] - '0') * 1;
    return ret;
}

int main()
{
    while (true)
    {
        int n;
        cin >> n;
        if (n == 0)
        {
            return 0;
        }
        vector<int> times(100000, 0);
        for (int i = 0; i < n; i++)
        {
            string s1, s2;
            cin >> s1 >> s2;
            int st = fmt(s1), fin = fmt(s2);
            times[st]++;
            times[fin]--;
        }
        for (int i = 0; i < times.size() - 1; i++)
        {
            times[i + 1] += times[i];
        }
        int ans = 0;
        for (int i = 0; i < times.size(); i++)
        {
            ans = max(ans, times[i]);
        }
        cout << ans << endl;
    }
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    ll n;
    cin >> n;
    ull sum = 0;
    vector<ull> a(n);
    rep (i,n) cin >> a[i],sum += a[i];
    ull ans = 0;
    sum -= a[0];
    rep(i,n-1) ans += (a[i] * (sum % MOD)) % MOD,ans %= MOD,sum -= a[i+1];
    cout << ans << endl;
}

Measured memory_bytes: 4856
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	int N;
	ll X[200200];
	ll Y[200200];
	
	static pair<ll, ll> XY[200200];
	static pair<ll, ll> YX[200200];
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> X[i] >> Y[i];
		XY[i] = make_pair(X[i], Y[i]);
		YX[i] = make_pair(Y[i], X[i]);
	}
	
	static ll F0[200200];
	static ll F1[200200];
	for(int i = 0; i < N; i++){
		F0[i] = X[i]-Y[i];
		F1[i] = X[i]+Y[i];
	}
	sort(F0, F0+N);
	sort(F1, F1+N);
	ll ans = max(F0[N-1]-F0[0], F1[N-1]-F1[0]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9884
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

ll calc(ll h, ll w) {
  ll mi = 1e18;
  REP(i, 1, h) {
    // try division
    vector<ll> tmp;
    ll t = (ll) i * w;
    tmp.push_back(t);
    ll qu = h - i;
    ll ww = w;
    if (ww < qu) {
      swap(qu, ww);
    }
    if (qu % 2 == 0) {
      swap(ww, qu);
    }
    tmp.push_back(qu * (ww / 2));
    tmp.push_back(qu * (ww - ww / 2));
    sort(tmp.begin(), tmp.end());
    mi = min(mi, tmp[2] - tmp[0]);
  }
  return mi;
}

int main(void){
  ll h, w;
  cin >> h >> w;
  ll mi = 1e18;
  mi = min(calc(h, w), mi);
  mi = min(calc(w, h), mi);
  cout << mi << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long l;
int main(){
    l a,c=0;
    cin>>a;
    l b[a];
    for(l i=0;i<a;i++){
        cin>>b[i];
        c+=b[i]-1;
    }
    cout<<c<<endl;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  string s;
  map<string,int> yey;
  string mxlen;
  string mostlen;
  int cnt = 0;
  while(cin){
    cin>>s;
    yey[s]++;
    if(mxlen.size() < s.size())mxlen = s;
    if(yey[s]>cnt){
      mostlen = s;
      cnt = yey[s];
    }
  }
  cout<<mostlen<<" "<<mxlen<<endl;
  return 0;
}

Measured memory_bytes: 1200
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int N;
    vector<int> m;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        m.push_back(tmp);
    }
    long long int sum1 = 0, sum2 = 0;;
    // for (int i = N - 1; i < 2 * N - 1; i++) {
    //     long long int sum = 0;
    //     for (int j = i + 1; j < i + N; j++) {
    //         if ((j - i) % 2) {
    //             sum += m[j % N];
    //         } else {
    //             sum -= m[j % N];
    //         }
    //     }
    //     cout << sum + m[i % N] << " ";
    // }
    for (int i = 1; i < N; i++) {
        if (i % 2 == 0) {
            sum2 += m[i];
        } else {
            sum2 -= m[i];
        }
    }
    for (int i = 0; i < N; i++) {
        cout << sum2 + sum1 + m[i] << " ";
        sum1 = -sum1 + m[i];
        sum2 = sum2 + m[(i + 1) % N];
        sum2 = -sum2;
    }
    putchar('\n');
    return 0;
}

Measured memory_bytes: 1784
import math
def comb(n, k):
    return math.factorial(n) // (math.factorial(n - k) * math.factorial(k))

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

v.sort(reverse=True)
max_avg = sum(v[:a]) / a
min_v = min(v[:a])

ans = 0
for i in range(a, b+1):
    if max_avg != sum(v[:i]) / i: break
    cnt1 = v[:i].count(min_v)
    cnt2 = v.count(min_v)
    ans += comb(cnt2, cnt1)

print(max_avg)
print(int(ans))

Measured memory_bytes: 3064
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int iseven(int n) {
    if(n % 2 == 0)
        return 1;
    if(n % 2 != 0)
        return 0;
}

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

    if(x == 2) {
        cout << 2 << endl;
        return 0;
    }

    x += iseven(x);

    while(x < 100005) {
        int flag = 1;
        // x自身より小さい奇数で割れるかチェック
        for(int i = 3; i <= x - 1; i += 2) {
            if(x % i == 0) {
                flag = 0;
            }
        }

        // 最後まで割れなかったら素数
        if(flag == 1) {
            cout << x << endl;
            return 0;
        } else {
            x += 2; //割れなかったら次の奇数
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    int x,y,z;
    int ans=0;

    cin >>x>>y>>z;
    printf("%d %d %d\n",z,x,y);
}

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

#define trav(a, A) for (auto & a : A)
#define f first
#define s second

typedef long long ll;

ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;

int main ()
{
	ios_base::sync_with_stdio (0);
	cin.tie (0);
	ll i, j, n;
	string s;
	cin >> s;
	ll ans = 0;
	if (s[1] == 'S')
	{
		if (s[0] == 'R' || s[2] == 'R') cout << 1;
		else cout << 0;
	}
	else
	{
		if (s[0] == 'R')
			if (s[2] == 'R') cout << 3;
			else cout << 2;
		else if (s[2] == 'R') cout << 2;
			else cout << 1;
	}
	cout << '\n';


	return 0;
}



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

int main () {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d){
    cout<<"Left"<<endl;
  }
  if(a+b==c+d){
    cout<<"Balanced"<<endl;
  }
    if(a+b<c+d){
    cout<<"Right"<<endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var ab = Enumerable.Repeat(0, n).Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
        var a = ab.Select(x => x[0]).OrderBy(x => x).ToArray();
        var b = ab.Select(x => x[1]).OrderBy(x => x).ToArray();
        int getMed(int[] a) => a.Length % 2 == 0 ? (a[a.Length / 2 - 1] + a[a.Length / 2]) : a[a.Length / 2] * 2;
        var diff = getMed(b) - getMed(a);
        Console.WriteLine(n % 2 == 0 ? diff + 1 : diff / 2 + 1);
    }
}

Measured memory_bytes: 55112
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

int main(){
	IO_STREAM;
	string S,T;	cin>>S>>T;
	int size=S.size();
	string ans="No";
	rep(i,0,size){
		string s;
		s=S[size-1]+S.substr(0,size-1);
		if(s==T){
			ans="Yes";
			break;
		}
		S=s;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3644
import math
from itertools import combinations

def main():
    k = int(input())
    res = 0
    memo = [[0 for _ in range(k+1)] for _ in range(k+1)]
    for i in range(1, k+1):
        for j in range(i, k+1):
            tmp = math.gcd(i,j)
            memo[i][j] = tmp
            memo[j][i] = tmp

    for i in range(1, k+1):
        res += i 

    for c in combinations(range(1,k+1),2):
        ab = memo[c[0]][c[1]]
        res += ab * 6

    for c in combinations(range(1,k+1), 3):
        ab = memo[c[0]][c[1]]
        abc = memo[ab][c[2]]
        res += abc * 6
    print(res)


if __name__ == '__main__':
    main()



Measured memory_bytes: 9440
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()	{
  int n, l;
  cin >> n >> l;
  string dict[n];
  for (int i = 0; i < n; i++)	{
    cin >> dict[i];
  }
  sort(dict, dict + n);
  for (int i = 0; i < n; i++)	{
    cout << dict[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MX = 1e10 + 10;;
unsigned long long fac[1000010];

#include <math.h>
#define PI 3.14159265358979323846264338327950L

long long gcd(long long a, long long b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
long long lcm(long long a, long long b) {
    return (a * b) / gcd(a, b);
}
long long digits(long long m) {
    long long cnt = 0;
    while (m) {
        cnt++;
        m /= 10;
    }
    return cnt;
}

unsigned long long power(unsigned long long x, unsigned long long y){
    unsigned long long res = 1;
    x = x % MOD;

    while (y > 0) {
        // If y is odd, multiply x with result 
        if (y & 1)
            res = (res * x) % MOD;

        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % MOD;
    }
    return res;
}
unsigned long long modInverse(unsigned long long n) {
    return power(n, MOD - 2);
}


int main() {
    long long l, r;
    cin >> l >> r;
    
    if (r - l > 2020) {
        cout << 0;
    }
    else {
        long long ans = 2020;
        for (long long i = l; i < r; i++) {
            for (long long j = l + 1; j <= r; j++) {
                ans = min(ans, ((i * j) % 2019));
            }
        }
        cout << ans;
    }

    return 0;
}

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

#define ll             long long 
#define mod            1000000007
#define FIO            ios_base::sync_with_stdio(false); cin.tie(NULL);
                  
void initial()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}


int main() 	 	
{
	initial();
	FIO;
    long long int n;
    cin>>n;
    
    long long int x =100;
    long long int count =0;
    
    while(x<n){
        
        x += (0.01)*x;
        count++;
    }
    
    cout<<count<<endl;
}




Measured memory_bytes: 3640
eval"N,*A="+`dd`.split*?,
c,d=[0,N].map{|i|y=A[i+N-1];A[i,N].map{|x|y^y=x}}
m=[k=-1]
f=->t{k=m[k]until k<0||d[k]==t;k+=1}
d.map{|x|m<<f[x]}
(2*N+~k=0).times{|i|p i+=1-N,A[N]^A[i]if f[c[i%N]]==N}

Measured memory_bytes: 94884
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
    int W = Integer.parseInt(sc.next());
    int H= Integer.parseInt(sc.next());
    int n= Integer.parseInt(sc.next());
int[] x=new int[n];
int[] y=new int[n];
int[] a=new int[n];
int[][] c=new int[W][H];
    for (int i = 0; i < W; i++) {
        for (int j = 0; j <H; j++) {
            c[i][j]=1;
        }
    }
    for (int i = 0; i <n; i++) {
        x[i]=Integer.parseInt(sc.next());
        y[i]=Integer.parseInt(sc.next());
        a[i]=Integer.parseInt(sc.next());
    }
int ans=0;
    for (int i = 0; i < n; i++) {
        if(a[i]==1){
            for (int j = 0; j <H ; j++) {
                for (int k = 0; k <x[i]; k++) {
                    c[k][j]=0;
                }
            }
        }else if(a[i]==2){
            for (int j = 0; j < H; j++) {
                for (int k=W-1; k >=x[i]; k--) {
                    c[k][j]=0;
                }
            }
        }else if(a[i]==3){
            for (int j = 0; j < W; j++) {
                for (int k = 0; k < y[i]; k++) {
                    c[j][k]=0;
                }
            }
        }else{
            for (int j = 0; j < W; j++) {
                for (int k = H-1; k >=y[i]; k--) {
                    c[j][k]=0;
                }
            }
        }
    }
    for (int i = 0; i < W; i++) {
        for (int j = 0; j < H; j++) {
            ans+=c[i][j];
        }
    }
out.println(ans);
}
}

Measured memory_bytes: 22356
import java.util.*;
import java.io.*;

public class Main {	
	private static void solve(){
		//Implement solution here.
		int N = ni();
		int M = ni();
		int X = ni();
		int[] C = new int[N];
		int[][] A = new int[N][M];
		
		for(int i = 0; i < N; i++) {
			C[i] = ni();
			for(int j = 0; j < M; j++) {
				A[i][j] = ni();
			}
		}
		
		
		
		int result = -1;
		for(int i = 0; i < (int)Math.pow(2, N); i++) {
			int[] score = new int[M];
			int cost = 0;
			String pattern = String.format("%0" + N + "d", Long.parseLong(Integer.toBinaryString(i)));
			for(int j = 0; j < N; j++) {
				if(pattern.charAt(j) == '1') {
					for(int k = 0; k < M; k++) {
						score[k] += A[j][k];
					}
					cost += C[j];
				}
			}
			boolean ok = true;
			for(int j = 0; j < M; j++) {
				if(score[j] < X) {					
					ok = false;
					break;
				} 
			}
			if(ok) {
				if(result == -1) {
					result = cost;
				} else {
					result = Math.min(result, cost);
				}
			}
		}
		System.out.println(result);
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 37752
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << endl;}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << endl;}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

struct UnionFind{
	Vec par;
	Vec ele;

	UnionFind(ll n){
		par.resize(n);
		ele.assign(n, 1);
		rep(i, n) par[i] = i;
	}

	ll root(ll x){
		if(par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(ll x, ll y){
		x = root(x), y = root(y);
		if(x != y){
			par[x] = y;
			ele[y] += ele[x];
			ele[x] = 0;
		}
	}

	bool same(ll x, ll y){
		return root(x) == root(y);
	}

	ll element(ll x){
		return ele[x];
	}
};

int main(void){
	ll n, m;
	cin >> n >> m;
	VecP e(m);
	rep(i, m){
		ll a, b;
		cin >> a >> b;
		e[i] = {--a, --b};
	}


	UnionFind uf(n);

	Vec ans(m+1);
	ans[m] = n*(n-1)/2;
	repr(i, m){
		ans[i] = ans[i+1];
		if(uf.same(e[i].fs, e[i].sc)) continue;
		ans[i] -= uf.element(uf.root(e[i].fs))*uf.element(uf.root(e[i].sc));
		uf.unite(e[i].fs, e[i].sc);
	}
	repn(i, m) co(ans[i]);

	return 0;
}


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

int main() {
    int n, k; cin >> n >> k;
    vector<int> l(n);
    rep(i, 0, n) {
        cin >> l[i];
    }
    sort(l.rbegin(), l.rend());
    int sum = 0;
    rep(i, 0, k) {
        sum += l[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
void main() {
	auto N = ri;
	int[] x, y, h;
	foreach(i; 0..N) {
		auto ip = readAs!(int[]), a = ip[0], b = ip[1], c = ip[2];
		x ~= a;
		y ~= b;
		h ~= c;
	}

	foreach(posY; 0..101)
	{
		foreach(posX; 0..101)
		{
			foreach(H; h.reduce!min..h.reduce!min+201)
			{
				bool flag = true;
				foreach(i; 0..N)
				{
					auto dist = max(0, H-abs(posX-x[i])-abs(posY-y[i]));
					if(dist != h[i])
					{
						flag = false;
						break;
					}
				}
				if(flag)
				{
					writefln("%d %d %d", posX, posY, H);
					return;
				}
			}
		}
	}
}

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

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
arr = gets.chomp!.split(" ")
n = arr[0].to_i
k = arr[1].to_i
#puts "n = #{n}\nk = #{k}"
arr = []
(n-1).times do|i|
    arr[i] = gets.chomp!.to_i
    #puts "arr[#{i}] = #{arr[i]}"
end
arr[n-1] = gets.to_i

arr.sort!
#pp arr
min = 0
max = k-1

mindiff = arr[max] - arr[min]
while max < n do
    diff = arr[max]-arr[min]
    if mindiff > diff then mindiff = diff end
    max += 1
    min += 1
end

puts mindiff


Measured memory_bytes: 4036
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int a[100],b[100],n,x,i,j,cnt;
	x=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=1;i<=100;i++){
		b[i]=0;
	}
	cnt=0;
	for(i=0;i<n;i++){
		for(j=1;j<=100;j++){
			if(a[i]==j){
				b[j]=1;
			}
		}
	}
	for(i=1;i<=100;i++){
		x=x+b[i];
	}
	cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int  ans = 0;
    int N;  cin >> N;
    for(int i = 0 ; i < N ; i++){
      	int input;
        cin >> input;
        ans += input - 1;
    }
 
    cout << ans << endl;
    return 0;
}


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

// int cal(int n){
//     if(log10(n)+1<=1){
//         return 9;
//     }else if((log10(n)+1) %2 == 1){
//         int n_new = n;
//         return n*
//     }
// }

//テストケースはあんまり見ないほうが良い。デバッグする能力が必要.
int main(){
    int n;
    cin >> n;
    int ans = 0;
    rep(i,n){
        if((int)(log10(i+1)+1)%2 == 1)++ans;
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll n, a, b, l, r, s;

int main() {
	cin >> n >> a >> b;
	cin >> l;
	rep(i,n-1) {
		cin >> r;
		s += min((r-l)*a, b);
		l = r;
	}
	cout << s << ln;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)

#include <iostream>
#include <vector>
using namespace std;

//重複順列
vector<ll> buf;
void permutation(ll i, const ll size, const ll range_start, const ll range_end)
{
    if (i == size) {
      // ここで所望の作業を行う
      for(ll itr:buf){
        cout << itr;
      }
    }
    else{
        for(ll j = range_start; j <= range_end; ++j){
            buf[i] = j;
            permutation(i + 1, size, range_start, range_end);
        }
    }
}

int main(void)
{
 string s;
 cin >> s;
 if(s=="ABC"){
   cout << "ARC" << endl;
 }else {
   cout << "ABC" << endl;
 }
 return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
typedef long long ll;
int main(){
	ll dp[maxn];
	ll n,W;
	ll w[105],v[105];
	memset(dp,0,sizeof(dp));
	scanf("%lld%lld",&n,&W);
	for(ll i = 1;i <= n;i++)
		cin >> w[i] >> v[i];
	for(ll i = 1;i <= n;i++){
		for(ll j = W;j >= 1;j--){
			if(j >= w[i]) dp[j] = max(dp[j],dp[j-w[i]] + v[i]);
		}
	}
	printf("%lld\n",dp[W]);
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main

 {
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	
	int w = sc.nextInt();int H = sc.nextInt();
	int x = sc.nextInt();int y = sc.nextInt();
	int r = sc.nextInt();
	if(y >= r && y <=H-r && x >=r && x <= w-r ){
		System.out.printf("Yes\n");
	}else{
		System.out.printf("No\n");
	}
	

}
}



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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

ll n;
vector <ll> val, lis, ans;
vector < vector<ll> > adj;
vector < pair<ll,ll> > operation;

void dfs(ll u, ll p)
{
    if(sz(lis) == 0) lis.pb(val[u]), operation[u] = mp(-1,0);
    else if(val[u] > lis[sz(lis)-1]) lis.pb(val[u]), operation[u] = mp(-1,0);
    else {
        ll pos = lower_bound(lis.begin(), lis.end(), val[u]) - lis.begin();
        ll org = lis[pos];
        lis[pos] = val[u];
        operation[u] = mp(pos,org);
    }
    ans[u] = sz(lis);
    fa(v,adj[u]) if(v != p) dfs(v,u);
    if(operation[u].ff == -1) lis.pop_back();
    else lis[operation[u].ff] = operation[u].ss;
}

int main()
{
    // Fast_IO(); 
    cin >> n; val.resize(n); adj.resize(n); operation.resize(n); ans.resize(n);
    f(i,0,n-1) cin >> val[i];
    f(i,1,n-1) {
        ll u, v; cin >> u >> v;
        u--; v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(0,0);
    f(i,0,n-1) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 29040
N, K = map(int,input().split())
H = list(map(int,input().split()))

dp = [1e9]*N
dp[0] = 0
for i, b in enumerate(H):
  if i != 0:
    x = max(0, i-K)
    dp[i] = min([abs(b-d)+p for d, p in zip(H[x:i], dp[x:i])])
print(dp[-1])


Measured memory_bytes: 13980
local mod = 1000000007
local mfl = math.floor

local function bmul(x, y)
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  local x0, y0 = x - x1 * 31623, y - y1 * 31623
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

local function bsub(x, y)
  return x < y and x - y + mod or x - y
end

local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
end

local function getComb(n, k)
  local ret = 1
  local inv = 1
  for i = 1, k do
    ret = bmul(ret, n + 1 - i)
    inv = bmul(inv, i)
  end
  return bmul(ret, modinv(inv))
end


local n = io.read("*n")
if n <= 2 then
  print(0)
  os.exit()
end
local lim = mfl(n / 3)
local ret = 0
for cnt = 1, lim do
  local z = n - cnt * 3
  ret = badd(ret, getComb(cnt + z - 1, z))
end
print(ret)


Measured memory_bytes: 2772
#include <bits/stdc++.h>
#define rep(i,a,b) for (i=a;i<b;i++)
#define rep2(i,a,b) for (i=a;i>=b;i--)
#define mod 1000000007
#define mod2 998244353
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF  1e9+5
#define f first
#define s second
#define endl '\n'
#define ll long long
#define ii pair <int,int>
#define pll pair <ll,ll>
#define vi vector <int>
#define vl vector <ll>
#define vvi vector < vi >
#define vii vector < ii >
#define vpl vector < pll >
#define vvii vector < vii >
#define vll vector < ll >
#define vb  vector <bool>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define pg priority_queue<ll, vector<ll>, greater<ll>>
#define pq priority_queue<ll>
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define cset(a) __builtin_popcountll(a)
#define FILL(a, b, T) fill_n((T *)a, sizeof(a) / sizeof(T), b)
#define debug(x) cerr << #x << " is " << x << endl;
#define st pair<ll,pll>
using namespace std;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// unordered_map<long long, int, custom_hash> safe_map;
// FOR VIEWERS, CODE STARTS HERE

int main()
{
    // #ifndef ONLINE_JUDGE
    //  freopen("input.txt","r",stdin);
    //  freopen("output.txt","w",stdout);
    // #endif
    FIO;
    ll t, q, n, m, prev, maxx,  i, j, k1, k2, k3, k, x, y, flag, sum, cnt, ans;
    cin>>n;
    vll v(n);
    rep(i,0,n)
        cin>>v[i];
    k = 0;
    rep(i,0,n)
    {
        if( v[i] == k + 1)
        {
            k++;
        }
    }
    if( k == 0)
        cout<<-1<<endl;
    else
        cout<<n - k<<endl;
    return 0;    
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================

int main() {
	
	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================
	

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

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (P[i] - 1 == i) {
			ans++;
			i++;
		}
	}

	cout << ans;



}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;

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

    int h, w;
    cin >> h >> w;
    int srow, scol, drow, dcol;
    cin >> srow >> scol >> drow >> dcol;
    --srow, --scol, --drow, --dcol;
    vector<string> grid(h);
    for (int i = 0; i < h; ++i) 
        cin >> grid[i];

    auto getID = [&](int row, int col) { return row * w + col; };
    auto valid = [&](int row, int col) { return row >= 0 && row < h && col >= 0 && col < w; };

    vector<vector<pair<int, int>>> adj(h * w);
    for (int row = 0; row < h; ++row) {
        for (int col = 0; col < w; ++col) {
            if (grid[row][col] == '#') continue;
            int u = getID(row, col);
            for (int i = -2; i <= 2; ++i) {
                for (int j = -2; j <= 2; ++j) {
                    int nr = row + i, nc = col + j;
                    if (!valid(nr, nc) || (i == 0 && j == 0) || grid[nr][nc] == '#') continue;
                    adj[u].emplace_back(getID(nr, nc), !((abs(i) == 1 && j == 0) || (abs(j) == 1 && i == 0)));
                }
            }
        }
    }

    // 0-1 BFS
    int start = getID(srow, scol), dest = getID(drow, dcol);
    vector<int> dist(h * w, INF);
    deque<int> dq;
    dq.push_front(start);
    dist[start] = 0;
    while (!dq.empty()) {
        int u = dq.front(); dq.pop_front();
        for (auto edge: adj[u]) {
            int v = edge.first, cost = edge.second;
            if (dist[u] + cost < dist[v]) {
                dist[v] = dist[u] + cost;
                if (cost) {
                    dq.push_back(v);
                } else {
                    dq.push_front(v);
                }
            }
        }
    }
    cout << (dist[dest] == INF ? -1 : dist[dest]) << '\n';
    
    return 0;
}

Measured memory_bytes: 101292
#include <stdio.h>

 #define MAX 100000

int left(int i){return 2*i;}

int parent(int i){return i/2;}

int right(int i){return 2*i+1;}

int main(){
  int H,i,A[MAX+1];

  scanf("%d",&H);

  for(i=1;i<=H;i++)
    scanf("%d",&A[i]);
  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1)
      printf("parent key = %d, ",A[parent(i)] );
    if(left(i)<=H)
      printf("left key = %d, ",A[left(i)]);
    if(right(i)<=H)
      printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }

  return 0;}



Measured memory_bytes: 2672
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long MOD = 1e9 + 7;

int N;
vector<ll> memo(2010, -1);

ll f(ll n) {
    if(n < 3) return 0;
    if(memo[n] != -1) return memo[n];
    ll tmp = 1;
    for(int i = n - 1; i > 2; i--) {
        tmp += f(n - i);
        tmp %= MOD;
    }
    memo[n] = tmp;
    return tmp;
}

int main() {
    cin >> N;
    cout << f(N) << endl;
}

Measured memory_bytes: 3628
// Author: Sayantanu
#include <bits/stdc++.h>

using namespace std;

#define ll long long int
const int mod = 1e9 + 7;
const ll INF = 1e18;

int main() {
    //code
    ll n,w;
    cin>>n>>w;
    ll weights[n],value[n];
    ll size = 0;
    for(int i = 0 ; i < n ; i++){
        cin>>weights[i]>>value[i];
        size += value[i];
    }
    vector<ll> dp(size+1,INF);
    dp[0] = 0;
    for(int i = 0 ; i < n; i ++){
        for(int j = (size - value[i]); j>=0; j--){
            dp[j+value[i]] = min(dp[j+value[i]],dp[j] + weights[i]);
        }
    }

    ll ans = 0;
    for(int i = 0; i<=size ; i++){
        if(dp[i]<=w){
            ans = i;
        }
    }

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

Measured memory_bytes: 3980
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    int ab = 0, xa = 0, bx = 0, ba = 0;
    Rep(n){
        Cin(string, s);
        For(i, (int)s.size()-1){
            if(s[i] == 'A' && s[i+1] == 'B') ab ++;
        }
        if(s[0] == 'B') (s.back() == 'A' ? ba : bx) ++;
        else if(s.back() == 'A') xa ++;
    }
    if(ba > 0){
        ab += ba-1;
        if(xa > 0) ab ++, xa --;
        if(bx > 0) ab ++, bx --;
    }
    
    Cout(ab + min(xa, bx));
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#define _GLIBCXX_DEBUG

#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define endl '\n'
#define fcout cout << fixed << setprecision(15)

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; (i) < (int)(n); i++)

using ll    = long long;
using ld    = long double;
using Pii   = pair<int, int>;
using Pll   = pair<ll, ll>;

constexpr int MOD       = (int)1e9 + 7;
constexpr int INF_int   = (int)(1 << 30);
constexpr ll INF_ll     = (ll)1e18 + 1;
constexpr ld PI         = 3.141592653589793L;

template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*追加部分*/



/*main関数*/

signed main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    ll a, b, c, d; cin >> a >> b >> c >> d;

    vector<ll> ans;
    ans.pb(a*c);
    ans.pb(a*d);
    ans.pb(b*c);
    ans.pb(b*d);

    sort(all(ans));
    cout << ans[3] << endl;

return 0;
}


Measured memory_bytes: 3708