akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int X;
int Y;
int K;
int mp[3000][3000];
long long dp[3000];
long long nx[3000];
long long d[4];
int main(){
  int Lj4PdHRW;
  int i;
  int j;
  int k;
  rd(X);
  rd(Y);
  rd(K);
  for(Lj4PdHRW=(0);Lj4PdHRW<(K);Lj4PdHRW++){
    rd(i);i += (-1);
    rd(j);j += (-1);
    rd(k);
    mp[i][j] = k;
  }
  for(i=(0);i<(X);i++){
    for(j=(0);j<(Y);j++){
      nx[j] = 0;
    }
    for(k=(0);k<(4);k++){
      d[k] = 0;
    }
    for(j=(0);j<(Y);j++){
      chmax(d[0], dp[j]);
      for(k=(4)-1;k>=(1);k--){
        chmax(d[k], d[k-1] + mp[i][j]);
      }
      {
        int a2conNHc;
        long long hCmBdyQB;
        if(4==0){
          hCmBdyQB = 0;
        }
        else{
          hCmBdyQB = d[0];
          for(a2conNHc=(1);a2conNHc<(4);a2conNHc++){
            hCmBdyQB = max_L(hCmBdyQB, d[a2conNHc]);
          }
        }
        nx[j] =hCmBdyQB;
      }
    }
    for(j=(0);j<(Y);j++){
      dp[j] = nx[j];
    }
  }
  wt_L(dp[Y-1]);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200813-1 [beta]

// --- original code ---
// int X, Y, K;
// int mp[3000][3000];
// ll dp[3000], nx[3000];
// ll d[4];
// {
//   int i, j, k;
//   rd(X,Y,K);
//   rep(K){
//     rd(i--, j--, k);
//     mp[i][j] = k;
//   }
//   rep(i,X){
//     rep(j,Y) nx[j] = 0;
//     rep(k,4) d[k] = 0;
//     rep(j,Y){
//       d[0] >?= dp[j];
//       rrep(k,1,4) d[k] >?= d[k-1] + mp[i][j];
//       nx[j] = max(d(4));
//     }
//     rep(j,Y) dp[j] = nx[j];
//   }
//   wt(dp[Y-1]);
// }


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

int main() {
  int N,A=0,B=0,M=1;
  cin>>N;
  vector<int> a(N);
for (int i=0;i<N;i++) {
  cin>>a.at(i);
  M*=(i+1);
}
  vector<int> b(N);
for (int i=0;i<N;i++) {
  cin>>b.at(i);
}
  for(int i=0;i<N;i++){
    M/=(N-i);
    A+=a.at(i)*M;
    B+=b.at(i)*M;
    for(int j=i+1;j<N;j++){
      if(a.at(i)<a.at(j)){
        a.at(j)--;
      }
      if(b.at(i)<b.at(j)){
        b.at(j)--;
      }
    }
  }
  
  cout<<abs(A-B)<<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt64)
}

func readInt() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func main() {
	n := readInt()
	var x []int
	var sum int
	var min int = 1000000
	for i := 0; i < n; i++ {
		x = append(x, readInt())
	}
	sort.Ints(x)
	for p := x[0]; p <= x[len(x)-1]; p++ {
		sum = 0
		for _, v := range x {
			sum += (v - p) * (v - p)
		}
		if sum < min {
			min = sum
		}
	}
	fmt.Println(min)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/

bool cnt[30];
signed main() {
	string s; cin >> s;
	if (s.size() != 26) {
		rep(i, s.size())cnt[s[i] - 'a']++;
		rep(i, 26) {
			if (!cnt[i]) {
				cout << s << (char)(i + 'a') << endl; return 0;
			}
		}
	}
	else if (s == "zyxwvutsrqponmlkjihgfedcba") {
		cout << -1 << endl;
	}
	else {
		for (int i = s.size() - 1; i > 0; i--) {
			if (s[i - 1] < s[i]) {
				memset(cnt, 0, sizeof(cnt));
				rep(j, i) {
					cnt[s[j] - 'a']++;
				}
				for (int j = s[i - 1] - 'a'; j < 26; j++) {
					if (!cnt[j]) {
						cout << s.substr(0, i - 1) << (char)(j + 'a') << endl;
						return 0;
					}
				}
			}
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int main(void)
{
  int W,a,b;
  cin >> W >> a >> b;
  int x;
  if(a < b){
    x = b - (W+a);
  }
  else{
    x = a - (W+b);
  }
  if(x>0){
    cout << x << endl;
  }
  else{
    cout << 0 << endl;
  }
  return 0;
}


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

  int i,j,a[101][101],b[1001],n,m;
  int sum;
  scanf("%d%d",&n,&m);

  for(i=0;i<n;i++){
    for(j=0;j<m;j++){

      scanf("%d",&a[i][j]);
    }
  }
  for(i=0;i<m;i++){
    scanf("%d",&b[i]);
  }

  for(i=0;i<n;i++){
    sum=0;
    for(j=0;j<m;j++){
      sum+= a[i][j]*b[j];
    }
    printf("%d\n",sum);
  }

  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
const int MAX = 1000;
int c[MAX + 1][MAX + 1];
int lcs(string x, string y)
{
	int m = x.length();
	int n = y.length();
	int maxLen = 0;
	x = ' ' + x;
	y = ' ' + y;
	for (int i = 1; i <= m; i++)
		c[i][0] = 0;
	for (int j = 1; j <= n; j++)
		c[0][j] = 0;
	for (int i = 1; i <= m; i++)
		for (int j = 1; j <= n; j++)
		{
			if (x[i] == y[j])
				c[i][j] = c[i - 1][j - 1] + 1;
			else
				c[i][j] = max(c[i - 1][j], c[i][j - 1]);
			maxLen = max(maxLen, c[i][j]);
		}
	return maxLen;
}
int main()
{
	int n;
	(cin >> n).get();
	for (int i = 0; i < n; i++)
	{
		string x, y;
		getline(cin, x);
		getline(cin, y);
		cout << lcs(x, y) << endl;
	}
}


Measured memory_bytes: 6928
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <array>
#include <cmath>

using namespace std;

using ll = long long int;

constexpr ll MOD = 1000000000 + 7;

// GCDを計算します
template <typename NumType>
NumType calcGCD(NumType a, NumType b) {
    if (a < b) {
        NumType tmp = a;
        a = b;
        b = tmp;
    }

    NumType r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

// 約数を数えます
template <typename NumType>
NumType cntDivisor(const NumType & num) {
    NumType cnt = 0;
    for(NumType i = 1; i * i <= num; ++i) {
        if(num % i == 0) {
            cnt++;
            if(i * i != num) cnt++;
        }
    }

    return cnt;
}

// [beg, end)の範囲を，添え字indexでループするfor文に置換します
#define FOR_RANGE(index, beg, end)     for (ll index = beg; index < N; ++index)

#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

template<class T>
T min(T a, T b) {
    return (a < b) ? a : b;
}

template<class T>
T max(T a, T b) {
    return (a > b) ? a : b;
}

using ll = long long int;
ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M);
}


ll powMod(ll a, ll n, ll mod){
    if(n == 0) return 1;
    if(n%2 == 0)
        return powMod(a, n/2, mod) * powMod(a, n/2, mod) % mod;
    else
        return a * powMod(a, n-1, mod)% mod;
}


ll ncrMod(ll n, ll r, ll mod){
    ll x=1, y=1;
    for(ll i = 1; i <= r; ++i){
        x *= n-i+1;
        x %= mod;
        y *= i;
        y %= mod;
    }
    return x * powMod(y, mod-2, mod) % mod;
}

int main() {
    ll n, a, b;

    cin >> n >> a >> b;

    ll total = powMod(2, n, MOD) - 1;

    // ll y_a = factorial(a);
    // ll y_b = factorial(b);

    // ll y_a2 = RepeatSquaring(y_a, MOD - 2, MOD);
    // ll y_b2 = RepeatSquaring(y_b, MOD - 2, MOD);

    // ll nCa = factorial(n, n - a + 1) * y_a2 % MOD;
    // ll nCb = factorial(n, n - b + 1) * y_b2 % MOD;

    ll nCa = ncrMod(n, a, MOD);
    ll nCb = ncrMod(n, b, MOD);

    ll ans = total - nCa - nCb;
    ans += MOD*2;
    ans %= MOD;

    cout << ans;

    return 0;
}



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


def main():
    n = int(input())
    a = list(map(int, input().split()))

    c = collections.Counter(a).most_common()
    ans = "No"
    if len(c) == 3 and c[0][1] == c[1][1] == c[2][1]:
        if c[0][0] ^ c[1][0] ^ c[2][0] == 0:
            ans = "Yes"
    elif len(c) == 2 and c[0][1] == 2 * c[1][1]:
        if c[0][0] ^ c[0][0] ^ c[1][0] == 0:
            ans = "Yes"
    elif len(c) == 1 and c[0][0] == 0:
        ans = "Yes"
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 20880
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#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 LL long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

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

int main(){
	int n;

	while(cin >> n, n){
		map<char, int> mp;
		int maxvote = 0;
		char maxvoteC = 'a';
		int secondvote = 0;
		char secondvoteC = 'a';
		bool flag = false;
		REP(i, n){
			char c;
			cin >> c;
			mp[c] += 1;
			if(mp[c] > maxvote){
				if(maxvoteC != c){
					secondvote = maxvote;
					secondvoteC = maxvoteC;
				}
				maxvote = mp[c];
				maxvoteC = c;
			}else if(mp[c] > secondvote){
				secondvote = mp[c];
				secondvoteC = c;
			}
			if(maxvote > secondvote + n-i-1){
				cout << maxvoteC << " " << i + 1 << endl;
				flag = true;
				REP(j, n-i-1){
					cin >> c;
				}
				break;
			}
		}
		if(!flag){
			cout << "TIE" << endl;
		}
	}
}

Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)



using namespace std;

bool is_integer( float x ){
    return floor(x)==x;
}


int main() {
    string s;
    bool ans = true;
    int count = 0;

    cin >> s;
    if(s[0] != 'A') ans = false;
    for(int i = 2; i < s.length()-1; i ++ ){
        if(s[i] == 'C') count ++;
    }
    if(count != 1) ans = false;
    for(int i = 0; i < s.length(); i ++){
        if(s[i] != 'A' && s[i] != 'C'){
            if(!islower(s[i])) ans = false;
        }
    }

    cout << ((ans)?"AC":"WA");
    return 0;
}


Measured memory_bytes: 3620
N = int(input())
S = input()
T = input()
MOD = 10**9 + 7

isPrevI = S[0] == T[0]
i = 1 if isPrevI else 2
ans = 3 if isPrevI else 6

while i < N:
    if S[i] == T[i]:
        if isPrevI:
            ans *= 2
            ans %= MOD
        isPrevI = True
        i += 1
    else:
        if isPrevI:
            ans *= 2
            ans %= MOD
        else:
            ans *= 3
            ans %= MOD
        isPrevI = False
        i += 2

print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	int a,x,i,j;
	char n[100001];
  	x=1;
	scanf("%d",&a);
	scanf("%s",n);
	for(i=0;i<a-1;i++){
		if(n[i]!=n[i+1]){
			x++;
		}
	}
	printf("%d",x);
	return 0;
}

Measured memory_bytes: 1824
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
using namespace std;


int main() {
	//cout << fixed << setprecision(10);
	long long int cou=0,ax=0;
	string str;
	cin >> str;
	for (int i = 0; i < str.length(); i++) {
		if (str[i] == 'A' || str[i] == 'T' || str[i] == 'G' || str[i] == 'C') {
			cou ++;
		}
		else {
			ax = max(ax, cou);
			cou = 0;
		}
	}
	ax = max(ax, cou);
	cout << ax;
}



Measured memory_bytes: 256
#!/usr/bin/python

import os
import sys
import itertools

while True:
    n, s = map(int, raw_input().split())
    if n == 0 and s == 0: break

    ans = 0
    for item in itertools.combinations(range(10), n):
        if sum(item) == s: ans += 1

    print ans

Measured memory_bytes: 6424
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

x=n0()
y=100

c=0
while y<x:
    y=int(y*1.01)
    c+=1
print(c)

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

int main(){
    string M1,D1; cin >> M1 >> D1;
    string M2,D2; cin >> M2 >> D2;
    
    if(D2=="1") cout << "1";
    else cout << "0";
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 100005
#define M 200005
#define seed 23333
#define Mo 1000000007

using namespace std;
int i,j,m,n,p,k;
int f[N],g[N],suff[N],sufg[N];
long long S[N],sum[N],A,B;
int down_f,down_g;
int Q_f[N],f_r,now_f;
int Q_g[N],g_r,now_g;
void jia(int &x,int y)
{
		x+=y; if (x>=Mo) x-=Mo; 
}
void jian(int &x,int y)
{
		x-=y; if (x<0) x+=Mo;
}
void ins_f(int x)
{
		while (Q_f[0]<=f_r&&sum[x]<=sum[Q_f[f_r]]) --f_r;
		Q_f[++f_r]=x;
}
void ins_g(int x)
{
		while (Q_g[0]<=g_r&&sum[x]<=sum[Q_g[g_r]]) --g_r;
		Q_g[++g_r]=x;
}
int main()
{
		scanf("%d%lld%lld",&n,&A,&B); S[0]=-(long long)2e18;
		for (i=1;i<=n;++i) scanf("%lld",&S[i]); S[n+1]=S[n];
		for (i=2;i<=n+1;++i) sum[i]=S[i]-S[i-1];
		f[1]=g[1]=1; Q_f[0]=Q_g[0]=1;
		for (i=1;i<=n;++i)
		{
				jia(suff[i],suff[i-1]);
				jia(sufg[i],sufg[i-1]);
				f[i]+=suff[i];
				g[i]+=sufg[i];
				//workf
				while (Q_f[0]<=f_r&&Q_f[Q_f[0]]<=i) ++Q_f[0];
				now_f=max(now_f,i);
				for (;Q_f[0]>f_r||sum[Q_f[Q_f[0]]]>=A;)
				{
						++now_f;
						ins_f(now_f);
				}
				down_f=max(down_f,i+1);
				while (down_f<=n&&S[down_f]-S[i-1]<B) ++down_f;
				if (down_f<=now_f) 
				jia(sufg[down_f],f[i]),jian(sufg[now_f+1],f[i]);
				//workg
				while (Q_g[0]<=g_r&&Q_g[Q_g[0]]<=i) ++Q_g[0];
				now_g=max(now_g,i);
				down_g=max(down_g,i+1); 
				while (down_g<=n&&S[down_g]-S[i-1]<A) ++down_g;
				for (;Q_g[0]>g_r||sum[Q_g[Q_g[0]]]>=B;)
				{
						++now_g;
						ins_g(now_g);
				}
				if (down_g<=now_g)
				jia(suff[down_g],g[i]),jian(suff[now_g+1],g[i]);
		}
		jia(suff[n+1],suff[n]); 
		jia(sufg[n+1],sufg[n]);
		jia(suff[n+1],sufg[n+1]);
		printf("%d\n",suff[n+1]);
}


Measured memory_bytes: 4096
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String ss;
    char ac,bc;
    ss = sc.next();
    ac = ss.charAt(0);
    ss = sc.next();
    bc = ss.charAt(0);
    
    int a = ac - '0';
    int b = bc - '0';
    int s = b;
    char wakame = ac;
    if(a>b){
      s = a; wakame = bc;
    }
    
    for(int i=0; i<s; ++i){
      System.out.print(wakame);
    }
  }
}

Measured memory_bytes: 21332
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;
const long long int INF = 99999999999999999;
struct ab {
	long long int a, b;
};

bool cmp(ab x,ab y){
	return x.a < y.a;
}

//union find木(グループわけができる)
int par[220000];
int unifind(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
	}
	return 0;
}
//木の根を求める
int unifind_root(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = unifind_root(par[x]);
	}
}
//同じグループか判定
bool unifind_same(int x, int y) {
	return unifind_root(x) == unifind_root(y);
}
//グループ併合
int unifind_unite(int x, int y) {
	x = unifind_root(x);
	y = unifind_root(y);
	if (x == y) {
		return 0;
	}
	par[x] = y;
}


int main() {
	complex<long double>cmpmp;
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	//cout << fixed << setprecision(10);
	string str;
	long long int a, b, c, d, n, time = 0, k, X[400005] = {}, no[200005][2] = {}, res[400005] = {},out=0;
	ab task[200005];
	cin >> n;
	unifind(200005);

	for (int i = 1; i <= 200000; i++) {
		no[i][0] = 1;
		no[i][1] = 1;
	}
	for (int i = 0; i < n; i++) {
		cin >> task[i].a >> task[i].b;
		unifind_unite(par[task[i].a], par[task[i].b + 100000]);
		no[task[i].a][0] = 0;
		no[task[i].b+100000][0] = 0;
		no[task[i].a][1] = 0;
		no[task[i].b + 100000][1] = 0;
	}
	for (int i = 1; i <= 200000; i++) {
		if (no[unifind_root(i)][0] == 0) {
			if (i <= 100000) {
				X[unifind_root(i)]++;
			}
		}
		if (no[unifind_root(i)][1] == 0) {
			if (i > 100000) {

				X[unifind_root(i) + 200000]++;
			}
		}
	}
	for (int i = 1; i <= 100000; i++) {
		if (X[unifind_root(i)] > 0) {
			res[unifind_root(i)] = X[unifind_root(i)];
		}
		

	}

	for (int i = 100001; i <= 200000; i++) {
		if (X[unifind_root(i)] > 0) {
			res[unifind_root(i)+200000] = X[unifind_root(i)+200000];
		}
	}
	for (int i = 1; i <= 200000; i++) {
		out += res[i]*res[i+200000];
		if (res[i] > 0) {
		}
	}
	cout << out-n;

}

Measured memory_bytes: 13312
using System;

class Program{
	public static void Main(){
		int N = int.Parse(Console.ReadLine());
		int[] d = new int[N];
		for (int i = 0; i < N; i++){
			d[i] = int.Parse(Console.ReadLine());
		}
		
		int q;
		
		for (int p = 0; p < N-1; p++){
			for (q = p + 1; q < N; q++){
				if (d[p] == d[q])
					d[q] = 0;
			}
		}
		
		int r = 0;
		for (int a = 0; a < N; a++){
			if (d[a] != 0)
				r++;
		}
		
		Console.WriteLine(r);
	}
}

Measured memory_bytes: 11092
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdio>
#include<utility>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
#define all(L) L.begin(),L.end()
using ll=long long;
#define RO 1
#define SI 2
#define PA 3

int N,M;
string S,T;

void dfs(int m,int bits,int &count){
    if(m>N) return;
    if(bits==0b111) count++;
    dfs(10*m+7,bits|0b100,count);
    dfs(10*m+5,bits|0b010,count);
    dfs(10*m+3,bits|0b001,count);
}

int main(){
    cin>>S>>T;
    bool flag=true;
    int n=S.size();
    vector<char> als(26,'!');
    rep(i,0,n){
        if(als[S[i]-'a']=='!') als[S[i]-'a']=T[i];
        else if((als[S[i]-'a']!='!')&&als[S[i]-'a']!=T[i]){
            flag=false;break;
        }
    }
    vector<char> alt(26,'!');
    rep(i,0,n){
        if(alt[T[i]-'a']=='!') alt[T[i]-'a']=S[i];
        else if((alt[T[i]-'a']!='!')&&(alt[T[i]-'a']!=S[i])){
            flag=false;break;
        }
    }    
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}    



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

class Program{

  static string ans;

  static int Main() {

    int a = int.Parse(Console.ReadLine());
    int b = int.Parse(Console.ReadLine());
    int c = int.Parse(Console.ReadLine());
    int d = int.Parse(Console.ReadLine());
    int e = int.Parse(Console.ReadLine());
    int k = int.Parse(Console.ReadLine());

    // ここまで入力

    if (e-a <= k ) {
      ans = "Yay!";
    } else {
      ans = ":(";
    }

    Console.WriteLine("{0}", ans);

    return 0;
  }

}


Measured memory_bytes: 11092
#include <stdio.h>

void print(int A[],int N){
    int i;
    for(i=0;i<N;i++){
        if(i>0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}

void insertionsort(int A[],int N){
    int i,j,k;
    for(i=1;i<N;i++){
        k=A[i];
        j=i-1;
        while(j>=0 &&A[j]>k){
            A[j+1]=A[j];
            j--;
        }
        A[j+1]=k;
        print(A,N);
    }
}

int main(){
    int i,j,N;
    int A[1000];
    
    scanf("%d",&N);
    for(i=0;i<N;i++)
    scanf("%d",&A[i]);
    
    print(A,N);
    insertionsort(A,N);
    
    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

const ll MX = 1e18;

int main(){
 int N;
  cin >> N;
  bool f0 =0;
  vector <long> As(N);
  REP(i,N){
   cin >> As[i] ;
    if (As[i] == 0){
     f0=1;
      break;
    }
  }
  
  if (f0){
  cout << 0 <<endl;
  }
  else {
   //no0
    
    bool OK =1;
    long ans =1;
    REP(i,N){
    
      if ( As[i]>MX/ans ){
        OK = 0;
         break;
      }
      ans *=As[i];
    }
    
    if (OK){
     cout << ans<<endl; 
    }else{
      cout <<"-1"<<endl;
    }
  }
}

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

int main(){
    int x = 0, max = 0;
    string s;
    int n;
    cin >> n;
    cin >> s;
    for(int i = 0; i < s.size(); ++i){
        if(s[i] == 'I') ++x;
        else --x;
        max = (max > x? max: x);
    }
    cout << max << endl;
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
void work(int x)
{
	if(!x) return;
	int r=x%2;if(r) x--;
	work(x/(-2));
	printf("%d",r>0?r:-r);
}
int main()
{
	int n;scanf("%d",&n);
	if(!n) printf("0\n");else work(n);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int MOD=1000000007;
const int nmax=101234;

int n,m,a[nmax],b[nmax],flg[nmax],st,f[nmax];
queue<int> q2;
vector<vector<int> > v2(nmax);

void bfs(int s){
    for(int i=0;i<v2[s].size();++i)
        if(flg[v2[s][i]]--==1){
            f[v2[s][i]]=s;
            q2.push(v2[s][i]);
        }
}

int main()
{
    scanf("%d %d",&n,&m);
    for(int i=1;i<n+m;++i){
        scanf("%d %d",&a[i],&b[i]);
        v2[a[i]].pb(b[i]);
        ++flg[b[i]];
    }
    for(int i=1;i<n+m;++i){
        if(flg[i]==0){
            st=i;
            break;
        }
    }
    q2.push(st);
    while(!q2.empty()){
        bfs(q2.front());
        q2.pop();
    }
    for(int i=1;i<=n;++i)
        printf("%d\n",f[i]);
    return 0;
}


Measured memory_bytes: 7936
n,m=map(int,input().split())
l = [list(map(int,input().split())) for _ in range(n)]
 
l.sort()
a=0
ans=0
for i,j in l:
    for k in range(int(j)):
        if a>=m:
            break
        else:
            ans+=int(i)
            a+=1
 
print(ans)

Measured memory_bytes: 27752
#include <stdio.h>

int main(void)
{
	int i,j,H,W;
	
	while(!(H==0&&W==0)){
		scanf("%d %d",&H,&W);
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				if(i==0||i==H-1||j==0||j==W-1){
					printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		if (H==0&&W==0) break;
		printf("\n");
	}
	
	return 0;
}

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

int n,u,v;
vector<vector<int>> g;
vector<int> dist;

void dfs(int x){
  for(auto nx:g[x]){
    if(dist[nx]!=-1) continue;
    dist[nx]=dist[x]+1;
    dfs(nx);
  }
}

int main(){
  cin>>n>>u>>v;
  u--; v--;
  g.resize(n);
  dist.assign(n,-1);
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--; b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  dist[v]=0;
  dfs(v);
  vector<int> dist2(n);
  rep(i,n) dist2[i]=dist[i];
  dist.assign(n,-1);
  dist[u]=0;
  dfs(u);
  
  int res=0;
  
  rep(i,n){
    if(g[i].size()==1){
      if(dist2[i]>dist[i]) res=max(res,dist2[i]);
    }
  }
  cout<<res-1<<endl;
}

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

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

def main():
    L = I()
    V = (L/3)**float(3.0)
    print("{:.12f}".format(V))

main()


Measured memory_bytes: 21244
A,B,M=map(int,input().split())

al=[]
a=input().split()
for i in a:
    al.append(int(i))
bl = []
b=input().split()
for i in b:
    bl.append(int(i))

cl=[]
for i in range(M):
    l=[]
    c = input().split()
    for i in c:
        l.append(int(i))
    cl.append(l)
    
l=[]
for i in cl:
    a=0
    a=al[i[0]-1]+bl[i[1]-1]-i[2]
    l.append(a)

Min=min(al) + min(bl)
if min(l) < Min:
    print(min(l))
else:
    print(Min)
        
    

Measured memory_bytes: 44884
n, m = map(int, input().split())
broken = [int(input()) for i in range(m)]
dp = [-1 for i in range(n+1)]
dp[0] = 1
dp[1] = 1
for b in broken:
    dp[b] = 0
for i in range(2, n+1):
    if dp[i] == -1:
      dp[i] = dp[i-1] + dp[i-2]
print(dp[n] % (10**9+7))

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

int main() {
  long long h;
  cin >> h;

  long long ans = 0;
  long long n = 1;
  while ( h > 0 ) {
    ans += n;
    h /= 2;
    n <<= 1;
  }

  cout << ans << endl;
  return 0;
}


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

#define LINF 1000000000000000001 // 1e18+1

map<int,int64_t> mp;
int i,j,k,N;
int64_t T,a;
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  cin >> N >> T;
  int64_t mn=LINF;
  for(i = 0;i < N;i++){
    cin >> a;
    mn = min(mn, a);
    mp[a - mn]++;
  }
  int64_t index = 0,ans = 0;
  for(auto itr=mp.begin(); itr!=mp.end();++itr) {
    j = (itr->first);
    if(index < j){
      index = j;
      ans = (itr->second);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6528
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class A
{
	public static void Main()
	{
		string[] args = Console.ReadLine().Split(' ');
		int x = Int32.Parse(args[0]);
		int a = Int32.Parse(args[1]);
		int b = Int32.Parse(args[2]);
		Console.WriteLine(Math.Abs(x - a) < Math.Abs(x - b) ? "A" : "B");
	}
}





Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}

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

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    int a, b;
    cin>>a>>b;
    int ans=0;
    int x=1;
    while (x<b)
    {
        x--;
        x+=a;
        ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3656
def is_odd_digit(x):
	i = 0
	while x != 0:
		x //= 10
		i += 1
	return i % 2 != 0

def main():
	n = int(input())
	
	ans = 0
	for i in range(1, n + 1):
		if is_odd_digit(i):
			ans += 1
	
	print(ans)

main()

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

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

  if (D == 22) {
    cout << "Christmas Eve Eve Eve" << endl;
  }
  else if (D == 23) {
    cout << "Christmas Eve Eve" << endl;
  }
  else if (D == 24) {
    cout << "Christmas Eve" << endl;
  }
  else if (D == 25) {
    cout << "Christmas" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int bi[30],n,k,kk,a[110000],b[110000];
long long s,ans;
int main(){
	scanf("%d%d",&n,&k);
	fo(i,1,n) scanf("%d%d",&a[i],&b[i]);
	fo(i,1,n) if ((a[i]|k)==k) ans+=b[i];
	bi[0]=1;
	fo(i,1,29) bi[i]=bi[i-1]<<1;
	fd(i,29,0)//29..1
		if (k&bi[i]){
			kk=(k^bi[i])|(bi[i]-1);
			s=0;
			fo(j,1,n) if ((a[j]|kk)==kk) s+=b[j];
			if (s>ans) ans=s;
		}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 896
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
using namespace std;
int main(){
	
	string s;
	int sum=0;
	while(cin>>s){
		string a="";
		for(int i=0;i<s.size();i++){
			if(s[i]>='0'&&s[i]<='9')
				a=a+s[i];
			else{
				if(a!="")
				sum+=stoi(a);
				a="";
			}
		}
		if(a!="")
		sum+=stoi(a);
		//cout<<sum<<endl;
	}
	cout<<sum<<endl;
	
}

Measured memory_bytes: 2968
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
string s,t,u;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>s>>t>>a>>b>>u;
    if(u==s)
        a--;
    if(u==t)
        b--;
        cout<<a<<" "<<b<<'\n';





}

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

int main()
{
    int n;
    cin >> n;
    vector<int> b(n-1);
    rep(i,n-1) cin >> b[i];
    vector<int>a(n);
    a[0]=b[0];
    for(int i = 1; i <= n-2; i++ ){
        a[i] =min(b[i],b[i-1]);
    }
    a[n-1] = b[n-2];
    int ans = 0;
    rep(i,n) ans += a[i];
    cout <<ans << endl;
  
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>

using namespace std;

void b_754(void) {
	string s;
	cin >> s;
	int min = 753;

	for (int i = 0; i < (s.size() - 2); i++) {
		int num =stoi(s.substr(i, 3));
		int dif = abs(753 - num);

		if (min > dif) min = dif;
	}

	cout << min << endl;
}

int main()
{
    b_754();

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long 
#define file(s) freopen(s".in","r",stdin);freopen(s".out","w",stdout);
using namespace std;
template<typename T>inline void chkmax(T &x,T y){x=(x>y)?x:y;}
template<typename T>inline void chkmin(T &x,T y){x=(x<y)?x:y;}
template<typename T>inline void read(T &x){
	int _=1;x=0;char __=getchar();
	while(!isdigit(__)){
		if(__=='-')_=-1;
		__=getchar();
	}
	while(isdigit(__)){
		x=(x<<3)+(x<<1)+(__^'0');
		__=getchar();
	}
	x*=_;
}
template<typename T>inline void write(T x){
	if(x==0){puts("0");return;}
	if(x<0)x=-x,putchar('-');
	int LEN=0,y[20];
	while(x){
		y[LEN++]=x%10;
		x/=10;
	}
	for(register int i=LEN-1;i>=0;--i)
		putchar(y[i]+'0');
	puts("");
}
const int maxm=2e5+10,mod=1e9+7,maxn=8e3+10;
int n;
int a[maxm],b[maxm];
int inv[maxn],fac[maxn];
int dp[maxn][maxn];
int ans;

inline int qpow(int x,int y){
	int ret=1;
	for(;y;y>>=1){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;
	}
	return ret;
}
inline int C(int x,int y){
	if(x<y)return 0;
	return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;
}

inline void	init(){
	read(n);
	int N=maxn-5;
	fac[0]=1,inv[0]=1;
	for(register int i=1;i<=N;++i)fac[i]=1ll*fac[i-1]*i%mod;
	inv[N]=qpow(fac[N],mod-2);
	for(register int i=N;i>=1;--i)inv[i-1]=1ll*inv[i]*i%mod;
}
int main(){
	init();
	for(register int i=1;i<=n;++i){
		read(a[i]),read(b[i]);
		dp[2002-a[i]][2002-b[i]]++;
	}
	for(register int i=1;i<=4002;++i)
		for(register int j=1;j<=4002;++j)
			(dp[i][j]+=(dp[i-1][j]+dp[i][j-1])%mod)%=mod;
	for(register int i=1;i<=n;++i)
		(ans+=(dp[a[i]+2002][b[i]+2002]-C((a[i]+b[i])*2,a[i]*2)))%=mod;
	cout<<1ll*(mod+1)/2*(ans+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 128896
#include <stdio.h>
int main(void){
	int h,n;
  	scanf("%d%d",&h,&n);
  	for(int i = 0; i<n;i++){
        int a;
    	scanf("%d",&a);
      	h-=a;
    }
  	if(h<=0){
      printf("Yes");
    }else{
    printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    ll A, B; cin >> A >> B;
    ll res = INF;
    REP(i, 1500){
        int x = 0.08 * i;
        int y = 0.10 * i;
        if(x==A and y==B){
            res = i;
            break;
        }
    }
    if(res==INF){
        cout << -1 << endl;
    } else {
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = []
b.append(a[0])
for mid in range(1, len(a)):
  b.append(b[mid - 1] + a[mid])
ans = 10**9

# 累積和から閉区間の合計を求める
def g_sum(l, r):
  if r < l:
    return 0
  res = b[r]
  if l != 0:
    res -= b[l-1]
  return res

lef = 1
rit = 2
for mid in range(2, n - 1):
  # 左
  while abs(g_sum(0, lef - 1) - g_sum(lef, mid - 1)) > abs(g_sum(0, lef) - g_sum(lef + 1, mid - 1)):
    lef += 1
  # 右
  while abs(g_sum(mid, rit - 1) - g_sum(rit, n - 1)) > abs(g_sum(mid, rit) - g_sum(rit + 1, n - 1)):
    rit += 1
  # 各区間の計算
  P = g_sum(0,lef - 1)
  Q = g_sum(lef, mid - 1)
  R = g_sum(mid, rit - 1)
  S = g_sum(rit, n - 1)
  # 最小値算出
  ans = min(ans, max(P,Q,R,S) - min(P,Q,R,S))
print(ans)

Measured memory_bytes: 25676
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

struct union_find {
	vector<int> v;
	union_find(int n) : v(n, -1) {}
	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

int main() {
	int N, M; cin >> N >> M;
	vector<vector<int> > a(N);
	rep(i, N) {
		int K; scanf("%d", &K);
		while (K--) {
			int x; scanf("%d", &x);
			a[i].pb(x);
		}
	}
	vector<int> A;
	rep(i, N) for (int x: a[i]) A.pb(x);
	sort(A.begin(), A.end());
	A.erase(unique(A.begin(), A.end()), A.end());
	M = A.size();
	rep(i, N) for (int& x: a[i]) x = lower_bound(A.begin(), A.end(), x) - A.begin();
	union_find uf(N + M);
	rep(i, N) for (int x: a[i]) uf.unite(i, N + x);
	cout << (uf.size(0) == N + M ? "YES" : "NO") << endl;
}


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

int main()
{
    int N;
    vector<int> d;
    cin >> N;
    copy_n(istream_iterator<int>(cin), N, back_inserter(d));

    sort(d.begin(), d.end());

    cout << d[N / 2] - d[N / 2 - 1] << endl;

    return 0;
}


Measured memory_bytes: 892
import numpy as np

N,D = map(int,input().split())

X = []
Y = []

for i in range(N):
  xi,yi = map(int,input().split())
  X.append(xi)
  Y.append(yi)

Z = [np.sqrt(xx**2+yy**2) for (xx, yy) in zip(X, Y)]


ans = sum(dist<=D for dist in Z)

print(ans)

Measured memory_bytes: 50612
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using Graph = vector<vector<int>>;
using Wgraph = vector<vector<pair<int, long long int>>>;
constexpr long long int INF = 1001001001001001LL;
constexpr long long int MOD = 1000000007LL;
constexpr double PI = 3.1415926535897932;
constexpr long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
constexpr long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = 1; i <= (n); i++)
#define DREP(i,n) for(int i = (n)-1; i >= 0; i--)
#define SREP(i,s,t) for(int i = s; i < t; i++)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define PB push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

int main(){
  
  lint x, y; cin >> x >> y;
  if(x < y) swap(x, y);
  if(x - y <= 1) cout << "Brown" << endl;
  else cout << "Alice" << endl;
  return 0;
}


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

#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);

int main() {
    fast_io;
    
    long long t;
    cin>>t;

    long long ans=1;
    
    vector<long long> arr;
    while(t--) {
        long long num;
        cin>>num;
        if(num==0) {
            cout<<0<<endl;
            return 0;
        }
        arr.push_back(num);
    }

    long long of=1e18;
    for(int i=0;i<arr.size();i++) {
        if(of/ans<arr[i]) {
            cout<<-1<<endl;
            return 0;
        }

        ans*=arr[i];
    }

    cout<<ans<<endl;

}




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

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, t;
	cin >> n >> t;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	int amax = 0, b = 0, ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] >= amax) amax = a[i];
		else {
			int tmp = amax - a[i];
			if (b < tmp) {
				ans = 1;
				b = tmp;
			} else if (b == tmp) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,n,s) for (int i = (s); i < (n); i++)
#define SIZE 50
using namespace std;
typedef long long int LL;

LL MOD;
int H, W, N, C, m[SIZE][SIZE];

int inOut(int x1, int y1, int x2, int y2) {
	int res;
	cout << "? " << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
	cin >> res;
	return res;
}

void _f(int x1, int y1, int x2, int y2, int n) {
	if ((x2-x1+1)*(y2-y1+1) == n) {
		for(int i = x1; i < x2 + 1; i++) {
			for(int j = y1; j < y2 + 1; j++) {
				m[i][j] = 1;
			}
		}
		return;
	}
	if (x1 == x2 && y1 == y2) {
		m[x1][y1] = inOut(x1, y1, x1, y1);
		return;
	}
	if (x2 - x1 > y2 - y1) {
		int _x = (x2 + x1) / 2;
		int r = inOut(x1, y1, _x, y2);
		if (r != 0) _f(x1, y1, _x, y2, r);
		if (r != n) _f(_x+1, y1, x2, y2, n-r);
	} else {
		int _y = (y2 + y1) / 2;
		int r = inOut(x1, y1, x2, _y);
		if (r != 0) _f(x1, y1, x2, _y, r);
		if (r != n) _f(x1, _y+1, x2, y2, n-r);
	}
}

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

	cin >> H >> W >> N >> MOD;

	memset(m, 0, sizeof(m));
/*
	int idx = 0;
	while (N) {
		int i = idx/W, j = idx%W;
		cout << "? " << i << " " << j << " " << i << " " << j << endl;
		cin >> m[i][j];
		if (m[i][j] > 0) {
			N--;
		}
		idx++;
	}
*/
	_f(0, 0, H-1, W-1, N);

	LL res = 0, p = 1;
	REP(i, H, 0) {
		REP(j, W, 0) {
			res = (res + p * m[i][j] % MOD) % MOD;
			p = p * 2 % MOD;
		}
	}
	cout << "! " << res << endl;
}

Measured memory_bytes: 596
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

#include <cmath>
#include <queue>
#include <stack>

using namespace std;

vector<char> alphaBet;

void makeAlphaBet() {
	alphaBet.clear();
	for (int i = 0; i < 26; ++i) {
		alphaBet.push_back('a' + i);
	}
	for (int i = 0; i < 26; ++i) {
		alphaBet.push_back('A' + i);
	}
	for (int i = 0; i < 10; ++i) {
		alphaBet.push_back('0' + i);
	}
	// for (int i = 0; i < 5; ++i) {
	// 	alphaBet.push_back('0' + i);
	// }
}

vector<string> f;
const int L = 128;
int totalL = 0;
int queryN = 0;
int maxQueryN = 850;

int makeQuery(string s) {
	cout << "? " << s << endl;
	int ans;
	cin >> ans;
	queryN += 1; 
	// if (queryN >= maxQueryN) {
	// 	for (;;);
	// }
	return ans;
}

void makeDecision(string s) {
	cout << "! " << s << endl;
}

void initF() {
	makeAlphaBet();
	int n = alphaBet.size();
	f = vector<string>(n);
	for (int i = 0; i < n; ++i) {
		f[i] = "";
	}
	totalL = 0;
	for (int i = 0; i < n; ++i) {
		string query = "";
		for (int j = 0; j < L; ++j) {
			query.push_back(alphaBet[i]);
		}
		int ans = makeQuery(query);
		f[i] = "";
		if (ans < L) {
			for (int j = 0; j < L - ans; ++j) {
				f[i].push_back(alphaBet[i]);
			}
		}
		totalL += (L - ans);
	}
}

string combine(string a, string b) {
	// cout << "combine " << a << " " << b << endl;
	if (a.length() == 0) {
		return b;
	}
	if (b.length() == 0) {
		return a;
	}
	int curA = 0, curB = 0;
	string res = "", tmp;
	int aL = a.length(), bL = b.length();
	while (curA < aL || curB < bL) {
		if (curA >= aL) {
			res.push_back(b[curB++]);
			continue;
		}
		if (curB >= bL) {
			res.push_back(a[curA++]);
			continue;
		}
		tmp = res + a[curA] + b.substr(curB);
		// tmp.push_back(a[curA]);
		// // res.push_back(b[curB]);
		// for (int i = curB; i < bL; ++i) {
		// 	tmp.push_back(b[curB]);
		// }
		int ans = makeQuery(tmp);
		if (ans + (int)(tmp.size()) == totalL) {
			res.push_back(a[curA++]);
			continue;
		} else {
			res.push_back(b[curB++]);
			continue;
		}
	}
	return res;
}

string getF(int l, int r) {
	if (l == r) {
		return f[l];
	}
	int mid = (l + r) / 2;
	string left = getF(l, mid);
	string right = getF(mid + 1, r);
	return combine(left, right);
}

bool cmp(const string &a, const string &b) {
	return a.length() > b.length();
}

string combineF() {
	while (f.size() > 1) {
		sort(f.begin(), f.end(), cmp);
		if (f.back().empty()) {
			f.pop_back();
			continue;
		}
		int size = f.size();
		string a1 = f[size - 1];
		string a2 = f[size - 2];
		string a = combine(a1, a2);
		f.pop_back(); f.pop_back();
		f.push_back(a);
	}
	return f[0];
}

int main() {
	initF();
	// makeDecision(getF(0, alphaBet.size() - 1));
	string res = combineF();
	cout << "! " << res << "\n";
	// cout << "! " << combineF() << endl;
	// return 0;
}

Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin>>S;
    int lenS=S.size();
    int juge[26];
    set<char> T;
    for(int i=0;i<lenS;i++){
        T.insert(S[i]);
        juge[i]=T.size();
        if(i!=0 && juge[i]==juge[i-1]){
            cout<<"no"<<endl;
            return 0;
        }
    }
    cout<<"yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

ans = "Yes"
H_max = H[0]
for i in range(1, N):
  if H[i] < H_max:
    if H_max - H[i] >= 2:
      ans = "No"
      break
  H_max = max(H_max, H[i])
print(ans)

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

int main(){
  int N,y;
  y = 0;
  
  cin >> N;
  
  while(N>0){
    int a,b;
    cin >> a >>b;
    y += b-(a-1);
    N--;
  }
  cout << y << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repBack(i, n) for (int i = n; i >= 0; i--)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int A,B;
    cin >> A >> B;
    int C,D;
    cin >> C >> D;
    int t = (C+(B-1))/B;
    int a = (A+(D-1))/D;
    if(t<=a){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
n,m=map(int,input().split())
a=[[int(i) for i in input().split()] for i in range(m)]
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
    l=[False]*n
    for j in range(n):
        if(i>>j & 1):
            l[j]=True
    #ランプの状態が決定
    light=0
    for x,aa in enumerate(a):
        cnt=0
        for y,k in enumerate(aa):
            if y==0:
                continue
            if l[k-1]==True:
                cnt+=1
        if cnt%2==p[x]:
            light+=1
    if light==m:
        ans+=1
print(ans)

Measured memory_bytes: 3064