akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, A[100001], B[100000];
    cin >> N;
    REP(i, N + 1) cin >> A[i];
    REP(i, N) cin >> B[i];
    ll ans = 0;
    REP(i, N) {
        ans += min(A[i], B[i]);
        if (B[i] > A[i]) {
            ans += min(A[i + 1], B[i] - A[i]);
            A[i + 1] -= min(A[i + 1], B[i] - A[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̒萔 (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int> > miti(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;

        a--;
        b--;

        miti[a].emplace_back(b);
        miti[b].emplace_back(a);
    }

    queue<int> room;
    room.push(0);
    vector<int> ans(n, -1);
    while (!room.empty()) {
        int num = room.front();  room.pop();
        for (int i : miti[num]) {
            if (ans[i] != -1) continue;
            ans[i] = num;
            room.push(i);
        }
    }

    cout << "Yes" << endl;
    rep(i, n) {
        if (i == 0) continue;
        cout << ans[i] + 1 << endl;
    }

    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 10208
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
    int n, max_val=-1000000, min_val=1000000, temp;
    long long sum=0;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &temp);
        sum += temp;
        max_val = max(temp, max_val);
        min_val = min(temp, min_val);
    }
    printf("%d %d %lld\n", min_val, max_val, sum);
    return 0;
}



Measured memory_bytes: 2720
#include <bits/stdc++.h>
using namespace std;
float n,a[100005];
float x,y,z;
int main()
{
    cin>>n;
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
        y=(1/a[i]);
        x+=y;
    }
    z=1/x;
    cout<<z;
    return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define MAX ('z' - 'a' + 1)
int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  string S; cin >> S;
  bool flag[MAX]{false};
  for (auto s : S) flag[s - 'a'] = true;
  for (int i{0}; i < MAX; ++i) {
    if (!flag[i]) {
      cout << static_cast<char>('a' + i) << "\n";
      return 0;
    }
  }
  cout << "None\n";
  return 0;
}


Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var Ai = Slist();
            var Bl = new List<Tuple<long, long>>();
            for(var i=0;i<M;++i)
            {
                var BC = Sarray();
                var B = BC[0];
                var C = BC[1];
                Bl.Add(Tuple.Create(B, C));
            }
            Ai.Sort();
            Bl.Sort((l, r) => (int)(r.Item2 - l.Item2));
            for (int i = 0, j = 0; i < Bl.Count; ++i)
            {
                for (var k = 0; k < Bl[i].Item1; ++k, ++j)
                {
                    if (N <= j)
                    {
                        WriteLine(Ai.Sum());
                        return;
                    }
                    if (Ai[j] < Bl[i].Item2)
                        Ai[j] = Bl[i].Item2;
                    else
                    {
                        WriteLine(Ai.Sum());
                        return;
                    }
                }
            }
            WriteLine(Ai.Sum());
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 32560
#include <stdio.h>

int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

int main()
{
    int a, b, c=0, i, j, l, d1, d2, d3, d[10010];
    char ar[13];
    gets(ar);
    l = strlen(ar);
    for(a=0; a<l-2; a++)
    {
        d1 = ar[a] - '1' + 1;
        d2 = ar[a+1] - '1' + 1;
        d3 = ar[a+2] - '1' + 1;
        d[c] = d1*100 + d2*10 + d3;
        d[c] = abs(d[c] - 753);
        c++;
    }
    qsort (d, c, sizeof(int), cmpfunc);
    printf("%d", d[0]);
    return 0;
}

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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");

private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	friend modnum inv(const modnum& m) { return m.inv(); }
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
	friend modnum neg(const modnum& m) { return m.neg(); }

	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<998244353>;

template <typename T> T pow(T a, long long b) {
	assert(b >= 0);
	T r = 1; while (b) { if (b & 1) r *= a; b >>= 1; a *= a; } return r;
}

int main() {
	using namespace std;
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	int N, M, K; cin >> N >> M >> K;
	vector<num> fact(N+1);
	fact[0] = 1;
	for (int i = 1; i <= N; i++) fact[i] = fact[i-1] * num(i);
	vector<num> ifact(N+1);
	ifact[N] = inv(fact[N]);
	for (int i = N; i >= 1; i--) ifact[i-1] = ifact[i] * num(i);

	num ans = 0;
	for (int k = 0; k <= K; k++) {
		num ways = num(M) * pow(num(M-1), N-1-k) * fact[N-1] * ifact[k] * ifact[N-k-1];
		ans += ways;
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 4788
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1){
		cerr << name << " : " << arg1 << std::endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args){
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
	}
#else
#define debug(...)
#endif
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define rall(c) c.rbegin(), c.rend()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
#define init(a, x) memset(a,x,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
// ordered_set X
//K-th smallest
//*X.find_by_order(k-1)
//NO OF ELEMENTS < A
//X.order_of_key(A)
const int L=1e6+7;
ll a[L], m = 1e9+7;
void fff()
{
	ll n, k;
	cin >> n >> k;
	FOR(i,0,n)cin >> a[i];	
	sort(a,a+n);
	if(a[0]>=0)
	{
		ll ans = 1;
		RFOR(i,n-1,n-k)
		{
			ans *= a[i];
			ans %=m;
		}
		cout << ans;
		return;
	}
	if(a[n-1] == 0 && (k&1))
	{
		cout << 0;
		return;
	}
	ll xx;
	if(a[n-1]<=0 && (k&1))
	{
		ll ans = 1;
		RFOR(i,n-1,n-k)
		{
			ans = (ans*a[i]);
			if(ans<0)
			{
				xx = abs(ans)/m;
				xx++;
				ans = (ans + xx*m)%m;
			}
			else ans %=m;
		}
		cout << ans<<ln;
		return;
	}
	ll ans = 1;
	if((k&1))
	{
		ans *= a[n-1];
		ans %=m;
		n--;
		k--;
	}
	ll l = 0, r = n-1;
	while(k>0)
	{
		if(a[l]*a[l+1]>a[r]*a[r-1])
		{
			ans *= a[l];
			if(ans<0)
			{
				xx = abs(ans)/m;
				ans = (ans + xx*m)%m;
			}
			else ans %=m;
			ans *= a[l+1];
			if(ans<0)
			{
				xx = abs(ans)/m;
				xx++;
				ans = (ans + xx*m)%m;
			}
			else ans %=m;
			l += 2;
			k-=2;
		}
		else
		{
			ans *= a[r];
			if(ans<0)
			{
				xx = abs(ans)/m;
				xx++;
				ans = (ans + xx*m)%m;
			}
			else ans %=m;
			ans *= a[r-1];
			if(ans<0)
			{
				xx = abs(ans)/m;
				xx++;
				ans = (ans + xx*m)%m;
			}
			else ans %=m;
			r -= 2;
			k-=2;	
		}
	}
	cout<<ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//int t;cin >> t;while(t--)
	fff();
	return 0;
}

Measured memory_bytes: 5184
import java.util.Scanner;

public class Main {
	private Scanner sc;
	
	int start, goal;
	
	int[][] map;
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		
		while (sc.hasNextLine() == true) {
			int num = Integer.parseInt(sc.nextLine());
			if (num == 0) break;
			
			start = Integer.parseInt(sc.nextLine()) - 1;
			goal = Integer.parseInt(sc.nextLine()) - 1;
			
			int lines = Integer.parseInt(sc.nextLine());
			
			map = new int[lines][num - 1];
			for (int i = 0; i < map.length; i++) {
				String nico = sc.nextLine();
				for (int j = 0; j < map[0].length; j++) {
					map[i][j] = nico.charAt(j) - '0';
				}
			}
			
			String ans = "1";
			for (int i = -1; i < lines; i++) {
				int tmp = judge(i);
				
				if (tmp != -1) {
					if (i == -1) ans = "0";
					else ans = (i + 1) + " " + tmp;
					break;
				}
			}
			System.out.println(ans);
		}
	}
	
	private int judge(int point) {
		int save = 0;
		
		int lim = 1;
		if (point > -1) lim++;
		
		for (int j = 0; j < lim; j++) {
			int p = start;
			
			for (int i = 0; i < map.length; i++) {
				if (p > 0) {
					if ((map[i][p - 1]) == 1) {
						p--;
						continue;
					}
				}
				
				if (p < map[0].length) {
					if (map[i][p] == 1) {
						p++;
						continue;
					}
				}
				
				if (i == point) {
					if (j == 0) {
						if (p == 0) {
							p = -1;
							break;
						}
						if (p > 1) {
							if (map[i][p - 2] == 1) continue;
						}
						
						save = p;
						p--;
					} else {
						if (p == map[0].length) {
							
							p = -1;
							break;
						}
						if (p < (map[0].length - 1))  {
							if (map[i][p + 1] == 1) continue;
						}
						
						p++;
						save = p;
					}
				}
			}
			if (p == goal) return save;
		}
		return -1;
	}
}

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

int main() {
  string x,y;
  cin >> x >> y;
  
  int A = 1;
  int B = 2;
  int C = 3;
  int D = 4;
  int E = 5;
  int F = 6;
 
  if(x < y){
      cout << "<" << endl;
    }
  
  else if(x == y){
    cout << "=" << endl;
  }
  
  else{
    cout << ">" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
}
void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
char S[100010], T[100010];
int A, B, C, D, Q, lenS, lenT, sum1[100010], sum2[100010];
int main(){
  rd(S);
  rd(T);
  rd(Q);
  lenS = strlen(S);
  lenT = strlen(T);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW= 0;Lj4PdHRW< (lenS-1) + 1;Lj4PdHRW++){
      S[Lj4PdHRW] = (S[Lj4PdHRW]=='A')?2:1;
    }
  }
  {
    int KL2GvlyY;
    for(KL2GvlyY= 0;KL2GvlyY< (lenT-1) + 1;KL2GvlyY++){
      T[KL2GvlyY] = (T[KL2GvlyY]=='A')?2:1;
    }
  }
  {
    int Q5VJL1cS;
    for(Q5VJL1cS= 1;Q5VJL1cS< (lenS) + 1;Q5VJL1cS++){
      sum1[Q5VJL1cS] = sum1[Q5VJL1cS - (1) + (0)] + S[Q5VJL1cS - (1) + (0)];
    }
  }
  {
    int e98WHCEY;
    for(e98WHCEY= 1;e98WHCEY< (lenT) + 1;e98WHCEY++){
      sum2[e98WHCEY] = sum2[e98WHCEY - (1) + (0)] + T[e98WHCEY - (1) + (0)];
    }
  }
  while(Q--){
    rd(A);
    rd(B);
    rd(C);
    rd(D);
    if( (sum1[B]-sum1[A-1])%3 == (sum2[D]-sum2[C-1])%3 ){
      wt_L("YES");
      putchar_unlocked('\n');
    }
    else{
      wt_L("NO");
      putchar_unlocked('\n');
    }
  }
  return 0;
}
// cLay varsion 20170408-3

// --- original code ---
// char S[100010], T[100010];
// int lenS, lenT;
// int Q, A, B, C, D;
// 
// int sum1[100010], sum2[100010];
// {
//   rd(S,T,Q);
//   lenS = strlen(S);
//   lenT = strlen(T);
// 
//   S[0..lenS-1] = (S[0..lenS-1]=='A')?2:1;
//   T[0..lenT-1] = (T[0..lenT-1]=='A')?2:1;
//   sum1[1..lenS] = sum1[0..] + S[0..];
//   sum2[1..lenT] = sum2[0..] + T[0..];
//   
//   while(Q--){
//     rd(A,B,C,D);
//     if( (sum1[B]-sum1[A-1])%3 == (sum2[D]-sum2[C-1])%3 ) wt("YES"); else wt("NO");
//   }
// }


Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define ll long long
#define uint unsigned int
#define c_double static_cast<double>
using namespace std;

struct Dmondai {
	int reqtime;
	int deadline;
};

void problem_D() {
	int N;
	cin >> N;
	vector<Dmondai> vec(N);
	for (int i = 0; i < N; i++) {
		cin >> vec[i].reqtime >> vec[i].deadline;
	}
	sort(vec.begin(), vec.end(), [](const Dmondai & left, const Dmondai & right) {return left.deadline < right.deadline; });

	int time_acc = 0;
	for (int i = 0; i < N; i++) {
		time_acc += vec[i].reqtime;
		if (time_acc > vec[i].deadline) {
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
}

int main() {
	problem_D();
}

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

struct Food{
  string name;int w,s;
  Food(string a,int b,int c){name=a;w=b;s=c;};
};

int main()
{
  int n;
  string f;
  int w,s;
  while(cin>>n,n){
    vector<Food>food;
    vector<int>v;
    vector<int>ans;
    for(int i=0;i<n;i++){
      v.push_back(i);
      cin>>f>>w>>s;
      food.push_back(Food(f,w,s));
    }

    double res=1e10;
    do{
      bool ok=true;
      double sum=food[v[n-1]].w;
      double sum2=n*food[v[n-1]].w;
      for(int i=n-2;i>=0;i--){
	if(food[v[i]].s<sum){
	  ok=false;
	  break;
	}
	sum+=food[v[i]].w;
	sum2+=(i+1)*food[v[i]].w;
      }
      if(ok && res>sum2/sum){
	res=sum2/sum;
	ans=v;
      }
    }while(next_permutation(v.begin(),v.end()));

    for(int i=0;i<n;i++){
      cout<<food[ans[i]].name<<endl;
    }
  }
}

Measured memory_bytes: 0
n,a,b = map(int,input().split())
c = list(map(int,input().split()))
ans = 0
for i in range(n-1):
    if (c[i+1] - c[i] ) * a >= b:
        ans += b
    else:
        ans += (c[i+1] - c[i] ) * a
print(ans)

Measured memory_bytes: 14252
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    E = [[] for _ in range(n)]
    edge_to_idx = {}
    for i in range(n - 1):
        u, v = map(int,input().split())
        u -= 1
        v -= 1
        E[u].append(v)
        E[v].append(u)
        edge_to_idx[u, v] = edge_to_idx[v, u] = i

    def path(source, target):
        par = [-1] * n
        stack = [(source, -1)]
        while stack:
            v, p = stack.pop()
            for nv in E[v]:
                if nv == p:
                    continue
                par[nv] = v
                stack.append((nv, v))
        res = 0
        while target != source:
            res |= 1 << edge_to_idx[target, par[target]]
            target = par[target]
        return res

    m = int(input())
    constraints = [None] * m
    for i in range(m):
        u, v = map(int,input().split())
        u -= 1
        v -= 1
        constraints[i] = path(u, v)

    res = 1 << (n - 1)
    # inc - exc principle
    for U in range(1, 1 << m):
        coef = 1 if bin(U).count('1') & 1 else -1
        binary = 0
        for i in range(m):
            if (U >> i) & 1:
                binary |= constraints[i]
        cnt = (n - 1) - bin(binary).count('1')
        res -= coef * (1 << cnt)

    print(res)
resolve()

Measured memory_bytes: 43804
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
object Main extends App {
  import scala.io.StdIn._


  val n = readInt
  val p = readLine.trim.split(' ').map(_.toInt).zipWithIndex.sortBy(_._1).map(_._2 + 1)

  println(makeString(p))
  def makeString(p: Array[Int]): String = {
    val str = Array.tabulate(p.length * 2){_ ⇒ '0'}
    @tailrec
    def sub(position: Int, pos: Int, max: Int = 0, stack: List[Int] = Nil): Boolean = {
      if (position == p.length) {
        for (i ← pos until str.length) str(i) = ')'
        true
      }
      else if (p(position) < max) false
      else {
        stack match {
          case Nil ⇒
            str(pos) = '('
            sub(position + 1, pos + 1, max, p(position)::stack)
          case h::t if h < p(position) ⇒
            str(pos) = ')'
            sub(position, pos + 1, math.max(h, max), t)
          case _ ⇒
            str(pos) = '('
            sub(position + 1, pos + 1, max, p(position)::stack)
        }
      }
    }
    if (sub(0, 0)) str.mkString
    else ":("
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
    @inline
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}


Measured memory_bytes: 117984
a,b,c=map(int,input().split())
if(((a==5)or(a==7)) and ((b==5)or(b==7)) and ((c==5)or(c==7))):
  if(a+b+c==17):
    print("YES")
  else:
    print("NO")
else:
  print("NO")  

Measured memory_bytes: 3060
#include <array>
#include <cassert>
#include <cstdio>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
using namespace std;

bool solve(int h, int w, array<int, 26> cnt) {
    int r1 = (h % 2) * (w % 2);
    int r2 = (h % 2) * (w / 2) + (w % 2) * (h / 2);
    assert  ((h * w - 2 * r2 - r1) % 4 == 0);
    int r4 = (h * w - 2 * r2 - r1) / 4;
    for (int c = 0; r4 --; ) {
        while (c < 26 and cnt[c] < 4) ++ c;
        if (c == 26) return false;
        cnt[c] -= 4;
    }
    for (int c = 0; r2 --; ) {
        while (c < 26 and cnt[c] < 2) ++ c;
        if (c == 26) return false;
        cnt[c] -= 2;
    }
    return true;
}

int main() {
    // input
    int h, w; scanf("%d%d", &h, &w);
    array<int, 26> cnt = {};
    repeat (y, h) repeat (x, w) {
        char c; scanf(" %c", &c);
        cnt[c - 'a'] += 1;
    }
    // solve
    bool result = solve(h, w, cnt);
    // output
    printf("%s\n", result ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int n,m,x;
    cin>>n>>m>>x;
    int c[n];
    int a[n][m];
    rep(i,n){
        cin>>c[i];
        rep(j,m)cin>>a[i][j];
    }
    ll ans=linf;
    rep(i,1<<n){
        ll v=0;
        int sum[m]={};
        rep(j,n){
            if(i&(1<<j)){
                v+=c[j];
                rep(k,m){
                    sum[k]+=a[j][k];
                }
            }
        }
        bool flag=true;
        rep(j,m){
            if(sum[j]<x)flag=false;
        }
        if(flag)ans=min(v,ans);
    }
    if(ans==linf)ans=-1;
    cout<<ans<<endl;
}


Measured memory_bytes: 3620
def fib(n):
    if n == 0 or n == 1:
        return 1
    if A[n] is not None:
        return A[n]
    A[n] = fib(n - 1) + fib(n - 2)
    return A[n]


A = [None] * (44 + 1)
n = int(input())
print(fib(n))

Measured memory_bytes: 7708
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int A, B;
  int C;
  vector<int> ans;
  while(cin>>A>>B){
    C = A+B;
    int i=1;
    int ten=1;
    while(true){
      if(C/ten==0){
        cout<<i-1<<endl;
        break;
      }
      else{
        ten *= 10;
        i++;
      }
    }
  }
}




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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define f first
#define s second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 100500;

ll mx(ll l, ll r){
	ll x = 0;
	for(int i = 0; i < 60; ++i){
		ll z = r;
		if(((r >> i) & 1LL))
			x ^= (1LL << i);
		else{
			z = (z / (1LL << i)) * (1LL << i);
			z--;
			if(l <= z)
				x ^= (1LL << i);
		}
	}
	return x;
}

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

	//cin.tie(NULL);
	//cout.tie(NULL);
	//ios_base::sync_with_stdio(false);

	//cout << setprecision(5) << fixed;

	ll L, r, ans;
	cin >> L >> r;
	
	ans = 1;

	ll l = r;

	while(L < l){
		ll la = 1, ra = l - 1;
		while(la <= ra){
			ll md = (la + ra) >> 1;
			if(mx(md, r) != mx(l, r)){
				la = md + 1;
			}else ra = md - 1;
		}
		la--;
		if(la < L){
			ans += l - L;
			break;
		}
		ans += l - la - 1;
		ll x = mx(la, r) - mx(l, r);
		if(la - x + 1 <= L){
			ans += 2LL * (la - L + 1);
			break;
		}	
		ans += 2LL * x;
		l = la - x + 1;
	}
	 
	cout << ans;

	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
    const int MAX =200002;
const int MOD = 1000000007;

     signed main(){
  int n,ans=0;
  cin>>n;
  int a,k;
  for(int i=0;i<n;i++){
      cin>>a>>k;
      if(k<=10000){
          while(a%k)a-=(a/k +1);
          ans^=(a/k);
      }else{
          int p=a/k;
          while(true){
              if((a-p*k)%(p+1)==0){
                  ans^=p;
                  break;
              }
              a-=((a-p*k)/(p+1)+1);
              p--;
          }
      }
  }
  if(ans)cout<<"Takahashi"<<endl;
  else cout<<"Aoki"<<endl;
 


     }


 


 






    





      

        


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] as = br.readLine().split(" ");
        int a1 = Integer.parseInt(as[0]);
        int a2 = Integer.parseInt(as[1]);
        int a3 = Integer.parseInt(as[2]);
        System.out.println(problem147a(a1, a2, a3));
    }

    private static String problem147a(int a1, int a2, int a3) {
        return( (a1 + a2 + a3) >= 22) ? "bust" : "win";
    }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,v.size())
#define all(v)(v).begin(),(v).end()
#define bit(n)(1ll<<(n))
#define uniq(v)sort(all(v));v.erase(unique(all(v)),v.end())
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,T&&t,U&&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(T&&...t){_print(cout,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#else
template<class...T>void dprint(T&&...t){_print(cerr,t...);}
#endif
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<<(ostream&o,const multiset<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(10);
    int m,d;
    cin>>m>>d;
    int ans=0;
    REP(i,1,d+1){
        if(i%10<2 || i/10<2)continue;
        if(1<=(i/10)*(i%10) && (i/10)*(i%10)<=m){
            ans++;
            dprint((i/10)*(i%10));
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
box = [1,2,3,4,5,6,7,8,9,10, 12, 14, 16,18,15,21,24,27,20,28,32,36,25,30,35,40,45,42,48,54,49,56,63,64,72,81]
if N in box:
  print('Yes')
else:
  print('No')


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


int main(){
    ll n; cin>>n;
    ll p=0,w=0,g=0,y=0;
    rep(i,n){
        char s; cin>>s;
        if(s=='P') p=1;
        else if(s=='W') w=1;
        else if(s=='G') g=1;
        else if(s=='Y') y=1;
    }
    if(p+w+g+y==3) cout<<"Three"<<endl;
    else cout<<"Four"<<endl;
    return 0;
}

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

int main(void){
    int H, W;
        
    string hori;
    int i;
    
    
    while(!cin.eof()){
        cin >> H >> W;
        if(!H && !W) return 0;
        
        hori = string(W, '#');
        cout << hori << endl;
        
        hori = "#" + string(W - 2, '.') + "#";
        
        for(i = 1; i < H - 1; i++){
            cout << hori << endl;
        }
        
        hori = string(W, '#');
        cout << hori << endl;
        
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int GCD(int a, int b) {if(b==0)return a; return GCD(b, a%b);}
int main() {
    int a, b, c; cin >> a >> b >> c;
    int sum = a*10 + b + c;
    sum = max(sum, a + 10*b + c);
    sum = max(sum, a + b + 10*c);
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
    int n,m,x;
    cin >> n >> m;
    int ans = 0;
    for(int i = 0; i < m;i++){
        cin >> x;
        ans += x;
    }
    if(ans > n){
        cout << -1 << endl;
    }else{
        cout << n-ans<< endl;
    }
    return 0;
}


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

int main() {
	int K, A, B;
	cin >> K >> A >> B;

	for (int i = A; i <= B; ++i) {
		if (i % K == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	return 0;
}

Measured memory_bytes: 3132
long long a,b,x,y,t;
long long m(long long a,long long b){return a>b?a:b;}
long long c(long long a,long long b){return a%b?a/b+1:a/b;}
main(){
	gets(&t);
	for(scanf("%lld%lld",&x,&y);~scanf("%lld%lld",&a,&b);){
		t=m(c(x,a),c(y,b));
		x=a*t;
		y=b*t;
	}
	printf("%lld\n",x+y);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <sstream>
// #include <cmath>
// #include <map>
// #include <set>
// #include <deque>
// #include <stack>
// #include <vector>
using namespace std;
#define debug freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
// #define PI acos(-1)
typedef long long ll;
const ll mod=1e9+7;

int N,P[20],Q[20],S[20];
int main()
{
	//debug;
	ios;
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>P[i];
		S[i]=P[i];
	}
	for(int i=0;i<N;i++) cin>>Q[i];
	sort(S,S+N);
	int cnt=1;
	int i;
	int a=0,b=0;
	do
	{
		for(i=0;i<N;i++)
		{
			if(S[i]!=P[i])
				break;
		}
		if(i==N) a=cnt;
		
		for(i=0;i<N;i++)
		{
			if(S[i]!=Q[i])
				break;
		}
		if(i==N) b=cnt;
		cnt++;
	}while(next_permutation(S,S+N));
	cout<<abs(a-b);
    return 0;
}


Measured memory_bytes: 3588
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    s = str(input().rstrip('\n'))
    print("Yes" if s.count("R") > s.count("B") else "No")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define dmp(x) cerr<<#x<<":"<<x<<endl
#define FOR(i,a,b) for(int i=(int)a,c=(int)b;i<c;++i)
#define rep(i,b) FOR(i,0,b)
#define ROF(i,a,b) for(int i=b-1,c=(int)a;i>=c;--i)
#define per(i,b) ROF(i,0,b)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

signed main(){
  int n,k;
  string s;
  cin>>n>>k>>s;
  s[k-1]+='a'-'A';
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int r,a;
    while(cin>>r>>a,r||a){
        int h,b;
        h=b=0;
        int t[4],w[4];
        for(int i=0,er=1000;i<4;i++,er/=10){
            t[i]=r/er;
            r-=t[i]*er;
            w[i]=a/er;
            a-=w[i]*er;
        }

        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                if(t[i]==w[j]){
                    if(i==j)h++;
                    else b++;
                    break;
                }
            }
        }
        cout<<h<<" "<<b<<endl;
    }
}

Measured memory_bytes: 1160
n,m = (int(i) for i in input().split())
array = [[int(i) for i in input().split()] for i in range(n)]
b = [int(input()) for i in range(m)]
for i in range(n):
    ans = 0
    for i2 in range(m):
        ans += array[i][i2]*b[i2]
    print(ans)

Measured memory_bytes: 8024
# include <cstring>
# include <cstdio>
# include <iostream>
# include <queue>
# define N 100050 //N为顶点个数 
# define M 200050 //N为顶点个数 
# define WQD 0x7f7f7f7f//无穷大 
int n;//图的顶点个数
int m;//图的边数 
struct Edge{int next,to, w;}  e[M<<1];//不用0号单元 
int head[N+1]; 
int dis[N+1];//存放源点到其他点的路径
bool vis[N+1];
bool book[N+1];
bool spfa(int s);//差分约束判断 
using namespace std;
int main()
{
	ios::sync_with_stdio ( false ) ;
	int u,v,w;
	memset(head,-1,sizeof(head));
	cin>>n>>m;
	for(int i=1; i<=m; i++)  //本题约束关系为=，要添加两条边 
	{
		cin>>u>>v>>w;//输入第i条边 ,i为编号 
		e[i]=(Edge){head[u],v,w};head[u]=i;
		e[m+i]=(Edge){head[v],u,-w};head[v]=m+i;
	}
	memset(book,0,sizeof(book));
	memset(dis,0x7f,sizeof(dis));
	for(int i=1; i<=n; i++)//每一个点都要校验到 
		if(!vis[i]) //如果i点没有校验，就用spfa校验和i点连通的区域 
		{
			vis[i]=1;
			if(spfa(i)==false)  {cout<<"No";return 0;}//有约束自相矛盾 
		}
	cout<<"Yes";//所有的点都符合条件 
	return 0;
}
bool spfa(int s)
{
 	queue<int>q;
 	//memset(book,0,sizeof(book));
	//memset(dis,0x7f,sizeof(dis));
	dis[s]=0;
	q.push(s);book[s]=1;	
	//如果没松弛就松弛，如果松弛过就判断是否符合约束条件，如果自相矛盾就是不可能的数据
	while(q.size()>0) 
	{
		int k=q.front();q.pop();//对头元素出队 
		book[k]=0;
		for(int i=head[k]; i!=-1; i=e[i].next)
		{
			int v=e[i].to;
			//题目的约束条件是= ，不相等，自相矛盾 
			if(dis[v]<WQD && dis[k]<WQD && dis[v]!=dis[k]+e[i].w)	return false;
			else if(dis[v]==WQD && dis[k]<WQD)//如果v点没松弛过，就松弛更新dis[v]的值 				
			{				
				dis[v]=dis[k]+e[i].w;//更新 
				if(book[v]==0)	{q.push(v);	book[v]=1;}//入队标记
				vis[v]=1;//标记该点已经检验过 
			}
			
		}		
    }
	return true;//别掉了这句 
}

Measured memory_bytes: 6908
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
struct Baby{
    ll idx0,actv;
    bool operator>(const Baby& r) const{
        return actv>r.actv;
    }
};
int main(void){
    ll N;cin>>N;
    vector<Baby> v;
    REP(i,N){
        ll a;cin>>a;
        v.push_back({i,a});
    }
    sort(ALLv(v),greater<Baby>());
    /*cout<<v[0].idx<<" "<<v[0].actv<<"\n";
    cout<<v[3].idx<<" "<<v[3].actv<<"\n";*/
    
    vector<vi> dp=vector<vi>(2001,vi(2001,0));ll ans=0;
    REP(l,N){
        REP(r,N){
            if(l+r==N){
                ans=max(ans,dp[l][r]);
                break;
            }
            ll idx=l+r;
            dp[l+1][r]=max(
                dp[l+1][r],
                dp[l][r]    + v[idx].actv * abs(v[idx].idx0-l)
            );
            dp[l][r+1]=max(
                dp[l][r+1],
                dp[l][r]    + v[idx].actv * abs(v[idx].idx0-(N-1-r) )
            );
        }
    }
    cout<<ans<<"\n";
}

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

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


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


int main() {
    ll N;
    cin >>N;
	vector<ll> p(N+1);
    repn(i,N) cin >>p[i];

    ll ans=0;

    ll v=0;

    repn(i,N){
        if(p[i]==i){v++;}
        if(i==N||p[i]!=i){ans+=(v+1)/2; v=0;}
    }

    cout <<ans;

}


Measured memory_bytes: 1024
import numpy as np

N,M,Q,*LRpq = map(int,open(0).read().split())
LR = LRpq[:2*M]
pq = LRpq[2*M:]

train_count = np.zeros((N,N),int)

for l,r in zip(LR[::2],LR[1::2]):
    train_count[l-1,r-1] += 1

query_ans = train_count[::-1,].cumsum(axis=0)[::-1,].cumsum(axis=1)

for p,q in zip(pq[::2],pq[1::2]):
    print(query_ans[p-1,q-1])

Measured memory_bytes: 66940
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


ll dp[101010][3];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<int>> a(N+5,vector<int>(3));
    REP(i,N) REP(j,3) cin >> a[i][j];
    
    for(int i=0;i<N;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j != k) chmax(dp[i+1][k], dp[i][j] + a[i][k]);
            }
        }
    }
    ll ans = 0;
    REP(i,3) chmax(ans, dp[N][i]);
    cout << ans << endl;
}

Measured memory_bytes: 8064
import numpy as np
N, K = map(int, input().split())
ub = K * 2
b = [[0 for j in range(ub + 1)] for i in range(ub + 1)]
ADD = {"B": 0, "W": K}

def create_bound(p, K, ub):
	if p - K + 1 >= 0:
		return [(p - K + 1, p + 1)]
	else:
		return [(0, p + 1), ((p - K + 1) % ub, ub)]

for i in range(N):
	x, y, c = input().split()
	nx = int(x) % ub
	ny = (int(y) + ADD[c]) % ub
	for add in [0, K]:
		for xlb, xub in create_bound((nx + add) % ub, K, ub):
			for ylb, yub in create_bound((ny + add) % ub, K, ub):
				b[xlb][ylb] += 1
				b[xlb][yub] -= 1
				b[xub][ylb] -= 1
				b[xub][yub] += 1

b_arr = np.array(b)
for i in range(ub):
	b_arr[i + 1, :] += b_arr[i, :]
for j in range(ub):
	b_arr[:, j + 1] += b_arr[:, j]
print(b_arr.max())


Measured memory_bytes: 75996
class FUnionFind
  attr_reader :nodes, :parents, :ranks

  def initialize(n)
    @parents = (0...n).to_a
    @nodes = @parents.map{ |x| [x] }
  end

  def find(i)
    @parents[i]
  end

  def union(i,j)
    i = @parents[i]; j = @parents[j]
    return if i == j
    j,i = i,j if @nodes[i].size < @nodes[j].size
    #p [i,j,@nodes[i],@nodes[j]]
    #p [i,j,@nodes[i].size,@nodes[j].size]
    @nodes[j].each{ |k| @parents[k] = i }
    @nodes[i].concat(@nodes[j])
    @nodes[j].clear
  end
end

N,M = gets.split.map &:to_i
uf = FUnionFind.new(N)
M.times {
  u,v = gets.split.map &:to_i
  uf.union(u-1,v-1)
}

n0,n1,o = 0,0,0
u0,u1 = uf.find(0),uf.find(1)
(0...N).each{ |n|
  #p [n, uf.find(n)]
  case uf.find(n)
  when u0; n0 += 1
  when u1; n1 += 1
  else      o += 1
  end
}
#$stderr.puts N - (n0+n1+o)
n0,n1 = n1,n0 if n0 > n1
p n0*(n0-1)/2 + (n1+o)*(n1+o-1)/2 - M

Measured memory_bytes: 13436
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    //    ifstream in("input.txt");
    //    cin.rdbuf(in.rdbuf());
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    
    int cnt = 0;
    rep(i, n)
    {
        while(a[i] % 2 == 0)
        {
            a[i] /= 2;
            ++cnt;
        }
    }
    
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll N,K,Q;
    cin>>N>>K>>Q;
    VL B(N,K-Q);
    VL A(Q);
    //問題通りだとO(NQ)でout
    rep(i,0,Q)cin>>A[i];
    rep(i,0,Q){
        B[A[i]-1]++;        
    }
    rep(i,0,N){
        if(B[i]>0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 2176
use std::io::*;
use std::str::FromStr;

fn fact(n: usize) -> usize {
    let mut res = 1;
    for i in 2..n+1 {
        res *= i;
    }
    return res;
}

fn po(n: usize, now: usize, d: &Vec<Vec<f64>>, list: &Vec<bool>) -> f64 {
    let mut sum = 0.0;
    let mut remain = 0;
    for i in 0..n {
        if !list[i] && i != now {
            remain += 1;
        }
    }

    for i in 0..n {
        if !list[i] && i != now {
            let mut l = list.clone();
            l[i] = true;
            sum += d[now][i] * fact(remain-1) as f64 + po(n, i, &d, &l);
        }
    }
    return sum;
}

fn main() {
    let n: usize = read();
    let mut x: Vec<i64> = vec![0; n];
    let mut y: Vec<i64> = vec![0; n];

    for i in 0..n {
        x[i] = read();
        y[i] = read();
    }

    let mut d: Vec<Vec<f64>> = vec![vec![0.0; n]; n];
    for i in 0..n {
        for j in i+1..n {
            let dx = x[i] - x[j];
            let dy = y[i] - y[j];
            let dis = ((dx*dx + dy*dy) as f64).sqrt();
            d[i][j] = dis;
            d[j][i] = dis;
        }
    }

    let mut sum = 0.0;
    for i in 0..n {
        let mut list = vec![false; n];
        list[i] = true;
        sum += po(n, i, &d, &list);
    }

    let fact = fact(n);

    println!("{}", sum / fact as f64)
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    char S[4];
    int result = 0;
    scanf("%s", S);
    
    for (int i = 0; i < 4; i++) {
        if (S[i] == '+') {
            result++;
        } else {
            result--;
        }
    }
    
    printf("%d", result);
    
    return 0;
}

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

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> Pair;
typedef vector<Pair> VP;

#define MOD 1000000007
#define times(n) rep(_idx, n)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mk make_pair
#define out(x) cout << (x) << endl;
#define DU(x) cerr << #x << " = " << (x) << endl;

template<typename _Ty>ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "[]";return ostr;}ostr << "[" << v.front();for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}ostr << "]";return ostr;}


int main() {
    int N;
    cin >> N;
    out(pow(N, 3));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int count=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size()/2;i++)
    {
        if(s[i]!=s[s.size()-i-1])
        {
            count++;
        }
    }
    cout<<count;
}


Measured memory_bytes: 256