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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int T = 2e5 + 4;
const int N = 21;

int n;
ll v[T];
ll acum[T][N];

bool noRep(int l, int r) {
    for(int i = 0; i < N; i++)
        if(acum[r][i]-acum[l-1][i] > 1) return 0;
    return 1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;

    for(int i = 1; i <= n; i++) {
        cin >> v[i];
        for(ll j = 1, casa = 0; j <= v[i]; j <<= 1, casa++)
            acum[i][casa] += ((v[i]&j) > 0);
        for(int j = 0; j < N; j++) acum[i][j] += acum[i-1][j];
    }

    int l = 1;
    int r = 1;
    ll ans = 0;

    while(r <= n) {
        while(l < r and (!noRep(l,r))) l++;
        while(r < n and noRep(l,r+1)) ans += (r-l+1), r++;
        ans += (r-l+1);
        r++;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 34688
def out(isA)
    print (isA ? 'A' : 'B')
end

n, k = gets.split.map(&:to_i)
S = gets.chomp.split('').map{|c| c=='A'}

i = 0
rev = false
toprev = false
while i < n
    if S[i] ^ rev
        if k == 1
            k -= 1
            toprev = true
        else
            k -= 2
            rev = !rev
            i += 1
        end
    else
        k -= 1
        rev = !rev
        i += 1
    end

    if k == 0 && i < n
        (i...n).each do |j|
            out(S[j] ^ rev ^ (j==i && toprev))
        end
        i.times do |j|
            out((i-j)%2 == 1)
        end
        exit
    end
end

if n%2 == 1
    out(k%2 == 0)
    n -= 1
end

n.times do |j|
    out(j%2 == 1)
end

Measured memory_bytes: 18556
console.log(function(args){
  const tmp = args.trim().split('\n').map( r=>r.split(' ') );
  const N = tmp.shift()[0]|0;
  const p = tmp[0].map(parseFloat);
  const dp = Array(N).fill(0).map(r=>Array(N+1).fill(.0));
  dp[0][0] = 1.0 - p[0];
  dp[0][1] = p[0];
  for ( let i = 0; i < N-1; i++ ) {
    for ( let j = 0; j <= i + 1; j++ ) {
      dp[i+1][j+1] += dp[i][j] * p[i+1];
      dp[i+1][j] += dp[i][j] * (1.0-p[i+1]);
    }
  }
  return dp[N-1].slice((N+1)/2).reduce((a,b)=>a+b).toString();
}(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 198380
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] abc = scanner.nextLine().split(" ", 3);
        String a = abc[0];
        String b = abc[1];
        String c = abc[2];

        if (a.charAt(a.length()-1) == b.charAt(0) && b.charAt(b.length()-1) == c.charAt(0)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 21588
package main

import(
	"fmt"
)

const MOD = 1000000000+7

func main(){
	var n,m int
	fmt.Scanln(&n,&m)
	a:=make(map[int]bool)
	for i,t:=0,0;i<m;i++{
		fmt.Scanln(&t)
		a[t]=true
	}
	x,y:=1,1
	if a[1]{y=0}
	for i:=2;i<n+1;i++{
		z:=0
		if !a[i-2]{z=x}
		if !a[i-1]{z=(z+y)%MOD}
		x,y=y,z
	}
	fmt.Println(y)
}

Measured memory_bytes: 5504
type ABC(stream:System.IO.TextReader) =
  member this.Scan1 f = stream.ReadLine() |> f
  member this.Scan2 f1 f2 = stream.ReadLine().Split() |> (fun a -> (f1 a.[0], f2 a.[1]))
  member this.Scan3 f1 f2 f3 = stream.ReadLine().Split() |> (fun a -> (f1 a.[0], f2 a.[1], f3 a.[2]))
  member this.Scan4 f1 f2 f3 f4 = stream.ReadLine().Split() |> (fun a -> (f1 a.[0], f2 a.[1], f3 a.[2], f4 a.[3]))
  member this.ScanVecH f = stream.ReadLine().Split() |> Array.map f
  member this.ScanVecV n f = [| for i in 1..n -> stream.ReadLine() |> f |]
  member this.ScanMatrix n f  = [ for i in 1..n do yield stream.ReadLine().Split() |> Array.map f ]
  member this.ScanCharMatrix n = [ for i in 1..n -> stream.ReadLine().ToCharArray() ]
  member this.Close () = stream.Close()

let util = ABC(stdin)

let N,K = util.Scan2 int int

let rec prob n k =
  if n >= k then 1.0
  else 0.5 * prob (n*2) k

[ for n in 1..N -> prob n K]
|> List.sum
|> fun a -> a / (float N)
|> printfn "%.12f"



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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> a(N, vector<int>(26));

  for (int i = 0; i < N; i++) {
    string s;
    cin>>s;
    for (int j = 0; j < s.size(); j++) {
      int k=s.at(j)-'a';
      a.at(i).at(k)++;
    }
      
  }
  for (int i = 0; i < 26; i++) {
    int mi=50;
    for (int j = 0; j < N; j++) {
      mi=min(mi,a.at(j).at(i));
    }
    while(mi--){
      char ans='a'+i;
      cout<<ans;
    }
  }
  
  
  
}

Measured memory_bytes: 256
def inpl():
    return tuple(map(int, input().split()))


def getPattern(i):
    return {j for j in range(N) if (i >> j) % 2}


def isOn(pattern):
    return all(P[i] == len(pattern & S[i]) % 2 for i in range(M))


N, M = inpl()
S = []
for _ in range(M):
    tmp = inpl()
    tmp = [t - 1 for t in tmp[1:]]
    S.append(set(tmp))
P = inpl()

ans = 0
for i in range(2**N):
    pattern = getPattern(i)
    ans += int(isOn(pattern))
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define LiangJiaJun main
#define pa pair<int,int>
using namespace std;
int n,gb[100004],ga[100004];
pa sa[100004],sb[100004];
int LiangJiaJun(){
    memset(gb,0,sizeof(gb));
    memset(ga,0,sizeof(ga));
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x;scanf("%d",&x);
        if(i&1)gb[x]++;
        else ga[x]++;
    }
    int ra=0,rb=0,ca=0,cb=0;
    for(int i=0;i<=100000;i++){
        sa[++ca]=make_pair(ga[i],i);
    }
    sort(sa+1,sa+ca+1);
    for(int i=0;i<=100000;i++){
        sb[++cb]=make_pair(gb[i],i);
    }
    sort(sb+1,sb+cb+1);
    if(sa[ca].second!=sb[cb].second)return printf("%d\n",n-(sa[ca].first+sb[cb].first)),0;
    else return printf("%d\n",min(n-(sa[ca].first+sb[cb-1].first),n-(sa[ca-1].first+sb[cb].first))),0;

    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int p[N], count=0;
    for(int i=0; i<N; i++) cin >> p[i];
    for(int i=0; i<N-2; i++){
        if (p[i] < p[i+1] && p[i+1] < p[i+2]) count++;
        else if (p[i] > p[i+1] && p[i+1] > p[i+2]) count++;
    }
    cout << count;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};


vector<ll> enum_div(ll n)//nの約数を列挙
{
	std::vector<ll> ret;
	for(ll i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

void solve(){
    ll N;
    cin >> N;

    ll ans = 0;
    // for (int k = 1; k*k-1 <= N; k++) {
    //     ll c = N / (k + 1);
    //     if (c * (k+1) == N) {
    //         cout << c << " " << k << endl;
    //         ans += k;
    //     }
    // }
    //
    // cout << ans << endl;

    vector<ll> r = enum_div(N);
    // for (auto i : r) {
    //     cout << i << endl;
    //     ans += N / i - 1;
    // }

    for (ll i = 0; i < (ll)r.size(); i++) {
        ll k = N / r[i] - 1;
        if (r[i] < k) {
            ans += k;
        }
        // ans += N / r[i] - 1;
    }
    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

class union_find {
private:
    vector<ll> par;
    vector<ll> ran;
    vector<ll> m_size;
public:
    union_find(ll n);
    ll find(ll x);
    void unite(ll x, ll y);
    bool same(ll x, ll y);
    ll size(ll x);
};

union_find::union_find(ll n){
    par.resize(n);
    ran.resize(n, 0);
    m_size.resize(n, 1);
    REP(i,n) par[i] = i;
};

ll union_find::find(ll x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    ll t = size(x)+size(y);
    m_size[x] = m_size[y] = t;
    if (ran[x] < ran[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (ran[x]==ran[y]) ran[x]++;
    }
};

ll union_find::size(ll x) {
    if (par[x] == x) return m_size[x];
    return size(par[x] = find(par[x]));
}

bool union_find::same(ll x, ll y) {
    return (find(x) == find(y));
};

int main(int argc, char const *argv[]) {
    int n, k, l;
    cin >> n >> k >> l;
    vector<int> p(k), q(k), r(l), s(l);
    union_find ufr(n);
    union_find uft(n);
    map<P, int> ans;

    REP(i,k) {
        cin >> p[i] >> q[i];
        --p[i],--q[i];
        ufr.unite(p[i],q[i]);
    }
    REP(i,l) {
        cin >> r[i] >> s[i];
        --s[i], --r[i];
        uft.unite(s[i],r[i]);
    }
    vector<int> a(n), b(n);
    REP(i,n) {
        a[i] = ufr.find(i); b[i] = uft.find(i);
        ans[{a[i],b[i]}]++;
    }

    REP(i,n) {
        cout << ans[{a[i], b[i]}] << endl;
    }
    return 0;
}

Measured memory_bytes: 24064
n, k, q=map(int,input().split())
point=[0]*n


for i in range(q):
    a=int(input())
    point[a-1]+=1

for i in range(n):
    end_point=k-q+point[i]
    if end_point<=0:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 4680
#include <bits/stdc++.h>
using namespace std;
  
 int main() {
 int N;
 cin >> N;
 vector<long long> a(N);
  for(int i= 0;i<N;i++){
    cin >> a[i];
  }
   int sum = 0;
  for(int i = 0;i<N;i++){
    int c = 0;
    while(1){
      if(a[i]%2 == 0){
        a[i] = a[i]/2;
        c++;
      }
      if(a[i]%2 != 0){
        sum += c;
        break;
      }
    }
  }
   cout << sum << endl;

 }

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
int Inf = (1<<30);
ll inf = (1LL<<60);
int main() {
	int n, q;;
	cin >> n >> q;
	string s;
	cin >> s;
	int i;
	V sum(n, 0);
	for (i = 1; i < n; i++) {
		if (s[i - 1] == 'A' && s[i] == 'C') sum[i]++;
		sum[i] += sum[i - 1];
	}
	V ans;
	for (i = 0; i < q; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		ans.push_back(sum[b] - sum[a]);
	}
	for (i = 0; i < ans.size(); i++) cout << ans[i] << endl;
	return 0;
}

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

int main() {
 string s;
 cin>>s;
s[s.size()]='s';
 if(s[s.size()-1]=='s')
 {
     s.push_back('e');
s.push_back('s');
 }
 else{
s.push_back('s');
 }

 cout<<s<<endl;
}

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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

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

//---------------------------------------------------------------
//---------------------------------------------------------------

int N;
int a[2][100];

int dp[2][100] = {};

int count(int i=0, int j=0) {
	int ans;
	if(dp[i][j] > 0)	return dp[i][j];
	
	if(i == 0 && j < N - 1) {
		ans = a[i][j] + max(count( 0, j + 1 ), count( 1 , j ));
	} else if(i == 0) {
		ans = a[i][j] + count( 1, j );
	} else if(j < N - 1) {
		ans = a[i][j] + count( 1, j + 1 );
	} else {
	   ans = a[i][j];
	}
	dp[i][j] = ans;
	return ans;
}

signed main(){
	cin >> N;
	
	REP(i, 0, 2)	REP(j, 0, N)	cin >> a[i][j];
	
	cout << count() << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m;
    cin >> n >> m;
    int l = (m+1)/2, r = m-l;
    for (int i = 0; i < l; ++i) {
        printf("%d %d\n", l-i, l+i+1);
    }
    for (int i = 0; i < r; ++i) {
        printf("%d %d\n", 2*l+r-i, 2*l+r+i+2);
    }
    return 0;
}

Measured memory_bytes: 3764
#include<iostream>

using namespace std;

int main(){
  int n,i;
  
  cin>>n;
  
  for(i=n;i<999;i++){
    if(i==111||i==222||i==333||i==444||i==555||i==666||i==777||i==888||i==999)
      break;
  }
  cout<<i<<endl;
  return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct BIT{
    vint dat;
    BIT(int n){
        dat.resize(n+1);
    }
    void add(int k,int x){
        for(k++;k<dat.size();k+=k&-k)dat[k]+=x;
    }
    int sum(int k){
        int ret=0;
        for(k++;k;k-=k&-k)ret+=dat[k];
        return ret;
    }
};

int N;
int P[111111];
int L[111111];

signed main(){
    cin>>N;
    rep(i,N)cin>>P[i];
    rep(i,N)cin>>L[i];

    rep(i,N)P[i+1]+=P[i];

    vector<int>v;
    rep(i,N)v.pb(P[i]);
    sort(all(v));v.erase(unique(all(v)),v.end());

    BIT bit(N+114);
    int ans=0;
    for(int i=0;i<N;i++){
        int x=lower_bound(all(v),P[i])-v.begin();
        ans+=bit.sum(N)-bit.sum(x);
        bit.add(x,1);
    }

    sort(P,P+N);
    rep(i,N){
        int tmp=P[i]-(i?P[i-1]:0);
        if(tmp<L[i]){
            cout<<-1<<endl;
            return 0;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 6232
#include<stdio.h>
#include<string.h>
#pragma warning (disable : 4996)
#define g ;

int main() {

	int group;
	scanf("%d", &group); g;
	
	int total = 0;
	for (int k = 0; k < group; k++)
	{
		int start, end;
		scanf("%d %d", &start, &end); g;
		total += (end - start + 1);
	}
	printf("%d", total);

	g;
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
//#define int unsigned long long
#define all(x) (x).begin(), (x).end()
#define double long double

using namespace std;

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

int MOD = 998244353;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;


set<int>st;
int A[100010], B[100010], N;
void add_div(int x) {
	st.insert(x);
	for (int i = 2; i*i <= (x); i++) {
		if (x%i == 0) {
			st.insert(i);
			st.insert(x / i);
		}
	}
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	vector<int>v;
	v.resize(3);
	REP(i, 3) {
		cin >> v[i];
	}
	VSORT(v);
	int ans = v[2] - v[0];
	print(ans);
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 1000
main(){
  int i,j,l,v,t;
  int A[N];
  scanf("%d",&l);
  for(i=0;i<l;i++){
    scanf("%d", &A[i]);
  }
  for(i=1;i<=l;i++){
  for(t=0;t<l;t++){
    printf("%d",A[t]);
    if(t != l-1) printf(" ");
    else printf("\n");
  }
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;

  }

  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <stack>
#include <algorithm>
#include <string.h>
#include <queue>
#include <iomanip>
#include <map>
#include <cmath>
#include <set>
#include <climits>
#include <complex>
#define fi first
#define FI first
#define SE second.first
#define TH second.second
#define se second
using namespace std;
typedef long double ld;
//typedef complex<double> cd;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<vector<vector<ll>>> Matrix;
typedef pair<int, ii> iii;
const int maxN = 2e5 + 9, MOD = 998244353, LG = 11, BASE = 29;

set<int> dvs;
int n, m;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n >> m;
    
    for(int i = 1; i * i <= m; i++){
        if(m % i == 0){
            dvs.insert(i), dvs.insert(m / i);
        }
    }
    
    int ans = 0;
    
    for(auto it = dvs.begin(); it != dvs.end(); it++){
        if(m / *it >= n){
            ans = *it;
        }
    }
    cout << ans << '\n';
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int n,k,ans;
string s;
vector<int> b;

int main(){
    cin>>n>>k>>s;
    s ='#'+s;
    for(int i=1;i<=n;i++){
        int j=i;
        while(j<=n && s[j]==s[i])
            j++;
        j--;
        b.push_back(j-i+1);
        i=j;
    }
    if((int)b.size() <= 3){
        return !printf("%d\n",n-1);
    }
    if(k>=((int)b.size()/2)){
        return !printf("%d\n",n-1);
    }
    printf("%d\n",min(n-1,n-(int)b.size()+2*k));

}


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

int main(void) {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  vector<pair<int,int>> diffidx;
  long long suma = 0, sumb = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    suma += A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
    sumb += B[i];
    diffidx.emplace_back(-(A[i] - B[i]), i);
  }

  if (suma < sumb) {
    cout << -1 << endl;
    return 0;
  }

  // 差が最大のやつから借りてくるのがベスト？
  sort(diffidx.begin(), diffidx.end());
  for (int i = 0;i < N;i ++)
    diffidx[i].first = -diffidx[i].first;

  int maxid = 0;
  int ret = 0;
  for (int i = 0; i < N; i++) {
    int nokori = B[i] - A[i];
    // cerr << nokori << endl;
    if (nokori > 0) ret++;
    while (nokori > 0) {
      if (diffidx[maxid].first <= 0) {
        cout << -1 << endl;
        return 0;
      }
      if (nokori < diffidx[maxid].first) {
        diffidx[maxid].first -= nokori;
        nokori = 0;
      } else {
        nokori -= diffidx[maxid].first;
        diffidx[maxid].first = 0;
      }
      if (diffidx[maxid].first == 0) maxid++;
    }
  }
  for (int i = 0; i < N; i++) {
    int id2 = diffidx[i].second;
    if (diffidx[i].first != (A[id2] - B[id2])) {
      // cerr << i << " " << diffidx[i].first << endl;
      ret++;
    }
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, long long K, vector<long long> a){
	vector<ll> sum(N+1);
	rep(i, N) {
		sum[i+1] = sum[i] + a[i];
	}
	vector<ll> v;
	rep(i, N+1) {
		rep(j, N+1) {
			if (i >= j) continue;
			v.push_back(sum[j]-sum[i]);
			// cout << sum[j]-sum[i] << " ";
		}
	}
	// cout << endl;

	ll res = 0;
	for (ll i = 42; i >= 0; i--) {
		ll now = res + (1LL << i);
		ll cnt = 0;
		// cout << bitset<40>(1LL << i) << endl;
		rep(j, N*(N+1)/2) {
			if ((v[j]&now) == now) cnt++;
		}
		if (cnt >= K) res = now;
		// cout << bitset<40>(res) << endl;
	}

	cout << res << endl;
}

int main(){	
	long long N;
	long long K;
	scanf("%lld",&N);
	vector<long long> a(N-1+1);
	scanf("%lld",&K);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&a[i]);
	}
	solve(N, K, a);
	return 0;
}



Measured memory_bytes: 6388
#include <queue>
#include <cstring>
#include <iostream>
using namespace std;
int W, H, sx, sy, gx, gy, N, c, d, x, y, r[111][111], vis[111][111];
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int main() {
	while(cin >> W >> H, W | H) {
		cin >> sx >> sy >> gx >> gy; sx--, sy--, gx--, gy--;
		memset(r, 0, sizeof(r));
		cin >> N;
		for(int i = 0; i < N; i++) {
			cin >> c >> d >> x >> y; x--, y--;
			int zx = (d ? 2 : 4), zy = (d ? 4 : 2);
			for(int j = 0; j < zy; j++) {
				for(int k = 0; k < zx; k++) {
					r[y + j][x + k] = c;
				}
			}
		}
		memset(vis, 0, sizeof(vis)); vis[sy][sx] = 1;
		queue<pair<int, int> > que; que.push(make_pair(sx, sy));
		while(!que.empty()) {
			pair<int, int> v = que.front(); que.pop();
			for(int i = 0; i < 4; i++) {
				int tx = v.first + dx[i], ty = v.second + dy[i];
				if(0 <= tx && tx < W && 0 <= ty && ty < H && !vis[ty][tx] && r[ty][tx] == r[v.second][v.first]) {
					vis[ty][tx] = 1;
					que.push(make_pair(tx, ty));
				}
			}
		}
		cout << (vis[gy][gx] ? "OK" : "NG") << endl;
	}
	return 0;
}

Measured memory_bytes: 3208
n = int(input())
x = 1
print "",
while x <= n:
	if x%3==0:
		print str(x),
	else:
		t = x
		while t:
			if t%10==3:
				print str(x),
				t = 0
			else:
				t /= 10
	x += 1
print

Measured memory_bytes: 6400
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

cpp_int GCD(cpp_int x, cpp_int y) {
	return x ? GCD(y % x, x) : y;
}

cpp_int LCM(cpp_int m, cpp_int n)
{
	if ((0 == m) || (0 == n))
		return 0;

	return ((m / GCD(m, n)) * n); // lcm = m * n / GCD(m,n)
}

int main() {
	int n;
	cin >> n;
	vector<cpp_int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	cpp_int ans = 1;
	rep(i, n) {
		ans = LCM(ans, a[i]);
	}
	ans--;
	cpp_int count = 0;
	rep(i, n) {
		count += ans % a[i];
	}
	cout << count << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(){

int x,a,b,c,d,cnt;
while(scanf("%d",&x)==1){
    cnt=0;
for(a=0;a<=9;a++){
for(b=0;b<=9;b++){
    for(c=0;c<=9;c++){
        for(d=0;d<=9;d++)
        if((a+b+c+d==x))
        cnt++;
    }
}
}
printf("%d\n",cnt);

}


return 0;
}

Measured memory_bytes: 596
#include<stdio.h>

#define MAX 10000
#define NIL -1

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

struct Node Tree[MAX];
int Depth[MAX], Height[MAX];

void setDepth(int, int);
int setHeight(int);
int Sibling(int);
void Print(int);

int main(){
  int n,i,num,l,r;
  int root = 0;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++) Tree[i].parent = NIL;

  for(i = 0 ; i < n ; i++){
    scanf("%d%d%d",&num,&l,&r);
    Tree[num].left = l;
    Tree[num].right = r;
    if(l != NIL) Tree[l].parent = num;
    if(r != NIL) Tree[r].parent = num;
  }

  for(i = 0 ; i < n ; i++) if(Tree[i].parent == NIL) root = i;

  setDepth(root,0);
  setHeight(root);

  for(i = 0 ; i < n ; i++) Print(i);

  return 0;
}

void setDepth(int x, int y){
  if(x == NIL) return;
  Depth[x] = y;
  setDepth(Tree[x].left, y+1);
  setDepth(Tree[x].right, y+1);
}

int setHeight(int x){
  int h1 = 0, h2 = 0;
  if(Tree[x].left != NIL) h1 = setHeight(Tree[x].left) + 1;
  if(Tree[x].right != NIL) h2 = setHeight(Tree[x].right) + 1;

  if(h1 > h2) return Height[x] = h1;
  else return Height[x] = h2;
}

int Sibling(int x){
  if(Tree[x].parent == NIL) return NIL;
  if(Tree[Tree[x].parent].left != x && Tree[Tree[x].parent].left != NIL){
    return Tree[Tree[x].parent].left;
  }
  if(Tree[Tree[x].parent].right != x && Tree[Tree[x].parent].right != NIL){
    return Tree[Tree[x].parent].right;
  }

  return NIL;
}

void Print(int x){
  int degree = 0;
  printf("node %d: ",x);
  printf("parent = %d, ",Tree[x].parent);
  printf("sibling = %d, ",Sibling(x));
  if(Tree[x].left != NIL) degree++;
  if(Tree[x].right != NIL) degree++;
  printf("degree = %d, ",degree);
  printf("depth = %d, ",Depth[x]);
  printf("height = %d, ",Height[x]);

  if(Tree[x].parent == NIL){
    printf("root\n");
  }
  else if(Tree[x].left == NIL && Tree[x].right == NIL){
    printf("leaf\n");
  }
  else printf("internal node\n");
}



Measured memory_bytes: 2044
#include <stdio.h>
int color[8];
int main(void){
	int N;
	scanf("%d",&N);
	int i,temp;
	for(i=0;i<N;i++){
		scanf("%d",&temp);
		if     (temp<400)color[0]=1;
		else if(temp<800)color[1]=1;
		else if(temp<1200)color[2]=1;
		else if(temp<1600)color[3]=1;
		else if(temp<2000)color[4]=1;
		else if(temp<2400)color[5]=1;
		else if(temp<2800)color[6]=1;
		else if(temp<3200)color[7]=1;
		else color[8]++;
	}
	int ans = 0;
	for(i=0;i<8;i++){
		if(color[i]==1)ans++;
	}
	if(ans==0 && color[8]>0){
		ans = 1;
		color[8]--;
	}
	int minans = ans;
	int maxans = ans += color[8];
	printf("%d %d",minans,maxans);
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
  int n;
  char s[10001];
  scanf("%d%s", &n, s);
  for (int i = 0; s[i] != '\0'; i++) {
    if ((s[i] += n) > 'Z') s[i] -= 26;
  }
  puts(s);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define db double
using namespace std;
int read() {
	char c = getchar();
	int x = 0, f = 1;
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (; isdigit(c); c = getchar())
		x = x * 10 + c - 48;
	return x * f;
}
int a, b, h, m;
int main() {
	cin >> a >> b >> h >> m;
	double c = (h * 30 + m * 0.5) - (m * 6);
	c /= 180;
	c *= 3.14159265358979323846264;
	printf("%.12lf\n", sqrt(a * a + b * b - 2 * a * b * cos(c)));
	return 0;
}

Measured memory_bytes: 4136
#include<stdio.h>
int main() {
  int A[3];
  int a = 0, b = 0;
  scanf("%d %d %d",&A[0],&A[1],&A[2]);
  for(int i = 0; i < 3; i++) {
    if(A[i] == 5) a++;
    if(A[i] == 7) b++;
  }
  if(a == 2 && b == 1) printf("YES");
  else printf("NO");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define All(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    int n;
    cin >> n;

    vector<ll> one(61);
    vector<ll> zero(61);

    rep(i,n){
        ll tmp;
        cin >> tmp;

        ll tmp2 = 1;

        rep(j,61){
            if(tmp & tmp2){
                one[j]++;
            }else{
                zero[j]++;
            }

            tmp2 *= 2;
        }
    }

    rep(i,61){
        //cerr << one[i] << " " << zero[i] << endl;
    }

    ll ans = 0;
    int k = 1;

    rep(i,61){

        ll tmp = (one[i] * zero[i]) % MODN;

        tmp = (tmp * k) % MODN;

        ans = (ans + tmp) % MODN;

        k = (k * 2) % MODN;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a[1000],b[1000],i,z=0;
  char op[1000];
  for(i=0;1;i++){
    scanf("%d%s%d",&a[i],&op[i],&b[i]);
    if(op[i]=='?')break;
    z++;
  }
  for(i=0;i<=z;i++){
    if(op[i]=='-')printf("%d\n",a[i]-b[i]);
    if(op[i]=='*')printf("%d\n",a[i]*b[i]);
    if(op[i]=='/')printf("%d\n",a[i]/b[i]);
    if(op[i]=='+')printf("%d\n",a[i]+b[i]);
  }
  return 0;
}

Measured memory_bytes: 608
/* Simplicity and Goodness */

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int maxN = 2e5+2;


void solve()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int need = 0;

    while(b <= a) b *= 2, need ++;

    while(c <= b) c *= 2, need ++;

    if(need <= k) puts("Yes");
    else puts("No");
}

int main()
{
    int t = 1;
    // scn(t);
    while(t --) {
        solve();
    }
    return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 2e5+23;

int a[N], b[N];

void solve() {
  int n; scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", a+i, b+i);
  }
  sort(a, a+n);
  sort(b, b+n);
  int lo = a[n/2], hi = b[n/2];
  if (n%2 == 0) {
    lo = a[n/2]+a[n/2-1];
    hi = b[n/2]+b[n/2-1];
  }
  printf("%d", hi-lo+1);
}

int main() {
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 5348
H, W, K = map(int, input().split())

MOD = 10 ** 9 + 7
dp = [[0] * W for _ in range(H + 1)]
dp[0][0] = 1
for i in range(H):
    for j in range(W):
        for k in range(1 << (W - 1)):
            # Check valid connection
            ok = True
            for l in range(W - 2):
                if (k >> l) & 1 and k >> (l + 1) & 1:
                    ok = False

            if not ok:
                continue

            if j > 0 and k >> (j - 1) & 1:
                dp[i + 1][j - 1] += dp[i][j]
                dp[i + 1][j - 1] %= MOD
            elif j < W - 1 and k >> j & 1:
                dp[i + 1][j + 1] += dp[i][j]
                dp[i + 1][j - 1] %= MOD
            else:
                dp[i + 1][j] += dp[i][j]
                dp[i + 1][j] %= MOD

print(dp[-1][K - 1])


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

using namespace std;
typedef long long ll;

const double eps = 1e-10;

struct Point {
  double x, y, z;
  Point() {}
  Point(double x, double y, double z) : x(x), y(y), z(z) {}
  Point operator+(const Point& p) const { return Point(x + p.x, y + p.y, z + p.z); }
  Point operator-(const Point& p) const { return Point(x - p.x, y - p.y, z - p.z); }
  Point operator*(double k) const { return Point(x * k, y * k, z * k); }
  friend istream& operator>>(istream& is, Point& p) { return is >> p.x >> p.y >> p.z; }
};

double abs(const Point& a) {
  return sqrt(a.x * a.x + a.y * a.y + a.z * a.z);
}

double dot(const Point& a, const Point& b) {
  return a.x * b.x + a.y * b.y + a.z * b.z;
}

Point cross(const Point& a, const Point& b) {
  return Point(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
}

double distanceSP(const Point& a, const Point& b, const Point& p) {
  return abs(cross(b - a, p - a)) / abs(b - a);
}

struct Circle {
  Point c;
  double r;
  ll l;
  Circle() {}
  friend istream& operator>>(istream& is, Circle& c) { return is >> c.c >> c.r >> c.l; }
};

bool isThrough(Point& a, Point& b, Circle& c) {
  if (dot(b - a, c.c - a) < -eps) return abs(c.c - a) - c.r < eps;
  if (dot(a - b, c.c - b) < -eps) return abs(c.c - b) - c.r < eps;
  return distanceSP(a, b, c.c) - c.r < eps;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  int n, q;
  cin >> n >> q;

  vector<Circle> cs(n);
  for (int i = 0; i < n; i++) {
    cin >> cs[i];
  }

  for (int i = 0; i < q; i++) {
    Point a, b;
    cin >> a >> b;

    ll ans = 0;
    for (int j = 0; j < n; j++) {
      if (isThrough(a, b, cs[j])) ans += cs[j].l;
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3276
N = int(input())
A = list(map(int, input().split()))
mod = int(1e+9 + 7)
def inved(a):
  x, y, u, v, k, l = 1, 0, 0, 1, a, mod
  while l != 0:
    x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
    k, l = l, k % l
  return x

frac = 1
for i in range(N - 1):
  frac *= i+1
  frac %= mod
T = 0
for i in range(N - 1):
  k = inved(i+1)
  T += (k * (A[N - 1] - A[i])) % mod
  T %= mod
print((T*frac)%mod)

Measured memory_bytes: 14484
class Main{
	public static void main(String[] args){
		java.util.Scanner sc = new java.util.Scanner( System.in );
		int a = Integer.parseInt( sc.next() );
		int b = Integer.parseInt( sc.next() );
		System.out.println( a*b + " " + ( 2*a + 2*b ) );
	}
}

Measured memory_bytes: 26016
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000+10];
priority_queue<long long>que;
long long temparr1[1000000+10];
long long temparr2[1000000+10];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=3*n;i++)
	scanf("%lld",&arr[i]);
	long long sum = 0;
	for(int i=1;i<=n;i++) que.push(-arr[i]),sum+=arr[i],temparr1[i]=sum;
	for(int i=n+1;i<=2*n;i++) que.push(-arr[i]),sum+=arr[i]+que.top(),que.pop(),temparr1[i]=sum;
	while(!que.empty()) que.pop();sum = 0;
	for(int i=3*n;i>2*n;i--) que.push(arr[i]),sum+=arr[i],temparr2[i]=sum;
	for(int i=2*n;i>=n+1;i--) que.push(arr[i]),sum+=arr[i]-que.top(),que.pop(),temparr2[i]=sum;
	long long ans = 0x8000000000000000;
	for(int i=n;i<=2*n;i++)ans = max(ans,temparr1[i]-temparr2[i+1]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 12660
#include <stdio.h>

int n,S[2000];
int solve(int,int);

int main(){
  int q, m,i;

  scanf("%d",&n);

  for(i=0;n > i;i++)
    {
      scanf("%d",&S[i]);
    }
  scanf("%d",&q);

  for(i=0;q>i;i++)
    {
      scanf("%d",&m);
      if(solve(0,m)==1)printf("yes\n");
      else printf("no\n");
    }
  return 0;
}

int solve(int i,int m)
{
  if(m==0)return 1;
  if(i>=n)return 0;
  int res = solve(i+1,m)||solve(i+1,m-S[i]);
  return res;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;cin>>n;
  long long int sum=0;
  for(int i=1;i<=n;i++){
    if((i%3!=0)&&(i%5!=0))
      sum+=i;
  }
  cout<<sum;
  return 0;
}  
  

Measured memory_bytes: 3652
# include <bits/stdc++.h>
# define ll long long
# define all(x) x.begin(), x.end()
# define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
# define MOD 1000000007
														
using namespace std;

vector <ll> factmod;
vector <ll> inversemod;
ll powmod(int x,int y){
	ll re=1;
	ll curr=x;
	while(y){
		if (y&1){
			re=(re*curr)%MOD;
		}
		curr=(curr*curr)%MOD;
		y>>=1;
	}
	return re;
}

ll combi (int x,int y){
	return factmod[y]*inversemod[x]%MOD*inversemod[y-x]%MOD;
}

int main(){
	fastio;
	int h,w,a,b;
	cin>>h>>w>>a>>b;
	h--;w--;a--;b--;
	factmod.assign(h+w,1);
	inversemod.assign (h+w,1);
	for (int i=1;i<h+w;i++){
		factmod[i]=factmod[i-1]*i%MOD;
		inversemod[i]=powmod(factmod[i],MOD-2);
	}
	ll ans=0;
	if (b<w){
		for (int h1=0;h1<h-a;h1++){
			ll tmp=combi(h1,h1+b)%MOD;
			ans=(ans+tmp*combi(h-h1,h-h1+w-b-1))%MOD;
		}
	}
	cout<<ans<<'\n';
	return 0;
}
	


Measured memory_bytes: 6276
//abc176_b.cpp
//Sat Aug 22 20:51:42 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	string s;
	cin >> s;

	int total = 0;
	rep(i,s.length()){
		int tmp = s[i]-'0';
		total += tmp;
	}


	if (total%9==0){
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<string> s(N);
    vector<int> t(N);
    for (int i = 0; i < N; i++) {
        cin >> s[i] >> t[i];
    }

    string X;
    cin >> X;

    int ans = 0;
    bool sleep = false;
    for (int i = 0; i < N; i++) {
        if (sleep) {
            ans += t[i];
        }
        if (s[i] == X) {
            sleep = true;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
testimonies = []
for _ in range(n):
    a = int(input())
    testimony = [list(map(int, input().split()))  for _ in range(a)]
    testimonies.append(testimony)
    
ans = 0
for i in range(2 ** n):
    honesty = [0 for _ in range(n)]
    for j in range(n):
        if ((i >> j) & 1):
            honesty[j] = 1
    #print(f'---- honesty: {honesty} ----')
    
    for j in range(n):
        contradiction = True
        if honesty[j]:
            #print(f'all of what {j+1} said are {testimonies[j]}')
            for testimony in testimonies[j]:
                #print(f'testimony: {testimony[0]} is {testimony[1]}')
                #print(f'fact: {testimony[0]} is {honesty[testimony[0] - 1]}')
                if honesty[testimony[0] - 1] == testimony[1]:
                    continue
                #print('contradiction happened!')
                contradiction = False
                break
            
        if not contradiction:
            break
    
    if contradiction:
        ans = max(ans, honesty.count(1))
    #print(f'ans: {ans}')

print(ans)
        

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

int main() {
  int h, w;
  cin >> h >> w;

  // 障害物の情報
  vector<vector<int>> xs(h);
  vector<vector<int>> ys(w);

  // 番兵として、h,wの0番目とn番目に障害物を入れる
  rep(i, w) {
    ys[i].push_back(0);
    ys[i].push_back(h+1);
  }
  rep(i, h) {
    xs[i].push_back(0);
    xs[i].push_back(w+1);
  }
  rep(i, h) {
    rep(j, w) {
      int x = j+1;
      int y = i+1;
      char c;
      cin >> c;
      // 障害物がある場合にxs,ysに障害物の情報を入れる
      if(c == '#') {
        xs[i].push_back(x);
        ys[j].push_back(y);
      }
    }
  }

  // ソートする
  rep(i, w) {
    sort(ys[i].begin(), ys[i].end());
  }
  rep(i, h) {
    sort(xs[i].begin(), xs[i].end());
  }

  // 明かりの数を調べる
  int max_cnt = 0;
  rep(i, h) {
    rep(j, w) {
      int x = j+1;
      int y = i+1;

      if(binary_search(xs[i].begin(), xs[i].end(), x) || binary_search(ys[j].begin(), ys[j].end(), y)) {
        // 障害物の上なのでskip
        continue;
      }

      auto l_at = lower_bound(xs[i].begin(), xs[i].end(), x);
      int xrange = *l_at - *prev(l_at) - 1;
      auto u_at = lower_bound(ys[j].begin(), ys[j].end(), y);
      int yrange = *u_at - *prev(u_at) - 1;

      // printf("(%d, %d): %d - %d\n", x, y, *next(l_at), *l_at);
      // printf("(%d, %d): xrange -> %d, yrange -> %d\n", x, y, xrange, yrange);

      int cnt = xrange + yrange - 1;
      max_cnt = max(cnt, max_cnt);
    }
  }

  cout << max_cnt << endl;
  return 0;
}

Measured memory_bytes: 34304
import sys
import math
from collections import Counter
import itertools
import fractions
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################
 
N=II()
S=[''.join(sorted(SR())) for _ in range(N)]
C=Counter(S)
ans = 0
for c in C.values():
    if c>1:
        ans+=c*(c-1)/2
print(int(ans))

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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;

int main(){
  int n;
  cin >> n;
  bool pow3 = false; int tmp = n;
  while(tmp % 3 == 0) tmp /= 3;
  if(tmp == 1) pow3 = true;
  double res = log(n)/double(log(3));
  cout << (pow3 ? res : (int)res + 1) << endl;
  return 0;
}

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

int main(){
    long long A, B,N;
    cin>>A>>B>>N;
    long x=min(B-1,N);
    cout<<A*x/B<<endl;

    return 0;
}


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

int main(){
    int a[5], k, i, j;
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;
    for(i=0; i<5; i++){
        for(j=i+1; j<5; j++){
            if(abs(a[i]-a[j]) > k){
                cout << ":(";
                return 0;
            }
        }
    }
    cout << "Yay!";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int a[44],n,i;

  scanf("%d",&n);

  a[0]=a[1]=1;

  for(i=2;i<=n;i++){
    a[i]=a[i-1]+a[i-2];
  }

  printf("%d\n",a[n]);
  return 0;
}



Measured memory_bytes: 2112
def sum_part(N, k):
  return k*(2*N-k+1)/2-k*(k-1)/2+1
  
N, K = map(int, input().split())
ans = 0
for k in range(K,N+2):
  ans += sum_part(N, k)
  
ans = ans % (10**9 + 7)
  
print(int(ans))

Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define PI 3.14159265359

int main(){
    int a, b; cin >> a >> b;
    string s; cin >> s;
    if(s[a] != '-'){
        cout << "No" << endl;
        return 0;
    }
    rep(i, a){
        if(s[i] < '0' or s[i] > '9'){
            cout << "No" << endl;
            return 0;
        }
    }
    repr(i, a+1, s.size()){
        if(s[i] < '0' or s[i] > '9'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3604
#include<iostream>
using namespace std;
int main(){  
     int p;
     int a[5]={1,2,3,4,5},b[5];
     for(int i=0;i<5;i++){
         cin >> b[i]; 
     }
     for(int n=0;n<5;n++){
         if(b[n]==0){
             p=a[n];
         }
     }
    cout << p;
    return 0;
 }

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

int main() {
    int n, m;
    cin >> n >> m;
    int a[n], sum[n+1];
    sum[0] = 0;
    rep(i, n) {
        cin >> a[i];
        sum[i+1] = (sum[i] + a[i]) % m;
    }
    ll ans = 0;
    map<int, int>mp;
    rep(i, n+1) {
        ans += mp[sum[i]];
        mp[sum[i]]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof a)
#define MAX 100005
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    if(t>=30)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 3600
const double = Float64
const int = Int64
const vint = Vector{int}
const vdouble = Vector{double}

int(x) = parse(int,x)

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  n = readint()[1]
  s = readline()

  c = 0
  d = Dict{Char,int}()
  d['R']=0
  d['G']=0
  d['B']=0
  for i in 1:n
    d[s[i]]+=1
  end
  
  for i in 1:n-2 
    for j in i+1:n-1
      if -i + 2j > n
        break
      end
      k = 2j-i
      if s[i] != s[j] && s[j]!=s[k] && s[i]!=s[k]
        c += 1
      end
    end
  end
  println(d['R']*d['G']*d['B']- c)
end

main()

Measured memory_bytes: 234716
#include<iostream>

using namespace std;

int main(){
  int N,i;
  int A[111111],B[111111];
  cin >> N;
  for(i=1;i<=N;i++)
    cin >> A[i];
  for(i=1;i<=N;i++)
    B[A[i]] = i;
  for(i=1;i<=N;i++)
    cout << B[i] << endl;
}

Measured memory_bytes: 1664
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

#define dump1(v) for(auto i:v) std::cout << i << ' '; std::cout << "\n";
#define dump2(v) for(auto i:v) { for(auto j:i) std::cout << j << ' '; std::cout << "\n"; }

/* <LCS> */
std::vector<std::vector<int> > LCS(std::string a, std::string b) {
	std::vector<std::vector<int> > dp(a.size()+1,std::vector<int>(b.size()+1));
	for(int i=0;i<a.size();i++) for(int j=0;j<b.size();j++) {
		if(a[i]==b[j]) dp[i+1][j+1]=dp[i][j]+1;
		else dp[i+1][j+1] = std::max(dp[i+1][j],dp[i][j+1]);
	}
	return dp;
}
/* <LCS> */


signed main() {
	std::string s;
	std::cin >> s;

	const std::string a = "AKIHABARA";

	std::string t = "A";
	for(auto i:s) {
		t+=i;
		t+='A';
	}

	if(LCS(s,a)[s.size()][a.size()]==s.size() && LCS(t,a)[t.size()][a.size()]==a.size()) {
		print("YES");
	} else print("NO");
	return 0;
}


Measured memory_bytes: 256