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

struct Kruskal {
  Kruskal () {}
  Kruskal (int n) { init(n); }

  struct UnionFind {
    vector<int> p, r;

    UnionFind() {}
    UnionFind(int size) { init(size); }

    void init(int size) {
      p.resize(size);
      r.resize(size);
      for (int i = 0; i < size; ++i) {
        p[i] = i; r[i] = 1;
      }
    }

    int root(int x) {
      if (p[x] == x) return x;
      else return p[x] = root(p[x]);
    }

    void unite(int x, int y) {
      x = root(x); y = root(y);

      if (x == y) return;

      if (r[x] > r[y]) swap(x, y);
      r[x] += r[y];
      p[y] = x;
    }

    bool same(int x, int y) {
      return root(x) == root(y);
    }
  };

  struct edges {
    edges () {}
    edges (int u, int v, long long cost) : u(u), v(v), cost(cost) {}
    bool operator<(const edges &e) const{
      return cost < e.cost;
    }

    int u, v;
    long long cost;
  };

  struct edge {
    edge () {}
    edge (int to, long long cost) : to(to), cost(cost) {}

    int to;
    long long cost;
  };

  vector<edges> E;
  vector<vector<edge>> G;

  void init(int n) {
    G.resize(n + 1);
  }

  void add(int u, int v, long long cost) {
    E.push_back(edges(u, v, cost));
  }

  void make_graph(edges e) {
    G[e.u].push_back(edge(e.v, e.cost));
    G[e.v].push_back(edge(e.u, e.cost));
  }

  long long kruskal(int n) {
    long long res = 0;
    UnionFind uf(n + 1);

    sort(E.begin(), E.end());
    for (auto &e : E) {
      if (!uf.same(e.u, e.v)) {
        res += e.cost;
        uf.unite(e.u, e.v);
        make_graph(e);
      }
    }

    return res;
  }

  long long kruskal() {
    return kruskal(G.size());
  }
};

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

  Kruskal g(n);
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;

    g.add(a, b, c);
  }

  cout << g.kruskal() << endl;
}

Measured memory_bytes: 5128
#include <bits/stdc++.h>
#include <math.h>
#include <sstream>
#include <deque>
#include <string>
#include <map>
#include <cctype>
#include <cstring>
#include <cstdio>
const int M = 1e9 + 7;
#define start \
    int t;    \
    cin >> t; \
    while (t--)
#define ll long long int
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define pb(x) push_back(x)
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
using namespace std;


// 1<<16 = 2^16

//insta  -------  __ansh7
//MSDIAN



int main()
{

 ll n;
 cin>>n;

 vector<ll>c;

 ll x=0;

 while(n--)
 {
     ll a,b;
     cin>>a>>b;

     if(a==b)
     {
         x++;
     }
     else
     {
         x=0;
     }

     c.pb(x);
 }

 if(*max_element(c.begin(),c.end())>=3)
 {
     cout<<"Yes";
 }
 else
 {
     cout<<"No";
 }
 





  


    return 0;
}

//sk mc

Measured memory_bytes: 3632
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.Int (Int64)
import Data.List (unfoldr)
import qualified Data.ByteString.Char8 as BS
import qualified Test.QuickCheck as QC

naive :: Integer -> Integer -> Integer -> Integer
naive x k d = minimum $ map abs $ iterate (>>= oneStep) (pure x) !! fromInteger k
  where
    oneStep :: Integer -> [Integer]
    oneStep y = [y + d, y - d]

solve :: Int64 -> Int64 -> Int64 -> Int64
solve x k d = let x' = abs x
                  (q,r) = x' `quotRem` d
              in if q <= k then
                   if even q == even k then
                     r
                   else
                     d - r
                 else
                   x' - k * d

main = do
  [x,k,d] <- map fromInteger . unfoldr (BS.readInteger . BS.dropWhile isSpace) <$> BS.getLine
  print $ solve x k d

prop :: Int64 -> QC.Positive (QC.Small Int64) -> QC.Positive Int64 -> Bool
prop x (QC.Positive (QC.Small k)) (QC.Positive d) = fromIntegral (solve x k d) == naive (fromIntegral x) (fromIntegral k) (fromIntegral d)

runTest :: IO ()
runTest = QC.quickCheck $ QC.forAll (QC.choose (1,15)) $ \k -> \x d -> prop x (QC.Positive (QC.Small k)) d


Measured memory_bytes: 3772
#include<iostream>
#include<vector>

using namespace std;

typedef long long ll;

int main(){
  int N; cin >> N;
  vector<int> x(N); vector<int>y(N); vector<long long> h(N);
  
  for(int i = 0 ; i < N; i++){ cin >> x[i] >> y[i] >> h[i];}
  
  for(int cx = 0; cx <= 100; cx++){
    for(int cy = 0; cy <= 100; cy++){
      ll hight = -1;
      for(int i = 0; i < N; i++){
    
        if( h[i] > 0){
          ll tmp = h[i] + abs( cx - x[i]) + abs( cy - y[i]);
          if( hight == -1){ hight = tmp;}
          else if(hight != tmp){ hight = -2; break;}}}
        
        if( hight == -2){ continue;}
      
      for(int j = 0; j < N; j++){
        if( h[j] == 0){
          ll tmp = abs( cx - x[j]) + abs(cy - y[j]);
          if( hight > tmp){ hight = -2; break;}}}
      
        if( hight == -2 ){ continue;}
      
        cout << cx << " " << cy << " " << hight << endl; return 0;
      }}
    
    return 0;}
                            

Measured memory_bytes: 256
def ccw(p1, p2, p3)
  return (p2[0] - p1[0])*(p3[1] - p1[1]) - (p2[1] - p1[1])*(p3[0] - p1[0])
end

n = gets.to_i

pt = []
n.times{|i|
  pt[i] = gets.split.map(&:to_f)
}

pt.sort! {|a, b| a[0] == b[0] ? a[1] <=> b[1] : a[0] <=> b[0]}

uh = [pt[0],pt[1]]
lh = [pt[-1],pt[-2]]

2.upto(pt.size-1){|i|
  n = uh.size - 1
  while n >= 1 && ccw(uh[n-1], uh[n], pt[i]) > 0
    uh.pop
    n -= 1
  end
  uh.push(pt[i])
}

(pt.size-3).downto(0){|i|
  n = lh.size - 1
  while n >= 1 && ccw(lh[n-1], lh[n], pt[i]) > 0
    lh.pop
    n -= 1
  end
  lh.push(pt[i])
}

hull = (lh + uh).uniq.reverse

nh = hull.size

start = 0
spt = [hull[0][0], hull[0][1]]
nh.times{|i|
  if hull[i][1] == spt[1] ? hull[i][0] < spt[0] : hull[i][1] < spt[1]
    spt = [hull[i][0], hull[i][1]]
    start = i
  end
}

puts nh
nh.times{|i|
  j = (i+start) % nh
  puts "%d %d" % hull[j]
}

Measured memory_bytes: 22368
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include <string.h>
using namespace std;
int a[100005];
int dp[100];

int main() {
	int n, a, b;
	vector<tuple<int, int>> vb;
	vector<tuple<int, int>> vr;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		vr.push_back(make_tuple(a, b));
	}
	sort(vr.begin(), vr.end());
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		vb.push_back(make_tuple(a, b));
	}
	sort(vb.begin(), vb.end());
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		int ty = -300;
		int tj = -1;
		for (int j = 0; j < n; j++) {
			if (get<0>(vb[i]) > get<0>(vr[j])) {
				if ((get<1>(vr[j]) < get<1>(vb[i])) && (ty < get<1>(vr[j])) && dp[j] == 0) {
					ty = get<1>(vr[j]);
					tj = j;
				}
			}
		}
		if (tj != -1) {
			dp[tj] = 1;
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

using namespace std;

const int N = 5050;
const long long inf = 1e18;

long long dp[N][N];
int p[N];

void upd(long long &a, long long b) {
  if (a > b)
    a = b;
}

int main() {
  int n, a, b;
  scanf("%d %d %d", &n, &a, &b);
  for (int i = 0; i < n; ++i) {
    scanf("%d", p+i);
  }
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= n; ++j)
      dp[i][j] = inf;
  dp[0][0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= n; ++j) {
      if (dp[i][j] >= inf) continue;
      upd(dp[i+1][j], dp[i][j] + (j > p[i] ? b : a));
      if (j < p[i])
        upd(dp[i+1][p[i]], dp[i][j]);
    }
  }
  long long ans = inf;
  for (int j = 0; j <= n; ++j)
    upd(ans, dp[n][j]);
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 198912
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
struct p {
    int day;
    int value;
};

int main(void){
    int N, M;
    vector<p> ab;
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        p pab;
        cin >> pab.day >> pab.value;
        ab.push_back(pab);
    }
    sort(ab.begin(), ab.end(), [](const p& x, const p& y) { return x.day < y.day;});
    
    priority_queue<int> que;
    long long int ans = 0;
    for (int i = 1; i <= M; i++) {
        if (ab.size() != 0)
            while(ab[0].day <= i) {
                que.push(ab[0].value);
                ab.erase(ab.begin());
                if (ab.size() == 0)
                    break;
            }
        
        if (!que.empty()) {
            ans += que.top();
            que.pop();
        }
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 1908
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	char c;
	cin>>c;
	cout<<++c;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N,X; cin>>N; 
    vector<ll> A(N);
    vector<ll> ans(N);
    ll sum=0;
    ll itido=0;
    rep(i,N) cin>>A[i],sum+=A[i],itido+=(i+1);
    if(sum%itido!=0){cout<< "NO"<<"\n"; return;}
    X=sum/itido;
    rep(i,N){
        ll sa=A[(i+1)%N]-A[i];
        if((X-sa)%N!=0 or X-sa<0){cout<< "NO"<<"\n"; return;}
        ans[i]=(X-sa)/N;
    }
    ll sum2=0;
    rep(i,N) sum2+=ans[i];
    if(sum2!=X) {cout<< "NO"<<"\n"; return;}
    cout<< "YES" <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 1792
N=int(input())

XY = [list(map(int,input().split())) for _ in range(N)]

x=[]
y=[]

for X,Y in XY:
    x.append(X)
    y.append(Y)
    
l1=[]
c=0
for i in range(N):
    for j in range(N):
        if i==j:
            continue;
        a=x[i]-x[j]
        b=y[i]-y[j]
        """
        if a<=0 and b>=0:
            a=-a
            b=-b
        elif a<=0 and b<=0:
            a=-a
            b=-b
        """
        l1.append(str(a)+"_"+str(b))
        #l1.append([a,b])
v=set(l1)
c=[]
for i in v:
    c.append(l1.count(i))
#c = collections.Counter(l1)      
#values, counts = zip(*c.most_common()) 
if c==[]:
    print(1)   
else:
    print(N-max(c))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

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

    int n;
    cin>>n;
    int k;
    cin>>k;

    rep(i, 1<<n) {
        int temp = i;
        vector<int> res;
        rep(j, n) {
            if (temp & 1) res.push_back(j);
            temp = temp >> 1;
        }
        if (res.size() != k) continue;
        cout<<i<<":"<<(i != 0 ? ' ' : '\n');
        rep(j, res.size()) cout<<res[j]<<(j != res.size() - 1 ? ' ' : '\n');
    }
}


Measured memory_bytes: 3240
program equal_cut
  implicit none
  integer :: n, i, j, k, l
  integer(8) :: a(0:200000), m, t
  a = 0_8
  read(*,*) n
  read(*,*) a(1:n)
  do i = 1, n
    a(i) = a(i) + a(i-1)
  end do
  m = 9000000000000000000_8
  t = 9000000000000000000_8
  i = 1
  do l = 3, n-1
    t = abs(a(2)+a(n)-2*a(l))
    if (m.ge.t) then
      m = t
      k = l
    end if
  end do
  m = 9000000000000000000_8
  t = 9000000000000000000_8
  do j = 2, n-2
    t = max(a(i)-a(0),a(j)-a(i),a(k)-a(j),a(n)-a(k)) &
    & - min(a(i)-a(0),a(j)-a(i),a(k)-a(j),a(n)-a(k))
    if (m.gt.t) m = t
    do while (abs(a(j+1)+a(0)-2*a(i+1)).le.abs(a(j+1)+a(0)-2*a(i)))
      i = i+1
      if (i.eq.j) exit
    end do
    if (k.lt.n-1) then
      do while (abs(a(j+1)+a(n)-2*a(k+1)).le.abs(a(j+1)+a(n)-2*a(k)))
        k = k+1
        if (k.eq.n-1) exit
      end do
    end if
  end do
  write(*,'(i0)') m
  stop
end program equal_cut

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

main()
{
    char s[3];
    scanf("%s",s);
    bool flag=0;
    if(s[0]==s[1] && s[1]==s[2])flag=1;
    if(s[1]==s[2] && s[2]==s[3])flag=1;
    puts(flag ? "Yes" : "No");
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pii> vpi;
typedef vector<vector<pii> > vvpi;

const int maxn = 2e5;
const ll mod = 998244353LL;
const ll inf = 1e9;

int main() {
	int i, j, a, b;
	cin >> a >> b;
	cout << max(a*b, max(a+b, a-b)) << "\n";

	return 0;
}

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

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

void dfs(vector<vector<char>>& v, int y, int x, bool w, bool b) {
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (v[ny][nx] == 'W') w = true;
        if (v[ny][nx] == 'B') b = true;
        if (!w & !b)
            v[y][x] = '0';
        else if (w & !b)
            v[y][x] = '1';
        else if (!w & b)
            v[y][x] = '2';
        else if (w & b)
            v[y][x] = '3';
    }
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (v[ny][nx] == '.') {
            dfs(v, ny, nx, w, b);
        }
    }
}

int solve(vector<vector<char>>& v, int y, int x, int& c) {
    c++;
    int m   = v[y][x] - '0';
    v[y][x] = '.';
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (v[ny][nx] == '0' || v[ny][nx] == '1' ||
            v[ny][nx] == '2' || v[ny][nx] == '3') {
            m = max(solve(v, ny, nx, c), m);
        }
    }
    return m;
}

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

    while (1) {
        int w, h;
        cin >> w >> h;
        if (!w & !h) break;
        vector<vector<char>> field;
        field.push_back(vector<char>(w + 2, '#'));
        for (int i = 0; i < h; i++) {
            vector<char> res;
            string tmp;
            cin >> tmp;
            res.push_back('#');
            for (int j = 0; j < w; j++) {
                res.push_back(tmp[j]);
            }
            res.push_back('#');
            field.push_back(res);
        }
        field.push_back(vector<char>(w + 2, '#'));
        int wCount = 0, bCount = 0, tmp;
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                if (field[i][j] == '.') {
                    dfs(field, i, j, false, false);
                }
            }
        }
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                if (field[i][j] == '0' || field[i][j] == '1' ||
                    field[i][j] == '2' || field[i][j] == '3') {
                    int c = 0;
                    int m = solve(field, i, j, c);
                    if (m == 2) bCount += c;
                    if (m == 1) wCount += c;
                }
            }
        }
        cout << bCount << " " << wCount << endl;
    }
}


Measured memory_bytes: 3364
#include <bits/stdc++.h>
using namespace std;
typedef long long lnt;
const lnt INF = 0x3f3f3f3f3f3f3f3fLL;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n, a[16][16]; lnt f[1<<16];
int main() {
	read(n);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) read(a[i][j]);
	for (int x = 0; x < (1<<n); x++)
		for (int i = 0; i < n; i++)
			for (int j = i+1; j < n; j++)
				if ((x>>i&1) && (x>>j&1)) f[x] += a[i][j];
	for (int i = 0; i < (1<<n); i++)
		for (int j = i; j; j = (j-1)&i)
			f[i] = max(f[i], f[j]+f[i^j]);
	return printf("%lld\n", f[(1<<n)-1]), 0;
}


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

int main()
{
    int N, X;
    cin >> N >> X;
    int p = 0;
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (p <= X)
            ans ++;
        else
            break;
        int L;
        cin >> L;
        p += L;
    }
    if (p <= X)
        ans ++;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int i,h,m,s;
    cin>>i;
    h=i/3600;
    m=(i-(i/3600*3600))/60;
    s=i-h*3600-m*60;
   cout <<h <<":"<<m<<":"<<s<< endl; 
   
   return 0;
}


Measured memory_bytes: 3096
import java.util.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
import java.util.Collections;


public class Main{
   
   

    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        String S=sc.next();
        int max=0;
        for(int i=1;i<N;i++){
            HashSet<Character>a=new HashSet<>();
            HashSet<Character>b=new HashSet<>();
            for(int j=0;j<i;j++){
                a.add(S.charAt(j));
            }
            for(int j=i;j<N;j++){
                b.add(S.charAt(j));
            }
            int x=0;
            List<Character>aa=new ArrayList<>(a);
            List<Character>bb=new ArrayList<>(b);
            for(int j=0;j<aa.size();j++){
                for(int k=0;k<bb.size();k++){
                    if(aa.get(j)==bb.get(k)){
                        x++;
                    }
                }
            }
            if(x>max){
                max=x;
            }
        }
        System.out.println(max);
        
        

    }

        
        
    }


Measured memory_bytes: 22868
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 1010
ll po(ll x,ll y){
    ll res=1;
    for(;y;y>>=1){
	if(y&1)res=res*x%mod;
	x=x*x%mod;
    }
    return res;
}
ll inv(ll x){
    return po(x,mod-2);
}
ll fac[N],ivf[N];
ll C(ll n,ll k){
    return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
ll dp[N],cop[N];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    fac[0]=1;
    for(ll i=1;i<N;i++)fac[i]=fac[i-1]*i%mod;
    rep(i,N)ivf[i]=inv(fac[i]);
    ll n,k;
    cin>>n>>k;
    rep(i,n+1)dp[i]=0; dp[0]=1;
    rep(u,k){
	ll a; cin>>a;
	rep(i,n+1)cop[i]=dp[i],dp[i]=0;
	rep(i,n+1)for(int j=0;j+i<=n&&j<=a;j++){
	    mad(dp[i+j],cop[i]*C(n-i,j)%mod*C(n-j,a-j));
	}
    }
    cout<<dp[n]<<endl;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
using lint=long long;
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n,m;cin>>n>>m;
  vector<int> a(m);
  vector<int> c(m,0);
  rep(i,m){
      int b;cin>>a[i]>>b;
      rep(j,b){
          int buf;cin>>buf;
          --buf;
          c[i]+=(1<<buf);
      }
  }
  vector<vector<lint>> dp(m,vector<lint>((1<<n),inf));
  dp[0][0]=0;
  dp[0][c[0]]=a[0];
  rep1(i,m-1){
      for(int j=0;j<(1<<n);++j){
          dp[i][j]=min(dp[i][j],dp[i-1][j]);
          dp[i][j|c[i]]=min(dp[i-1][j]+a[i],dp[i][j|c[i]]);
      }
  }
  int res=dp[m-1][(1<<n)-1];
  if(res==inf)res=-1;
  cout<<res<<"\n";
  return 0;
}

Measured memory_bytes: 35404
//Name: List of Top 3 Hills
//Level: 1
//Category: ????????????
//Note:

using System;

class AOJ {
    static void Main(string[] args)
    {
        int[] n = new int[10];

        for (int i = 0; i < 10; i++)
            n[i] = int.Parse(Console.ReadLine());

        Array.Sort(n);

        for (int i = 0; i < 3; i++)
            Console.WriteLine(n[9-i]);
    }
}

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


int main(){
    ll n;
    cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    ll ans = 0;
    REP(i, n){
        char ai = a.at(i), bi = b.at(i), ci = c.at(i);
        if(ai != bi && bi != ci && ai != ci){
            ans += 2;
        }else if((ai != bi && bi == ci) || (ai == bi && bi != ci) || (ai == ci && ai != bi)){
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define ll long long
int a[3], ans = 0;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	for(int i=0;i<3;i++){
		cin>>a[i];
	}
	sort(a, a+3);
	for(int i=0;i<2;i++){
		ans += a[i];
	}
	cout<<ans;

	return 0;
}

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

using namespace std;

#define MAX 1000001
using ull = unsigned long long;

const ull b = 1000000007ULL;

vector<ull> rolling_hash(char* S, int N, vector<ull>& p)
{
    vector<ull> h(N + 1);
    for (int i = 0; i < N; i++) {
        h[i + 1] = h[i] * b + S[i];
        p[i + 1] = p[i] * b;
    }
    return h;
}

int main()
{
    char S[MAX];
    scanf("%s", S);
    
    int N = strlen(S);
    vector<ull> p(N + 1);
    p[0] = 1;
    
    auto h = rolling_hash(S, N, p);    
    
    int mini = MAX;
    for (int i = 0; i < N; i++) {
        int A = i + 1;
        int B = (N - 3 * A) / 2;

        if (B <= 0) break;
        if ((N - 3 * A) % 2 != 0) continue;

        auto A1 = h[A] - h[0] * p[A];
        auto B1 = h[A + B] - h[A] * p[B];
        auto A2 = h[A * 2 + B] - h[A + B] * p[A];
        auto B2 = h[2 * (A + B)] - h[A * 2 + B] * p[B];
        auto A3 = h[N] - h[2 * (A + B)] * p[A];

        if (A1 == A2 && A2 == A3 && B1 == B2) {
            mini = min(mini, A + B);
        }
    }    
    
    if (mini == MAX) {
        printf("mitomerarenaiWA\n");
    } else {
        printf("Love ");
        for (int i = 0; i < mini; i++) {
            printf("%c", S[i]);
        }
        printf("!\n");
    }        
    return 0;
}

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

int main()
{
int i;
char S[ 5 ];

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> S;

	i = count( &S[ 0 ], &S[ 3 ], 'o' );

	cout << 700 + i * 100 << endl;

	return 0;
}


Measured memory_bytes: 256
//start of jonathanirvings' template v3.0.3 (BETA)

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

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int n,m,k;

int main()
{
  scanf("%d %d %d",&n,&m,&k);
  FORN(i,0,n) FORN(j,0,m)
  {
    int ada = i * m + j * n - 2 * i * j;
    if (ada == k) 
    {
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}










Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000)

def ins(): return input().split()
def ii(): return int(input())
def iil(): return list(map(int, ins()))
def lin(): return list(input())
def iin(): return map(int, ins())

import copy
n = ii()
dic = {1: ['a']}
dic.update({i+2:[] for i in range(9)})
def getnext(dic):
    tmp = {i+1:[] for i in range(10)}
    for i, v in dic.items():
        for j in v:
            for k in range(i+1):
                if i == k:
                    tmp[i+1].append(j+chr(k+0x61))
                else:
                    tmp[i].append(j+chr(k+0x61))
    return tmp
for i in range(n-1):
    dic = getnext(dic)
tmp = []
for i in range(10):
    tmp += dic[i+1]
tmp.sort()
for i in tmp:
    print(i)

Measured memory_bytes: 14496
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main() {
  ll n,l,t,x;
  ll x0,w0;
  int w;
  ll count=0;
  ll sw;
  vector<pair<ll,int>> ans;
  vector<pair<ll,int>> ri;
  vector<pair<ll,int>> le;
  vector<pair<ll,int>> all;
  cin>>n>>l>>t;
  vector<ll> nans(n,0);
  for(int i=0;i<n;i++){
    cin>>x>>w;
    if(i==0){
      x0=x;
      w0=w;
    }
    if(w==1) le.emplace_back(pair(x,i));
    else ri.emplace_back(pair(x,i)); 
    all.emplace_back(pair(x,i));
  }
  sort(all.begin(),all.end());
  for(int i=0;i<n;i++){
    if(w0==1){
      if((int)ri.size()<=i)break;
      count+=(2*t/l+(((l+ri[i].first-x0)%l)<(2*t%l)));

    }else{
      if((int)le.size()<=i)break;
      count+=(2*t/l+(((l-le[i].first+x0)%l)<=(2*t%l)));
    }
  }
  if(w0==1){
    sw=count%n;
  }else{
    sw=(n-count%n)%n;
  }

  for(pair<ll,int> x:le){
    ans.emplace_back(pair((x.first+t)%l,x.second));
  }
  for(pair<ll,int> x:ri){
    ans.emplace_back(pair((l-(l-x.first+t)%l)%l,x.second));    
  }


  sort(ans.begin(),ans.end());
  int key1,key2;
  for(int i=0;i<n;i++){
    if(ans[i].second==0)key1=i;  
  }
  for(int i=0;i<n;i++){
    if(all[i].second==0)key2=i;  
  }
  for(int i=0;i<n;i++){
    nans[all[(key2+i+sw)%n].second]=ans[(i+key1)%n].first;
  }
  
  for(int i=0;i<n;i++){
    cout<<nans[i]<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 10812
n, k = io.read('n'), io.read('n')
x, y = {}, {}
for i = 1, n do x[i], y[i] = io.read('n'), io.read('n') end

-- Discretize
rx, ry = {}, {}
for i = 1, n do rx[i], ry[i] = {x[i], i}, {y[i], i} end
pair_cmp = function (lhs, rhs) return lhs[1] < rhs[1] end
table.sort(rx, pair_cmp)
table.sort(ry, pair_cmp)
for i = 1, n do x[rx[i][2]], y[ry[i][2]] = i, i end
for i = 1, n do rx[i], ry[i] = rx[i][1], ry[i][1] end

-- O(n^4)
-- Prefix sum
p = {}
for i = 0, n do
    p[i] = {}
    for j = 0, n do p[i][j] = 0 end
end
for i = 1, n do p[x[i]][y[i]] = 1 end
for i = 1, n do
    for j = 1, n do
        p[i][j] = p[i][j] + p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1]
    end
end

-- Iteration
ans = 1 << 62
for l = 1, n do
    for r = l + 1, n do
        for d = 1, n do
            for u = d + 1, n do
                if p[r][u] - p[l - 1][u] - p[r][d - 1] + p[l - 1][d - 1] >= k then
                    ans = math.min(ans, (rx[r] - rx[l]) * (ry[u] - ry[d]))
                end
            end
        end
    end
end

print(ans)


Measured memory_bytes: 760
#include <iostream>

 int main() {

	 char x;
	 char y;

	 std::cin >> x >> y;



	 if (x == y) {
		 std::cout << "=" << std::endl;
	 }
	 else if (x < y) {
		 std::cout << "<" << std::endl;
	 }
	 else if (x > y) {
		 std::cout << ">" << std::endl;
	 }

	 return 0;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int cnt,m,g[100];
void insertionsort(int a[],int n,int g){
  for(int i=g;i<n;++i){
    int v=a[i],j=i-g;
    while(j>=0&&a[j]>v){
      a[j+g]=a[j];
      j=j-g;
      ++cnt;
    }
    a[j+g]=v;
  }
}
void shellsort(int a[],int n){
  int h=1;
  g[0]=1;
  while(4*h<n){
    g[++m]=4*h+1;
    h=4*h+1;
  }
  for(int i=m;i>=0;--i) insertionsort(a,n,g[i]);
}
int main(){
  int a[1000000],n;
  cin>>n;
  for(int i=0;i<n;++i) cin>>a[i];
  shellsort(a,n);
  cout<<m+1<<endl;
  for(int i=m;i>=0;--i){
    cout<<g[i];
    if(i) cout<<" ";
  }
  cout<<endl<<cnt<<endl;
  for(int i=0;i<n;++i) cout<<a[i]<<endl;
  return 0;
}



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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

vector<bool> prime_numbers()
{
    vector<bool>primeNum(100005, true);
    primeNum.at(0) = false; primeNum.at(1) = false;
 
    int N = 100001;
    REP(x, 2, floor(sqrt(N)))
    {
        if (primeNum.at(x) == false) continue;
     
        for(int y = x; y < N; y += x)
        {
            if (y == x)
            {
                primeNum.at(y) = true;
            }
            else 
            {
                primeNum.at(y) = false;
            }
        }
    }
    return primeNum;
}

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

    vector<int> l(Q);
    vector<int> r(Q);
    rep(i,Q) cin >> l[i] >> r[i];
    vector<bool> isPrime = prime_numbers();

    vector<ll> dp(1, 0);
    rep(i, isPrime.size())
    {
        if( isPrime[i] && isPrime[(i+1)/2] ) dp.push_back(dp[dp.size()-1]+1);
        else dp.push_back(dp[dp.size()-1]);
    }
    rep(i, Q)
    {
        cout << dp[r[i]+1] - dp[l[i]] << endl;
    }
}


Measured memory_bytes: 2424
x, y, z, k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse = True)
b = sorted(list(map(int, input().split())), reverse = True)
c = sorted(list(map(int, input().split())), reverse = True)
d = []
e = []
for m in range(x):
    for n in range(y):
        d.append(a[m]+b[n])
d.sort(reverse = True)
for m in range(z):
    for n in range(min(3000, len(d))):
        e.append(c[m]+d[n])
e.sort(reverse = True)
for n in range(k):
    print(e[n])

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#define INF numeric_limits<int>::infinity()
#pragma endregion


int main()
{
    int n;
    while(true) {
        cin >> n;
        if (n==0) return 0;
        vi v(2,0);
        rep(i,n) {
            int a, b;
            cin >> a >> b;
            if (a>b) {
                v[0] += a + b;
            } else if (a<b) {
                v[1] += a + b;
            } else {
                v[0] += a;
                v[1] += b;
            }
        }
        printf("%d %d\n", v[0], v[1]);
    }
    return 0;
}

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

namespace ABC084A
{
    class Program
    {
        static void Main(string[] args)
        {
            int M,s;
            M = int.Parse(Console.ReadLine());
            s = 0;
            s += 48 - M;
            Console.Write(s);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
// Problem : C - Connect Cities
// Contest : AtCoder - ACL Beginner Contest
// URL : https://atcoder.jp/contests/abl/tasks/abl_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vint vector<int>
#define sint set<int>
#define mint map<int,int>
#define pint pair< int,int >
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define precision(x) cout<<fixed<<setprecision(x);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define present(container, element) (container.find(element)!=container.end())
#define fint fast;test
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }
int n,m;
vector<vint>adj;
vector<int>vis;
void dfs(int node)
{
	vis[node]=true;
	for(auto child:adj[node]){
		if(!vis[child])
			dfs(child);
	}
}
void solve(){
	rd(n,m);
	adj.resize(n+1,vint());
	vis.resize(n+1);
	FOR(i,m)
	{
		int u,v;
		rd(u,v);
		adj[u].pb(v);
		adj[v].pb(u);
	}
	int ans=0;
	rep(i,1,n+1)
	{
		if(!vis[i]){
			ans++;
			dfs(i);
		}
	}
	pp(ans-1);
	return;	
}


int32_t main() {
    // fint{
    	fast;
    	solve();
    // }
    return 0;
}


Measured memory_bytes: 10604
L, R = map(int, input().split())
mod = 2019

minimum = 2019
for i in range(L, R):
    mod_i = i % mod
    for j in range(i+1, R+1):
        mod_j = j % mod
        result = (mod_i * mod_j) % mod
        if result < minimum:
            minimum = result
        if minimum == 0:
            print(0)
            exit(0)
print(minimum)


Measured memory_bytes: 39024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
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; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

vector<int> g[100000];

int depth[100000];
int dist[100000];
int parent[100000];

int dfs(int cur, int pre, int dep) {
  int res = 0;
  depth[cur] = dep;
  FOR(it, g[cur]) {
    if (*it == pre) continue;
    parent[*it] = cur;
    int dis = dfs(*it, cur, dep + 1);
    chmax(res, dis + 1);
  }
  dist[cur] = res;
  return res;
}

int main() {
  int n,u,v;
  while(cin>>n>>u>>v) {
    REP(i,n) g[i].clear();
    u--;v--;
    REP(i,n-1) {
      int a, b;
      input(a,b);
      a--;b--;
      g[a].push_back(b);
      g[b].push_back(a);
    }
    dfs(v, -1, 0);
    int pa = (depth[u] + 1) / 2 - 1;

    // output(depth,n);
    // output(dist,n);
    // cout << pa << endl;

    if (pa == 0 && dist[u] == 0 && depth[u] >= 2) {
      cout << 1 << endl;
      continue;
    }
    int ans = pa;
    int cur = u;
    while(pa--) {
      cur = parent[cur];
    }
    ans += dist[cur];

    if (depth[u] % 2 == 0) ans++;
    cout << ans << endl;
  }
}


Measured memory_bytes: 13312
x = int(input())

def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1
    
while True:
    ans = is_prime(x)
    if ans == True:
        print(x)
        exit()
    else:
        x += 1

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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int aliceTensu, bobTensu;
  for (int i = 0; i < vec.size(); i++) {
    if (i % 2 == 0) aliceTensu += vec.at(i);
    else bobTensu += vec.at(i);
  }
  
  cout << aliceTensu - bobTensu << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int date;
	int max;
	int i;
	int num[101] = {0};
	
	while (scanf("%d", &date) != EOF){
		num[date] += 1;
	}
	
	max = 0;
	for (i = 1; i < 101; i++){
		if (max <= num[i]){
			max = num[i];
		}
	}
		
	for (i = 1; i < 101; i++){
		if (num[i] == max){
			printf("%d\n", i);
		}
	}
	
	return (0);
}
	

Measured memory_bytes: 596
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000000
#define MAX 200001
#define MOD 1000000007
ll fac[MAX], finv[MAX], inv[MAX];
const int MX = 1000005;
const double PI = acos(-1);

Graph d(200, vector<int>(200, 1000000000));

void warshall_floyd(int n){
    for(int k = 0; k < n; k++){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}
int main(){
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r(R);
    for(int i = 0; i < R; i++){
        cin >> r[i];
        r[i]--;
    }
    for(int i = 0; i < M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--;b--;
        d[a][b] = min(c, d[a][b]);
        d[b][a] = min(c, d[a][b]);
    }
    warshall_floyd(N);
    vector<int> v;
    int ans = 1000000000;
    for(int i = 0; i < R; i++) v.push_back(i);
    do{
        int res = 0;
        for(int i = 1; i < R; i++){
            res += d[r[v[i-1]]][r[v[i]]];
        }
        ans = min(ans, res);
    }while(next_permutation(v.begin(), v.end()));
    cout << ans << endl;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int a[maxn];
set<int> st;
int main()
{
	//IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>a[i];
	REP(i,n) st.insert(a[i]);
	sort(a,a+n);
	int up=a[n-1];
	REP(i,n) a[i]=min(a[i],up-a[i]);
	sort(a,a+n);
	if(st.count(a[n-1])) cout<<up<<" "<<a[n-1]<<'\n';
	else cout<<up<<' '<<up-a[n-1];
	return 0;
}


Measured memory_bytes: 5376
import sys, random, math
from bisect import bisect_left, bisect_right
input = sys.stdin.readline

def main():
    inf = 10 ** 20

#    t = int(input())
#    t, a, b = map(int, input().split())
    t = 1
    
    for _ in range(1, t+1):
    #    print("Case #{}: ".format(_), end = '')
        
        h1, m1, h2, m2, k = map(int, input().split())
        m1 += h1*60
        m2 += h2*60
        print(m2-m1-k)
        
        
main()

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

int main () {
    int a, b; cin >> a >> b;

    int t;
    if (a < b){
        t = a;
        a = b;
        b = t;
    }

    if (a - b <= (16 - (2 * b)) / 2)
        cout << "Yay!";
    else 
        cout << ":(";
}

Measured memory_bytes: 3572
#include<stdio.h>
int main(void){
	int a,b,t,c,f;
	char s;
	for(;;){
	scanf("%d %c %d",&a,&s,&b);
	if(s=='+'){
		t=a+b;
	}
	
	if(s=='-'){
		t=a-b;
	}
	
	
	if(s=='/'){
		t=a/b;
	}
	
	
	if(s=='*'){
		t=a*b;
	}
		if(s=='?'){
		break;
		}
		printf("%d\n",t);
	}

		
}

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

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

    int a[n];
    multiset<int>s;

    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        auto j=s.lower_bound(-a[i]+1);
        if(j==s.end())
        {
            s.insert(-a[i]);
        }
        else
        {
            s.erase(j);
            s.insert(-a[i]);
        }
    }

    cout<<s.size();
}

Measured memory_bytes: 5760
import os, sys, re, math

n,k = [int(s) for s in input().split(' ')]

ret = 0
for i in range(n):
    if i+1 >= k:
        ret += 1
    else:
        a = math.ceil(math.log(k/(i+1), 2))
        ret += (0.5) ** a

print(ret / n)


Measured memory_bytes: 39280
n = gets.to_i
d = gets.split.map(&:to_i).sort
m = gets.to_i
t = gets.split.map(&:to_i).sort
ans = true
j = 0
m.times do |i|
    j += 1 while j < n && t[i] > d[j]
    if j < n && t[i] == d[j]
        j += 1
    else
        ans = false
        break
    end
end
puts (ans ? "YES" : "NO")

Measured memory_bytes: 33480