akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#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 LLFOR(i, a, b) for(long long i = (a); i < (b); ++i)
#define LLRFOR(i, a, b) for(long long i = (a); i >= (b); i--)
#define SORT(v, n) sort(v, v+n)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define LLREP(i, n) for(long long i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)
#define LLRREP(i, n) for(long long i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T MAX(T a,T b){if(a>b){return a;}return b;}
template <typename T>
inline T MIN(T a,T b){if(a<b){return a;}return b;}
template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

signed main(void){
	cin.tie(0);
   ios::sync_with_stdio(false);
   
   int a, b;
   string s;
   cin >> a >> b;
   cin >> s;

   bool yes = true;

   REP(i, a){
      if(s[i] < '0' || s[i] > '9') yes = false;
   }
   if(s[a] != '-') yes = false;
   FOR(i, a+1, s.size()){
      if(s[i] < '0' || s[i] > '9') yes = false;
   }

   if(yes == true) cout << "Yes" << endl;
   else cout << "No" << endl;

	rtn 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;

vector<int> v;
int cur;
int room;
vector<int> G[1000];
int dist[1000];
vector<int> his;

void dfs(int p, int d) {
	int r = v[cur];
	if(r < 0) {
		int x = his[his.size() - 1 + r];
		G[x].push_back(p);
		G[p].push_back(x);
		return;
	}
	int now = room++;
	his.push_back(now);
	dist[now] = d;
	if(p != -1) {
		G[now].push_back(p);
		G[p].push_back(now);
	}

	while(G[now].size() < r) {
		cur++;
		dfs(now, d + 1);
	}
	his.pop_back();
}


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

	int n;
	cin >> n;
	while(n--) {
		v.clear();
		for(int i = 0; i < 1000; i++) {
			G[i].clear();
		}

		int a;
		while(cin >> a, a) v.push_back(a);
		cur = room = 0;
		dfs(-1, 0);
		for(int i = 0; i < room; i++) {
			cout << i + 1;
			sort(G[i].begin(), G[i].end());
			for(int r : G[i]) cout << " " << r + 1;
			cout << endl;
		}
	}
}

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

fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut py: Vec<Vec<i64>> = vec![vec![]; n];
    let mut input: Vec<(usize, i64)> = vec![];
    for _ in 0..m {
        let (p, y) = (read::<usize>() - 1, read::<i64>());
        input.push((p, y));
        py[p].push(y);
    }
    for i in &mut py {
        i.sort();
    }
    for i in &input {
        let (p, y) = *i;
        let up = p + 1;
        let down = py[p].binary_search(&y).unwrap() + 1;
        let keta6 = 10_usize.pow(5);
        let mut check = keta6;
        while check > up {
            print!("0");
            check /= 10;
        }
        print!("{}", up);
        check = keta6;
        while check > down {
            print!("0");
            check /= 10;
        }
        println!("{}", down);
    }
}

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


Measured memory_bytes: 13820
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define CHMAX(a,b) a = max(a,b)
#define CHMIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define newline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;
const VI dx = {1, 0, -1, 0};
const VI dy = {0, 1, 0, -1};

int main()
{
    ll n, ans = 0ll;
    cin>>n;
    VLL a(n), b(n), c(n);
    REP(i,n) cin>>a[i];
    SORT(a);
    REP(i,n) cin>>b[i];
    SORT(b);
    REP(i,n) cin>>c[i];
    SORT(c);

    VLL ab(n), bc(n);
    REP(i,n) {
        ab[i] = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        bc[i] = upper_bound(c.begin(), c.end(), b[i]) - c.begin();
    }

    REP(i,n) {
        //cout<<ab[i]<<" "<<bc[i]<<endl;
        ans += ab[i] * (n - bc[i]);
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 7184
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        String s;
        for (int i = 0; i < h; i++) {
            s = sc.next();
            System.out.println(s);
            System.out.println(s);
        }
        sc.close();
    }
}

Measured memory_bytes: 23380
function Main(input) {
    input = input.trim();
    const tmp = input.split(" ");
    let a = parseInt(tmp[0],10);
    const b = parseInt(tmp[1],10);
    let c = parseInt(tmp[2],10);
    const d = parseInt(tmp[3],10);

    while(true){
        if(c - b > 0){
            c -= b;
        }else{
            console.log("Yes");
            break;
        }
        if(a - d > 0){
            a -= d;
        }else{
            console.log("No");
            break;
        }
    }
    
}
 
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29560
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	class UnionFind {
		int[] par, rank;
		UnionFind(int n) {
			par  = new int[n + 1];
			rank = new int[n + 1];
			init(n);
		}
		void init(int n) {
			for (int i = 0; i <= n; i++) {
				par[i] = i;
				rank[i] = 0;
			}
		}
		
		int find(int x) {
			if (par[x] == x)
				return x;
			else
				return par[x] = find(par[x]);
		}
		
		void unite(int x, int y) {
			x = find(x);
			y = find(y);
			if (x == y)
				return;
			
			if (rank[x] < rank[y]) {
				par[x] = y;
			} else {
				par[y] = x;
				if (rank[x] == rank[y])
					rank[x]++;
			}
		}
		
		boolean same(int x, int y) {
			return find(x) == find(y);
		}
	}

	class Edge {
		int u, v;
		double cost;
		Edge(int u, int v, double cost) {
			this.u = u; this.v = v; this.cost = cost;
		}
	}
	class Pair {
		int y, x;
		Pair(int y, int x) {
			this.y = y; this.x = x;
		}
	}

	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();

		Pair[] pairs = new Pair[n + 1];
		for (int i = 1; i <= n; i++) {
			int x = scan.nextInt();
			int y = scan.nextInt();
			pairs[i] = new Pair(y, x);
		}

		double sum = 0;
		Edge[] edges = new Edge[m];
		for (int i = 0; i < m; i++) {
			int p = scan.nextInt();
			int q = scan.nextInt();
			int _y = Math.abs(pairs[p].y - pairs[q].y);
			int _x = Math.abs(pairs[p].x - pairs[q].x);
			double cost = Math.sqrt(_y * _y + _x * _x);
			sum += cost;
			edges[i] = new Edge(p, q, cost);
		}
		
		Arrays.sort(edges, new Comparator<Edge>() {
			@Override
			public int compare(Edge e1, Edge e2) {
				return e1.cost - e2.cost > 0 ? -1 :
				       e1.cost - e2.cost < 0 ?  1 :
				    	                        0 ;
			}
		});
		UnionFind uf = new UnionFind(n);
		
		double res = 0;
		for (int i = 0; i < m; i++) {
			Edge e = edges[i];
			if (!uf.same(e.u, e.v)) {
				uf.unite(e.u, e.v);
				res += e.cost;
			}
		}
		System.out.printf("%.4f", sum - res);
	}
	public static void main(String[] args) {
		new Main().run();
	}

}


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

int main()
{
  int n;

  while (cin >> n, n){
    int p, pn, m = 0, a, b;

    for (int i = 0; i < n; i++){
      cin >> pn >> a >> b;
      if (a + b > m){
        m = a + b;
        p = pn;
      }
    }
    cout << p << ' ' << m << endl;
  }
}

Measured memory_bytes: 1160
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

int main(){
	int N, M;
	cin >> N >> M;
	vector<int> yakusu;
	for(int i=1; i<=sqrt(M); i++){
		if(M % i == 0){
			yakusu.PB(i);
			yakusu.PB(M/i);
		}
	}
	sort(yakusu.begin(), yakusu.end());

	int tmp = *lower_bound(yakusu.begin(), yakusu.end(), N);
	cout << M / tmp << endl;
}

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

int gcd(int x, int y) {
  if (y == 0) return x;
  else return gcd(y, x % y);
}

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

  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  int d = A.at(0);
  for (int i = 1; i < N && d != 1; i++) {
    d = gcd(A.at(i), d);
  }

  cout << d << endl;
}


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

using namespace std;

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

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

ll r,g;

int main(){
  cin >> r >> g;
  cout << g*2-r << endl;
}


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

namespace B
{
    class Program
    {
        class Restaurant
        {
            public string City { get; set; }
            public int Score { get; set; }

            public Restaurant(string city, int score)
            {
                City = city;
                Score = score;
            }
        }

        static Dictionary<int, Restaurant> restaurants;

        static void Main(string[] args)
        {
            restaurants = new Dictionary<int, Restaurant>();
            int n = RInt();
            for (int i = 0; i < n; i++)
            {
                string[] vs = RArSt();
                restaurants.Add(i + 1, new Restaurant(vs[0], int.Parse(vs[1])));
            }

            foreach (var item in restaurants.OrderBy(x=> x.Value.City).ThenByDescending(x=> x.Value.Score))
            {
                Console.WriteLine(item.Key);
            }

        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}


Measured memory_bytes: 11616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

ll dp[MX][MX];
inline void chmax(ll& a, ll b) {
  a = max(a, b);
}

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back


int main(){
    ll a, b, n;
    cin >> a >> b >> n;
    
    if (n >= b) {
       ll c = (n/b + 1)*b-1;
       if (c-1 > n) c = c-b;
       n = c;
    }
    
    ll x = a*n/b;
    ll y = n/b;
    cout << x - a*y << endl; 
}

Measured memory_bytes: 3648
# 等差等比数列

def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n, m = map(int, input().split())
    print(2 ** m * (18 * m + n) * 100)




if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
using namespace std;
#define int long long
int n;
int a[2000020];
int l[2000020];
int r[2000020];
stack<int>st1;
stack<int>st2;
inline int read()
{
	int a=0,b=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') b=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){a=a*10+ch-'0';ch=getchar();}
	return a*b;
}
int ans;
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)
	a[i]=read();
	for(int i=1;i<=n;i++)
	{
		while(!st1.empty()&&a[st1.top()]>=a[i]) st1.pop();
		if(st1.empty()) l[i]=1;
		else l[i]=st1.top()+1;
		st1.push(i);
	}
	for(int i=n;i>=1;i--)
	{
		while(!st2.empty()&&a[st2.top()]>=a[i]) st2.pop();
		if(st2.empty()) r[i]=n;
		else r[i]=st2.top()-1;
		st2.push(i);
	}
	for(int i=1;i<=n;i++)
	ans+=(r[i]-i+1)*(i-l[i]+1)*a[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 11648
/* 
   AOJ 1165
   Pablo Squareson's Headache
   2015.4.29
 */

#include<stdio.h>

struct block
{
  int x, y;
};


int width = 1, height = 1;

void calc_width_height(int n)
{
  int i, target_block, direction, max_x = 0, max_y = 0, min_x = 0, min_y = 0;
  struct block block_array[200];

  block_array[0].x = 0;
  block_array[0].y = 0;

  for(i = 1; i < n; i++)
    {
      scanf("%d %d", &target_block, &direction);
      switch(direction)
	{
	case 0:
	  block_array[i].x = block_array[target_block].x - 1;
	  block_array[i].y = block_array[target_block].y;
	  break;
	case 1:
	  block_array[i].x = block_array[target_block].x;
	  block_array[i].y = block_array[target_block].y - 1;
	  break;
	case 2:
	  block_array[i].x = block_array[target_block].x + 1;
	  block_array[i].y = block_array[target_block].y;
	  break;
	case 3:
	  block_array[i].x = block_array[target_block].x;
	  block_array[i].y = block_array[target_block].y + 1;
	  break;
  	}   
    }
  for(i = 0; i < n; i++)
    {
      if(max_x < block_array[i].x)
	{
	  max_x = block_array[i].x;
	}
      if(max_y < block_array[i].y)
	{
	  max_y = block_array[i].y;
	}
      if(min_x > block_array[i].x)
	{
	  min_x = block_array[i].x;
	}
      if(min_y > block_array[i].y)
	{
	  min_y = block_array[i].y;
	}
    }

  /* for(i = 0; i < n; i++) */
  /*   { */
  /*     printf("[%d]: x = %d, y = %d\n", i, block_array[i].x, block_array[i].y); */
  /*   } */

  width += max_x - min_x;
  height += max_y - min_y;
  
  return ;
}

int main(void)
{
  int n; 
  while(1)
    {
      scanf("%d", &n);
      if(n == 0)
	{
	  break;
	}
      
      width = 1;
      height = 1;

      calc_width_height(n);
      printf("%d %d\n", width, height);
      
    }
  return 0;
}

Measured memory_bytes: 600
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, a, n) for(ll i = a; i < (ll)(n); ++i)
#define repr(i, a, n) for(ll i = n - 1; (ll)a <= i; --i)
#define ENDL '\n'
typedef pair<int, int> Pi;
typedef pair<ll, ll> PL;
constexpr ll mod = 1000000007;  // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 + 99);
const ld PI = acos((ld)-1);
const vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
template <typename T, typename U> inline bool chmin(T& t, const U& u) {
  if(t > u) {
    t = u;
    return 1;
  }
  return 0;
}
template <typename T, typename U> inline bool chmax(T& t, const U& u) {
  if(t < u) {
    t = u;
    return 1;
  }
  return 0;
}
template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

template <typename T, typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(; n; n >>= 1) {
    if(n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template <typename T, typename Y>
ostream& operator<<(ostream& os, const pair<T, Y>& p) {
  return os << "{" << p.fs << "," << p.sc << "}";
}
template <typename T> ostream& operator<<(ostream& os, const V<T>& v) {
  os << "{";
  for(auto e : v) os << e << ",";
  return os << "}";
}
template <typename... Args> void debug(Args&... args) {
  for(auto const& x : {args...}) { cerr << x << ' '; }
  cerr << ENDL;
}

template <typename T> struct UnionFind {
  vector<T> Parent;

  UnionFind(T N) { Parent = vector<T>(N, -1); }

  T root(T A) {
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }

  T size(T A) { return -Parent[root(A)]; }

  bool connect(T A, T B) {
    A = root(A);
    B = root(B);
    if(A == B) return false;
    if(size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;

    return true;
  }

  bool same(T A, T B) { return root(A) == root(B); }
};

signed main() {
  cin.tie(0);
  cerr.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n, q;
  cin >> n >> q;
  UnionFind<int> uf(n);
  rep(i,0,q){
    ll t,u,v;cin>>t>>u>>v;
    if(t==0)uf.connect(u,v);
    else cout<<uf.same(u,v)<<ENDL;
  }
}
//! ( . _ . ) !
// CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3932
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	std::string s; cin >> s;

	if(s.size() & 1) printf("No\n");
	else {
		if(s.substr(0, n / 2) == s.substr(n / 2, n / 2)) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}


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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define inf 1000000100

int main()
{
    int k, s;
    cin >> k >> s;
    int ans = 0;

    for(int i = 0; i <= min(s, k); i++)
    {
        if(s - i > 2*k)
        {
            continue;
        }

        ans += min(s - i, k) - ((s - i) - min(s - i, k)) + 1;
    }

    cout << ans << endl;
}


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

int main() {
  string N;

  cin >> N;

  if ((N[0] == N[1] && N[1] == N[2])
   || (N[1] == N[2] && N[2] == N[3])) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
A = LI()
ans = 0
if A[0] != 1:
    ans += 1

A[0] = 1
G = [[] for _ in range(n)]
for i in range(1, n):
    G[A[i] - 1] += [i]

def dfs(u):
    global ans
    d = 0
    for v in G[u]:
        d = max(d, dfs(v) + 1)
    if d == k - 1:
        ans += (A[u] != 1)
        return -1
    return d

dfs(0)
print(ans)


Measured memory_bytes: 184228
#include <iostream>
#include <bits/stdc++.h>
#include <sstream>
#define PI 3.14159265358979323846264338327950L
#define ll long long
using namespace std;

int main(){
    int n;
    cin >> n;
    if(n>=30){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 3592
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        int res1 = a + b;
        int res2 = a - b;
        int res3 = a * b;

        int ans = Math.max(res1, res2);
        int ans1 = Math.max(ans, res3);
        int ans2 = Math.max(ans, res3);

        System.out.println(ans2);
    }
}


Measured memory_bytes: 23636
#include <iostream>
#include <algorithm>
#include <cstring>
#include<cstdio>
#include <cmath>
using namespace std;


int get_sum(int a)
{
	int sum = 0;

	while (a != 0){
		sum += a % 10;
		a =a / 10;
	}
	return sum;
}

int main()
{
	int n, a, b, ans = 0, box;

	cin >> n >> a >> b;

	for (int i = 1; i <= n; i++){
		box = get_sum(i);
		if (box >= a&&box <= b)
			ans += i;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
h = [int(i) for i in input().split()]
inf = 10**9
dp = [inf] * n
dp[0] = 0

dp[1] = dp[0] + abs(h[1] - h[0])

for i in range(2,n):
    x = dp[i-1] + abs(h[i] - h[i-1])
    y = dp[i-2] + abs(h[i] - h[i-2])
    dp[i] = min(x,y)
print(dp[n-1])


Measured memory_bytes: 14052
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 1000000000
typedef long long ll;
typedef pair<ll,int> P;

int main(){
  int N,h[110000];
  ll dp[110000];
  cin>>N;
  for(int i=0;i<N;i++) cin>>h[i];

  for(int i=0;i<N;i++) dp[i]=INF;
  dp[0]=0;
  for(int i=0;i<N-1;i++){
    dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
    if(i+2<N) dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
  }
  cout<<dp[N-1]<<endl;
}


Measured memory_bytes: 1408
# vim: set fileencoding=utf-8:

def main():
    x = input()
    ans = (x /11)*2
    if 0 < x%11 < 7:
        ans = ans + 1
    elif 7 <= x%11 < 11:
        ans = ans + 2
                
    print(ans)

if __name__ == "__main__":
    main()

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


int main() {

  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  int more = max(X, Y);
  int less = min(X, Y);

  int sum1 = min((A+B), C*2) * less;
  int sum2 = A * (X-less) + B * (Y-less);
  int sum3 = C * (X + Y - less*2) * 2;

  cout << sum1 + min(sum2, sum3) << endl;

  
  
}


Measured memory_bytes: 256
#!/usr/bin/env python3


def main():
    #N = map(int, open(0).read().split())
    N = list(input().split())
    N = int(N[0] + N[1])
    # print(type(N))

    grid = []
    i = 0
    flag = True

    while i * i <= N:
        if i * i == N:
            print('Yes')
            flag = False
        i += 1

    if flag == True:
        print('No')

main()


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

int main() {
    int N,K;
    cin >> N >> K;
    int res = 0;
    for(int i=0; i<N; ++i) {
        int h;
        cin >> h;
        if(h >= K) ++res;
    }
    cout << res << endl;
}

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

int main(){
  string S;
  cin >> S;
  string a = S.substr(0, 2);
  string b = S.substr(2, 2);
  vector<string> check = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"};
  bool check_a = (find(check.begin(), check.end(), S.substr(0, 2)) != check.end());
  bool check_b = (find(check.begin(), check.end(), S.substr(2, 2)) != check.end());
  if(check_a == true && check_b == true){
    cout << "AMBIGUOUS" << endl;
  }else if(check_a == true && check_b == false){
    cout << "MMYY" << endl;
  }else if(check_a == false && check_b == true){
    cout << "YYMM" << endl;
  }else if(check_a == false && check_b == false){
    cout << "NA" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    if(!a)
        cout<<1<<endl;
    if(!b)
        cout<<2<<endl;
    if(!c)
        cout<<3<<endl;
    if(!d)
        cout<<4<<endl;
    if(!e)
        cout<<5<<endl;

    return 0;
}


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

int formula(int x, int y, int z) {
    return x * x + y * y + z * z + x * y + y * z + x * z;
}

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

    vector<int> count(100000, 0);

    for(int i = 1; i <= 100; i++) {
        for(int j = 1; j <= 100; j++) {
            for(int k = 1; k <= 100; k++) {
                int n = formula(i,j,k);
                count[n]++;
            }
        }
    }

    for(int i = 1; i <= N; i++) {
        cout << count[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3732
##2つの整数 K,Sが与えられます。
##入力は以下の形式で標準入力から与えられる。
##K S
k, s = gets.chomp.split(" ").map(&:to_i)

##3つの変数 X,Y,Zがあり、0 ≦ X,Y,Z ≦ Kを満たす整数の値を取ります。
##X+Y+Z=S を満たす X,Y,Zへの値の割り当ては何通りありますか。

##制約
##2 ≦ K ≦ 2500 | 0 ≦ S ≦ 3K | K,Sは整数である。

##問題文の条件を満たす X,Y,Zの組が何通りあるか出力せよ。
num = ((k+1)*2)+(k-1)
a_way = Array.new(num, 0)

mid_idx_b, mid_idx_e = 0, 0
plus_v = 1
(0..k).each do |idx|
  idx_l = num - 1 -idx
  # print(" #{plus_v}")
  # print(" #{idx}")
  # print(" #{idx_l},")
  if idx == 0
    a_way[idx] = a_way[idx_l] = plus_v + 0
  else
    a_way[idx] = a_way[idx_l] = plus_v + a_way[idx-1]
  end
  plus_v += 1
  
  mid_idx_b, mid_idx_e = idx, idx_l
end
# print("\n")
# p a_way

mid_idx_b, mid_idx_e = mid_idx_b+1, mid_idx_e-1
# print("mid_idx_b: #{mid_idx_b}, ")
# print("mid_idx_e: #{mid_idx_e}\n")

minus_v = k - 1
(mid_idx_b..mid_idx_e).each do |idx|
  idx_l = num - 1 -idx
  # print(" #{minus_v}")
  # print(" #{idx}")
  # print(" #{idx_l},")
  a_way[idx] = a_way[idx_l] = minus_v + a_way[idx-1]
  
  minus_v -= 2
  
  break if idx == idx_l || minus_v < 0
end
# print("\n")
# p a_way

p a_way[s]

Measured memory_bytes: 3836
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())


def digitSum(n):
    s = str(n)
    array = list(map(int, s))
    return sum(array)

def main():
    N = I()
    dig_sum = digitSum(N)
    print("Yes" if dig_sum%9==0 else "No")

main()



Measured memory_bytes: 28788
n = str(input())
dai = ["Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M"]
syou = ["q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"]
if n in dai:
  print('A')
else:
  print('a')


Measured memory_bytes: 9084
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)
input = sys.stdin.readline
from copy import deepcopy 

MAXN = 1005
MAXV = MAXN * (MAXN - 1)//2
G = [[] for _ in range(MAXV)]

id = [[-1] * MAXN for _ in range(MAXN)]
def toId(i,j):
    if i > j:
        i,j = j,i
    return id[i][j]


finished = [0] * MAXV
dp = [-1] * MAXV
def dfs(v):
    if dp[v] != -1:
        if finished[v] == 0:
            return -1
        return dp[v]
    dp[v] = 0
    for e in G[v]:
        res = dfs(e)
        if res == -1:
            return -1
        dp[v] = max(dp[v],res + 1)
    finished[v] = 1
    return dp[v]


def main():
    n = int(input())
    a = [[int(i) - 1 for i in input().split()] for _ in range(n)]

    v = 0
    for i in range(n):
        for j in range(i + 1,n):
            id[i][j] = v
            v += 1
    
    for i in range(n):
        for j in range(n - 1):
            a[i][j] = toId(i,a[i][j])
        for j in range(n - 2):
            G[a[i][j]].append(a[i][j + 1])
    
    ans = 0
    for i in range(v):
        res = dfs(i)
        if res == -1:
            ans = -1
            break
        ans = max(ans,dfs(i) + 1)
    
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 151536
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

#define INF 4000000000000000000LL;

using namespace std;

int main()
{
	int n, k, count;
	long long int x, y;
	long long int s=INF;
	map<long long int,long long int> xm, ym;
	scanf("%d %d", &n, &k);
	for(int i=0; i<n; i++){
		scanf("%lld %lld", &x, &y);
		xm[x]=y;
		ym[y]=x;
	}
	int j=0;
	for(auto itr=xm.begin(); itr!=xm.end(); itr++){
		long long int x1=itr->first, y1=itr->second;;
		auto itr2=itr;
		itr2++;
		while(itr2!=xm.end()){
			long long int x2=itr2->first, y2=itr2->second;;
			for(auto itry=ym.begin(); itry!=ym.end(); itry++){
				long long int y3=itry->first, x3=itry->second;
				if(x1<=x3 && x2>=x3){
					count=1;
				}else{
					count=0;
				}
				auto itry2=itry;
				itry2++;
				while(itry2!=ym.end()){
					long long int y4=itry2->first, x4=itry2->second;
					if(x1<=x4 && x4<=x2){
						count++;
					}
					if(count>=k){
						long long int s2=(x2-x1)*(y4-y3);
						if(s>s2){
							s=s2;
						}
						break;
					}
					itry2++;
				}
			}
			itr2++;
		}
	}

	printf("%lld\n", s);
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int D= sc.nextInt();
		if (D==7||D==5||D==3) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 27080
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007

long long calc(int n, int m){
    long long ans = 1;
    while(n > 0){
      ans = ans*n%mod;
      n -= 1;
    }
    while(m > 0){
      ans = ans*m%mod;
      m -= 1;
    }
    return ans;
}

int main(){
  int n, m;
  cin >> n >> m;
  long long ans = calc(n, m);
  if ( n == m){
    ans = ans * 2 % mod;
  } else if ( n + 1 != m && n != m + 1){
    ans = 0;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function moveup(x::Array{Int,1},n)
	k = length(x)
	for i in 1:k-1
		if x[k-i+1] > n-1
			x[k-i] += div(x[k-i+1],n)
			x[k-i+1] = x[k-i+1]%n
		end
	end
	if x[1] > n-1
		0
	else
		x
	end
end

function main()
	a,b = readline() |> split |> parseMap
	r = 0
	while 2^r <= b
		r += 1
	end
	c = zeros(Int,r+1)
	d = zeros(Int,r+1)
	c[r+1] = a
	d[r+1] = b
	c = moveup(c,2)
	d = moveup(d,2)
	ans = 0
	if a%2==0
		p = a+1
	else
		p = a
	end
	if b%2 == 0
		q = b-1
	else
		q = b
	end
	if div(q-p,2)%2==0
		ans += 1
	end
	for i in 1:r
		t = 2^i
		k = 0
		p = ceil(a/t)*t
		q = floor(b/t)*t
		if p > b
			if c[r+1-i] == 1
				k += b-a+1
			end
		else
			if c[r+1-i] == 1
				k += p-a
			end
			if d[r+1-i] == 1
				k += b-q+1
			end
		end
		if k%2 == 1
			ans += t
		end
	end
	if a == b
		println(a)
	else
		println(ans)
	end
end
main()

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


int main() {

long N;
cin>>N;

cout<<N<<":";

vector<long> p(1000005);
p[2]=1;
p[3]=1;
for(int i=6;i<=1000000;i+=6){
  int tmp=i-1;
  bool isprime=1;
  for(int j=2;j<=sqrt(tmp);j++){
    if(tmp%j==0) isprime=0;
  }
  if(isprime) p[i-1]=1;

  tmp=i+1;
  isprime=1;
  for(int j=2;j<=sqrt(tmp);j++){
    if(tmp%j==0) isprime=0;
  }
  if(isprime) p[i+1]=1;

}

for(int i=0;i<10;i++){
  //cout<<i<<" "<<p[i]<<endl;
}

int i=2;
int tmp=N;

while(i<=sqrt(N)){
  if(p[i]==1) while(tmp%i==0){
    cout<<" "<<i;
    tmp/=i;
  }
  i++;
}

if(tmp>1) cout<<" "<<tmp;
cout<<endl;
}



Measured memory_bytes: 10796
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

const double EPS = 1e-10;

int n;
double R,L,P,E,T,ans,ansl,ansr;

bool equal(double a, double b){
  return fabs(a-b) < EPS;
}

void dfs(double l, double r, double pr, int k){
  double mid = (l + r) / 2.0;
  if(ansl < l && r < ansr || k >= n && ansl < mid && mid < ansr){
    ans += pr;
    return;
  } else if(k >= n || r < ansl && !equal(r,ansl) || ansr < l && !equal(ansr,l)) return;


  if(mid > T || equal(T,mid)){
    dfs(l, mid, pr*(1.0-P), k+1);
    dfs(mid, r, pr*P, k+1);
  } else {
    dfs(mid, r, pr*(1.0-P), k+1);
    dfs(l, mid, pr*P, k+1);
  }

}

int main(){
  while(cin >> n){
    cin >> L >> R >> P >> E >> T;
    ans = 0.0;
    ansl = T - E;
    ansr = T + E;
    dfs(L, R, 1.0, 0);
    printf("%.7f\n",ans);
  }
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;

double dot(P a,P b){
  return real(b*conj(a));
}

double cross(P a,P b){
  return imag(b*conj(a));
}

P init(P a){
  return a/max(0.0001,abs(a));
}

int ax,ay,bx,by,cx,cy;

P A,B,C;
double sinA,cosA,sinB,cosB,sinC,cosC;

double funcC(double ra){
  double L=0,R=10000,M;
  for(int i=0;i<50;i++){
    M=(L+R)/2.0;
    if( M/sinC*cosC + ra/sinA*cosA + sqrt( 4.0*ra*M ) < abs(A-C) ) L=M;
    else R=M;
  }
  return L;
}

double funcB(double ra){
  double L=0,R=10000,M;
  for(int i=0;i<50;i++){
    M=(L+R)/2.0;
    if( M/sinB*cosB + ra/sinA*cosA + sqrt( 4.0*ra*M ) < abs(A-B) ) L=M;
    else R=M;
  }
  return L;
}

bool check(double ra){
  double rb=funcB(ra);
  double rc=funcC(ra);

  if( rb/sinB*cosB + rc/sinC*cosC + sqrt( 4.0*rb*rc ) < abs(C-B) ){
    return true;
  }else{
    return false;
  }
}

int main(){
  while(1){
    cin>>ax>>ay>>bx>>by>>cx>>cy;
    if(ax==0&&ay==0&&bx==0&&by==0&&cx==0&&cy==0)break;
    A=P(ax,ay),B=P(bx,by),C=P(cx,cy);
    P AB=init(B-A),AC=init(C-A);
    AB=(AB+AC)*0.5;
    sinA = abs(cross(AB,AC))/abs(AB);
    cosA = dot(AB,AC)/abs(AB);
    
    P BA=init(A-B),BC=init(C-B);
    BA=(BA+BC)*0.5;
    sinB = abs(cross(BA,BC))/abs(BA);
    cosB = dot(BA,BC)/abs(BA);

    P CA=init(A-C),CB=init(B-C);
    CA=(CA+CB)*0.5;
    sinC = abs(cross(CA,CB))/abs(CA);
    cosC = dot(CA,CB)/abs(CA);

    double L=0,R=10000,M;
    for(int i=0;i<50;i++){
      M=(L+R)/2.0;
      if(check(M))R=M;
      else L=M;
    }

    printf("%.10f %.10f %.10f\n",L,funcB(L),funcC(L));
  }
  return 0;
}

Measured memory_bytes: 1220
uses math;
const fi='knapsack2.inp';
      fo='knapsack2.out';
      maxn=100;
      maxv=200000;
var n,w:int32;
    maxval:uint64;
    we,v:array[1..maxn] of uint32;
    f:array[0..maxn,0..maxv] of uint32;
//=============================
procedure nhap;
var i:int32;
begin
   readln(n,w); maxval:=0;
   for i:=1 to n do
   begin
     readln(we[i],v[i]);
     maxval:=maxval+v[i];
   end;
end;
//=============================
function min(x,y:int64):int64;
begin
   if x>y then exit(y)
   else exit(x);
end;
//=============================
procedure xuli;
var i,j:int32;
begin
   for i:=0 to n do
    for j:=0 to maxval do f[i,j]:=maxlongint;
   f[0,0]:=0;
   for i:=0 to n-1 do
    for j:=0 to maxval do
     if f[i,j]<>maxlongint then
      begin
         f[i+1,j]:=min(f[i+1,j],f[i,j]);
         if f[i,j]+we[i+1]<=w then
         f[i+1,j+v[i+1]]:=min(f[i+1,j+v[i+1]],f[i,j]+we[i+1]);
      end;
   for i:=maxval downto 0 do
    if f[n,i]<=w then break;
   write(i);
end;
//=============================
begin
//   assign(input,fi); reset(input);
//   assign(output,fo); rewrite(output);
   nhap;
   xuli;
//   close(input); close(output);
end.


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

using namespace std;

typedef long long int ll;

const ll mod = 1e9 + 7;

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

  ll n, W;
  cin >> n >> W;
  vector < ll > w(n + 1), v(n + 1);
  for(int i = 1; i <= n; i++) cin >> w[i] >> v[i];
  vector < vector < ll >  > dp(W + 1, vector < ll > (n + 1, 0));

  ll mx = LLONG_MIN;
  for(int i = 0; i <= W; i++){
    for(int j = 1; j <= n; j++){
      if(i - w[j] >= 0) dp[i][j] = max(dp[i][j - 1], dp[i - w[j]][j - 1] + v[j]);
      dp[i][j] = max(dp[i][j], dp[i][j - 1]);
      mx = max(mx, dp[i][j]);
      //cout << " i = " << i << " j = " << j << " dp[i][j] = " << dp[i][j] << endl;
    }
  }

  cout << mx << '\n';
}


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

using namespace std;


typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n ; 
int a[maxn];
int ans[maxn];
pii pos[maxn];

int main(){
    migmig
	cin >> n;
	for(int i = 1 ; i <= n ; i ++){
		cin >> a[i];
		pos[i] = {a[i] , i};
	}
	sort(pos+1 , pos + n+ 1);
	int cur = 1 , cnt =0;
	for(int i = 1 ; i <= n ; i ++){
		cnt = 0;
		if(ans[pos[i].first])dokme("No");
		ans[pos[i].first] = pos[i].second;
		if(pos[i].second == 1)continue;
		while(cur <= pos[i].first){
			if(!ans[cur]){
				ans[cur] = pos[i].second;
				cnt++;
				if(cnt == pos[i].second-1)
					break;
			}
			cur++;
		}
		if(cnt < pos[i].second-1)dokme("No");
	}
	cur = n*n;
	for(int i = n ; i  ; i -- ){
		cnt = 0;
		if(pos[i].second == n)continue;
		while(cur >= pos[i].first){
			if(!ans[cur]){
				ans[cur] = pos[i].second;
				cnt++;
				if(cnt == n - pos[i].second)
					break;
			}
			cur--;
		}
		if(cnt < n-pos[i].second)dokme("No");
	}
	cout << "Yes" << endl;
	for(int i = 1 ; i <= n*n ; i ++ )
		cout << ans[i] << ' ';
	
    return(0);
}

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

namespace ABC147
{
    class C
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = new int[N];
            int[,] x = new int[20, 20];
            int[,] y = new int[20, 20];
            for (int i = 0; i < N; i++)
            {
                A[i] = int.Parse(Console.ReadLine());
                for (int j = 0; j < A[i]; j++)
                {
                    int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    x[i, j] = input[0];
                    y[i, j] = input[1];
                }
            }

            int res = 0;
            for (int bit = 0; bit < (1 << N); bit++)
            {
                int count = 0;
                bool ok = true;
                for (int i = 0; i < N; i++)
                {
                    if ((bit & (1 << i)) <= 0) continue;
                    count++;
                    for (int j = 0; j < A[i]; j++)
                    {
                        if ((bit & (1 << (x[i, j] - 1))) > 0)
                        {
                            if (y[i, j] == 0) ok = false;
                        }
                        else
                        {
                            if (y[i, j] == 1) ok = false;
                        }
                    }
                }
                if (ok) { res = Math.Max(res, count); }

            }

            Console.WriteLine(res);

        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;
i64 giant = 4000000000000000000;

using namespace std;


int main() {
	double w, h, x, y;
	cin >> w >> h >> x >> y;
	long double ans = w * h / 2;
	int ans2 = 0;
	if (x == w / 2 && y == h / 2)ans2++;
	cout << ans << " " << ans2 << endl;
	return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int a,b;
    Scd2(a,b);

    if( a == 1) a+=11111;
    if( b == 1) b+=11111;
    if( a > b ){
        printf ("Alice\n");
    }else if(a == b){
        printf ("Draw\n");
    }else{
        printf ("Bob\n");
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  char str[100000];
    scanf("%s",str);
    
  int i=0,a,b;

  
while(str[i]!='\0'){
if(i%2==0){if(str[i]=='0')a++;else b++;}
if(i%2==1){if(str[i]=='1')a++;else b++;}
i++;
}

if(a<b) printf("%d",a);
else  printf("%d",b);
 return 0;
}

Measured memory_bytes: 256
#include<cstdio>


int main(void)
{
	int r;

	while(scanf("%d", &r)==1)
	{
		int rank=0;
		const char *symbol[]={"ABC", "ARC", "AGC"};
		if(r>=1200) rank++;
		if(r>=2800) rank++;
		printf("%s\n", symbol[rank]);
	}

	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
  int W,H,x,y,r;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if(((x>=r)&&(y>=r))&&((x+r)<=W)&&((y+r)<=H)){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 2140
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
#define puts(x) cout << x << endl
using namespace std;
int input() {
	int r;
	cin >> r;
	//scanf("%lld", &r);
	return r;
}
int ans;
signed main() {
	int a, b, n; cin >> a >> b >> n;
	if (b > n)puts(a*n / b - a * (n / b));
	else puts(a*(b - 1) / b - a * ((b - 1) / b));
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second

constexpr int mod = 1000000007;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value
int N;
int A[100010];

int backet[100];

void solve() {

	cin >> N;
	multiset<int> mm;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		auto it = mm.lower_bound(A[i]);
		if (it != mm.begin()) {
			mm.erase(--it);
		}
		mm.insert(A[i]);
	}

	cout << mm.size() << endl;

	return;

}

int main() {

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

	solve();

	return 0;

}


Measured memory_bytes: 5376
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(f); }
	constexpr itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(l - 1); }
	constexpr itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool amax(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool amin(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool samax(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool samin(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }
template <class T> constexpr T difference(const T &a, const T &b) {
	return a <= b ? b - a : a - b;
}

#include <algorithm>
#include <iostream>
#include <utility>
#include <tuple>

int main() {
	usize n;
	::std::cin >> n;
	::std::vector<u32> a(n);
	for (auto &e : a) {
		::std::cin >> e;
	}
	const auto is_ok = [&](const usize sig)->bool {
		::std::vector<::std::pair<u32, usize>> pos({ {0,0} });
		u32 prev{ 0 };
		for (const auto e : a) {
			if (prev >= e) {
				while (pos.back().first > e) {
					pos.pop_back();
				}
				u32 p = e;
				while (true) {
					if (p == 0) return false;
					if (pos.back().first != p) {
						pos.emplace_back(p, 0);
					}
					if (pos.back().second == sig - 1) {
						pos.pop_back();
						--p;
						continue;
					}
					break;
				}
				++pos.back().second;
			}
			prev = e;
		}
		return true;
	};
	usize ng = 0, ok = n;
	while (ok - ng > 1) {
		const usize mid = (ng + ok) / 2;
		if (is_ok(mid))ok = mid;
		else ng = mid;
	}
	::std::cout << ok << ::std::endl;
	return 0;
}


Measured memory_bytes: 1656