akhauriyash/Code-Regression huggingface dataset:
/*
	ID: Abhinav
	LANG: C++11
	TASK: inna and matrix
	*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;	
int main()
{
    int n,count =0;
    cin>>n;
    ll arr[n];
  
    for(int i=0;i<n;++i)
    {
      cin>>arr[i];
    }
  
    for(int i=0;i<n;++i)
    {
      for(int j=i+1;j<n;++j)
      {
        for(int k=j+1;k<n;++k)
        {
          if(arr[i]+arr[j]>arr[k] &&  arr[j]+arr[k]>arr[i] && arr[i]+arr[k]>arr[j] )
          {
            if(arr[i]!=arr[j] && arr[i] !=arr[k] && arr[j]!=arr[k])
            count++;
          }
        }
      }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <set>
#include <utility>

using namespace std;

typedef pair<int, int> ip;

int a[1 << 18], n;

set<ip> s[1 << 18];
int res[1 << 18];

int main() {
	scanf("%d", &n);
	int m = n;
	n = (1 << n);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	for (int i = 0; i < n; i++)
		s[i].insert(ip(a[i], i));
	for (int i = 0; i < n; i++) {
		while (s[i].size() > 2) s[i].erase(s[i].begin());
		if (s[i].size() == 2) res[i] = (*s[i].begin()).first + (*s[i].rbegin()).first;
		for (int j = 0; j < m; j++) if ((i&(1 << j)) == 0) {
			for (set<ip>::iterator it = s[i].begin(); it != s[i].end(); it++)
				s[i | (1 << j)].insert(*it);
		}
	}
	for (int i = 1; i < n; i++) {
		if (res[i - 1] > res[i]) res[i] = res[i - 1];
		printf("%d\n", res[i]);
	}
	return 0;
}

Measured memory_bytes: 54144
#include<iostream>
using namespace std;
int a[10],bo;
void dfs(int x,int l,int r)
{
    if(x==10)
        return ;
    if(bo)
        return ;
    if(a[x]>l)
        dfs(x+1,a[x],r);
    else if(a[x]>r)
        dfs(x+1,l,a[x]);
    else
    {
        bo=1;
        return ;
    }
}
    int main()
    {

        int n,i;
        cin>>n;
        while(n--)
        {
            bo=0;
            for(i=0;i<10;i++)
            {
                cin>>a[i];
            }
            dfs(0,0,0);
            if(bo)
                cout<<"NO"<<endl;
            else
                cout<<"YES"<<endl;
        }
        return 0;
    }

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

void swap(int A[], int i, int j)
{
    int t = A[i];
    A[i]  = A[j];
    A[j]  = t;
}

int partition(int A[], int p, int r)
{
    int x = A[r], i = p - 1;
    for (int j = p; j <= r; j++) {
        if (A[j] > x) continue;
        swap(A, ++i, j);
    }
    return i;
}

int main()
{
    int n;
    cin >> n;
    int A[n];
    for (int i = 0; i < n; i++) cin >> A[i];
    int p = partition(A, 0, n - 1);
    for (int i = 0; i < n; i++) {
        if (i == p) cout << "[" << A[i] << "]";
        else cout << A[i];
        if (i == (n - 1)) cout << endl;
        else cout << " ";
    }
    return 0;
}

Measured memory_bytes: 3436
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n, p;
  cin >> n >> p;
  map <ll, ll> s;
  for (ll i = 2; i*i <= p; i++) {
    if (p%i == 0) {
      s[i] = 0;
      while (p%i == 0) {
        s.at(i)++;
        p /= i;
      }
    }
  }
  if (p > 1) s[p] = 1;
  ll res = 1;
  for (auto i : s) {
    res *= (ll)pow(i.first, i.second/n);
  }
  cout << res << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Main {
    public static void main(String[] args) throws IOException {
       Scanner in = new Scanner(System.in);
       int a, b;
       a = in.nextInt();
       b = in.nextInt();
       int d = a/b;
       int r = a%b;
       double f = (double)a / b;
       System.out.printf("%d %d %f\n", d, r, f);
    }
}

Measured memory_bytes: 17244
#include<stdio.h>
#include<math.h>

int main(void)
{
	int N, n=0, i;
	
	scanf("%d", &N);
	
	for(i=0; i<10; i++){
		n += (N / (int)pow(10.0,i)) % 10;
	}
	
	if(N%n == 0){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 256
def main():
  s = input()
  p = len(s)
  i = 0
  ans = 0
  for i in range(2 ** (p-1)):
    t = s[0]
    for j in range(0,p-1):
      if (i & (1 << j)):
        t = t + "+"
      t = t + s[j+1]
      
    #print(bin(i),t,eval(t))
    ans += eval(t)
    
  print(ans)
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 8936
Q = int(input())
AB = [tuple(map(int, input().split())) for _ in range(Q)]
for A, B in AB:
    C = (A * B)**0.5

    if A == B:
        print(A * 2 - 2)
    else:
        if C.is_integer():
            C -= 1

        C = int(C)

        if C * (C + 1) >= A * B:
            print(C * 2 - 2)
        else:
            print(C * 2 - 1)

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

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

 int v,w,y,z;
 int a = 0;

 for (int i = A; i <= B; i++) {
 
  v =  A / 10000 % 10;
  w =  A / 1000  % 10;
  y =  A / 10    % 10;
  z =  A         % 10;

  if (v != z || w != y) {
     A++;
   }
  
  else if (v == z && w == y) {
   a++;
   A++;
   }

  }

  cout << a << endl;

return 0;

}


Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m,c = li()
b = list(li())
a = [list(li()) for _ in range(n)]

ans = 0
for ai in a:
    if sum([aij*bi for aij, bi in zip(ai, b)]) + c > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3064
import math
p=1
q=1
while p==1:
    o=0
    n=int(input())
    if n==0:
        break
    else:
        x=math.factorial(n)
        while q==1:
            y=x%10
            if y==0:
                o+=1
                x=x//10
            else:
                break
    print(o)


Measured memory_bytes: 5788
#include<stdio.h>//??????H cm ?????? W cm ???????????¢?????????????????°??????
 
int main(void){
  
    int a,b,i,j;
 
    while(1){
        scanf("%d %d",&a,&b);
        if(a==0&&b==0)
            break;
        for(i=0;i<a;i++){
            if(i==0||i==(a-1)){
                for(j=0;j<b;j++)
                    printf("#");
            }
            else {
                printf("#");
                for(j=1;j<b-1;j++)
                    printf(".");
                printf("#");
            }
                printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;

int n;
int inp[N], c[N];

int last[N];
long long dp[N];

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

    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> inp[i];

    int tt = 0;
    for(int i = 1; i <= n; i++)
        if(inp[i] != inp[i - 1])
            c[++tt] = inp[i];
    n = tt;

    dp[0] = 1;
    for(int i = 1; i <= n; i++)
    {
        if(last[c[i]])
            dp[i] = dp[last[c[i]]];

      //  cerr << dp[i] << " DP " << endl;

        dp[i] = (dp[i - 1] + dp[i]) % MOD;
        last[c[i]] = i;
    }

    cout << dp[n] << endl;

    return 0;
}



Measured memory_bytes: 4224
import           Control.Monad
import           Data.List
main = do
    x <- replicateM 5 readLn :: IO [Int]
    let a:aa = reverse $ sortOn (\i -> f i) x
    print $ sum (map (\i -> i + f i ) aa) + a
  where
    f n = if n `mod` 10 == 0 then 0 else 10 - n `mod` 10

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define int  long long int
#define fi first
#define se second
#define pb push_back
#define soo(v) sort(v.rbegin(),v.rend())
#define so(v) sort(v.begin(),v.end())
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define endl '\n'
#define dbv(v) cout<<endl;cout<<#v<<"-->> ";for(auto it:v){cout<<it<<" ";}cout<<endl;
#define dbm(m)cout<<endl;cout<<#m<<"-->> ";for(auto it:m){cout<<it.fi<<" "<<it.se<<endl;}
#define dbs(s)cout<<endl;cout<<#s<<"-->> ";for(auto it:s){cout<<it<<" ";}cout<<endl;
#define mod 2019
#define db1(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl;
#define mx 1e18
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v)  *min_element(v.begin(),v.end())
#define double long double
#define re(s) reverse(s.begin(),s.end())
#define io std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pp 1000000000000000000
int powe(int x,int n)
{
  if(n==0)return 1;
  if(n%2==0)
    return powe((x%mod*x%mod)%mod,n/2)%mod;
  return (x%mod*powe((x%mod*x%mod)%mod,(n-1)/2))%mod;
}
int gcd(int A,int B)
{
  if(B==0)return A;
  return gcd(B,A%B);
}
int32_t main()
{
  io
int n;
cin>>n;map<int,int>m;int nn=n;
for(int i=2;i<=sqrt(n);i++)
{
 while(n%i==0)
 {
  n/=i;
  m[i]++;
 }
}
if(n>2)
{
  m[n]++;
}
//dbm(m);
vector<int>vv;
for(auto it:m)
{
  for(int j=1;j<=it.second;j++)
  {
    vv.pb(pow(it.first,j));
  }
}int ans=0;

  for(int i=0;i<vv.size();i++)
  {
    if(nn%vv[i]==0)
    {
      ans++;
      nn/=vv[i];
      
    }
  }
//dbv(vv)
cout<<ans<<endl;
}

Measured memory_bytes: 4088
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define all(a) a.begin(), a.end()
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 2 * 205000;
const int mod = (int) 1e9 + 7;

long long binpow(long long x, long long p) {
  long long res = 1;
  while (p) {
    if (p & 1) {
      res = (res * x) % mod;
      p--;
    } else {
      x = (x * x) % mod;
      p /= 2;
    }
  }
  return res % mod;
}

long long inv(long long x) {
  return binpow(x, mod - 2) % mod;
}

long long f[MAXN], invF[MAXN];

long long cnk(long long n, long long k) {
    long long res = f[n];
    res = res * invF[k] % mod;
    res = res * invF[n - k] % mod;
    return res % mod;
}

int n;
vector<int> g[MAXN];
long long dp[MAXN];
long long ans[MAXN];
int sz[MAXN];

void calcDp(int v, int par = -1) {
    sz[v] = 1;
    for (int to : g[v]) {
        if (to != par) {
            calcDp(to, v);    
            sz[v] += sz[to];
        }
    }
    dp[v] = 1;
    int rem = sz[v] - 1;
    for (int to : g[v]) {
        if (to == par) {
            continue;
        }
        dp[v] = 1ll * dp[v] * cnk(rem, sz[to]) % mod;
        dp[v] = 1ll * dp[v] * dp[to] % mod;
        rem -= sz[to];
    }
}

void calcAns(int v, long long fromPar, int par = -1) {
    // cerr << v << " " << fromPar << endl;
    ans[v] = dp[v];
    if (par != -1) {
        int szPar = n - sz[v];
        int curSz = sz[v] - 1;
        ans[v] = 1ll * ans[v] * fromPar % mod;
        ans[v] = 1ll * ans[v] * cnk(curSz + szPar, szPar) % mod;
    }
    for (int to : g[v]) {
        if (to == par) {
            continue;
        }
        long long curFromPar = ans[v];
        int toSz = sz[to];
        int curSz = n - 1 - sz[to];
        curFromPar = curFromPar * inv(dp[to]) % mod;
        curFromPar = curFromPar * inv(cnk(curSz + toSz, toSz)) % mod;
        calcAns(to, curFromPar, v);
    }
}

int main() {

    scanf("%d", &n);
    for (int i = 0; i < n - 1; i++) {
        int from, to;
        scanf("%d %d", &from, &to);
        from--; to--;
        g[from].push_back(to);
        g[to].push_back(from);
    }

    f[0] = 1; invF[0] = inv(1);
    for (int i = 1; i <= 2 * n; i++) {
        f[i] = 1ll * f[i - 1] * i % mod;
        invF[i] = inv(f[i]);
    }

    calcDp(0);
    calcAns(0, 1);

    // for (int i = 0; i < n; i++) {
    //     cerr << dp[i] << " ";
    // }
    // cerr << endl;

    for (int i = 0; i < n; i++) {
        printf("%lld\n", ans[i]);
    }

    return 0;
}


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

int main(){
	int n;
	while (cin >> n ) {
		if (n == 0) { break; }
		int dot[2][1001] = {}, max = 0, kake = 42, han;
		string inl;
		for (int i = 0; i < n; i++) {
			cin >> inl;
			for (int j = 1; j <= n; j++) {
				han = inl[j - 1];
				if (han == kake) {
					dot[1][j] = 0;
				}
				else {
					dot[1][j] = min({ dot[0][j],dot[1][j - 1],dot[0][j - 1] }) + 1;
				}
				if (max < dot[1][j]) {
					max = dot[1][j];
				}
			}
			for (int i = 1; i <= n; i++) {
				dot[0][i] = dot[1][i];
			}
		}
		cout << max << endl;
	}

	return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp
ld pi = 3.141592653589793;;

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ld a, b, h ,m;
    cin >> a >> b >> h >> m;

    //時
    ld a_x = a * cos((pi*h / 6) + (pi*m / 360));
    ld a_y = a * sin((pi*h / 6) + (pi*m / 360));

    //分
    ld b_x = b * cos(pi*m/30);
    ld b_y = b * sin(pi*m/30);
    /*
    cout << a_x << endl;
    cout << a_y << endl;
    cout << b_x << endl;
    cout << b_y << endl;
    */
    ld ans = 0;

    ld tmp = (a_x - b_x) * (a_x - b_x);
    ld tmp2 = (a_y - b_y) * (a_y - b_y);
    /*
    cout << tmp << endl;
    cout << tmp2 << endl;
    */
    cout << sqrt(tmp + tmp2) << endl;
 



}

Measured memory_bytes: 4168
#include<iostream>
#include<string>
#include <bits/stdc++.h>
#include<vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <math.h>
#include <iomanip>
using namespace std;
using ll = long long;

int main(){
  char a;
  cin >> a;
  if(isupper(a)){
    cout << "A" << endl;
  }else{
    cout << "a" << endl;
  }
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){
    int r,D;cin >> r >> D;
    int x;cin >> x;
    Rep(i,10){
        x = r*x - D;
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 3576
n=int(input())
s=[]
for i in range(n):
    t=int(input())
    s.append(t)
ans=sum(s)
if ans%10==0:
    m=200
    for i in range(n):
        if s[i]%10!=0 and s[i]<m:
            m=s[i]
    if m==200:
        ans=0
    else:
        ans-=m
print(ans)

Measured memory_bytes: 3060
from numpy import argsort
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_sorted = sorted(A)
B_sorted = sorted(B) + [0]
for i, (a, b) in enumerate(zip(A_sorted, B_sorted)):
    if a > b:
        print("No")
        exit()
for i, (a, b) in enumerate(zip(A_sorted, B_sorted)):
    if a <= B_sorted[i-1]:
        print("Yes")
        exit()

A_rank = list(argsort(argsort(A)))
B_rank = list(argsort(argsort(B)))
B_rank_inv = [2*N] * N
for i, b in enumerate(B_rank):
    B_rank_inv[b] = i
a = 0
for i in range(N-1):
    a = A_rank[B_rank_inv[a]]
    if a==0:
        print("Yes")
        exit()
print("No")


Measured memory_bytes: 33176
// template version 1.14
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;
const int MOD=1e9+7;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  int n,m;cin>>n>>m;/*{{{*/
  vector<int> a(n);
  rep(i, n) {
    cin>>a[i];
  }
  sort(all(a));
  dump(a);

  vi b(a);
  rep(i,1,n) b[i]+=b[i-1];
  dump(b);/*}}}*/

  int left = 0;/*{{{*/
  int right = 20000000000000000+3;
  auto isright = [&](int x) {  // right: out
    int cnt = 0;  // xいじょうになるペアの数
    rep(i, n){
      int c = a.end() - lb(all(a), x-a[i]);
      cnt += c;
    }
    if (cnt>=m) return false;
    else        return true;
  };
  while (right-left>1){
    int mid = (right+left)/2;
    if (isright(mid)) { right = mid;}
    else{ left = mid; }
  }
  dump(right-1);/*}}}*/
  int need = right-1;

  int ans = 0;
  rrep(i, n){
    if(m>=1 && 2*a[i]>need){
      ans += 2*a[i];
      m--;
    }

    int j = ub(all(a), need-a[i]) - a.begin();
    if (m>=2*(i-j) && i>0 && (i-j)>0){
      if (j-1>=0){
        dump(b[i-1] - b[j-1]);
        ans += 2*(b[i-1] - b[j-1]);
      }
      else        ans += 2*(b[i-1]);
      ans += 2*(i-j)*a[i];
      m -= 2*(i-j);
    }
    else{
      rrep(k, j, i){
        if (m>=2){
          ans += 2*(a[k]+a[i]);
          m -= 2;
        }
        else if (m==1){
          ans += (a[k]+a[i]);
          m -= 1;
        }
      }
    }
  }
  dump(ans,m);
  ans += need*m;
  cout << ans << endl;

  return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  ll N;
  cin >> N;
  vector<ll> H(N);
  for (int i = 0; i < N; ++i) {
    cin >> H[i];
  }
  ll ret = 0;
  ll r=0;
  ll now =H[0];
  for (int j = 1; j < N; ++j) {
    if(now>=H[j]){
      now=H[j];
      r++;
    }else{
      if(ret<r)
        ret=r;
      r=0;
      now=H[j];
    }
  }
  if(ret<r)
    ret=r;
  cout << ret << endl;
}


Measured memory_bytes: 1024
N, M = map(int, input().split())

INF = 10**9
dp = [[INF]*(1<<N) for _ in range(M+1)]
dp[0][0] = 0

for i in range(M):
  a, b = map(int, input().split())
  c = sum(map(lambda x: 1 << (int(x)-1), input().split()))
  for j in range(1<<N):
    k = j|c
    dp[i+1][j] = min(dp[i+1][j], dp[i][j])
    dp[i+1][k] = min(dp[i+1][k], dp[i][k], dp[i][j] + a)

ans = dp[-1][-1]

if ans == INF:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 107584
import sys
sys.setrecursionlimit(10 ** 5)

N = int(input())

C = [-1] * N  # Colors
E = [[] for _ in range(N)]  # Edges
swap = {0: 1, 1: 0}


def coloring(v, c):
    C[v] = c
    for e in E[v]:
        if C[e[0]] == -1:
            coloring(e[0], c if e[1] % 2 == 0 else swap[c])


for i in range(N - 1):
    u, v, w = map(int, input().split())
    E[u - 1].append((v - 1, w))
    E[v - 1].append((u - 1, w))

coloring(0, 0)

for c in C:
    print(c)


Measured memory_bytes: 157344
#include <bits/stdc++.h>
//#include <ext/rope>

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define last(s) (s)[(int)((s).size())-1]
#define prelast(s) (s)[(int)((s).size())-2]
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define elif else if
#define left asdasd
#define next zaza
//#define prev azaz
#define cclear cout<<flush;
#define x0 kerker
//#define time chas
#define y0 lolik
#define x1 ashkjl
#define y1 fakakaka
#define y2 ololol
#define x2 jejejejej
#define kchay ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define files freopen("robot.in", "r", stdin);freopen("robot.out", "w", stdout);
#define ref svyazi
// #define int long long
#define lint __int128
#define ii pair<int, int>
#define llong long long
#define ld long double
#define list spisok
#define tm kozerog
    
    
const ld eps = 1e-9;
const ld Pi = acos(-1);
const int md = (1e9+7);
// const int fakmd = 998244353;
// const int mod = (1 << 30) + 1;

using namespace std;
//using namespace __gnu_cxx;

/*

*/

bool used[10];
vector<int> g[10];
int x, y;

void dfs(int x, int gl = 1) {
    used[x] = true;
    if(gl == 4) {
        cout << "YES";
        exit(0);
    }
    
    for(auto& i : g[x]) {
        if(used[i])continue;
        dfs(i, gl + 1);
    }
    used[x] = false;
}

int32_t main() {
    kchay;
    // files;
    for(int i = 1; i <= 3; i++) {
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    
    for(int i = 1; i <= 4; i++) {
        dfs(i);
    }
    
    cout << "NO";
    return 0;
}

Measured memory_bytes: 256
// AOJ 2765: Steelyard
// 2017.10.10 bal4u@uu

#include <stdio.h>

int main()
{
	int l, n, x, w, left, right;

	scanf("%d%d", &l, &n);
	left = right = 0;
	while (n-- > 0) {
		scanf("%d%d", &x, &w);
		if      (x < 0)  left += -x * w;
		else if (x > 0) right +=  x * w;
	}
	if      (left == right) puts("0");
	else if (left < right) printf("1\n-1 %d\n", right-left);
	else                   printf("1\n1 %d\n", left-right);
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/****** define constant end ********/
/****** define variable start ******/
ll n, a, b;
vl p;
/******* define variable end *******/
int solve() {
	cin >> n >> a >> b;
	p.resize(n);
	ll q1 = 0;
	ll q2 = 0;
	ll q3 = 0;
	REP(i ,n){
		cin >> p[i];
		if(p[i] <= a){
			q1++;
		}else if(p[i] >= a + 1 && p[i] <= b){
			q2++;
		}else if(p[i] >= b + 1){
			q3++;
		}
	}
	cout << min(q1, min(q2, q3)) << endl;

	return 0;
}

int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    total = sum(a)
    count = 0

    for ai in sorted(a, reverse=True):
        if (ai * 4 * m) >= total:
            count += 1

    if count >= m:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


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

int main() {
	int h,w;
	cin >> h >> w;
	char a[h][w];
	bool ok = true;
	//上からh左からw
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			if (i == 0) {
				if (j == 0) {
					if (a[i][j] == '#') {
						if (a[i+1][j] != '#' && a[i][j+1] != '#') {
							ok = false;
						}
					}
				} else if (j == w - 1) {
					if (a[i][j] == '#') {
						if (a[i+1][j] != '#' && a[i][j-1] != '#') {
							ok = false;
						}
					}
				} else {
					if (a[i][j] == '#') {
						if (a[i+1][j] != '#' && a[i][j+1] != '#' && a[i][j-1] != '#') {
							ok = false;
						}
					}
				}
			} else if (i == h - 1) {
				if (j == 0) {
					if (a[i][j] == '#') {
						if (a[i-1][j] != '#' && a[i][j+1] != '#') {
							ok = false;
						}
					}
				} else if (j == w - 1) {
					if (a[i][j] == '#') {
						if (a[i-1][j] != '#' && a[i][j-1] != '#') {
							ok = false;
						}
					}
				} else {
					if (a[i][j] == '#') {
						if (a[i-1][j] != '#' && a[i][j+1] != '#' && a[i][j-1] != '#') {
							ok = false;
						}
					}
				}
			} else {
				if (j == 0) {
					if (a[i][j] == '#') {
						if (a[i-1][j] != '#' && a[i+1][j] != '#' && a[i][j+1] != '#') {
							ok = false;
						}
					}
				} else if (j == w - 1) {
					if (a[i][j] == '#') {
						if (a[i-1][j] != '#' && a[i+1][j] != '#' && a[i][j-1] != '#') {
							ok = false;
						}
					}
				} else {
					if (a[i][j] == '#') {
						if (a[i-1][j] != '#' && a[i+1][j] != '#' && a[i][j+1] != '#' && a[i][j-1] != '#') {
							ok = false;
						}
					}
				}
			}
		}
	}
	if (ok) {
		cout << "Yes";
	} else {
		cout << "No";
	}
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int count = 0;
  rep(i,n) if(s.substr(i,3)=="ABC") count++;
  
  cout << count << endl;
  
}


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

typedef pair<string, int> P;
int W, H, N, dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
string rgb = "RGB";

bool check(const string& s)
{
  char c = s[0];
  for(int i = 0; i < W * H; i++)
    if(s[i] != c)
      return false;
  return true;
}

string f(char c, string s)
{
  char a = s[0];
  N = 0;
  queue<int> q;
  q.push(0);
  q.push(0);
  while(!q.empty())
  {
    int x = q.front(); q.pop();
    int y = q.front(); q.pop();
    if(s[y * W + x] == c)
      continue;
    s[y * W + x] = c;
    N++;
    for(int i = 0; i < 4; i++)
    {
      int tx = x + dx[i], ty = y + dy[i];
      if(tx >= 0 && tx < W && ty >= 0 && ty < H && 
          s[ty * W + tx] == a)
      {
        q.push(tx);
        q.push(ty);
      }
    }
  }
  return s;
}

int main()
{
loop:
  stringstream ss;
  string s;
  cin >> W >> H;
  if(!W)
    return 0;

  for(int y = 0; y < H; y++)
  {
    for(int x = 0; x < W; x++)
    {
      string tmp;
      cin >> tmp;
      ss << tmp;
    }
  }
  s = ss.str();
  queue<P> q;
  q.push(make_pair(s, 0));
  while(!q.empty())
  {
    P p = q.front(); q.pop();
    char c = p.first[0];
    for(int i = 0; i < 3; i++)
    {
      if(c != rgb[i])
      {
        q.push(make_pair(f(rgb[i], p.first), p.second + 1));
        if(N == W * H)
        {
          cout << p.second << endl;
          goto loop;
        }
      }
    }
  }
}

Measured memory_bytes: 39056
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int N,x,a[100010],b[100010];
char s[100];
int read()
{
	static int x;
	static char ch;
	static bool pd;
	pd = true;
	x = 0;
	for (ch=getchar();ch>'9'||ch<'0';ch=getchar()) if (ch == '-') pd = false;
	for (;ch>='0' && ch<='9';ch=getchar()) x = x * 10 + ch - '0';
	return x * (pd ? 1 : -1);
}
void find_ans(int l,int r)
{

} 
int main()
{
	N = read();x = 0;
	for (int i = 0;i<N;++i) a[i] = -1;
	printf("0\n");fflush(stdout);
	scanf("%s",s);a[0] = s[0]=='M';
	b[0] = a[0];
	for (int i = 1;i<N;++i) b[i] = b[i-1]^1;
	int l = 1,r = N - 1,mid;
	while (true)
	{
		mid = (l + r)>>1;
		printf("%d\n",mid);fflush(stdout);
		scanf("%s",s);
		if (s[0] == 'V') return 0;
		a[mid] = s[0] == 'M';
		if (a[mid] == b[mid]) l =  mid + 1;
		else r = mid - 1;
	}
	return 0;
}

Measured memory_bytes: 1620
#include<vector>
#include<map>
#include<iostream>
using namespace std;
#define df 0
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long int li;


li pow2(int a){
  li s=1;
  rep(i,a){
    (s*=2)%=MOD;
  }
  return s;
}

int main(){
  map<int,li> mp;
  int n; cin >>n;
  rep(i,n){
    li a; cin >>a;
    int k=0;
    while(a){
      if(a%2) mp[k]++;
      a/=2;
      k++;
    }
  }
  li s=0;
  for(auto x:mp){
    if(df)printf("[%d %d]",x.first,x.second);
    li temp=x.second*(n-x.second)%MOD;
    (s+=pow2(x.first)*temp%MOD)%=MOD;
  }
  printf("%ld",s);
}

/// confirm df==0 ///


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
  
int main(void)
{

  float radius;
 
  float area;
 
  float length;
  
  scanf("%f", &radius);
 
  length =  2 * M_PI * radius;
  printf("%.3f\n", length);
 
  return 0;
}

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

int a[3];
int b[3];
int c[3][3];

int main() {
	for(int i=0;i<3;i++) {
		for(int j=0;j<3;j++) {
			cin>>c[i][j];
		}
	}
	a[0]=0;
	a[1]=c[1][0]-c[0][0];
	a[2]=c[2][0]-c[0][0];
	b[0]=c[0][0];
	b[1]=c[0][1];
	b[2]=c[0][2];
    string ans="Yes";
	for(int i=0;i<3;i++) {
		for (int j=0;j<3;j++) {
			if(a[i]+b[j]!=c[i][j]) ans="No";
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y<a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[201101][33];
int l[201111];
int j[1];

long long x,y,z,mod=1000000007;
//string r;
char r[200101];

P u[1];
queue<int> q;
//stack<P> s;

vector<int> v;

bool as(P a,P b)
{
  return a.x<b.x;
}

int f(int n)
{
  if(n>a) return 0;
  if(l[n]>=0) return l[n];
  l[n]=mod;
  for(int h=0;h<26;h++)
    l[n]=min(l[n],f(o[n][h])+1);
  return l[n];
}

void g(int n)
{
  if(n>a) return;
  int k=mod,m=0;
  for(int h=0;h<26;h++)
  if(k>f(o[n][h])) k=f(o[n][h]),m=h;
  printf("%c",m+'a');
  g(o[n][m]);
}

int main()
{
  scanf("%s",r+1);
  a=strlen(r+1);
  for(int t=1;t<=a;t++)
    r[t]-='a';
  for(int h=0;h<26;h++)
    o[a][h]=a+1;
  for(int t=a;t>=0;t--)
  {
    if(t) o[t-1][r[t]]=t;
    for(int h=0;h<26;h++)
      if(!o[t][h]) o[t][h]=o[t+1][h];
  }
  //for(int h=0;h<26;h++)
  //  printf("%d ",o[1][h]);
  memset(l,-1,sizeof(l));
  //printf("%d",f(0));
  g(0);
}
//3




Measured memory_bytes: 27264
fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(java.util.Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: java.util.Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val S = sc.next()

        var ans = 0
        for (i in 1 until N) {
            val a = S.substring(0, i).toList().distinct()
            val b = S.substring(i)
            val c = a.map {
                if (b.contains(it)) 1 else 0
            }.sum()
            if (ans < c) ans = c
        }
        pw.println(ans)
    }
}


Measured memory_bytes: 33572
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

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

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

vector<int> dfs(int now, set<int> &used, vector<vector<int>> &g) {

    for (int next : g[now]) {
        if (contain(used, next))continue;
        used.insert(next);
        auto ans = dfs(next, used, g);
        ans.push_back(now);
        return ans;
    }

    return {now};

}

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

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

        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);

    }

    int s1 = 0, s2 = g[0][0];

    set<int> used;
    used.insert(s1);
    used.insert(s2);
    vector<int> v1 = dfs(s1, used, g);
    vector<int> v2 = dfs(s2, used, g);

    cout << (v1.size() + v2.size()) << endl;

    reverse(v2.begin(), v2.end());
    for (int i : v1) cout << i + 1 << ' ';
    for (int i : v2) cout << i + 1 << ' ';
    cout << endl;


}



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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int cnt[3] = {0};
  for (int i = 0; i < n; i++) {
    if (a[i]%2 == 1) {
      cnt[0]++;
    }
    else if (a[i]%4 == 0) {
      cnt[1]++;
    }
    else {
      cnt[2]++;
    }
  }
  if (cnt[2] >= 1) {
    cnt[0]++;
  }
  if (cnt[0] < cnt[1] + 2) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long   // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define in(s,x) s.find(x) != s.end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<pair<int,int>> VPII;
const ll mod=1000000007;
const ll INF= 1LL<<60-1;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << pair_var.first << " " << pair_var.second ;return os;}
template<class tContainer>
long long sum(tContainer const& iContainer) {return  std::accumulate(std::begin(iContainer), std::end(iContainer), 0LL);}

// head


int m,n,k,res,tmp,tmp2,tmp3,h,w,x,y;
VI a;
deque<PII> que;
string s;
//VI b;
vector<PII> g[2100600];
int b[2100000];
int c[210] = {};
int rui[210000];
set<int> ch;

signed main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  res = (1+n)*n/2;
  res -= (n/3*3+0)*(n/3+1)/2;
  res -= (n/5*5+0)*(n/5+1)/2;
  res += (n/15*15+0)*(n/15+1)/2;
  cout << res << '\n';
}

Measured memory_bytes: 52892
//
// Created by mamurai on 16/09/08.
//

#include <stdio.h>
#include <string.h>

char s[100100];
int a = -1;
int b = -1;

int main() {
    scanf("%s", s);

    int len = strlen(s);
    for (int i = 0; i < len - 1; ++i) {
        if (s[i] == s[i + 1]) {
            a = i + 1;
            b = i + 2;
            break;
        }
    }
    for (int j = 0; j < len - 2; ++j) {
        if (s[j] == s[j + 2]) {
            a = j + 1;
            b = j + 3;
            break;
        }
    }

    printf("%d %d\n", a, b);

    return 0;
}

Measured memory_bytes: 256
//Code by Anshuman Das Gupta

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define MOD 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define loop(I,N) for(int i=I;i<N;i++)
#define sortvec(V) sort(V.begin(),V.end())
#define vec vector<int>
#define endl "\n"
using namespace std;
#define PI 3.14159265359
int fast_power(int base, int power) {
    int result = 1;
    while (power > 0) {

        if (power & 1) {
            result = (result * base) % MOD;
        }
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result % MOD;
}

bool isPrime(int x) {
    for (int i = 2; i <= sqrt(x); i++) {
        if (x % i == 0)
            return false;
    }
    if (x == 1)
        return false;
    return true;
}

int binsearch(int a[], int f, int r, int x) {
    while (f <= r) {
        int mid = (f + r) / 2;
        if (a[mid] == x)
            return mid;
        else if (a[mid] > x) {
            r = mid - 1;
        }
        else {
            f = mid + 1;
        }
    }
    return -1;
}
void sieve(int a[], int n) {
    a[0] = 0;
    a[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] == 1) {
            for (int j = i + i; j <= n; j += i) {
                a[j] = 0;
            }
        }
    }
}
int lcm(int x, int y) {
    return (x * y) / __gcd(x, y);
}
int32_t main() {
#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        int a, b, n;
        cin >> a >> b >> n;
        int y = (a - 1) / n;
        int x = b / n;
        cout << x - y << endl;
    }
    return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(int i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(int i=(a);i<(n);i++)cout<<(arr)[i]<<' ';

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}

int main(){
	fast;
	ll n, m;
	cin>>n>>m;
	ll k, ans = 0, a[m][n] = {}, aa;
	forn(i, 0, n){
		cin>>k;
		forn(j, 0, k){
			cin>>aa;
			aa--;
			a[aa][i]++;
		}
	}
	forn(i, 0, m){
		ll f = 1;
		forn(j, 0, n){
			if(a[i][j] == 0){
				f = 0;
				break;
			}
		}
		ans+=f;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3656
N = int(input())
S = input()
i = 0
j = N - 1
ans = 0
while i < j:
    while i < N and S[i] == 'R':
        i += 1
    while j > 0 and S[j] == 'W':
        j -= 1
    if i >= j:
        break
    ans += 1
    i += 1
    j -= 1
print(ans)


Measured memory_bytes: 9284
#include<iostream>
#include<stdio.h>
#include<cctype>
#include<string>
#include<cmath>
using namespace std;

int main() {
	int x, y;
	int d,n,m=1;
	cin >> x >> y;
	if (x <= y) {
		swap(x, y);
}
		d = x % y;
		m = d;
		while (m != 0) {
			

			
			m = y % d;
		
			y = d;
			d = m;
		
		}
	
		cout << y<<endl;

	return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60 ; const ll MOD=1e9+7 ;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//-------------------

ll n,m,d;
int main(){
    cin >> n >> m >> d;
    ld sm = 0.0;
    if(d==0){
        sm = (ld)1/n * (m-1);
    }else{
        sm = (ld)2.0 * (n-d)/(n*n) * (m-1);
    }
    //ld ans = ((ld)sm)/pow(n,m);
    //cout << sm;
    cout << setprecision(10) << fixed << sm;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using ll = long long;
const int INF = 1e6;
using namespace std;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    ll n;
    cin >> n;
    string s = to_string(n);
    int size = s.size();
    int ans = (s[0]-'0')-1 + (size-1)*9;
    bool check = true;
    rep1(i,size-1){
        if(s[i]!='9') check = false;
    }
    if(check) ans = (size-1)*9 + (s[0]-'0');
    cout << ans << endl;
}

Measured memory_bytes: 3724
S=list(input())
length = len(S)
z1 = 0
z2 = 0
z3 = 0
if S[0] == "A":
    z1 = 1

for i in range(2,length-1):
    if S[i] == "C":
        z2 = z2 + 1

for i in range(length):
    if S[i].islower()==False:
        z3 = z3 + 1       

if [z1,z2,z3] == [1,1,2]:
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using P = pair<int, int>;
using MATRIX = vector< vector<ll> >;
template <class T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <class T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}

int main() {
  int N;
  int x[200000], y[200000];
  cin >> N;
  rep(i, N) {
    cin >> x[i] >> y[i];
  }
  int z[20000], w[200000];
  rep(i, N) {
    z[i] = x[i] + y[i];
    w[i] = x[i] - y[i];
  }
  sort(z, z + N);
  sort(w, w + N);
  int ans = 0;
  ans = max(z[N-1] - z[0], w[N-1] - w[0]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6044
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  long long n, m, l, a[100][100], b[100][100], c[100][100] = {};
  cin >> n >> m >> l;
  rep(i, n) rep(j, m) {
    cin >> a[i][j];
  }
  rep(j, m) rep(k, l) {
    cin >> b[j][k];
  }
  rep(i, n) rep(j, m) rep(k, l) {
    c[i][k] += a[i][j] * b[j][k];
  }
  rep(i, n) {
    rep(k, l) {
      cout << (k == 0 ? "": " ") << c[i][k];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3200
#include<stdio.h>

int main()
{
    int n,k,i;
    int count = 0;
    scanf("%d %d", &n, &k);
    int h[n + 1];

    for (i = 1; i < n + 1;i++)
        scanf("%d", &h[i]);

    for (i = 1; i < n + 1;i++)
        if(h[i]>=k)
            count++;
    printf("%d\n",count);
    return 0;
}

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

#define lld long long
#define pii pair<int,int>
#define pll pair<lld,lld>
#define pb push_back
#define next nextt
#define Inf 1000000000
#define Linf 1000000000000000000LL
#define Mod 1000000007

using namespace std;

int N,M;
lld a[300002],sum[300002],tmp[300002];
lld d[300002],d1[300002],d2[300002];
struct data{
	lld a,b;
	data(){}
	data(lld a,lld b):a(a),b(b){}
};
struct CHT{
	int cr,cf;
	data line[300002];
	void init(){
		cr = cf = -1;
	}
	lld ccw(data x,data y,data z){
		return (x.a*y.b+y.a*z.b+z.a*x.b)-(x.b*y.a+y.b*z.a+z.b*x.a);
	}
	lld f(int num,lld x){
		return line[num].a*x+line[num].b;
	}
	lld getv(lld x){
		while(cf && f(cf-1,x) > f(cf,x)) cf--;
		return f(cf,x);
	}
	void add(lld a,lld b){
		while(cr > 0 && ccw(line[cr-1],line[cr],data(a,b)) <= 0) cr--;
		cf = min(cf,cr);
		if(cr != cf) return;
		cr++; cf++;
		line[cr] = {a,b};
	}
}cht;

void setting(lld D[]){
	cht.init();
	for(int i=1; i<=N; i++) sum[i] = sum[i-1]+a[i];
	cht.add(0,0);
	for(lld i=1; i<=N; i++){
		D[i] = max(cht.getv(i)+(i*(i+1)/2)-sum[i],D[i-1]);
		cht.add(-i,D[i]+sum[i]+(i*(i-1)/2));
	}
}

void divide(int s,int e){
	if(s == e){
		d[s] = max(d1[s-1]+d2[s+1]+1-a[s],d[s]);
		return;
	}
	int m = (s+e)>>1;
	lld res;
	divide(s,m);
	divide(m+1,e);
	cht.init();
	for(lld i=s-1; i<m; i++){
		cht.add(-i,d1[i]+sum[i]+(i*(i-1)/2));
	}
	for(lld i=e; i>=m+1; i--){
        tmp[i] = cht.getv(i)+(i*(i+1)/2)-sum[i]+d2[i+1];
	}
	res = -Linf;
	for(lld i=e; i>=m+1; i--){
        res = max(res,tmp[i]);
        d[i] = max(res,d[i]);
	}
	cht.init();
	for(lld i=m+2; i<=e+1; i++){
		cht.add(-i,d2[i]-sum[i-1]+(i*(i+1)/2));
	}
	res = -Linf;
	for(lld i=s; i<=m; i++){
        res = max(cht.getv(i)+(i*(i-1)/2)+sum[i-1]+d1[i-1],res);
		d[i] = max(res,d[i]);
	}
}

int main(){
	scanf("%d",&N);
	for(int i=1; i<=N; i++){
        scanf("%lld",&a[i]);
		d[i] = -Linf;
	}
	setting(d1);
	reverse(a+1,a+N+1); setting(d2); reverse(a+1,a+N+1); reverse(d2+1,d2+N+1);
	for(int i=1; i<=N; i++) sum[i] = sum[i-1]+a[i];
	divide(1,N);
	scanf("%d",&M);
	for(int i=1; i<=M; i++){
		int x; lld y;
		scanf("%d %lld",&x,&y);
		printf("%lld\n",max(d1[x-1]+d2[x+1],d[x]+a[x]-y));
	}

	return 0;
}


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

int n,p,stone,check;

int main(){
	while(cin >> n >> p){
		if ((n == 0)&&(p == 0)){
			break;
		}
		int A[n];
		for (int i = 0; i <= n-1; i++){
			A[i] = 0;
		}
		stone = p;
		check = 0;

		while (check == 0){
			for(int i = 0; i <= n-1; i++){
				if (stone != 0){
					A[i] += 1;
					stone += -1;
					if (A[i] == p){
						cout << i << endl;
						check = 1;
						break;
					}
				}
				else if ((stone == 0)&&(check == 0)){
						stone = A[i];
						A[i] = 0;
				}
				//cout << i << A[i] << stone << endl;

			}
		}
	}
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    map<int,int> mp;
    for(int i = 0; i < n; i++){
        int t;
        cin >> t;
        if(mp.find(t) == mp.end())
            mp[t] = 1;
        else
            mp[t] += 1;
    }
    int count = 0;
    for(auto x:mp){
        if(x.first > x.second)
            count += x.second;
        else if(x.first < x.second)
            count += x.second-x.first;
    }
    cout << count;
}

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

using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(0); 
  cin.tie(0); 
  
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  cout << min(a, b) + min(c, d) << endl;
}


Measured memory_bytes: 3620