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

using namespace std;
typedef long long ll;
const int N = 12, INF = 1e8;
int n, m, x;
int a[N][N], c[N], lvl[N];

int main() {
    cin >> n >> m >> x;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) cin >> a[i][j];
    }
    int ans = INF;
    for (int k = 1; k < (1 << n); k++) {
        fill(lvl, lvl + N, 0);
        int cost = 0;
        for (int i = 0; (1 << i) <= k; i++) {
            if (k & (1 << i)) {
                for (int j = 0; j < m; j++) lvl[j] += a[i][j];
                cost += c[i];
            }
        }
        bool ok = 1;
        for (int j = 0; j < m; j++) if (lvl[j] < x) ok = 0;
        if (ok) ans = min(ans, cost);
    }
    if (ans == INF) ans = -1;
    cout << ans << "\n";
}


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

int main(){
  int A,B;
  string S,T,U;
  cin >> S >> T >> A >> B >> U;
  if (U == S) A--;
  else B--;
  cout << A << " " << B << endl;
}
                   


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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int N,K;
signed main() {
    cin>>N;
    for(int i=0;i<100;i++){
        for(int j=0;j<100;j++){
            if(i*4+j*7==N){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int K;
  while (cin >> K) {
    if (K == 1) {
      cout << 1 << endl;
      cout << 1 << endl;
      continue;
    }
    int side = 0;
    for (int n = 1; 2 * n <= 500; n++) {
      if (2 * n <= K && K <= 4 * n) {
        side = 2 * n;
        break;
      }
    }
    assert(1 <= side && side <= 500);
    cout << side << endl;
    for (int i = 0; i < side; i++) {
      for (int j = 0; j < side; j++) {
        int v;
        if (i % 2 == 0) {
          v = (j + i) % side;
        } else {
          v = side + (j + i) % side;
        }
        if (v >= K) v -= side;
        cout << v + 1 << " ";
      }
      cout << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1152
function Main(input){
var A = input.split(" ")[0];
A = parseInt(A,10);
var B = input.split(" ")[1];
B = parseInt(B,10);

var ab = B % A
if(ab === 0){
    console.log(A + B);
}else{
    console.log(B - A);
}





    
}





Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main() {
int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  if(a == 0){
    cout << 1 << endl;
  }else if(b == 0){
    cout << 2 << endl;
  }else if(c == 0){
    cout << 3 << endl;
  }else if(d == 0){
    cout << 4 << endl;
  }else if(e == 0){
    cout << 5 << endl;
  }

}

Measured memory_bytes: 3620
#include <cstdio>

#include <algorithm>

#define LL long long

#define maxn 200010

using namespace std;

int a[maxn],n,cnt[maxn],mx;//cnt[]统计相同数值的元素数量

LL ans,out;

int main(){

	int i;

	scanf("%d",&n);

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

	for(i=1;i<=mx;i++)

		if(cnt[i]>=2)ans+=(LL)cnt[i]*(cnt[i]-1)/2;//任选2个

	for(i=1;i<=n;i++)
    {

		if(cnt[a[i]]>=2){

			out=ans-cnt[a[i]]*(cnt[a[i]]-1)/2;//先扣除

			out+=(cnt[a[i]]-1)*(cnt[a[i]]-1-1)/2;//再加回

		}
		else out=ans;

		printf("%lld\n",out);

	}

	return 0;

}


Measured memory_bytes: 3584
N = int(input())
A = []
for i in range(N):
    a = list(map(int, input().split()))
    A.append(a)

A.sort(key=lambda x:x[1])    
count = 0
for i in range(N):
    count += A[i][0]
    if count > A[i][1]:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 53716
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
const int maxn = 1e5 + 55;
int n, E = -1, C = -1;
vector<vpi> g;
vi sz, maxch;
ll ans = 0;
void dfs(int v = 1, int p = 1) {
	maxch[v] = 0, sz[v] = 1;
	for(auto i : g[v]) {
		if(i.first == p) continue;
		dfs(i.first, v);
		sz[v] += sz[i.first], maxch[v] = max(maxch[v], sz[i.first]);
		if(n%2 == 0 && sz[i.first] == n/2) E = i.second;
		ans += i.second * 2ll * min(n-sz[i.first], sz[i.first]);
	}
	maxch[v] = max(maxch[v], n - sz[v]);
	if(maxch[v] < (n+1)/2) C = v;
}
int mn(int v) {
	ll m = 1<<30;
	for(auto i : g[v]) m = min(m, i.second);
	return m;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	g.resize(n+1);
	sz.resize(n+1);
	maxch.resize(n+1);
	for(int f, t, c, i = 1; i < n; i++) {
		cin >> f >> t >> c;
		g[f].pb({t, c});
		g[t].pb({f, c});
	}
	dfs();
	if(E!=-1) ans -= E;
	else ans -= mn(C);
	cout << ans;
}


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

int main()
{
    ll t=1,i,j,k,a,b,n,x,y,m;
    cin>>n;
    ll cnt,f=0;
    vector<ll>v,u;
    ll sum=0;
    m=1000000007;
    for(i=0;i<n;i++)
    {
        cin>>k;
        v.push_back(k);
    }
    for(i=n-1;i>=0;i--)
    {
        sum=(sum+v[i]);
       // cout<<sum<<endl;
        u.push_back(sum);
    }
    reverse(u.begin(),u.end());
//    cout<<u[0]<<endl;
//    cout<<u[1]<<endl;
    ll ans=0,p=0;
    for(i=0;i<n;i++)
    {
        p=u[i]-v[i];
        ans=((ans%m)+(((p%m)*(v[i]%m)))%m)%m;
    }
    cout<<ans%m<<endl;
    return 0;
}


Measured memory_bytes: 7992
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<string> W(N);
	for (int i = 0; i < N; i++) cin >> W[i];
	string ans = "Yes";
	map<string, bool> M;
	for (int i = 0; i < N - 1; i++) {
		if (M[W[i + 1]]) ans = "No";
		int num = W[i].size() - 1;
		if (W[i][num] != W[i + 1][0]) ans = "No";
		M[W[i]] = true;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3608
n, m = map(lambda x: int(x), input().split())
a = [0] * m
b = [0] * m
c = [0] * m
for i in range(m):
    a[i], b[i], c[i] = map(lambda x: int(x), input().split())

def dijkstra(graph, start, end):
    cost = [1000*100 for _ in range(n+1)]
    fixed = [False for _ in range(n+1)]
    cost[start] = 0
    fixed[start] = True
    tmp_sta = start
    while True:
        tmp_min = 1000*100
        for i in graph[tmp_sta]:
            cost[i[0]] = min(cost[i[0]], cost[tmp_sta]+i[1])
        for i in range(1, n+1):
            if tmp_min > cost[i] and fixed[i] == False:
                tmp_min = cost[i]
                tmp_sta = i
        if tmp_sta == end:
            return tmp_min
        else:
            fixed[tmp_sta] = True
    
graph = {}
for i in range(1, n+1):
    graph[i] = []
for i in range(m):
    graph[a[i]].append((b[i], c[i]))
    graph[b[i]].append((a[i], c[i]))
    
ans = 0
for i in range(m):
    if c[i] > dijkstra(graph, a[i], b[i]):
        ans += 1
print(ans)

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

int main(){
	string S;
	cin>>S;
	string year,month,day;
	year=S.substr(0,4);
	month=S.substr(5,2);
	day=S.substr(8,2);
	if(year<"2019"){
		cout<<"Heisei"<<endl;
	}
	else if(year=="2019"){
		if(month<="04"){
			cout<<"Heisei"<<endl;
		}
		else{
			cout<<"TBD"<<endl;
		}
	}
	else cout<<"TBD"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int mxN=2e6+10,M=1e9+7;
int mod(int a,int M){int ret=a%M; if(ret<0)ret+=M;return ret;}
int exp(int a,int b,int M){
    if(b==0LL)return 1LL;
    if(b==1LL)return mod(a,M);
    int t=exp(a,b/2,M);
    if(b%2)return mod(a*mod(t*t,M),M);
    return mod(t*t,M);
}

int fat(int x){
    int f=1;
    for(int i=2;i<=x;i++){
        f=mod(f*mod(i,M),M);
    } 
    return mod(f,M);
}

int a,b;

int x,y;
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>x>>y;
    if((x+y)%3!=0){
        cout<<0;
        return 0;
    }
    //achar movimentos a e b
    a=(2*y-x)/3;
    b=(2*x-y)/3;
    if(a<0 || b<0){
        cout<<0;
        return 0;
    }
    //cout<<a<<" "<<b<<"\n";
    //cout<<fat[a+b]<<"\n";
    //cout<<fat[a]<<" "<<fat[b]<<"\n";
    int resp=mod(mod(fat(a+b)*exp(fat(a),M-2,M),M)*exp(fat(b),M-2,M),M);
    cout<<resp;



}

Measured memory_bytes: 384
x,y = map(int,input().split())
if x == 1 and y == 1:
    print(1000000)
elif x == 1 and y == 2 or x == 2 and y == 1:
    print(500000)
elif x == 2 and y == 2 or x == 3 and y == 1 or x == 1 and y == 3:
    print(400000)
elif x == 3 and y == 2 or x == 2 and y == 3 or x == 1 and y >= 4 or x >= 4 and y == 1:
    print(300000)
elif x == 3 and  y == 3 or x == 2 and y >= 4 or x >= 4 and y == 2:
    print(200000)
elif x == 3 and y >= 4 or x >= 4 and y == 3:
    print(100000)
else:
    print(0)

Measured memory_bytes: 9188
a,b,c,d=input()
p = True
for i in ('+','-'):
    for j in ('+','-'):
        for k in ('+','-'):
            if eval(a+i+b+j+c+k+d)==7:
                print(a+i+b+j+c+k+d+'=7')
                p = False
                break
        else:
            continue
        break
    else:
        continue
    break
if p:
    print(u'バーカ')

Measured memory_bytes: 3060
/*
  || Shree Ganeshay Namah ||

     || Jai Shree Ram ||
  || Nabh Sparsham Diptam ||
*/
#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
#define mod 1000000000000000001
#define block 180
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f1 first
#define s1 second
int jai_shree_ram()
{
    return 1;
}
int shree_ganeshay_namah()
{
    return 1;
}
ll power(ll x,ll y)
{
    ll r=1;
    while(y>0)
    {
        if(y%2!=0)
            r=r*x;
        x=x*x;
        y=y/2;
    }
    return r;
}
ll ncr(ll n,ll k)
{

    ll c[k+1];
    memset(c,0,sizeof(c));
    c[0]=1;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=min(i,k);j>0;j--)
            c[j]=c[j]+c[j-1];
    }
    return c[k];
}

bool prime[500001];
void sieve()
{
    ll i,j;
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(i=2;i<=sqrt(100001);i++)
    {
        if(prime[i])
        {
            for(j=i*i;j<=100001;j=j+i)
                prime[j]=false;
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,i,j;
    cin>>n;
    ll a[n];
    map<ll,ll>c;
    set<ll>l;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        c[a[i]]++;
    }
    sort(a,a+n);
    if(n==1)
    {
        cout<<1;
        return 0;
    }
    ll f=0,s=0;
    map<ll,ll>m;

    ll x;

    for(i=0;i<n;i++)
    {
        if(c[a[i]]>1)
            {
                l.insert(a[i]);
                continue;
            }
        ll x=a[i];
        ll p=0;
        for(j=1;j<=sqrt(x);j++)
        {
            if(x%j==0)
            {
                if(l.find(j)!=l.end())
                {
                    p=1;
                    break;
                }
                ll z=x/j;
                if(x%z==0 &&l.find(z)!=l.end())
                {
                    p=1;
                    break;
                }
            }
            if(p==1)
                break;

        }
        if(!p)
            f++;
        l.insert(a[i]);
    }
    cout<<f;
    return 0;

}


Measured memory_bytes: 27020
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 


int main(){
    ios_base::sync_with_stdio(0); 
    cin.tie(0);
    LL n;
    cin >> n;
    if(n%1000 == 0){
        cout << 0 << endl;
    }else{
        cout << 1000 - n%1000 << endl;
    }

    cout.flush();
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,X,count=0;
  cin>>A>>B>>C>>X;
  for(int i=0;i<A+1;i++){
    for(int j=0;j<B+1;j++){
      for(int k=0;k<C+1;k++){
        if(i*500+j*100+k*50==X)
          count++;
      }
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 3616
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( iter = $ iter : ident , $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut $ iter = s . split_whitespace ( ) ; input_inner ! { $ iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , mut $ var : usize $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , $ var : usize $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , { chars : $ base : expr } ) => { read_value ! ( $ iter , String ) . chars ( ) . map ( | c | ( c as u8 - $ base as u8 ) as usize ) . collect ::< Vec < usize >> ( ) } ; ( $ iter : expr , { char : $ base : expr } ) => { read_value ! ( $ iter , { chars : $ base } ) [ 0 ] } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , char ) => { read_value ! ( $ iter , chars ) [ 0 ] } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
const INF: usize = 1_001_001_001;
use std::cmp::min;
fn main() {
    input! { n, a: [usize; n] };
    let c = (0..n).map(|i| (a[i] + 1) % 2).collect::<Vec<_>>();
    let b = (0..n)
        .map(|i| if a[i] == 0 { 2 } else { a[i] % 2 })
        .collect::<Vec<_>>();
    let mut dp = vec![vec![INF; 5]; n + 1];
    dp[0][0] = 0;
    let v = vec![&a, &b, &c, &b, &a];
    for i in 0..n {
        let ni = i + 1;
        for j in 0..4 {
            dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
        }
        for j in 0..5 {
            dp[ni][j] = min(dp[ni][j], dp[i][j] + v[j][i]);
        }
    }
    println!("{}", dp[n].iter().min().unwrap());
}


Measured memory_bytes: 28920
/*
 * src.cpp
 *
 *  Created on: 2016/07/27
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

typedef pair<int,char> P;

P p[5];

int main(){
	int a,b;
	do{
		cin>>a>>b;
		if (a || b){
			p[0]=P(a+b,'A');
			FOR(i,1,5){
				cin>>a>>b;
				p[i]=P(a+b,'A'+i);
			}
			sort(p,p+5);
			cout<<p[4].second<<" "<<p[4].first<<endl;
		}
	}while (a || b);
	return 0;
}

Measured memory_bytes: 1164
/**
*   Bismillahir Rahmanir Rahim.
*   Imtiaz_rafi
*   PCIU, CHITTAGONG
**/
#include<bits/stdc++.h>
using namespace std;
#define speed ios::sync_with_stdio(0);cin.tie(0);
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
#define rep(i,a) for(ll i=0;i<a;i++)
#define rep1(i,begin,end) for(ll i=begin;i<=end;i++)
#define all(v)   v.begin(),v.end()
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define pb push_back
#define pf push_front
#define mp make_pair
#define pi acos(-1)
// bitshift (1LL<<(3)) *2^3
typedef long long int ll;
typedef vector<ll>vi;
typedef map<ll,ll>m;
typedef map<char,ll>mc;
typedef set<ll>st;
typedef set<char>sc;
ll dx[] ={-1,+1,0,0,+1,-1,+1,-1};
ll dy[] ={0,0,-1,+1,+1,+1,-1,-1};
const ll mx = 1e5+123;
bool vis[mx];
vi adj[mx];
ll a,k,b[mx],dp[mx];
ll solve(ll i)
{
    if(i==a) return 0;
    if(dp[i]!=-1) return dp[i];
    ll x=INT_MAX;
    for(ll j=1;j<=k;j++)
    {
        if(i+j<=a)
            x=min(x,abs(b[i]-b[i+j])+solve(i+j));
    }
    return dp[i]=x;
}
int main()
{
    speed;
    cin>>a>>k;
    rep1(i,1,a)
        cin>>b[i];
    mem(dp,-1);
    cout<<solve(1)<<endl;
}



Measured memory_bytes: 13740
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

int main() {
	int n;
	cin >> n;
	vi a(1e5 + 5);
	rep(i, n) {
		int k;
		cin >> k;
		a[k]++;
	}
	int ret = a[0] + a[1];
	for (int i = 1; i < 1e5 + 1; i++) {
		int t = a[i - 1] + a[i] + a[i + 1];
		ret = max(ret, t);
	}
	cout << ret << endl;
}

Measured memory_bytes: 640
n = int(input())
p = list(map(int, input().split()))

c = 0
for i in range(1, n-1):
	if ((p[i-1]<p[i] and p[i]<p[i+1])
		or (p[i+1]<p[i] and p[i]<p[i-1])):
		c += 1
print(c)


Measured memory_bytes: 2940
a = [int(_) for _ in input().split()]
if len(a) == 3 and all(-100 <= item <= 100 for item in a):
    if a[0] == a[1]:
        print(a[2])
    elif a[0] == a[2]:
        print(a[1])
    elif a[1] == a[2]:
        print(a[0])
else:
    print('hoge!')

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			int m = in.nextInt();
			UnionFind uf = new UnionFind(n + m);

			for (int i = 0; i < n; i++) {
				int k = in.nextInt();
				for (int j = 0; j < k; j++) {
					int l = in.nextInt() - 1;
					uf.link(i,n + l);
				}
			}

			Set<Integer> set = new HashSet<>();
			for (int i = 0; i < n; i++) {
				set.add(uf.root(i));
			}

			out.println(set.size() > 1 ? "NO" : "YES");

		}
	}

	public static class UnionFind {
		int[] data;

		public UnionFind(int n) {
			data = new int[n];
			Arrays.fill(data, -1);
		}

		boolean link(int x, int y) {
			x = root(x);
			y = root(y);
			if (x != y) {
				if (data[y] < data[x]) {
					data[y] += data[x];
					data[x] = y;
				} else {
					data[x] += data[y];
					data[y] = x;
				}
			}
			return x != y;
		}

		int root(int x) {
			return data[x] < 0 ? x : (data[x] = root(data[x]));
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 43848
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc061_c
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = GetLongList();
            var N = NK[0];
            var K = NK[1];
            var abd = new SortedDictionary<long, long>();

            for(int i = 0; i < N; i++) 
            {
                var ab = GetIntList();
                if (!abd.ContainsKey(ab[0])) abd.Add(ab[0], 0);
                abd[ab[0]] += ab[1]; 
            }

            long kk = 0;
            foreach(var key in abd.Keys) 
            {
                kk += abd[key];
                if(K <= kk)
                {
                    Console.WriteLine(key);
                    break;
                }
            }
        }

        public static string GetStr() => Console.ReadLine();
        public static int GetInt() => int.Parse(Console.ReadLine());
        public static long GetLong() => long.Parse(Console.ReadLine());
        public static double GetDouble() => double.Parse(Console.ReadLine());
        public static decimal GetDecimal() => decimal.Parse(Console.ReadLine());

        public static List<string> GetStrList() => Console.ReadLine().Split(' ').ToList();
        public static List<int> GetIntList() => Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        public static List<long> GetLongList() => Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
        public static List<double> GetDoubleList() => Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToList();
        public static List<decimal> GetDecimalList() => Console.ReadLine().Split(' ').Select(x => decimal.Parse(x)).ToList();

    }
}


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

int main(){
  int m, f, r, i;
  for(i = 0; ;i++){
    scanf("%d %d %d", &m, &f, &r);
    if(m == -1 && f == -1 && r == -1) break;
    else if(m == -1 || f == -1) printf("F\n");
    else if(m + f >= 80) printf("A\n");
    else if(80 > m + f && m + f >= 65)printf("B\n");
    else if(65 > m + f && m + f >= 50)printf("C\n");
    else if(50 > m + f && m + f >= 30){
      if(r >= 50)printf("C\n");
      else printf("D\n");
    }
    else if(m + f < 30) printf("F\n");
  }
}


Measured memory_bytes: 3152
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;

const int MAX_N = 153;
const int MAX_M = MAX_N/2+2;
const int MAX_K = 11;
const int INF = 1<<29;

int N, M;
int K[MAX_N];
int X[MAX_N][MAX_K], D[MAX_N][MAX_K];
int T[MAX_N][MAX_K][MAX_M];

int calcCost(int si, int sj, int di, int dj) {
  if(D[si][sj] == -1 || D[di][dj] == -1) return 0;
  return (D[si][sj] + D[di][dj]) * abs(X[si][sj] - X[di][dj]);
}

int solve() {
  fill(T[0][0], T[MAX_N][0], INF);
  T[0][0][0] = 0;

  for(int i = 1; i < N; ++i) {
    for(int j = 0; j < K[i]; ++j) {
      for(int k = 0; k <= 1; ++k) {
	for(int m = 0; m <= M; ++m) {
	  int pi = i-1-k;
	  int pm = m-k;
	  if(pi < 0) continue;
	  if(pm < 0) continue;
	  for(int pj = 0; pj < K[pi]; ++pj) {
	    T[i][j][m] = min(T[i][j][m],
			     T[pi][pj][pm] + calcCost(pi,pj,i,j));
	  }
	}
      }
    }
  }

  int res = INF;
  for(int m = 0; m <= M; ++m) res = min(res, T[N-1][0][m]);
  return res;
}

int main() {
  while(cin >> N >> M && (N | M)) {
    N += 2;
    for(int i = 0; i < N; ++i) {
      if(i == 0 || i+1 == N) {
	K[i] = 1;
	X[i][0] = D[i][0] = -1;
      } else {
	cin >> K[i];
	for(int j = 0; j < K[i]; ++j) {
	  cin >> X[i][j] >> D[i][j];
	}
      }
    }
    cout << solve() << endl;
  }
  return 0;
}

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

long v[1<<20],n,e1=0;

int main(){
    cin>>n;
    for(int i=0;i < n;i++)
    {
        cin>>v[i];v[i]*=-1;
    }

    sort(v,v+n);

    for(int i=0;i < n-1;i++)
    {
        if(v[i]==v[i+1]){
            if(e1){
                cout<<e1*v[i];return 0;
            }else{
                e1=v[i];
                i++;
            }
        }
    }
    cout<<0<<endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
int n,m,q,a[100005],b[100005],ans=INF;
int main(void){
    cin>>n>>m>>q;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<m;i++)cin>>b[i];
    for(int i=0;i<q;i++){
        int x,y,c;
        cin>>x>>y>>c;
        ans=min(ans,a[x-1]+b[y-1]-c);
    }
    sort(a,a+n);
    sort(b,b+m);
    ans=min(ans,a[0]+b[0]);
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var N int
	fmt.Scanf("%d", &N)
	stones := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &stones[i])
	}
	fmt.Println(solve(N, stones))
}

func solve(N int, stones []int) int {
	dp := make([]int, N)
	dp[0] = 0
	dp[1] = abs(stones[1] - stones[0])
	for i := 2; i < N; i++ {
		// dp[i]: min_{j=1}^2(dp[i-j]+abs(arr[i]-arr[i-j]))
		dp[i] = min(dp[i-1]+abs(stones[i]-stones[i-1]), dp[i-2]+abs(stones[i]-stones[i-2]))
	}
	return dp[N-1]
}

func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 5504
H, W, K = map(int, input().split())
C = [[] for _ in range(H)]
for i in range(H):
    hoge = input()
    for j in range(W):
        C[i].append(hoge[j])
#print(C)
import copy
ans = 0
for i in range(2**H):
    for j in range(2**W):
        tmp = copy.deepcopy(C)
        for k in range(H):
            if i>>k&1:
                for m in range(W):
                    tmp[k][m] = "r"
        for l in range(W):
            if j>>l&1:
                for n in range(H):
                    tmp[n][l] = "r"
        cnt = 0
        for a in range(H):
            for b in range(W):
                if tmp[a][b] == "#":
                    cnt += 1
        #print(tmp)
        if cnt ==K:
            ans += 1

print(ans)


Measured memory_bytes: 71648
#include <cstdio>

using namespace std;

const int MAX_H = 101;
const int MAX_W = 101;
int H, W;
char blocks[MAX_H][MAX_W];

int init() {
	scanf("%d%d", &H, &W);

	if (H == 0 && W == 0) return -1;
	
	for (int i = 0; i < H; i++) {
		scanf("%s", blocks[i]);
	}
	
	return 0;
}

void fill(int row, int col) {
	char type = blocks[row][col];
	blocks[row][col] = ' ';
	
	int di[] = {1, -1, 0, 0};
	int dj[] = {0, 0, 1, -1};
	
	for (int k = 0; k < 4; k++) {
		int ti = row + di[k];
		int tj = col + dj[k];
		
		if (0 <= ti && ti < H && 0 <= tj && tj < W) {
			if (blocks[ti][tj] == type) {
				fill(ti, tj);
			}
		}
	}
}

void solve() {
	int ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (blocks[i][j] != ' ') {
				fill(i, j);
				ans++;
			}
		}
	}
	printf("%d\n", ans);
}

int main() {
	while (!init()) {
		solve();
	}
}

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

typedef long long int ll;
#define endl "\n"
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pair<int, int>>
#define mems(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define forn(i, s, e) for(int i = s; i < (e); ++i)
#define FASTIO                                                                                     \
	ios_base::sync_with_stdio(false);                                                              \
	cin.tie(NULL);
#define FILEIO                                                                                     \
	freopen("./input.txt", "r", stdin);                                                            \
	freopen("./output.txt", "w", stdout);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)                                                                                  \
	for(auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); blockTime.second;  \
		debug("%s : %lld ms\n ",                                                                   \
			  d,                                                                                   \
			  chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() -   \
														  blockTime.first)                         \
				  .count()),                                                                       \
			 blockTime.second = false)
const int M = 1e9 + 7;

template <class T>
T ABS(const T& x) {
	return x > 0 ? x : -x;
}
ll gcd(ll n1, ll n2) { return n2 == 0 ? ABS(n1) : gcd(n2, n1 % n2); }
ll lcm(ll n1, ll n2) { return n1 == 0 && n2 == 0 ? 0 : ABS(n1 * n2) / gcd(n1, n2); }
ll ceil2(ll a, ll b) { return (a + b - 1) / b; }

int main() {
	FASTIO
#ifdef LOCAL
	FILEIO
#endif
	int k;
	cin >> k;
	int val = 0;
	for(int i = 0; i < k; ++i) {
		val *= 10;
		val += 7;
		val %= k;
		if(val == 0) {
			cout << i + 1 << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(void){
	int a,b,c,n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a,&b,&c);
		if(c*c==a*a+b*b||a*a==b*b+c*c||b*b==a*a+c*c)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

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

class Dice {
 public:
  vector<int> numbers;
  explicit Dice(vector<int> nums) : numbers{nums} {};
  auto roll(int i, int j, int k, int l) {
    auto tmp = numbers.at(i);
    numbers.at(i) = numbers.at(j);
    numbers.at(j) = numbers.at(k);
    numbers.at(k) = numbers.at(l);
    numbers.at(l) = tmp;
  };

  auto roll_S() { roll(0, 4, 5, 1); };
  auto roll_E() { roll(0, 3, 5, 2); };
  auto roll_C() { roll(1, 3, 4, 2); };  // clock wise
};

bool is_equiv(Dice d1, vector<int> d2) {
  int cnt = 0;
  for (size_t i = 0; i < 6; i++) {
    for (size_t j = 0; j < 4; j++) {
      if (d1.numbers == d2) return true;
      d1.roll_C();
    }

    if (cnt % 2 == 0) {
      d1.roll_S();
    } else {
      d1.roll_E();
    }

    cnt += 1;
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  vector<vector<int>> dices(n, vector<int>(6));

  for (size_t i = 0; i < n; i++) {
    for (size_t j = 0; j < 6; j++) {
      cin >> dices.at(i).at(j);
    }
  }

  for (size_t i = 0; i < n - 1; i++) {
    auto d1 = dices.at(i);
    Dice dice{d1};
    for (size_t j = i + 1; j < n; j++) {
      auto d2 = dices.at(j);

      if (is_equiv(dice, d2)) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}



Measured memory_bytes: 3160
X,Y,Z,K = map(int,input().split())

Q = []
topK = []
dic = {}

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort()
B.sort()
C.sort()

Q.append([X-1,Y-1,Z-1])
dic[(X-1,Y-1,Z-1)] = 1

while len(Q) > 0:

    now = Q.pop(0)

    if len(topK) < K:
        
        #if ( now[0] , now[1] , now[2]) not in dic:
        #dic[ ( now[0] , now[1] , now[2]) ] = 1
        topK.append( A[now[0]] + B[now[1]] + C[now[2]] )
        topK.sort()
            
        if now[0] != 0 and (now[0]-1 , now[1] , now[2]) not in dic:
            Q.append([ now[0]-1 , now[1] , now[2] ])
            dic[( now[0]-1 , now[1] , now[2] )] = 1
        if now[1] != 0 and (now[0] , now[1]-1 , now[2]) not in dic:
            Q.append([ now[0] , now[1]-1 , now[2] ])
            dic[( now[0] , now[1]-1 , now[2] )] = 1
        if now[2] != 0 and (now[0] , now[1] , now[2]-1) not in dic:
            Q.append([ now[0] , now[1] , now[2]-1 ])
            dic[( now[0] , now[1] , now[2]-1 )] = 1


    elif topK[0] < A[now[0]] + B[now[1]] + C[now[2]]:

        #if ( now[0] , now[1] , now[2] ) not in dic:

        #dic[ (now[0] , now[1] , now[2])] = 1
            #topK.append( A[now[0]] + B[now[1]] + C[now[2]] )
        del topK[0]
        topK.append(A[now[0]] + B[now[1]] + C[now[2]])
        topK.sort()

        if now[0] != 0 and (now[0]-1 , now[1] , now[2]) not in dic:
            Q.append([ now[0]-1 , now[1] , now[2] ])
            dic[( now[0]-1 , now[1] , now[2] )] = 1
        if now[1] != 0 and (now[0] , now[1]-1 , now[2]) not in dic:
            Q.append([ now[0] , now[1]-1 , now[2] ])
            dic[( now[0] , now[1]-1 , now[2] )] = 1
        if now[2] != 0 and (now[0] , now[1] , now[2]-1) not in dic:
            Q.append([ now[0] , now[1] , now[2]-1 ])
            dic[( now[0] , now[1] , now[2]-1 )] = 1
     

topK.sort()
#print (dic)

for i in range(K):

    print (topK[-1-i])


Measured memory_bytes: 50924
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const ll MOD = 998244353;
//}}}

int main(){
  string s;
  int N;
  cin >> s;
  cin >> N;
  for(int i = 0; i < s.size(); i += N){
    cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#define lli long long int
#define mp make_pair
#define pb push_back
using namespace std;

const lli mod = 1e9 + 7;

lli power(lli x, lli y) {
    x %= mod;
    if (y == 0) return 1;
    return ((y % 2 == 1 ? x : 1) * power(x * x, y / 2)) % mod;
    // return ((y % 2 == 1 ? x : 1) * power(x * x, y / 2));
}

vector <long long int> primeNumbers;

void SieveOfEratosthenes(int n){
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++){ 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for (int p=2; p<=n; p++){
      if (prime[p]){
        primeNumbers.push_back(p);
      }
    }        
}

#define MAXN 100005
vector < vector < int> > v(MAXN);
int d[MAXN];
int vis[MAXN];
long long int dp[MAXN][2];
//dp[i][0] is for black
//dp[i][1] is for white

void dfs(int vertex){
  vis[vertex] = 1;
  for(int i = 0;i<v[vertex].size();i++){
    int node = v[vertex][i];
    if(vis[node] == 1);
    else{
      // temp = false;
      vis[node] = 1;
      dfs(node);
      vis[node] = 0;
    }
  }
      // dp[vertex][0] += dp[node][1];
      // dp[vertex][0] %= mod;
      // dp[vertex][1] += dp[node][0] + dp[node][1];
      // dp[vertex][1] %= mod;

  for(int i = 0;i<v[vertex].size();i++){
    int node = v[vertex][i];
    if(vis[node] == 1);
    else{
      vis[node] = 1;
      dp[vertex][0] *= dp[node][1];
      dp[vertex][0] %= mod;
      dp[vertex][1] *= (dp[node][0] + dp[node][1])%mod;
      dp[vertex][1] %= mod;
    }
  }

}

void pre(){
}

void solve(){
  int n;
  cin>>n;
  for(int i = 0;i<n-1;i++){
    int x,y;
    cin>>x>>y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for(int i = 0;i<=n;i++){
    dp[i][0] = 1;
    dp[i][1] = 1;
  }

  int root = 1;
  dfs(root);
  int ans = dp[root][0]%mod + dp[root][1]%mod;
  ans %= mod;
  

  // for(int i = 1;i<=n;i++){
  //   cout<<dp[i][0]<<' '<<dp[i][1]<<endl;
  // }



  cout<<ans;



















}
 
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
 
  int t;
  // cin>>t;
  // scanf("%d",&t);
  t = 1;
  pre();
  while(t--){
    // cout<<
    solve();
 
    if(t>0){
      cout<<endl;
      // printf("\n");
    } 
  }
 
 
  cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
 
  return 0;
}


Measured memory_bytes: 16180
N=int(input())
T,A=map(int,input().split())
H=list(map(int,input().split()))
X=1000
for n in range(N):
    if abs((T-H[n]*0.006)-A)<X:
        X=abs((T-H[n]*0.006)-A)
        num=n
print(num+1)

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

using namespace std;

const int N = 1e5 + 5;

int a[N];

int main() {
  int n, m, v, p;
  scanf("%d %d %d %d", &n, &m, &v, &p);
  for (int i = 0; i < n; ++i)
    scanf("%d", a+i);
  sort(a, a+n);
  long long sum = 0;
  long long need = 1LL * v * m;
  int ans = p;
  for (int i = 0, j = 0; i < n-p; ++i) {
    long long up = a[i] + m;
    while (j <= n-p && a[j] <= up) {
      sum += a[j];
      ++j;
    }
    if (j > n-p) {
      long long tot = 1LL * m * i + 1LL * (p-1) * m + 1LL * (n - (p-1) - i) * up - sum;
      if (tot >= need) {
        ++ans;
      }
    }
    sum -= a[i];
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


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

    if(C>=A && C<=B) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys

N = int(input())
obs = []
lowerbound = 1
for i in range(N):
    x, y, h = map(int, input().split())
    obs.append((x, y, h))
    lowerbound = max(lowerbound, h)


def find_height(cx, cy):
    upperbound = 10 ** 12
    summit = None
    for x, y, h in obs:
        s = h + abs(cx - x) + abs(cy - y)
        if s < lowerbound:
            return None
        if h == 0:
            upperbound = min(upperbound, s)
        elif summit is None:
            summit = s
        elif summit != s:
            return None
        if summit is not None and (summit > upperbound or summit < lowerbound):
            return None
    return summit


for cx in range(0, 101):
    for cy in range(0, 101):
        ch = find_height(cx, cy)
        if ch is not None:
            print(cx, cy, ch)
            sys.exit()


Measured memory_bytes: 42588
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#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 repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

int d[1000];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b; cin >> a >> b;
	cout << max({ a + b,a - b,a*b }) << endl;
	return 0;
}

Measured memory_bytes: 384
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

/* 
 * First 0.
 * new play c=min(left,right)
 * 2: f(0)
 * 3: min(f(0), f(1))
 * 4: ...
 * Greedy, send them in biggest first
 * and always choose best possible position.
 * Maintain list of all adj-pairs in circle
 * to find best.
 */
void solve() {
    cini(n);
    cinai(a,n);

    sort(all(a), greater<int>());

    if(n==2) {
        cout<<a[0]<<endl;
        return;
    }

    multiset<pair<int,pii>> p;

    p.insert({-a[1], { a[0], a[1] }});
    p.insert({-a[2], { a[1], a[2] }});
    p.insert({-a[2], { a[2], a[0] }});
    
    int ans=a[0];
    ans+=a[1];

    for(int i=3; i<n; i++) {
        auto it=p.begin();
        ans-=it->first;
        int l=it->second.first;
        int r=it->second.second;
        p.erase(it);
        p.insert({-min(l,a[i]), {l,a[i]}});
        p.insert({-min(a[i],r), {a[i],r}});
    }
    cout<<ans<<endl;
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


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

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    if((b-1)%(a-1)==0) {
    cout<<(b-1)/(a-1)<<endl;;
    }
    else{
    cout<<(b-1)/(a-1) +1<<endl;;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



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

  cout<<"ABC"<<N<<"\n";

  return 0;
}


Measured memory_bytes: 256
// agrawal117
//chahatagrawal117 
#include<bits/stdc++.h>
#define mod 1000000007
#define endl '\n'
typedef  long long int ll ; 
using namespace std;
#define MAX 1002
int main()
{
    int arr[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2,  5, 4, 1, 4, 1, 51};
    ll k; cin>>k;
    cout<<arr[k-1]<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }


        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var Ai = Slist();

            var ans = 1;
            for (var i = 1; i < N;)
            {
                var divu = false;
                var s = i;
                for (; s < N; ++s)
                {
                    if (!(Ai[s - 1] <= Ai[s]))
                    {
                        divu = true;
                        break;
                    }
                }
                var divd = false;
                var t = i;
                for (; t < N; ++t)
                {
                    if (!(Ai[t] <= Ai[t - 1]))
                    {
                        divd = true;
                        break;
                    }
                }
                i = Max(s, t) + 1;
                if (divu && divd)
                    ++ans;
            }
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 22112