akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)


//union-find
#define UFLIMIT (1<<20)
int unicnt[UFLIMIT+10];//正ならcnt、非正なら根のindex
void ufinit(int n){rep(i,0,n)unicnt[i]=1;}
int root(int x){return unicnt[x]<=0?-(unicnt[x]=-root(-unicnt[x])):x;}
int same(int x,int y){return root(x)==root(y);}
void uni(int x,int y){if((x=root(x))==(y=root(y)))return;if(unicnt[x]<unicnt[y]){int t=x;x=y;y=t;}unicnt[x]+=unicnt[y];unicnt[y]=-x;}
#undef UFLIMIT


ll h,w;
char s[410][410];
int main(){
	scanf("%lld%lld",&h,&w);
	rep(i,0,h)scanf(" %s",s[i]);
	ufinit(h*w*2);
	//黒のマス=i*w+j、白のマス=i*w+j+h*w
	rep(i,0,h)rep(j,0,w){
		if(s[i][j]=='#'){
			if(i-1>=0)if(s[i][j]!=s[i-1][j])uni(i*w+j,(i-1)*w+j+h*w);
			if(i+1< h)if(s[i][j]!=s[i+1][j])uni(i*w+j,(i+1)*w+j+h*w);
			if(j-1>=0)if(s[i][j]!=s[i][j-1])uni(i*w+j,i*w+(j-1)+h*w);
			if(j+1< w)if(s[i][j]!=s[i][j+1])uni(i*w+j,i*w+(j+1)+h*w);
		}else{
			if(i-1>=0)if(s[i][j]!=s[i-1][j])uni(i*w+j+h*w,(i-1)*w+j);
			if(i+1< h)if(s[i][j]!=s[i+1][j])uni(i*w+j+h*w,(i+1)*w+j);
			if(j-1>=0)if(s[i][j]!=s[i][j-1])uni(i*w+j+h*w,i*w+(j-1));
			if(j+1< w)if(s[i][j]!=s[i][j+1])uni(i*w+j+h*w,i*w+(j+1));
		}
	}
	ll a[410*410*2]={};
	rep(i,0,h)rep(j,0,w){
		ll temp=root(i*w+j);
		a[temp]++;
	}
	ll ans=0;
	rep(i,0,h)rep(j,0,w){
		ans+=a[root(i*w+j+h*w)];
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
    
    string a;
    int ans = 0;
    cin >> a;

    if(a[0]=='1')ans+=1;
    if(a[1]=='1')ans+=1;
    if(a[2]=='1')ans+=1;

    cout << ans << endl;
    
}

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

using  namespace std;

int main(){
  string text;
  while(true){
    getline(cin,text,'\n');
    if (text=="END OF INPUT")
      break;
    int n = 0;
    for(int i=0;i<(int)text.size();i++){
      if (text[i] ==' '){
	cout <<n;
	n = 0;
      }
      else{
	n++;
      }
    }
    cout <<n << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    string s; cin>>s;
    ll n=s.size(),ans=10000;
    rep(i,n-2){
        ll a=(s[i]-'0')*100+(s[i+1]-'0')*10+s[i+2]-'0';
        chmin(ans,abs(a-753));
    }
    cout<<ans<<endl;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N; cin >> N;
    vi a(N); REP(i, N) cin >> a[i];
    int ans = 0;
    REP(i, N)
    {
        while(a[i] % 2 == 0)
        {
            ans++;
            a[i] /= 2;
        }
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int mod = 1e9+7;
const int maxn = 1e5+5;
LL fac[maxn], inv[maxn];

int cnk(const int n, const int k)
{
    if (n == 0 || n < k)
        return 0;
    return fac[n] * inv[k] % mod * inv[n-k] % mod;
}

int pow(LL a, int k)
{
    LL ans = 1;
    while (k) {
        if (k & 1) {
            ans *= a; ans %= mod;
        }
        a *= a; a %= mod; k >>= 1;
    }
    return ans;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    fac[0] = inv[0] = 1;
    FOR(i,1,maxn) {
        fac[i] = fac[i-1] * i % mod;
        inv[i] = pow(fac[i],mod-2);
    }
    int n,k;
    while (cin >> n >> k) {
        vector<LL> A(n);
        FOR(i,0,n)
            cin >> A[i];
        sort(ALL(A));
        LL ans = 0;
        FOR(i,0,n) {
            ans += cnk(i,k-1) * A[i];
            ans %= mod;
            ans -= cnk(n-i-1,k-1) * A[i];
            ans %= mod;
        }
        ans += mod;
        ans %= mod;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
int main() {
	string s,ans;
	cin >> s;
	if(s=="Sunny") ans="Cloudy";
	else if(s=="Cloudy") ans="Rainy";
	else ans="Sunny";
	cout << ans << endl;
}


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

int main() {
	
	int n, m;
	scanf("%d %d", &n, &m);
	vector<int> v(n);
	for(int i = 0; i < n; i++) {
		v[i] = 0;
	}
	for(int i = 0; i < m; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		v[a - 1] += 1;
		v[b - 1] += 1;
	}
	for(int i = 0; i < n; i++) {
		printf("%d\n", v[i]);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 200005;
const int B = 256;

int main(){
	string s;
	cin >> s;
	sort(all(s));
	if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) puts("Yes");
	else puts("No");
}


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

#define ff first
#define ss second
#define pb push_back

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

const int N = 100005;

int main() {
	int n;
	char s[N], t[N];
	scanf("%d", &n);
	scanf("%s %s", s, t);
	for(int i = 0; i < 2 * n; i++){
		if(i&1){
			printf("%c", t[i/2]);
		}
		else{
			printf("%c", s[i/2]);
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <limits>
#include <set>
#include <map>

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

    if (s[2] == s[3] && s[4] == s[5]) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
    return 0;
}


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

int main() {
    using namespace std;
    string S; cin >> S;
    deque<char> ds;
    for(int i=0; i<S.length(); i++){
        ds.push_back(S[i]);
    }
    int q; cin >> q;
    bool isReversed = false;
    for(int i=0; i<q; i++){
        int t;
        cin >> t;
        if(t==1) {
            isReversed=!isReversed;
            continue;
        }
        int f;
        char c;
        cin >> f >> c;
        if((f==1 && !isReversed) || (f==2 && isReversed)){
            ds.push_front(c);
        } else{
            ds.push_back(c);
        }
    }
    for(int i=0; i<ds.size(); i++){
        if(isReversed)cout<<ds[ds.size()-1-i];
        else cout<<ds[i];
    }
    cout << endl;
    return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};
static const int INF = 1e9+7;

int main() {
  int n;
  while(cin >> n, n) {
    vector<vector<int>> dist(11, vector<int> (11, INF));
    int v = 0;
    int a, b, c;

    rep(i, 0, n) {
      cin >> a >> b >> c;
      dist[a][b] = c;
      dist[b][a] = c;
      dist[a][a] = 0;
      dist[b][b] = 0;
      v = max(v, a+1);
      v = max(v, b+1);
    }

    rep(i, 0, v) {
      dist[i][i] = 0;
    }

    rep(k, 0, v) {
      rep(i, 0, v) {
        rep(j, 0, v) {
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        }
      }
    }

    int cost = INF;
    int town;
    rep(i, 0, v) {
      int c = 0;
      rep(j, 0, v) {
        c += dist[i][j];
      }

      if (c < cost) {
        cost = c;
        town = i;
      }
    }

    cout << town << ' ' << cost << endl;
  }

  return 0;
};



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

char str[100100];

main()
{
    scanf("%s",str);
    int loop=1;
    for(int i=2;str[i];i++)
    {
        if(str[i]!=str[i-2])
        {
            loop=0;
            break;
        }
    }
    if(loop==1)printf("Second\n");
    else if(str[0]!=str[strlen(str)-1])
        printf("%s\n",strlen(str)%2==0?"Second":"First");
    else
        printf("%s\n",strlen(str)%2==1?"Second":"First");
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
string s;
int main()
{
    ll n, i;

    cin>>n;
    cin.ignore();
    cin>>s;
    if(s.size()%2!=0)
    {
        printf("No\n");
        return 0;
    }
    for(i=0; i<s.size()/2; i++)
    {
        if(s[i]!=s[i+s.size()/2])
        {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


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

const int N = 111111, M = 111111;
int n, m;

long long int fact(int x) {
    if(x <= 1) return 1;
    long long int ans = 1;
    for(long long int a = 2; a <= x; a++) {
        ans *= a;
        ans %= MOD;
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    if(n < m) {
        int a = n;
        n = m;
        m = a;
    }
    if(n - m > 1) {
        cout << 0 << endl;
        return 0;
    }
    long long int ans = fact(n) * fact(m) % MOD;
    if(n == m) {
        ans *= 2;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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;

// 最大公約数
ll gcd(ll a, ll b){
	if(b == 0) return a;
	return gcd(b, a%b);
}

// 素因数分解
map<ll, ll> prime_factor(ll n){
	map<ll, ll> res;
	for(ll i = 2; i * i <= n; i++){
		while( n % i == 0){
			++res[i];
			n /= i;
		}
	}
	if( n != 1 ) res[n] = 1;
	return res;
}

int main(){
	ll a,b;
	cin >> a >> b;
	
	ll gcdvalue = gcd(a,b);
	map<ll, ll> primap = prime_factor(gcdvalue);

	cout << primap.size()+1 << endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7
P = 2 ** 61 - 1

N = int(readline())
m = map(int, read().split())
A, B = zip(*zip(m, m))

pow2 = [1] * (N + 10)
for n in range(1, N + 10):
    pow2[n] = pow2[n - 1] * 2 % MOD

def inv_mod(a):
    b = P
    u, v = 1, 0
    while a:
        t = b // a
        a, b = b - t * a, a
        u, v = v - t * u, u
    if b < 0:
        v = -v
    return v % P

def to_key(a, b):
    if a == 0:
        return -1
    x = inv_mod(a) * b % P
    return x

def pair_key(key):
    if key == -1:
        return 0
    if key == 0:
        return -1
    return P - inv_mod(key)
  
counter = defaultdict(int)
origin = 0
for a, b in zip(A, B):
    if a == b == 0:
        origin += 1
        continue
    key = to_key(a, b)
    counter[key] += 1

answer = origin
k = 1
for key, cnt in counter.items():
    key1 = pair_key(key)
    if key1 not in counter:
        k *= pow2[cnt]
    elif key < key1:
        x, y = cnt, counter[key1]
        k *= pow2[x] + pow2[y] - 1
    k %= MOD
answer += k - 1
answer %= MOD
print(answer)


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

int main()
{
  int n,x,sum=0;
  cin>>n>>x;
  vector<int> v(n);
  for(int &i:v) {cin>>i;sum+=i;}
  int y = *min_element(v.begin(),v.end());
  int ans = n;
  x-=sum;
  ans += x/y;
  cout<<ans<<"\n";
  
  
  
  return 0; 
}


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


int main(){
  int N,K;
  int ans = 0;
  cin >> N >> K;

  for(int i=0; i<N; i++){
    int x;
    cin >> x;
    int y = K - x;

    if(x < y){
      ans += x;
    }
    else{
      ans += y;
    }

  }

  cout << ans*2 << endl;

  return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <list>
#include <set>
using namespace  std;

constexpr int INF = std::numeric_limits<int>::max();

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

    map<int, vector<pair<int, int>>> tree;
    for (int i = 0; i < N - 1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        tree[u].emplace_back(v, w);
        tree[v].emplace_back(u, w);
    }

    vector<int> V(N, -1);
    vector<int> stack, depth;
    stack.push_back(0);
    V[0] = 0;
    while (!stack.empty()) {
        int k = stack.back(); stack.pop_back();

        int c = V[k];
        for (auto &p : tree[k]) {
            int v = p.first;
            int w = p.second;
            if (V[v] != -1) {
                continue;
            }

            V[v] = (c + (w % 2)) % 2;
            stack.push_back(v);
        }
    }

    for (int c : V) {
        cout << c << endl;
    }
}

Measured memory_bytes: 12288
using System;

namespace ITP_7_D{
    public class Program{
        static double[][] array1;
        static double[][] array2;

        public static void Main(string[] args){
            string[] temp = Console.ReadLine().Split(' ');
            int n = int.Parse(temp[0]);
            int m = int.Parse(temp[1]);
            int l = int.Parse(temp[2]);
            array1 = new double[n][];
            array2 = new double[m][];
            double[] answer = new double[l];

            //??\?????????????????¢??°????????????
            MakeArray1(n,m);
            MakeArray2(m,l);

            //?¨?????????????
            for(int i=0; i<n; i++){
                for(int k=0; k<m; k++){
                    for(int t=0; t<l; t++){
                        answer[t] += array1[i][k] * array2[k][t];
                    }
                }
                for(int z=0; z<l; z++){
                    if(z!=0) Console.Write(" ");
                    Console.Write(answer[z]);
                }
                answer = new double[l];
                Console.WriteLine();
            }
        }

        private static void MakeArray1(int row,int column){
            for(int i=0; i<row; i++){
                string[] test = Console.ReadLine().Split(' ');
                array1[i] = new double[column];
                for(int k=0; k<column; k++){
                    array1[i][k] = int.Parse(test[k]);
                }
            }
        }

        private static void MakeArray2(int row,int column){
            for(int i=0; i<row; i++){
                string[] test = Console.ReadLine().Split(' ');
                array2[i] = new double[column];
                for(int k=0; k<column; k++){
                    array2[i][k] = int.Parse(test[k]);
                }
            }
        }
    }
}

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

int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n;
    string s;
    cin >> s;
    n = s.size();
    vector<int> ans(n);
    
    rep(ri,2){
        {
            int cnt = 0;
            rep(i,n){
                if(s[i]=='R') cnt++;
                else {
                    ans[i] += cnt/2;
                    ans[i-1] += (cnt+1)/2;
                    cnt = 0;
                }
            }
        }
        reverse(ans.begin(), ans.end());
        reverse(s.begin(), s.end());
        rep(i,n){
            if(s[i] == 'L') s[i] = 'R';
            else s[i] = 'L';
        }
    }
    rep(i,n) cout << ans[i] << endl;
}


Measured memory_bytes: 1104
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
mod = 10**9+7

dp = [[0 for i in range(M)] for j in range(N)]
sum_dp = [[0 for i in range(M)] for j in range(N)]


if S[0] == T[0]:
    dp[0][0] = 1
    sum_dp[0][0] = 1

for i in range(1, N):
    if S[i] == T[0]:
        dp[i][0] = 1
    sum_dp[i][0] = (sum_dp[i-1][0] + dp[i][0])%mod

for j in range(1, M):
    if S[0] == T[j]:
        dp[0][j] = 1
    sum_dp[0][j] = (sum_dp[0][j-1] + dp[0][j])%mod

for i in range(1, N):
    for j in range(1, M):
        if S[i] == T[j]:
            dp[i][j] = (sum_dp[i-1][j-1] + 1)%mod
        sum_dp[i][j] = (sum_dp[i-1][j] + sum_dp[i][j-1] - sum_dp[i-1][j-1] + dp[i][j])%mod

print((sum_dp[N-1][M-1]+1)%mod)

Measured memory_bytes: 107868
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i,0,(n))
#define pb(n) push_back(n)
#define mp(n,m) make_pair(n, m)
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
int n;
vector<string> s;

bool outOfRange(int y, int x){
	if(y < 0 || y >= n || x < 0 || x >= n){
		return true;
	}
	return false;
}

bool check(int ny, int nx, int dir){
	if(outOfRange(ny, nx)) return true;
	for(int i = 0; i < 4; i++){
		if(i == (dir+2)%4) continue;
		int nny = ny + dy[i], nnx = nx + dx[i];
		if((!outOfRange(nny, nnx)) && s[nny][nnx] == '#'){
			return true;
		}
	}
	return false;
}

int main(){
	int d;
	cin>>d;
	for(int i = 0; i < d; i++){
		if(i!=0) printf("\n");
		cin>>n;
		s = vector<string>(n,string(n, ' '));
		pii pos = pii(n-1, 0);
		int dir = 0;
		while(1){
			if(s[pos.fi][pos.se]=='#') break;
			s[pos.fi][pos.se] = '#';
			int ny = pos.fi+dy[dir], nx = pos.se+dx[dir];
			int cnt = 4;
			while(check(ny, nx, dir) &&(--cnt)){
				dir++;
				dir%=4;
				ny = pos.fi+dy[dir]; nx = pos.se+dx[dir];

			}
			if(cnt == 0) break;
			pos=pii(ny ,nx);
		}
		rep(i, n){
			cout<<s[i]<<endl;
		}
	}
}

Measured memory_bytes: 1232
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;
const int MAX_COUNT = 100;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	unordered_map<int, int> m;
    for(int i = 1; i < MAX_COUNT; ++i) {
    	for(int j = 1; j < MAX_COUNT; ++j) {
    		for(int k = 1; k < MAX_COUNT; ++k) {
    			m[i*i + j*j + k*k + i*j + j*k + i*k]++;
    		}
    	}
    }
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i) {
    	if(m.count(i)) {
    		cout << m[i] << "\n";
    	} else {
    		cout << 0 << "\n";
    	}
    }
	return 0;
}


Measured memory_bytes: 4524
#include <bits/stdc++.h>
    using namespace std;
 
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define mod 1000000007
    #define qmod 998244353
    #define M 1000001
    #define endl "\n"
    #define all(a) (a).begin(),(a).end()
    #define rep(i,a,b) for(int i=a;i<b;++i)
    #define repr(i,a,b) for(int i=a;i>=b;--i)
    #define F first
    #define S second
    #define pb push_back
    #define mp make_pair

    typedef long long ll;
    typedef pair<int,int> pii;
    typedef vector<int> vi;
    typedef vector<string> vs;
    typedef vector<pii> vii;
    typedef vector<vi> vvi; 

    int main(){
        
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin); 
    // freopen("output.txt","w",stdout);   
    // #endif  
 
        fast;
        int n,m;
        cin>>n>>m;
        cout<<n*(n-1)/2 + m*(m-1)/2;
        return 0;  
    } 

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>

using namespace std;

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const db PI = acos(-1);
const db ERR = 1e-12;

const int MX = 500005;

char buf[MX];
int D[MX];

int main()
{
	int N;
	scanf("%d%s", &N, buf+1);
	int ans = 0, cur = 0;
	vector<int> L;
	for(int i = 1; i <= N; i++){
		if( buf[i] == '1' ) cur++;
		else cur = 0;
		D[i] = max(D[i], D[i-1]);
		if( cur && buf[i+1] == '0' && buf[i+2] == '1' ) D[i+2] = max(D[i+2], D[i-cur] + cur);
		if( cur && buf[i+1] == '0' && buf[i+2] == '1' ) D[i+2] = max(D[i+2], D[i-cur+1] + cur-1);
		if( cur && i >= cur+2 && buf[i-cur] == '0' && buf[i-cur-1] == '1' ) D[i] = max(D[i-cur-2] + cur, D[i]);
	}
	printf("%d\n", D[N]);
}


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

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

	for(int i=1; i <= 9; ++i){
		for(int j=1; j <= 9; ++j ){
			if(N == i*j){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	
	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
while True:
    length = int(input())

    if length == 0:
        break

    oldList = [int(item) for item in input().split(" ")]
    operateCount = 0

    while True:

        numberCount = {}
        for item in oldList:
            if item in numberCount:
                numberCount[item] += 1
            else:
                numberCount[item] = 1

        newList = []
        for number in oldList:
            newList.append(numberCount[number])

        if oldList == newList:
            print(str(operateCount))
            items = [str(item) for item in newList]
            items = " ".join(items)
            print(items)
            break

        operateCount += 1
        oldList = newList



Measured memory_bytes: 5604
#include<stdio.h>
int main()
{
    int m,f,r,sum=0,i;
    for(;scanf("%d%d%d",&m,&f,&r);)

    {
    if(m==-1 && f==-1 && r==-1)
    break;
    else if(m<=50 && f<=50 && r<=100)
       { sum=m+f;
        if(m==-1 || f==-1 || m+f<30)
            printf("F\n");
        else if(sum>=80)
            printf("A\n");
        else if(sum>=65 && sum<80)
            printf("B\n");
        else if(sum>=50 && sum<65)
            printf("C\n");
            else if(sum>=30 && sum<50 && r>=50)
            printf("C\n");
        else if(sum>=30 && sum<50)
            printf("D\n");
         }
    }
    return 0;
}



Measured memory_bytes: 2108
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int i = 1;
        while(s.hasNext()){
            int x = s.nextInt();
            if(x == 0) break;
            System.out.println("Case " + i + ": " + x);
            i++;
        }
    }

}

Measured memory_bytes: 32996
N, A, B, C, D = map(int, input().split())

if (A <= N or C <= N):
   if N % A == 0:
      X = int(N / A) * B
   else:
      X = int(N / A + 1) * B
   if N % C == 0:
      Y = int(N / C) * D
   else:
      Y = int(N / C + 1) * D
else:
   X = B
   Y = D
   
if X <= Y:
   print(int(X))
else:
   print(int(Y))


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
int n,k;
int dizi[100007][3];
long long int dp[100007][3];
int main()
{
	
	cin >> n;k=2;
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n;i++)
		cin >> dizi[i][0] >> dizi[i][1] >> dizi[i][2];
	dp[0][0]=dizi[0][0];
	dp[0][1]=dizi[0][1];
	dp[0][2]=dizi[0][2];
	for(int i=1;i<n;i++)
	{
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+dizi[i][0];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+dizi[i][1];
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+dizi[i][2];
			
	}
	cout << max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
}

Measured memory_bytes: 3712
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        long[] abck=cin.ArrayLong(4,0);
        if(abck[0]-abck[1]>1000000000000000000||abck[1]-abck[0]>1000000000000000000)Console.WriteLine("Unfair");
        else if(abck[3]%2==0)Console.WriteLine(abck[0]-abck[1]);
        else Console.WriteLine(abck[1]-abck[0]);
    }


}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public static void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }//Answer.IntArrayAns(x);
    public static void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
int main()
{
    // #ifndef MHT
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

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

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(3e5) + 5;
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
string dir = "RDLU";
#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 SORT(v) sort((v).begin(), (v), end())
#define SORTR(v) sort((v).rbegin(), (v), rend())
#define ALL(v) (v).begin(), (v).end()

map<ll, ll> prime_factor(ll n) {
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

ll factrial[MAX_N], inverse[MAX_N];  //階乗と逆元を保持

ll power(ll x, ll n) {  //繰り返し二乗法
    ll ans = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ans = ans * x % MOD;
        }
        x = x * x % MOD;
        n >>= 1;
    }
    return ans;
}

void init(ll n) {
    factrial[0] = 1;
    inverse[0] = 1;
    for (ll i = 1; i <= n; i++) {
        factrial[i] = (factrial[i - 1] * i) % MOD;  //階乗を求める
        inverse[i] = power(factrial[i], MOD - 2) % MOD;  //オイラーの定理で逆元を求める
    }
}

ll nCk(ll n, ll k) {
    return factrial[n] * inverse[k] % MOD * inverse[n - k] % MOD;
}


int main() {
    ll n, m;
    cin >> n >> m;
    init(MAX_N-5);
    map<ll,ll> mp = prime_factor(m);
    ll ans = 1;
    for(auto itr : mp){
        ans *= nCk(n-1+itr.second,n-1);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
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;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));


signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n;cin >> n;
    ll mxm=0;
    ll ans=0;
    rep(i,n){
        ll a; cin >> a;
        if(mxm<a)mxm=a;
        else{
            ans+=(mxm-a);
        }
    }
    cout<<ans<<endl;
}


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

int val[100005];

int main()
{
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    int curr = 0;
    for(int i=1;i<s.length();i++)
    {
        if(s[i]=='C'&& s[i-1]=='A')
        {
            curr++;
            val[i] = curr;
        }
        else
        {
            val[i] = curr;
        }
        
    }
    while(q--){
        int ans = 0;
        int l,r;
        cin >> l >> r;
        l--,r--;
        cout << val[r]-val[l] << endl;
    }
}


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

const int MAX = pow(10, 6);

int main()
{
    lol result{0};
    lol n; cin >> n;
    //int k; cin >> k;

    vector<bool> dp(1000001, true);
    
    vector<int> a(n);
    //vector<int> b(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    sort(ALL(a));
    //b = a;

    REP(i, n - 1)
    {
        if((i >= 1) && (a[i] == a[i - 1]))
        {
            dp[a[i]] = false;
            continue;
        }
        else
        {
            for(int j = 2; a[i]*j <= a[n-1]; j++)
            {
                dp[a[i]*j] = false;
            }
        }
    }
    if(a[n - 1] == a[n - 2])
        dp[a[n - 1]] = false;

    REP(i, n)
    {
        if(dp[a[i]] == true)
            result++;
    }
    
    

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 4028
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define rep(i,a,b) for(int i = a; i <= b;i++)


int main(void){
  int k,a,b;
  scanf("%d",&k);
  scanf("%d%d",&a,&b);
  int count = 0;

  rep(i,a,b){
    if(i%k == 0){
      printf("OK");
      count ++;
      break;
    }
  }
  if(count == 0){
    printf("NG");
  }

  return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <cstdio>
#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
using namespace std;
int main()
{
	int e; while (cin >> e , e)
	{
		int m = 214214, x = 0;
		rep(z, 101) rep(y, 1001)
		{
			x = e - (y * y + z * z * z);
			if (e == x + (y * y) + (z * z * z) && x >= 0 ) 
			{ m = min(x + y + z, m); }
			else if (e > x + (y * y) + (z * z * z)) { break; }
		}
		printf("%d\n", m);
	}
	return 0;
}

Measured memory_bytes: 3140
## A - DDCC Finals
X, Y = map(int, input().split())
money = 0
if X == 1:
    money += 300000
elif X == 2:
    money += 200000
elif X == 3:
    money += 100000
if Y == 1:
    money += 300000
elif Y == 2:
    money += 200000
elif Y == 3:
    money += 100000
if X == 1 and Y == 1:
    money += 400000
print(money)

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


int c[1010];
int w[1010];
int sum[1010];
int dp[1010][1010];

int f(int l, int r){
	if(dp[l][r] != -1) return dp[l][r];
	int len = r - l;
	if(len == 1) return dp[l][r] = 1;

	int ok = 0;
	if(c[l] >= sum[r] - sum[l + 1] && f(l + 1, r)) ok = 1;
	if(c[r - 1] >= sum[r - 1] - sum[l] && f(l, r - 1)) ok = 1;
	return dp[l][r] = ok;
}

int dp2[1010];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> c[i] >> w[i];
		sum[i + 1] = sum[i] + w[i];
	}

	memset(dp, -1, sizeof dp);
	fill((int*)begin(dp2), (int*)end(dp2), 1 << 25);
	dp2[0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j <= n; j++){
			if(f(i, j)){
				dp2[j] = min(dp2[j], dp2[i] + 1);
			}
		}
	}

	cout << dp2[n] << endl;
}

Measured memory_bytes: 7200
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}

signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	int x,y;
    cin>>x>>y;
    bool flag=0;
    for(int i=0;i<=x;i++)
    {
        int h = i*2 + (x-i)*4;
        if(h==y)
        flag=1;
    }
    if(flag)
    cout<<"Yes";
    else
    {
        cout<<"No";
    }
    

return 0;
}

Measured memory_bytes: 3676
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;

const int K = 100005;
int uf[200005];

int id(int v) {
	return (uf[v]==v)?v:uf[v]=id(uf[v]);
}

void merge(int v, int u) {
	uf[id(v)] = id(u);
}

bool same(int u, int v) {
	return id(u)==id(v);
}

int n,m;

int main() {
	ios::sync_with_stdio(0); cin.tie();
	cin >> n >> m;
	for(int i = n+m-1; i >=0; --i)
		uf[i] = i;
	for(int i = 0; i < n; ++i) {
		int k,l;
		cin >> k;
		while(k--) {
			cin >> l;
			merge(i,l+n-1);
		}
	}
	for(int i = 1; i < n; ++i) {
		if(!same(0,i)) {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
	return 0;

	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;


int main()
{
   FAST/**/
   
   ll n,m;
   cin>>n>>m;
   
   if(m == n)
        cout<<"Yes";
   else cout<<"No";    
        
   
   return 0;        
}  
   

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const int INF=1e9;

int main(){
  int v,e;
  cin>>v>>e;
  
  int G[15][15];
  rep(i,v){
    rep(j,v) G[i][j]=INF;
  }
  
  int s,t,d;
  rep(i,e){
    cin>>s>>t>>d;
    G[s][t]=d;
  }
  
  int dp[1<<v][v];
  rep(i,(1<<v)){
    rep(j,v) dp[i][j]=INF;
  }
  dp[0][0]=0;
  
  for(int s=0;s<(1<<v);s++){
    for(int i=0;i<v;i++){
      for(int j=0;j<v;j++){
        if((s&(1<<j))==0) continue;
        if(G[i][j]==INF) continue;
        dp[s][j]=min(dp[s][j],dp[s-(1<<j)][i]+G[i][j]);
      }
    }
  }
  
  if(dp[(1<<v)-1][0]==INF) cout<<-1<<endl;
  else cout<<dp[(1<<v)-1][0]<<endl;

  return 0;
}


Measured memory_bytes: 5000
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

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

int main(void)
{
	int a, b;
	cin >> a >> b;
	if (a + b >= 10) { cout << "error" << endl; }
	else { cout << a + b << endl; }
	return 0;
}


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

int main(){
  int i, j, n, bool=1, cnt=0;
  double sq;
  int a[10000];

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

  for(i=0; i<n; i++){
    sq = sqrt(a[i]);
    for(j=2; j<a[i]; j++){
      if(j > sq) break;
      else if(a[i]%j == 0) {
	bool = 0;
	break;
      }
    }
    if(bool == 1){
      cnt ++;
      /* printf("%d\n", a[i]); */
    }
    bool = 1;
  }

  printf("%d\n", cnt);
}



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

const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
    if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
    if(H==T) return -1;return *H++;
}
inline int read()
{
    int x=0;char c=Get();
    while(!isdigit(c)) c=Get();
    while(isdigit(c)) x=x*10+c-'0',c=Get();
    return x;
}

const int N=100010;
int a[N],b[N],n;
int _a[N<<1],_b[N];
int fa[N<<1],sz[N<<1];

int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}

int main()
{
    n=read();
    int xora=0,xorb=0,ans=0;
    for(int i=1;i<=n;i++) xora^=(_a[i]=a[i]=read());
    for(int i=1;i<=n;i++) xorb^=(_b[i]=b[i]=read());
    a[++n]=xora;b[n]=xorb;_a[n]=a[n];_b[n]=b[n];
    sort(_a+1,_a+1+n);sort(_b+1,_b+1+n);
    for(int i=1;i<=n;i++) if(_a[i]!=_b[i]) return !puts("-1");
    for(int i=1;i<n;i++) ans+=(a[i]!=b[i]);
    if(ans==0) return !puts("0");
    int hs=unique(_a+1,_a+1+n)-(_a+1);
    for(int i=1;i<=hs;i++) fa[i]=i,sz[i]=1;
    for(int i=1;i<=n;i++)
    {
        a[i]=lower_bound(_a+1,_a+1+hs,a[i])-_a;
        b[i]=lower_bound(_a+1,_a+1+hs,b[i])-_a;
        int x=find(a[i]),y=find(b[i]);
        if(x!=y) fa[x]=y,sz[y]+=sz[x];
    }
    if(a[n]==b[n]&&sz[find(a[n])]==1) ans++;
    for(int i=1;i<=n;i++) ans+=(fa[i]==i&&sz[i]>1);
    cout<<ans-1<<endl;
    return 0;
}

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

using namespace std;

#define rep(i,m,n) for(int i=m;i<n;i++)


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

 double res=0;
  rep(i,0,n) {
    int a;
    cin >> a;
   res+=1.0/a; 
  }
   
  

   cout << setprecision(15) << 1.0/res << endl;
}

Measured memory_bytes: 256
#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 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	int r, D;
	int A, B;
	int x[11];
	cin >> r >> D >> x[0];

	REP(i, 10){
		x[i + 1] = r * x[i] - D;
		cout << x[i + 1] << endl;
	}
}


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

#define int ll
#define mainspring cout<<"mainspring\n";
#define barrel cout<<"barrel\n";
#define escapement cout<<"escapement\n";

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second
#define tik(i,a,b) for(int i = a; i < b; i++)
#define tok(i,a,b) for(int i = a; i >= b; i--)
#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}

typedef long long ll;
typedef unsigned long long ull;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " ";
    err(++it, args...);
}

const int MOD = 1E9 + 7, MAXN = 5E5 + 1000;

ll pow(ll x, ll y) {
	if(y == 0)
	return 1;
	ll temp = pow(x, y/2);
	temp = (temp*temp)%MOD;
	if(y%2 == 1)
		temp *= x;
	return temp%MOD;
}

int pr[MAXN];
vi primes;

int32_t main() {
	for(int i = 2; i < MAXN; i++) {
		if(pr[i] != 0)
			continue;
		primes.pb(i);
		for(int j = i; j < MAXN; j+= i)
			pr[j] = i;
	}
	int n, k;
	cin >> n >> k;
	int res = 0;
	int tot = 0;
	int arr[k + 1] = {0};
	for(int g = k; g >= 1; g--) {
		int np = k/g;
		int num = pow(np, n);
		for(int j = g + g; j <= k; j += g)
			num = (num - arr[j] + MOD)%MOD;
		res = (res + (num*g)%MOD)%MOD;
		arr[g] = num;
		//tot += num;
	}
	//error(tot);
	cout << res;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int INF=1<<29;

int main(){
	int n,m; cin>>n>>m;
	vector<int> G[1000];
	rep(i,m){
		int u,v; cin>>u>>v; u--; v--;
		G[u].emplace_back(v);
	}

	vector<int> ans;
	rep(u,n){
		int d[1000],pre[1000];
		bool vis[1000]={};
		queue<int> Q; Q.push(u);
		rep(v,n) d[v]=INF;
		d[u]=0;
		vis[u]=true;
		while(!Q.empty()){
			int v=Q.front(); Q.pop();
			for(int w:G[v]){
				if(!vis[w]){
					vis[w]=true;
					d[w]=d[v]+1;
					pre[w]=v;
					Q.push(w);
				}
				else if(w==u){
					vector<int> tmp;
					tmp.emplace_back(v);
					int z=pre[v];
					while(z!=u) tmp.emplace_back(z), z=pre[z];
					tmp.emplace_back(u);
					if(ans.empty() || tmp.size()<ans.size()) ans=tmp;
				}
			}
		}
	}

	if(ans.empty()) cout<<-1<<endl;
	else{
		cout<<ans.size()<<endl;
		for(int x:ans) cout<<x+1<<endl;
	}

	return 0;
}


Measured memory_bytes: 256