akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

const double PI = acos(-1.0), EPS = 1e-6;
const long long inf = 2e12 + 12;
const int MAXN = 200005, MAXM = 100005, Mod = 1000000007 , MAXLog = 20;

int Fact[MAXN], FactInv[MAXN];

int mul(int x, int y) {
    return 1LL * x * y % Mod;
}

int add(int x, int y) {
    return (0LL + x + y) % Mod;
}

int power(int b, int e, int mod) {
    if (e == 0) return 1;
    int x = power(b, e >> 1, mod);
    x = 1LL * x * x % mod;
    if (e & 1)
        x = 1LL * x * b % mod;

    return x;
}

int nCr(int n, int r) {
    if (n < r)
        return 0;
    return mul(Fact[n], mul(FactInv[r], FactInv[n - r]));
}


void pre(int H, int W) {
    Fact[0] = 1;
    FactInv[0] = 1;
    for (int i = 1; i <= H + W; ++i){
        Fact[i] = mul(Fact[i - 1], i);
        FactInv[i] = power(Fact[i], Mod - 2, Mod);
    }
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int H, W, A, B;
    cin >> H >> W >> A >> B;
    pre(H, W);
    int X = H - A;
    int Y = W - B;
    int ans = 0;
    for (int i = 0; i < X; ++i) {
        ans = add(ans, mul(nCr(i + B - 1, i), nCr(H - i + Y - 2, H - 1 - i)));
    }

    cout << ans << '\n';


    // X = H - A + 1
    // Y = W - B + 1
    // sum from i = 0 to i = X - 1
    // i + 1 + B - 2 C i * H - 1 - i + Y C H - i - 1


    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define fill(a,val) memset(a,val,sizeof(a))
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define pb push_back
#define SQ(a) (a)*(a)

#define M 315
using namespace std;
 

int main()
{
    std::ios::sync_with_stdio(false);
    int T = 1;
    //cin>>T;
    while(T--)
    {
       int n,k;
       cin>>n>>k;
       vector<int> a(n);
       for(int i = 0;i<n;i++)
       {
        cin>>a[i];
       }
       sort(a.begin(),a.end());
       int ans = 0;
       for(int  i = 0;i<k;i++)
       {
            ans+=a[i];
       }
       cout<<ans;
    }   
    
    return 0;
}


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

int main(){
  int n,m;
  cin >> n;
  int ans = 0;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
      cin >> a[i];
  }
  cin >> m;
  vector<int> b(m);
  for(int i = 0; i < m; i++){
      cin >> b[i];
      for(int j = 0; j < n; j++){
          if(a[j] == b[i]){
              ans ++;
              break;
          }
      }
  }
  
  
  cout << ans << endl;
}


Measured memory_bytes: 3088
#pragma GCC optimize ("O3")
#define _CRT_DISABLE_PERFCRIT_LOCKS
#include <bits/stdc++.h>

using namespace std;
#define BOOST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define fileIn freopen("1.txt", "r", stdin)
#define fileOut freopen("output.txt", "w", stdout)
#define dbg(n) cout << n <<"\n"
#define dbg2(n) cout << n <<" "
#define all(a) a.begin(), a.end()
#define cinArr(arr) for(auto &v : arr) cin>>v
#define coutArr(arr) for(auto &v : arr) cout<<v<<" "
#define FOR(i, a, b) for(int i = a; i < b; i++)
typedef int64_t ll;
typedef uint64_t ull;
typedef vector<int> vi;
typedef vector<vi > vii;


int main()
{
    BOOST;
    int n;
    cin>>n;
    vi va(n), c(n);
    cinArr(va);
    cinArr(c);
    int ans = 0;
    FOR(i, 0, n){
        if(va[i] - c[i] > 0) ans += va[i] - c[i];
    }
    cout<<ans;
    return 0;
}





















Measured memory_bytes: 256
#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__)
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    int n, s = 0;
    cin >> n;
    for(int i = n; i > 0;){
        s += i % 10;
        i /= 10;
    }
    if(n % s == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p, a, b) for (ll p = a; p < b; p++)
#define F first
#define S second
using namespace std;

typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<ld> vld;
typedef pair<ll, ll> pll;

int main()
{
    ll t, i, j, k, ans, n, m, sum = 0, x;

    //cin>>t;
    t = 1;
    while (t--)
    {
        cin >> n >> m;
        string s;
        vll wa(n + 1), ac(n + 1);

        ll c1 = 0, c2 = 0;
        rep(p, 0, m)
        {
            cin >> x >> s;
            if (s == "WA")
                wa[x]++;
            else
            {
                if (ac[x] == 0)
                {
                    c1++;
                    c2 += wa[x];
                    ac[x] = 1;
                }
            }
        }

        cout << c1 << " " << c2;
    }

    return 0;
}


Measured memory_bytes: 4752
s=input()
x=0;y=0
for i in range(len(s)):
  if s[i]=='C':
    x=i+1
    break
for j in range(len(s)):
  if s[j]=='F':
    y=j+1
if x*y!=0 and x<y:print('Yes')
else:print('No')

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

public class Main{

    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] a = new int[n];
        String[] t = br.readLine().split(" ");
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(t[i]);
        }

        selectionSort(a, n);
    }

    public static void selectionSort(int[] a, int n){
        int minj, temp = 0, count = 0;
        for(int i = 0; i < n; i++){
            minj = i;
            for(int j = i; j < n; j++){
                if(a[j] < a[minj]){
                    minj = j;
                }
            }
            if(i != minj)count++;
            temp = a[i];
            a[i] = a[minj];
            a[minj] = temp;
        }
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < n; i++){
            if(i != 0)sb.append(" ");
            sb.append(a[i]);
        }
        sb.append("\n").append(count);
        System.out.println(sb);
    }

}

Measured memory_bytes: 24340
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		Set<Integer> set = new HashSet<>();

		//入力値取得
		int N = scan.nextInt();

		Set<Integer> AList = new TreeSet<>();
		Set<Integer> dpl = new HashSet<>();

		for (int i = 0; i < N; i++) {
			int A = scan.nextInt();

			if (dpl.contains(A)) {
				set.add(A);
			} else {
				dpl.add(A);
				AList.add(A);
			}
		}

		//WK変数
		Set<Integer> ald = new HashSet<>();

		for (int A : AList) {
			if (!ald.contains(A)) {
				for (int j = 2; j * A <= 1000000; j++) {
					set.add(j * A);
					ald.add(j * A);
				}
			}
		}

		//演算
		int result = 0;

		for (int A : AList) {
			if (!set.contains(A)) {
				result++;
			}
		}

		//結果出力
		System.out.println(result);
	}
}

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

int main(){
    long long a=0,b=0,A=0,B=0,ans=0;

    cin >> a >> b;
    for (int i=0;i<b;i++){
        A = A*10 + a;
    }
    for (int i=0;i<a;i++){
        B = B*10 + b;
    }
    if(B<A){
        cout << A << endl;
    } else{
        cout << B << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,t,x,y;
    cin>>n>>t;
    vector<ll>v;
    for(ll i=0;i<n;i++)
    {
        cin>>x>>y;
        if(y<=t) v.push_back(x);
    }
    sort(v.begin(),v.end());
    if(v.size()==0) cout<<"TLE"<<endl;
    else cout<<v[0]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;

int main()
{
	string O, E;
	cin >> O >> E;

	string res = "";
	for (size_t i = 0; i < O.size(); i++) {
		res += O[i];
		if (i < E.size())
			res += E[i];
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())

mod = 10 ** 9 + 7

def mod_pow(x:int, y:int):
    if y % 2 == 0:
        return (mod_pow(x, y // 2) ** 2) % mod
    elif y == 1:
        return x % mod
    else:
        return ((mod_pow(x, y // 2) ** 2) * x) % mod

def mod_inverse(a:int):
    return (mod_pow(a, mod - 2)) % mod

def mod_nCr(n:int, r:int):
    num, den = 1, 1
    for i in range(r):
        num = (num * (n - i)) % mod
        den = (den * (r - i)) % mod
    return (num * mod_inverse(den)) % mod

ans = (mod_pow(2, n) - mod_nCr(n, a) - mod_nCr(n, b) - 1)  % mod
print(ans)

Measured memory_bytes: 3064
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

ll solve(string s, int k) {
    ll n = s.size();
    if (n < k) return 0;
    if (s[0] == '0') return solve(s.substr(1, n - 1), k);

    ll ans = 0;
    if (k == 1) {
        ans += s[0] - '0';
        ans += (n - 1) * 9;
    } else if (k == 2) {
        ans += (s[0] - '0' - 1) * 9 * (n - 1);
        ans += 81 * (n - 1) * (n - 2) / 2;
        string t = s.substr(1, n - 1);
        ans += solve(t, 1);
    } else if (k == 3) {
        ans += (s[0] - '0' - 1) * 81 * (n - 1) * (n - 2) / 2;
        ans += 729 * (n - 1) * (n - 2) * (n - 3) / 6;
        string t = s.substr(1, n - 1);
        ans += solve(t, 2);
    }

    return ans;
}

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

    string s;
    int k;
    cin >> s >> k;

    cout << solve(s, k) << "\n";
    return 0;
}

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

int main() {
	int n, s;
	int  i;
	int max, min;
	int sum;
	int avg;
	while(cin >> n, n != 0) {
		sum = max = 0;
		min = 11111;
		for(i=0;i<n;i++) {
			cin >> s;
			max = (s > max)?s:max;
			min = (s < min)?s:min;
			sum += s;
		}
		avg = (sum-max-min)/(n-2);
		cout << avg << endl;
	}
	return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, int> pli;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MN = 100010;

int N;
ll D[MN];
int sz[MN];
vi g[MN];
ll val[MN];

ll sum;

int dfs(int v, int p) {
	int t = 1;
	for (int to : g[v]) if (to != p) {
		int num = dfs(to, v);
		sum += (ll)num * (N - num);
		t += num;
	}
	return t;
}

int main() {
	cin >> N;

	map<ll, int> T;
	rep(i, N) {
		cin >> D[i];
		sz[i] = 1;
		T[D[i]] = i;
	}

	vector<pii> es;

	rep(tt, N - 1) {
		auto it = T.end(); --it;

		int v = it->se;
		ll d = it->fi;
		ll up = d - (N - sz[v] * 2);

		T.erase(d);

		if (!T.count(up)) {
			puts("-1");
			return 0;
		}

		int p = T[up];
		g[p].pb(v);
		g[v].pb(p);
		es.eb(v, p);
		sz[p] += sz[v];
	}

	dfs(0, -1);
	ll s = 0;
	rep(i, N) s += D[i];

	if (s != sum * 2) {
		puts("-1");
		return 0;
	}

	rep(i, N-1) {
		printf("%d %d\n", es[i].fi + 1, es[i].se + 1);
	}

	return 0;
}

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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, rev;
    long double cap;
	Edge(ll _to, long double _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, long double cap, bool revFlag, long double revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
	ll n=5;
	vec<ll> x(5);
	REP(i,n) cin>>x[i];
	REP(i,n) if(x[i]==0){
		cout<<i+1<<en;
		return;
	}
}

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

	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}


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


int main()
{
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (y-r >= 0 && y+r <= H && x-r >= 0 && x+r <= W)	
		cout << "Yes" << endl;
	else 
		cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 3124
/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define PB push_back
#define E end()
#define PB push_back
typedef vector<ll> vctr;
#define REP(i,a,b) for (long long i = a; i < b; i++)
#define RREP(i,a,b) for (long long i = a; i > b; i--)
#define buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');


/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
void solve() {
	string s;
	cin>>s;
	if(s[s.size()-1]=='s'){
		s+="es";
	}
	else{
		s+="s";
	}
	cout<<s;
}




int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
// online submission
#endif
	long long test;
	test = 1;
	// cin >> test;
	while (test--) {
		solve();
		// cout << "\n";
	}


}

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

int main()
{
  int M, D;
  cin >> M >> D;
  int cnt = 0;
  for (int i = 1; i <= M; i++)
  {
    for (int j = 1; j <= D; j++)
    {
      int tempi = i;
      int m = tempi;
      int tempj = j;
      int d1 = tempj % 10;
      tempj /= 10;
      int d10 = tempj % 10;
      if (d1 >= 2 and d10 >= 2 and d1 * d10 == m)
        cnt++;
    }
  }
  cout << cnt << endl;
}


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

int main(){
	string s1,s2;
	cin>>s1>>s2;

	int c=0;
	for(int i=0;i<s1.length();i++){
		if(s1[i]==s2[i])
			c++;
	}
	cout<<c<<endl;
	return 0;
}


Measured memory_bytes: 256
/*
  Contest 063
  A - Restricted
  Rakesh Kumar --> 28/08/2020
 */

#include <bits/stdc++.h>



int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0); std::cout.tie(0);

    int a = 0, b = 0;
    std::cin >> a >> b;
    if (a + b < 10)
        std::cout << a + b << std::endl;
    else
        std::cout << "error" << std::endl;

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>

using namespace std;

struct Node {
    int parent;
    int left;
    int right;

    Node() : parent(-1), left(-1), right(-1) {}
};

void print_preorder(vector<Node>& tree, int index) {
    if (index == -1)
        return;

    cout << ' ' << index;
    print_preorder(tree, tree[index].left);
    print_preorder(tree, tree[index].right);
}

void print_inorder(vector<Node>& tree, int index) {
    if (index == -1)
        return;

    print_inorder(tree, tree[index].left);
    cout << ' ' << index;
    print_inorder(tree, tree[index].right);
}

void print_postorder(vector<Node>& tree, int index) {
    if (index == -1)
        return;

    print_postorder(tree, tree[index].left);
    print_postorder(tree, tree[index].right);
    cout << ' ' << index;
}

int find_root(vector<Node>& tree) {
    int root = -1;
    for (int i = 0; i < tree.size(); ++i) {
        if (tree[i].parent == -1) {
            root = i;
            break;
        }
    }
    return root;
}

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

    vector<Node> tree(n);
    for (int i = 0; i < n; ++i) {
        int id;
        cin >> id;
        cin >> tree[id].left >> tree[id].right;
        tree[tree[id].left].parent = id;
        tree[tree[id].right].parent = id;
    }

    int root = find_root(tree);

    cout << "Preorder\n";
    print_preorder(tree, root);
    cout << '\n';

    cout << "Inorder\n";
    print_inorder(tree, root);
    cout << '\n';

    cout << "Postorder\n";
    print_postorder(tree, root);
    cout << '\n';
}



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

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



    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    
    int A,B,C,D,i;

    cin >>A>>B>>C>>D;

    while(1){
        
        C = C - B;
        if(C <=0 )
            break;
        A = A - D;
        if( A <= 0)
            break;
    }
    
    if(A <= 0){
        cout << "No"<<endl;
    }
    else
    {
        cout <<"Yes"<<endl;
    }
    

    return 0;
}

Measured memory_bytes: 3648
N = int(input())


def dfs(x):
    if x > N:
        return 0
    s = str(x)
    if s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0:
        ret = 1
        # print(x)
    else:
        ret = 0
    ret += dfs(10 * x + 7)
    ret += dfs(10 * x + 5)
    ret += dfs(10 * x + 3)
    return ret


print(dfs(0))



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
bool oper( char c)
{
    if(c=='A')
    return true;
    if(c=='T')
      return true;
     if(c=='G')
      return true;
     if(c=='C')
     return true;
    return false;
}
int main()
{
     string s;
     cin>>s;
     int maxs=0,sum=0;
     for(int i=0;i<s.length();i++)
     {
         if(oper(s[i]))
             sum++;
         else
         {  maxs=max(maxs,sum);
             sum=0;
         }

     }
      maxs=max(maxs,sum);
     cout<<maxs<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

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; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

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

  int n;
  cin >> n;
  vector<vector<pair<int, int>>> c(n);
  rep(i, n) {
    int a; cin >> a;
    rep(j, a) {
      int x, y; cin >> x >> y;
      c[i].emplace_back(x-1, y);
    }
  }

  int ans = 0;
  for (int i = 0; i < (1L<<n); i++) {
    bool flag = true;
    rep(j, n) {
      bool m = true;
      for (auto& p : c[j]) {
        if (((i>>p.first) & 1) != p.second) m = false;
      }
      if (((i>>j) & 1) != m) flag = false;
    }
    if (flag) {
      bitset<16> bs(i);
      chmax(ans, int(bs.count()));
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("6");
            WillReturn.Add("3 1 2 4 2 1");
            //2
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("4");
            WillReturn.Add("1 2 3 4");
            //0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("10");
            WillReturn.Add("3 3 3 3 4 4 4 5 5 5");
            //20
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        checked {
            List<string> InputList = GetInputList();
            long[] AArr = InputList[1].Split(' ').Select(X => long.Parse(X)).ToArray();

            var Query = AArr.GroupBy(A => A).OrderByDescending(A => A.Key);
            var HenList = new List<long>();

            foreach (var EachItem in Query) {
                if (EachItem.Count() >= 4) {
                    HenList.Add(EachItem.Key);
                    HenList.Add(EachItem.Key);
                }
                else if (EachItem.Count() >= 2) {
                    HenList.Add(EachItem.Key);
                }
                if (HenList.Count >= 2) break;
            }

            if (HenList.Count >= 2) {
                Console.WriteLine(HenList[0] * HenList[1]);
            }
            else Console.WriteLine(0);
        }
    }   
}


Measured memory_bytes: 31068
#include <stdio.h>
#include <algorithm>

using namespace std;

int main() {
    int a[4];
    for (int i = 0; i < 4; i++) {
        scanf("%d", &a[i]);
    }
    sort(a, a + 4);
    puts(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9 ? "YES" : "NO");
    return 0;
}


Measured memory_bytes: 128
n, a, b = map(int, input().split())
N = range(1, n+1)
ans = 0
for n in N:
    s = 0
    q, mod = divmod(n, 10)
    s += mod
    q, mod = divmod(q, 10)
    s += mod
    while q != 0:
        q, mod = divmod(q, 10)
        s += mod
    if a <= s and s <= b:
        ans += n
print(ans)

Measured memory_bytes: 3064
import           Control.Monad
import qualified Data.ByteString.Char8       as BS
import           Data.Maybe
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine

main = do
  n <- getInt

  as <- VM.new (n+1)
  VM.write as n (0::Int)

  forM_ [0..(n-1)] $ \i -> do a <- getInt
                              VM.write as i a
  let solve i npairs | i == n = return npairs
                     | otherwise = do
                         ai <- VM.read as i
                         ai1 <- VM.read as (i+1)
                         if ai >= 2
                           then do let m = ai `div` 2
                                   VM.write as i (ai-2*m)
                                   solve i (npairs + m)
                           else if ai == 1 && ai1 > 0
                                then do VM.write as i (0::Int)
                                        VM.write as (i+1) (ai1 - 1)
                                        solve (i+1) (npairs+1)
                                else solve (i+1) npairs

  ans <- solve 0 0
  print ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  int A[N];
  rep(i,N) cin >> A[i];
  int sum[N];
  sum[0] = A[0];
  for(int i=1;i<N;i++){
    sum[i] = sum[i-1] + A[i];
  }
  int a = sum[N-1] / N;
  int b = (sum[N-1] + N-1) / N;
  int ans1{}, ans2{};
  rep(i,N){
    ans1 += (a-A[i]) * (a-A[i]);
    ans2 += (b-A[i]) * (b-A[i]);
  }
  cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,coun=0;
    //cin>>n;

    for(int i=1;i<=5;i++)
    {
        cin>>x;
        if(x==0){
            cout<<i<<endl;
            return 0;
        }
    }

}


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

typedef struct sp {
    int number;
    string name;
    int point;
} Data;


int com(const void *a, const void *b) {
    Data da = *(Data *)a;
    Data db = *(Data *)b;
    if(da.name == db.name) return db.point - da.point;
    else if(da.name > db.name) return 1;
    else if(da.name < db.name) return -1;
}

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

    Data a[n];
    for(int i = 0; i < n; i++) {
        a[i].number = i + 1;
        cin >> a[i].name;
        cin >> a[i].point;
    }

    qsort(a, n, sizeof(Data), com);

    for(int i = 0; i < n; i++) {
        cout << a[i].number << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toLong() }.sortedDescending()
    var ans = 0L
    val q = ArrayDeque<Long>()
    q.add(a[0])
    for (i in 1 until n) {
        ans += q.poll()
        q.add(a[i])
        q.add(a[i])
    }
    println(ans)
}


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


/********************************************************************/
#define M1 1000000007
#define M2 998244353
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPR(i,a,b) for(ll i=b-1;i>=a;i--)
#define forr(i,n) for(ll i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
#define DB pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<ll>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)
void FAST() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y % x, x);
}

ll powM(ll x, ll y, ll m) {
	ll ans = 1, r = 1;
	x %= m;
	while (r > 0 && r <= y)
	{
		if (r & y)
		{
			ans *= x;
			ans %= m;
		}
		r <<= 1;
		x *= x;
		x %= m;
	}
	return ans;
}

map<long long, long long> factorize(long long n) {
	map<long long, long long> ans;
	for (long long i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ans[i]++;
			n /= i;
		}
	}
	if (n > 1) {
		ans[n]++;
		n = 1;
	}
	return ans;
}
/* **********END OF TEMPLATE*********** */
int main() {
	FAST();
	ll k;
	cin >> k;
	string s;
	cin >> s;
	ll n = s.size();
	if (n <= k)
		cout << s;
	else {
		for (int i = 0; i < k; i++)
			cout << s[i];
		cout << "...";
	}
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  




void solve(){
	int k , n ; 
	cin >> k >> n ; 
	vi v(n) ; re(v);
	vi dif ; 
	rep(i,1,n){
		dif.pb(v[i] - v[i-1]);
	}
	dif.pb(v[0]-v[n-1]+k);
	int tot = accumulate(all(dif),0);
	int ans = MOD ;
	trav(i,dif){
		ans = min(ans,tot-i);
	}
	cout << ans << endl;
}


signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 6896
#include <iostream>
#include <algorithm>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int mod = 1000000007;

int calc(int keta, int lowerX, int upperY) {
	int dp[61][2][2] = {0};
	int i, j, k, nx, ny;
	
	dp[keta][0][0] = 1;
	for (i = keta; i > 0; i--) {
		int digX = (lowerX >> (i - 1)) % 2;
		int digY = (upperY >> (i - 1)) % 2;
		rep(j, 2) {
			rep(k, 2) {
				rep(nx, 2) {
					if (j == 0 && nx == 0 && digX == 1) {
						continue;
					}
					rep(ny, 2) {
						if (nx == 1 && ny == 0) continue;
						if (k == 0 && ny == 1 && digY == 0) {
							continue;
						}
						
						int nj = ((j == 1) || (nx > digX));
						int nk = ((k == 1) || (ny < digY));
						
						(dp[i - 1][nj][nk] += dp[i][j][k]) %= mod;
					}
				}
			}
		}
	}
	
	//dp[0][*][*]
	int ret = 0;
	rep(j, 2) rep(k, 2) ret += dp[0][j][k];
	ret %= mod;
	return ret;
}

signed main() {
	int l, r;
	cin >> l >> r;
	
	int ans = 0;
	for (int i = 0; i < 60; i++) {
		int lowerX = l - (1LL << i);
		int upperY = r - (1LL << i);
		if (upperY < 0 || lowerX >= (1LL << i)) continue;
		lowerX = max(0LL, lowerX);
		upperY = min((1LL << i) - 1, upperY);
		int res = calc(i, lowerX, upperY);
		ans += res;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int w,h,n,x,y,a,cnt,box[101][101],i,j,k;
	cnt=0;
	scanf("%d %d %d",&w,&h,&n);
	for(i=1;i<=h;i++){
		for(j=1;j<=w;j++){
			box[i][j]=0;
		}
	}
	for(i=1;i<=n;i++){
		scanf("%d %d %d",&x,&y,&a);
		if(a==1){
			for(j=1;j<=h;j++){
				for(k=1;k<=x;k++){
					box[j][k]=1;
				}
			}
		}
		if(a==2){
			for(j=1;j<=h;j++){
				for(k=x+1;k<=w;k++){
					box[j][k]=1;
				}
			}
		}
		if(a==3){
			for(j=1;j<=y;j++){
				for(k=1;k<=w;k++){
					box[j][k]=1;
				}
			}
		}
		if(a==4){
			for(j=y+1;j<=h;j++){
				for(k=1;k<=w;k++){
					box[j][k]=1;
				}
			}
		}
	}
	for(i=1;i<=h;i++){
		for(j=1;j<=w;j++){
			if(box[i][j]==0){
				cnt++;
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}

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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val>
Val gcd(Val a, Val b) {
//use ll or int for gcd
    if (b==0) return a;
    else return gcd(b, a%b);
}
template <typename Val>
Val vec_max(vector<Val> v){
  return *max_element(v.begin(),v.end());
}
template <typename Val>
Val vec_min(vector<Val> v){
  return *min_element(v.begin(),v.end());
}
template <typename Val>
void show_vec(vector<Val> *v){
  cout<<endl;
  rep(i,v->size()){
    cout<<v->at(i)<<" ";
  }
  cout<<endl;
}

template <typename Val,typename Number>
void count_vector(vector<Val>* A,vector<pair<Number,Val>>*R){
  sort(A->begin(),A->end());
  int count = 1;
  rep(i,A->size()){
    if(i<A->size()-1){
      if(A->at(i)==A->at(i+1))count++;
      else{
        R->emplace_back(count,A->at(i));
        count = 1;
      }
    }else{
      R->emplace_back(count,A->at(i));
    }
  }
}




//---------------------------------------------------------------
int main(){
  ll N;
  cin>>N;
  vector<pair<ll,ll>>F;
  llrep(i,sqrt(N)){
    ll I = i+1;
    if(N%I==0){
      F.emplace_back(I,N/I);
    }
  }
  ll ans = to_string(N).size();
  llrep(i,F.size()){
    ll A,B;
    A = to_string(F.at(i).first).size();
    B = to_string(F.at(i).second).size();
    if(max(A,B)<ans){
      ans = max(A,B);
    }

  }

  cout<<ans<<endl;





}


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

int	main()
{
	int	N, L;
	cin >> N >> L;
	vector<string>	S_vec(N);
	for (int i = 0; i < N; ++i)
		cin >> S_vec.at(i);
	sort(S_vec.begin(), S_vec.end());
	cout << accumulate(S_vec.begin(), S_vec.end(), string()) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	string s; cin >> s;
	int n = s.size();
	set<int> st;
	REP(i, n)
	{
		if (s[i] == '1') st.insert(i + 1);
	}
	vector<bool> v(n / 2 + 1);
	for (auto i : st)
	{
		if (!st.count(n - i))
		{
			cout << -1 << endl;
			return 0;
		}
		if (i <= n / 2) v[i] = true;
	}
	if (!v[1])
	{
		cout << -1 << endl;
		return 0;
	}
	int tmp = 2;
	int nx = 3;
	FOR(i, 1, n / 2 + 1)
	{
		if (i == 1)
		{
			cout << "1 2" << endl;
			continue;
		}
		cout << tmp << " " << nx << endl;
		if (v[i])
		{
			tmp = nx;
		}
		nx++;
	}
	REP(i, n - n / 2 - 1)
	{
		cout << tmp << " " << nx << endl;
		nx++;
	}
	return 0;
}

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

using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (int)n; i++)

int main(){
  string s;
  cin >> s;
  for (std::size_t i = 0; i < s.size(); i++) {
    cout << "x";
  }
  cout << endl;
}


Measured memory_bytes: 3568
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n";
#define ll long long

int main() {
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    cout << (((e-a)<=k)?"Yay!":":(") << "\n";
    return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

city = [e,d, c, b, a]
result = 'Yay!'
for i, c in enumerate(city):
    for cC in city[i + 1:len(city)]:
        if (c - cC) > k:
            result = ':('
            break;
print(result)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
int main ()
{
  int A,B,C,K;
  cin>>A>>B>>C>>K;
  int B1=K-A;
  int C1=K-B-A;
  if(B1<0)
  {
    B1=0;
  }
  if(C1<0)
  {
    C1=0;
  }
  cout<<min(A,K)-C1<<endl;
  return 0;
}

Measured memory_bytes: 3588
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N  = sc.nextInt();
		
		int[] array = new int[2*N];
		
		for(int i = 0 ; i < 2*N ; i++){
			array[i] = sc.nextInt();
		}
		sc.close();
		Arrays.sort(array);
		
		int sum = 0;
		for(int i = 1 ; i < 2*N ; i+=2){
			sum += Math.min(array[i], array[i-1]);
		}
		
		System.out.println(sum);
	}
}


Measured memory_bytes: 10068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


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

	ll N,A,B,C,D;
	cin >> N >> A >> B >> C >> D;
	string s;
	cin >> s;
	s+="####";
	s="##"+s;
	A++;B++;C++;D++;
	ll l = s.size();
	vector<bool> AC(l+1,false),BD(l+1,false);
	AC[A] = true;
	BD[B] = true;
	FOR(i,A+1,C+1)AC[i] = (AC[i-1]||AC[i-2])&&(s[i]=='.');
	FOR(i,B+1,D+1)BD[i] = (BD[i-1]||BD[i-2])&&(s[i]=='.');
	if(D>C){
		if(AC[C]&&BD[D]){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}else{
		bool rest = false;
		FOR(i,B-1,D){
			if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.'){
				rest = true;
			}
		}
		if(AC[C]&&BD[D]&&rest){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
}


Measured memory_bytes: 720
h,w,k=map(int,input().split())
board=[list(input()) for _ in range(h)]
ans=0
for paint_h in range(2**h):
  for paint_w in range(2**w):
    cnt=0
    for i in range(h):
      for j in range(w):
        if (paint_h>>i)&1==0 and (paint_w>>j)&1==0:
          if board[i][j]=='#':
            cnt+=1
    if cnt==k:
      ans+=1
print(ans)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using P = pair<int,int>;
set<P> ps;
int h, w, m, hh[300005], ww[300005], a, b, hmax, wmax, hms[300005], wms[300005], eh, ew;
int main(){
	scanf("%d%d%d", &h, &w, &m);
	rep(i,m){
		scanf("%d%d", &a, &b); a--; b--;
		hmax = max(hmax, ++hh[a]);
		wmax = max(wmax, ++ww[b]);
		ps.emplace(a,b);
	}
	rep(i,h) if(hh[i] == hmax) hms[eh++] = i;
	rep(i,w) if(ww[i] == wmax) wms[ew++] = i;
	rep(i,eh) rep(j,ew) if(!ps.count({hms[i],wms[j]})){
		return 0 * printf("%d\n", hmax+wmax);
	}
	printf("%d\n", hmax+wmax-1);
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1e9 + 7
#define INF 1 << 28
#define INFL 1 << 61
#define EPS (1e-10)

using namespace std;

typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> ps(n);

  rep(i, n) { cin >> ps[i]; }

  int ans = 0;
  rep(i, n - 1) {
    if (i + 1 == ps[i]) {
      swap(ps[i], ps[i + 1]);
      ans++;
    }
  }

  if (ps[n - 1] == n) {
    swap(ps[n - 1], ps[n - 2]);
    ans++;
  }

  cout << ans << endl;
}


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


int main(){
  int a,b,c;
  cin >>a>>b>>c;
  int sum = 0;
  vector <int> ans;
  for(int i=1;i<=c;i++){
    if(c%i==0)ans.push_back(i);
  }
  for(auto i : ans){
    if(a<=i&&b>=i)sum++;
  }
  cout<<sum<<endl;
}




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

int	main()
{
	int	X, Y;
	cin >> X >> Y;
	bool	feasible = false;
	for (int i = 0; i <= X; ++i) {
		if (2 * i + 4 * (X - i) == Y) {
			feasible = true;
			break;
		}
	}
	if (feasible)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N;
    cin >> N;
    set<string> S;
    string prev;
    cin >> prev;
    S.insert(prev);
    rep(i, N - 1) {
        string s;
        cin >> s;
        if (S.count(s) > 0 || prev.at(prev.size() - 1) != s.at(0)) {
            cout << "No" << endl;
            return 0;
        }
        prev = s;
        S.insert(prev);
    }
    cout << "Yes" << endl;
}


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

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int k[10];
int s[10][10];
int p[10];
bool SwON[10] = { false };

int main()
{
	int N, M, ans = 0;

	cin >> N >> M;
	rep(i, M) {
		cin >> k[i];
		rep(j, k[i]) cin >> s[i][j];
	}
	rep(i, M) cin >> p[i];

	while (true) {
		bool ok = true;
		bool end = true;

		rep(i, M) {
			int cnt = 0;
			
			rep(j, k[i]) if (SwON[s[i][j] - 1]) cnt++;

			if (cnt % 2 != p[i]) {
				ok = false;
				break;
			}
		}

		if (ok) ans++;

		rep(i, N) if (!SwON[i]) end = false;
		if (end) break;

		rep(i, N) {
			if (SwON[i]) {
				SwON[i] = false;
				continue;
			}
			SwON[i] = true;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def pr2(x):
  ret = 0
  while x%2 == 0:
    ret += 1
    x //= 2
  return ret
n = int(input())
s = input()
x = []
flg = 0
if s.count("2") >= 1:
  for i in range(n-1):
    t = abs(int(s[i+1])-int(s[i]))
    x.append(t%2)
else:
  flg = 1
  for i in range(n-1):
    t = abs(int(s[i+1])-int(s[i]))
    x.append(t//2)
n -= 1
num2 = 0
ans = 0
for i in range(n):
  if i == 0:
    ans += x[i]
    continue
  num2 += pr2(n-i)-pr2(i)
  if num2>0:
    continue
  else:
    ans += x[i]
if ans%2:
  print(flg+1)
else:
  print(0)

Measured memory_bytes: 120112
#include <iostream>

using namespace std;
int main(){
  int n;
  cin >> n;
  int ret = 0;
  for(int i = 1; i <= n; i+=2){
    int cnt = 0;
    for(int j = 1; j <= i; j++){
      if(i%j == 0) cnt++;
    }
    if(cnt == 8) ret++;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::ops::Bound::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout]
fn main() {
    input! {
        R: usize, C: usize, K: usize,
        yxv: [(usize, usize, i64); K],
    }

    let mut items = vec![vec![0; C+1]; R+1];
    for (y, x, v) in yxv {
        items[y][x] = v;
    }

    let mut dp = vec![vec![vec![0; C+1]; R+1]; 5];
    for y in 1..R+1 {
        for x in 1..C+1 {
            let mut from_above = 0;
            for i in 0..=3 {
                from_above = max(from_above, dp[i][y-1][x]);
            }
            dp[0][y][x] = max(dp[0][y][x], from_above);
            dp[1][y][x] = max(dp[1][y][x], from_above + items[y][x]);
            for k in 0..=3 {
                let from_left = dp[k][y][x-1];
                dp[k][y][x] = max(dp[k][y][x], from_left);
                dp[k+1][y][x] = max(dp[k+1][y][x], from_left + items[y][x]);
            }
            dp[4][y][x] = 0;
        }
    }
    let mut ans = 0;
    for i in 0..=3 {
        ans = max(ans, dp[i][R][C]);
    }
    println!("{}", ans);

}


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

using namespace std;

typedef long long ll;

struct data{
    int a, b;
    data(){}
    data(int a, int b): a(a), b(b){}

    bool operator<(const data &r)const{
        if(b==r.b) return a<r.a;
        return b<r.b;
    }
};

int n;
int a[100002], b[100002];
int aSort[100002];
data arr[100002];
bool just;

map<int, int> mp;
int link[100002];
int cnt;

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%d", &arr[i].a);
    for(int i=1; i<=n; i++) scanf("%d", &arr[i].b);
    sort(arr+1, arr+n+1);
    for(int i=1; i<=n; i++){
        a[i] = aSort[i] = arr[i].a, b[i] = arr[i].b;
    }
    sort(aSort+1, aSort+n+1);
    for(int i=1; i<=n; i++){
        if(aSort[i] > b[i]){
            printf("No");
            return 0;
        }
    }
    for(int i=1; i<n; i++){
        if(aSort[i] == aSort[i+1] || a[i] == aSort[i]){
            printf("Yes");
            return 0;
        }
        if(b[i] >= aSort[i+1]){
            just=1;
        }
    }
    if(a[n] == aSort[n]){
        printf("Yes");
        return 0;
    }
    if(!just){
        for(int i=1; i<=n; i++){
            mp[aSort[i]] = i;
        }
        for(int i=1; i<=n; i++){
            link[i] = mp[a[i]];
        }
        int i=1;
        do {
            i=link[i];
            cnt++;
        } while(i!=1);

        printf("%s", cnt==n?"No":"Yes");
    }
    else{
        printf("Yes");
    }
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll a,b,k;
    cin>>a>>b>>k;
    ll temp=min(a,k);
    k-=temp;
    a-=temp;
    if(k>0){
        temp= min(b,k);
        b-=temp;
        k-=temp;
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
l=[]
for i in range(n):
    a=int(input())
    l.append(a)
s=sorted(l)
for i in range(n):
    if l[i]==s[len(s)-1]:
        print(s[len(s)-2])
    else:
        print(s[len(s)-1])

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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>         vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)            for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

int main() {
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

  int k;
  string s = "ACL";
  cin >> k;
  loop(k) cout << s;
  cout << endl;
  return 0;
}



Measured memory_bytes: 3652
class Array
  include Comparable
  def cumsum(s = 0); map{|k| s += k } end
  def diff; s = self[0]; self[1...(self.size)].map{|k|d=k-s; s=k; d} end
end
include Math
mod = 10 ** 9 + 7
def max(a,b); a > b ? a : b end
def min(a,b); a < b ? a : b end
def swap(a,b); a, b = b, a  end
def yn(f); puts f ? "Yes" : "No" end
def yes; puts "Yes"; exit end
def no; puts "No"; exit end
#(n, k), (s, k), a, f = $<.map{|l| l.to_s.split.map(&:to_i) }
n = gets.to_s.to_i
a = gets.to_s.split.map{|e|e.to_i}.sort
#m = Array.new(n){ gets.to_s.split.map{|e|e.to_i} }
#s = gets.to_s.chomp
ans = 1
inf = 10 ** 18
a.each do |t|
  ans *= t
  if ans > inf
    puts "-1"
    exit
  end
end

puts ans

Measured memory_bytes: 23068