akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& a) {
  os << "{";
  for (size_t i = 0; i < a.size(); ++i) os << (i > 0 ? "," : "") << a[i];
  return os << "}";
}

constexpr ll MOD = 1000000007;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

struct UnionFind {
  vector<int> par, weight;
  UnionFind(int n) : par(n, -1), weight(n) {}
  void unite(int x, int y, int w = 0) {
    w += get_weight(x);
    w -= get_weight(y);
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (par[x] > par[y]) swap(x, y), w = -w;
    par[x] += par[y];
    par[y] = x;
    weight[y] = w;
    return;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int find(int x) {
    if (par[x] < 0) return x;
    int r = find(par[x]);
    weight[x] += get_weight(par[x]);
    return par[x] = r;
  }
  int sizeOf(int x) { return -par[find(x)]; }
  int get_weight(int x) {
    find(x);
    return weight[x];
  }
  int diff(int x, int y) { return get_weight(y) - get_weight(x); }
};
int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    uf.unite(a, b);
  }

  int ans = 0;
  rep(i, 0, n) { ans = max(ans, uf.sizeOf(i)); }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4852
local n=io.read("n")
local sum=0
local map={[0]=1}
for i=1,n do
    sum=sum+io.read("n")
    map[sum]=(map[sum] or 0)+1
end

local counter=0
for k,v in pairs(map) do
    counter=counter+v*(v-1)//2
end
print(counter)

Measured memory_bytes: 14708
#include <iostream>

using namespace std;

int f(int n) {
    int ret = 0;

    while (n > 0) {
        ret += n % 10;
        n /= 10;
    }

    return ret;
}

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

    cout << (n%f(n)?"No":"Yes") << endl;
}


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

int main() {

//  freopen("input", "r", stdin);
  int n;
  cin>>n;
  int s=-1,ans=0,last;
  for(int i=0;i<n;i++)
  {
    int t;
    cin>>t;
    if(s==-1){s=0;}
    else if(s==0){
      if(t>last)s=1;
      else if(t<last)s=2;

    }
    else if(s==1){
       if(t<last){
        ans++;
        s=0;
      }
    }
    else {
      if(t>last){
        ans++;
        s=0;
      }

    }
    last=t;
  }
  cout<<ans+1<<endl;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
typedef long long ll;

const int INF = 1e9;
const long long LLINF = 1e18;

int n, m;
bool edge[8][8];
int dfs(int cur, bool visited[]){
    bool flag=true;
    REP(i, 0, n){
        if(visited[i]==false){
            flag=false;
            break;
        }
    }
    if(flag) return 1;

    int cnt=0;
    REP(i, 0, n){
        if(edge[cur][i]==false) continue;
        if(visited[i]==true) continue;

        visited[i]=true;
        cnt+=dfs(i, visited);
        visited[i]=false;
    }
    return cnt;
}
int main() {
    cin>>n>>m;
    REP(i, 0, m){
        int a, b;
        cin>>a>>b;
        edge[a-1][b-1]=true;
        edge[b-1][a-1]=true;
    }

    bool visited[8];
    REP(i, 0, 8) visited[i]=false;

    visited[0]=true;
    cout<<dfs(0, visited)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{
	reus;
	int a,p,sum=0;
	cin>>a>>p;
	sum=a*3+p;
	cout<<sum/2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define bg begin()
#define en end()
#define vvl(n,m) vector<vector<ll> > a( n , vector<ll> (m))
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll gcd(ll a,ll b){
    if(a==0)
    return b;
    else
    return gcd(b%a,a);
}
ll maxSubArraySum(ll a[], ll size) 
{ 
    ll max_so_far = -1000000000000000, max_ending_here = 0; 
  
    for (ll i = 0; i < size; i++) 
    { 
        max_ending_here = max_ending_here + a[i]; 
        if (max_so_far < max_ending_here) 
            max_so_far = max_ending_here; 
  
        if (max_ending_here < 0) 
            max_ending_here = 0; 
    } 
    return max_so_far; 
} 
ll countPairs(ll arr[], ll n) 
{ 
    map<ll, ll> map; 
    for (ll i = 0; i < n; i++) {
        if (map.find(arr[i]-i) == map.end()) { 
            map[arr[i]-i] = 1; 
        } 
        else { 
            map[arr[i]-i]++; 
        } 
    }
    ll res = 0; 
    for (auto x : map) { 
        ll cnt = x.second; 

        res += ((cnt * (cnt - 1)) / 2); 
    } 
  
    return res; 
} 
ll findSubarraySum(ll arr[], ll n, ll sum) 
{ 
    unordered_map<ll, ll> prevSum; 
  
    int res = 0; 
  
    int currsum = 0; 
  
    for (int i = 0; i < n; i++) { 
        currsum += arr[i]; 
        if (currsum == sum)  
            res++;         
  
        if (prevSum.find(currsum - sum) !=  
                                  prevSum.end())  
            res += (prevSum[currsum - sum]);
        prevSum[currsum]++; 
    } 
  
    return res; 
} 
ll sod(ll x){
    ll r,sum=0;
    while(x>0){
        r=x%10;
        x/=10;
        sum+=r;
    }
    return sum;
}
long long modpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main()
{
    fast
    string s,t;
    ll c=0,max=0;
    cin>>s>>t;
    ll r=t.size(),i,j;
    ll a=s.size();
    for(i=0;i<a-r+1;i++){
        c=0;
        for(j=i;j<i+r;j++){
            if(t[j-i]==s[j]){
                c++;
            }
        }
        if(c>max)
        max=c;
    }
    cout<<(r-max);
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
        ifstream in("input.txt");
        ofstream out("output.txt");
        #define cin in
        #define cout out
#endif
int main(){
	int n, k;
	cin>>n>>k;
	vector<int> v(n);
	for(int i=0;i<n;i++)
		cin>>v[i];
	vector<int> dp(n+1,1e9);
	dp[0]=0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<i+1+k;j++)
			if(j<n)
				dp[j]=min(dp[j],dp[i]+abs(v[i]-v[j]));
	cout<<dp[n-1];
} 

Measured memory_bytes: 1024
S = input()
len_S = 4 # 4 = len(input())

for i in range(1 << (len_S-1)):
  tmp = int(S[0])
  ans = S[0]
  for j in range(len_S-1):    
    if (i>>j)&1:
      tmp += int(S[j+1])
      ans += "+"
    else:
      tmp -= int(S[j+1])
      ans += "-"
    ans += S[j+1]
  if tmp == 7:
    ans += "=7"
    print(ans)
    exit()

Measured memory_bytes: 3064
i = 0
first   = 1
second  = 1
third  = 1
while i < 10
  mt = gets.to_i
  if mt >third
    if mt >second
      if mt >first
        third = second
        second = first
        first = mt
      else
        third = second
        second = mt
      end
    else
      third = mt
    end
  end
  i = i + 1
end
puts first
puts second
puts third





Measured memory_bytes: 6856
n, c, k = map(int, input().split())
T = [int(input()) for _ in range(n)]
T.sort()
cnt = 0
ans = 1
t = T[0]
for i in range(n):
    cnt += 1
    if cnt > c or T[i] > t + k:
        ans += 1
        cnt = 1
        t = T[i]
print(ans)

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

def abc155a(s):
    b = False
    if( s[0] == s[1] ):
        if(s[2] != s[0]):
            b = True
    if( s[1] == s[2] ):
        if(s[0] != s[1]):
            b = True
    if( s[2] == s[0] ):
        if(s[1] != s[2]):
            b = True
    return(b)

###
# main
if(__name__ == '__main__'):
    # input
    s = input().split(" ")

    b = abc155a(s)

    # output
    if( True == b ):
        print("Yes")
    else:
        print("No")
# else:
    # do nothing


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define shalaby ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);cerr.tie(0);

using namespace std;

inline int D()
{
    int t;
    scanf("%d",&t);
    return t;
}
inline ll llD()
{
    ll t;
    scanf("%lld",&t);
    return t;
}

const ll OO=-1e18;
int xt[4]= {1,0,0,-1};
int yt[4]= {0,1,-1,0};
////////////////////////////////////////////////////////////////////////////////////

const int N = 1e6+1;



ll mem[1005][1005],n,m,mod=1e9+7;
bool valid(int x,int y)
{
    return x>-1 && y>-1 && x<n && y<m;
}
void init()
{
    memset(mem,-1,sizeof mem);
}
char grid[1009][1009];
ll solve(int i=0,int j=0)
{
  ///  cout<<i<<" "<<j<<endl;
    if(!valid(i,j)|| grid[i][j]=='#')
        return 0;
    if(i==n-1 && j==m-1 && grid[i][j]=='.')
    {
    return 1;
    }
    ll &ret=mem[i][j];
    if(~ret)return ret%mod;

   ret=((solve(i+1,j)%mod)+(solve(i,j+1)%mod))%mod;
   return ret%mod;
}
int main()
{
int T=1;
///T=D();

while(T-->0)
{
    init();
cin>>n>>m;
for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
    cin>>grid[i][j];
cout<<solve();

}

}


Measured memory_bytes: 12452
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,c;
    cin>>n;
    while(n--)
    {
        cin>>a>>b>>c;
        if((a*a)==(b*b)+(c*c) || (b*b)==(a*a)+(c*c) || (c*c)==(b*b)+(a*a))
        {
            cout<<"YES\n";
        }
        else
            cout<<"NO\n";
    }
    return 0;
}



Measured memory_bytes: 2988
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)
#define trav(x, v) for (auto &x : v)

#define sz(x) int((x).size())
#define eb(x...) emplace_back(x)

using ll = int64_t;
using ld = long double;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

constexpr ll inf = 2e18;
constexpr int M = 1e9 + 7;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n; cin >> n;
	ld p[n]; rep(i, 0, n) cin >> p[i];
	ld dp[n + 1];
	rep(i, 0, n + 1) rep(x, 0, n + 1) dp[x] = 0;
	dp[0] = 1;
	rep(i, 0, n) {
		per(x, 0, n)
			dp[x + 1] = p[i] * dp[x] + (1 - p[i]) * dp[x + 1];
		dp[0] = (1 - p[i]) * dp[0];
	}
	ld ans = 0;
	rep(x, n / 2, n) ans += dp[x + 1];
	cout << fixed << setprecision(10) << ans;
}

Measured memory_bytes: 384
object Main extends App {

  import scala.io.StdIn._
  import scala.math._
  solve
  def solve: Unit = {
    val Array(m, nMin, nMax) = readLine.trim.split(' ').map(_.toInt)
    if (m == 0) return
    val points = Array.tabulate(m) { _ ⇒ readLine.trim.toInt }.sorted.reverse
    val gaps = (nMin to nMax).reverse.maxBy { i ⇒ points(i - 1) - points(i) }
    println(
      gaps
    )
    solve
  }
}


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

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;
}
struct Unionfind {
    vector<int> par;

    Unionfind(int n) : par(n) {
        for(int i = 0; i < n; ++i) par[i] = i;
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] =ry;
    }

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

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

    int n;
    cin >> n;

    const int num = 1000000;
    vector<int> cnt(num+1, 0);
    vector<int> a(n);

    int a_1_cnt = -1;
    rep(i, n) {
        cin >> a[i];
        if(a[i] == 1) ++a_1_cnt;
        if(a_1_cnt >= 2) {
            cout << 0 << endl;
            return 0;
        }
        for(int j = a[i]; j <= num; j += a[i]) ++cnt[j];
    }

    int ans = 0;
    rep(i, n) {
        if(cnt[a[i]] == 1) ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7936
from collections import deque
H, W = map(int, input().split())
cy, cx = map(int, input().split())
dy, dx = map(int, input().split())
cy -= 1
cx -= 1
dy -= 1
dx -= 1

S = [input() for _ in range(H)]

worps = [[float('inf')]*W for _ in range(H)]
used = [[False]*W for _ in range(H)]
q = deque([[cy, cx]])

worp = 0
while q:
    v = {}
    while q:
        y, x = q.popleft()
        used[y][x] = True
        worps[y][x] = min(worps[y][x], worp)

        for h in range(-2+y, 3+y):
            for w in range(-2+x, 3+x):
                if 0 <= h and h < H and 0 <= w and w < W and S[h][w] == ".":
                    v[(h, w)] = True

        for h, w in [[0, 1], [0, -1], [1, 0], [-1, 0]]:
            ny, nx = y+h, x+w
            if 0 <= ny and ny < H and 0 <= nx and nx < W:
                if not used[ny][nx] and S[ny][nx] == ".":
                    q.appendleft([ny, nx])

    worp += 1
    for h, w in v.keys():
        if not used[h][w]:
            q.appendleft([h, w])
            used[h][w] = True

ans = worps[dy][dx]
if ans != float('inf'):
    print(ans)
else:
    print(-1)


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

int main() {
    string w;
    cin >> w;
    int alp[26];
    for (int i = 0; i < 26; i++) {
        alp[i] = 0;
    }

    for (int i = 0; i < w.size(); i++) {
        alp[(int)(w[i] - 'a')]++;
    }

    for (int i = 0; i < 26; i++) {
        if (alp[i] & 1) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  int length;
    
  cin >>length;

  vector<int> q;

  int opr, val;
  for(int i=0; i<length; i++){
    cin >> opr; 

    switch(opr){
      case 0:
        cin >> val;
        q.push_back(val);
        break;

      case 1:
        cin >> val;
        cout << q[val] << endl;
        break;

      case 2:
        q.pop_back();
        break;
    }

  }
  

}



Measured memory_bytes: 3900
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.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;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

////////// Union-Find木 //////////

struct UnionFind{
  vector<int> par,siz;						//par[i]:iの親の番号
  UnionFind(int N):par(N),siz(N,1ll){		//最初は全てが根であるとして初期化
    for(int i=0; i<N; i++) par[i]=i;
  }
  
  int root(int x){						//データxが属する木の根
    if(par[x]==x) return x;
    return par[x]=root(par[x]);
  }
  
  void unite(int x,int y){				//xとyの木を併合
    int rx=root(x);
    int ry=root(y);
    if(rx==ry) return;
    if(siz[rx]<siz[ry]) swap(rx,ry);
    siz[rx]+=siz[ry];
    par[ry]=rx;
  }
  
  bool same(int x,int y){				//x,yが属する木が同じならtrueを返す
    int rx=root(x);
    int ry=root(y);
    return rx==ry;
  }
  
  int size(int x){
    return siz[root(x)];
  }
};

//////////////////////////////////////////////////

int main(){
  int N,M;
  cin>>N>>M;
  
  UnionFind U(N);
  REP(i,M){
    int A,B;
    cin>>A>>B;
    A--,B--;
    U.unite(A,B);
  }
  
  int ans=0;
  REP(i,N) chmax(ans,U.size(i));
  co(ans);
  return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

int H, W;
string s[100];
bool done[100][100];
bool adj1, adj2;

bool inside(int x, int y) {
    return 0 <= x && x < H && 0 <= y && y < W;
}

void dfs(int x, int y) {
    if (!inside(x, y)) return;
    if (done[x][y]) return;
    if (s[x][y] == 'W') {
        adj1 = true;
        return;
    }
    if (s[x][y] == 'B') {
        adj2 = true;
        return;
    }

    done[x][y] = true;
    dfs(x + 1, y);
    dfs(x - 1, y);
    dfs(x, y + 1);
    dfs(x, y - 1);
}

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

    while (cin >> W >> H, W) {
        int n1 = 0, n2 = 0;
        rep(i, H) cin >> s[i];

        rep(i, H) {
            rep(j, W) {
                if (s[i][j] == '.') {
                    adj1 = false, adj2 = false;
                    rep(k, H) rep(l, W) done[k][l] = false;
                    dfs(i, j);
                    if (adj1 && !adj2) n1++;
                    if (!adj1 && adj2) n2++;
                }
            }
        }

        cout << n2 << " " << n1 << endl;
    }
}

Measured memory_bytes: 3204
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] data = new int[n][2];
        for (int i=0;i<m;i++){
            int p = sc.nextInt()-1;
            String s = sc.next();
            if (data[p][0]==0&&s.equals("WA")){
                data[p][1]++;
            }else if (data[p][0]==0&&s.equals("AC")){
                data[p][0]++;
            }
        }
        int ac=0;
        int wa=0;
        for (int i=0;i<n;i++){
            ac+=data[i][0];
            if (data[i][0]==1)wa+=data[i][1];
        }
        System.out.println(ac+" "+wa);

    }
}


Measured memory_bytes: 63396
import sys
input = sys.stdin.readline

def main():
    n,m = map(int,input().split())
    p = list(map(int,input().split()))
    xy = [list(map(int,input().split())) for _ in range(m)]

    class UnionFind(object):
        def __init__(self, n=1):
            self.par = [i for i in range(n)]
            self.rank = [0 for _ in range(n)]
            self.size = [1 for _ in range(n)]

        def find(self, x):
            if self.par[x] == x:
                return x
            else:
                self.par[x] = self.find(self.par[x])
                return self.par[x]

        def union(self, x, y):
            x = self.find(x)
            y = self.find(y)
            if x != y:
                if self.rank[x] < self.rank[y]:
                    x, y = y, x
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1
                self.par[y] = x
                self.size[x] += self.size[y]

        def all_group_members(self):
            return_list = [list() for i in range(n)]
            for i in range(n):
              return_list[self.find(i)].append(i)
            return return_list

    uf = UnionFind(n)
    ans = 0
    for x,y in xy:
        uf.union(x-1,y-1)
    for v in uf.all_group_members():
        set1 = set()
        for i in v:
            set1.add(p[i]-1)
        ans += len(set(v)&set1)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 122456
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);
    
    int h, w, n;
    char[][] map;
    int[][] cheese;
    int x, y;
    int dis;
    
    void run(){
	while(sc.hasNext()){
	    h = sc.nextInt();
	    w = sc.nextInt();
	    n = sc.nextInt();
	    if(n==0) break;

	    map = new char[h][w];
	    cheese = new int[n][2];

	    for(int i=0; i<h; i++){
		String s = sc.next();
		for(int k=0; k<w; k++){
		    map[i][k] = s.charAt(k);
		    if(map[i][k]=='S'){
			x = k;
			y = i;
		    }
		    else if(map[i][k]!='X' && map[i][k]!='.'){
			int c = map[i][k] - 49;
			cheese[c][0] = k; // x
			cheese[c][1] = i; // y
		    }
		}
	    }

	    dis = 0;
	    for(int i=0; i<n; i++){
		//System.out.println("++"+i);
		dis += solve(x, y, i);
		x = cheese[i][0];
		y = cheese[i][1];
	    }
	    System.out.println(dis);
       
	}
    }

    int solve(int nx, int ny, int level){
	//System.out.println("*"+nx+" "+ny+" "+level);
	boolean[][] visit = new boolean[h][w];
	LinkedList<int[]> que = new LinkedList<int[]>();
      	que.add(new int[]{nx, ny, 0});
	
	while(que.size()>0){
	    int[] p = que.pollFirst();
	    nx = p[0];
	    ny = p[1];
	    int sum = p[2];

	    if(nx==cheese[level][0] && ny==cheese[level][1])
		return sum;

	    if(visit[ny][nx]) continue;
	    visit[ny][nx]=true;

	    for(int i=0; i<4; i++){
		int a = nx+dX[i];
		int b = ny+dY[i];
		if(a>=0 && a<w && b>=0 && b<h && 
		   map[b][a]!='X'){
		    que.add(new int[]{ a, b, sum+1 });		
		}
	    }
	}
	return -1; // 使わない   
    }
    
    int[] dX = {0, 1, -1, 0};
    int[] dY = {1, 0, 0, -1};
}

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

void dfs(int x, int y);
int h, w, ans = 0;

vector<vector<int>> maze;

int main() {
    cin >> h >> w;
    vector<vector<int>> field(h, vector<int>(w, 0));
    rep(i, h) {
        string str;
        cin >> str;
        rep(j, w) {
            if(str.at(j) == '#') field.at(i).at(j) = -1;
        }
    }
    maze = field;
    rep(i, h) rep(j, w) {
        if(maze.at(i).at(j) == -1) continue;
        dfs(i, j);
    }
    cout << ans << endl;
}

void dfs(int x, int y) {
    vector<vector<int>> dis(h, vector<int>(w, -2));
    dis.at(x).at(y) = 0;
    queue<pair<int, int>> que;
    que.push(make_pair(x, y));
    while(que.size()) {
        pair<int, int> p = que.front();
        que.pop();
        if(0 <= p.first - 1 && p.first - 1 <= h - 1 && 0 <= p.second && p.second <= w - 1 && maze.at(p.first - 1).at(p.second) != -1 && dis.at(p.first - 1).at(p.second) == -2) {
            que.push(make_pair(p.first - 1, p.second));
            dis.at(p.first - 1).at(p.second) = dis.at(p.first).at(p.second) + 1;
        }
        if(0 <= p.first + 1 && p.first + 1 <= h - 1 && 0 <= p.second && p.second <= w - 1 && maze.at(p.first + 1).at(p.second) != -1 && dis.at(p.first + 1).at(p.second) == -2) {
            que.push(make_pair(p.first + 1, p.second));
            dis.at(p.first + 1).at(p.second) = dis.at(p.first).at(p.second) + 1;
        }
        if(0 <= p.first && p.first <= h - 1 && 0 <= p.second - 1 && p.second - 1 <= w - 1 && maze.at(p.first).at(p.second - 1) != -1 && dis.at(p.first).at(p.second - 1) == -2) {
            que.push(make_pair(p.first, p.second - 1));
            dis.at(p.first).at(p.second - 1) = dis.at(p.first).at(p.second) + 1;
        }
        if(0 <= p.first && p.first <= h - 1 && 0 <= p.second + 1 && p.second + 1 <= w - 1 && maze.at(p.first).at(p.second + 1) != -1 && dis.at(p.first).at(p.second + 1) == -2) {
            que.push(make_pair(p.first, p.second + 1));
            dis.at(p.first).at(p.second + 1) = dis.at(p.first).at(p.second) + 1;
        }
    }
    rep(i, h) rep(j, w) {
        ans = max(ans, dis.at(i).at(j));
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
# define ll int64_t
#define rep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back

using namespace std;

bool compare_by_b(pair<string,int> a,pair<string,int> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,int> a,pair<string,int> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

int main(){
    ll n,maxi=0;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    ll num=0;
    rep(k,n-1) {
        if(a[k]>=a[k+1]) num++;
        if(a[k]<a[k+1] || (k==n-2 && a[k]>=a[k+1])) {
            if(maxi<=num) maxi = num;
            num=0;
        }
    }
    cout<<maxi<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int N=3e5+10;
typedef pair<int,int> pii;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,ans[N],lim[N],rem[N];
pii a[N];
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) a[i].fi=lim[i]=gi(),a[i].se=i;
    sort(a+1,a+n+1);
    int p=1;
    for(int i=1;i<=n;i++) {
        ans[a[i].fi]=a[i].se;
        for(int j=1;j<=a[i].se-1;j++) {
            while(ans[p]) p++;
            ans[p]=a[i].se; p++;
        }
        if(p-1>a[i].fi) return puts("No"),0;
    }
    for(int i=1;i<=n;i++) rem[i]=n-i;
    for(int i=p;i<=n*n;i++) {
        if(ans[i]) continue;
        for(int j=1;j<=n;j++) if(rem[j]&&lim[j]<i) { ans[i]=j;rem[j]--;break; }
        if(!ans[i]) return puts("No"),0;
    }
    puts("Yes");
    for(int i=1;i<=n*n;i++) printf("%d ",ans[i]);
    return 0;
}
//orzgzy
//鸡贼明年进队超稳


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

int main(){
	int n;
	cin >> n;
	int h[n],highest[n];
	int count = 1;
	for(int i = 0;i < n;i++){
		cin >> h[i];
		if(i==0){
			highest[0] = h[0];
		}else{
			if(h[i] > highest[i-1]){
				highest[i] = h[i];
			}else{
				highest[i] = highest[i-1];
			}
		}
	}
	for(int i = 1;i < n;i++){
		if(h[i] >= highest[i-1]){
			count++;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;

pair<double, int> a[8], b[6], c[8];

int main()
{
    for (int j = 0; j < 3; j++) {
        for (int i = 0; i < 8; i++)
            cin >> a[i].second >> a[i].first;

        sort(a, a + 8);

        for (int i = 0; i < 2; i++) {
            c[j * 2 + i] = a[i]; 
            b[j * 2 + i] = a[i + 2];
        }
    }

    sort(b, b + 6);

    c[6] = b[0];
    c[7] = b[1];

    for (int i = 0; i < 8; i++)
        cout << c[i].second << " "
        << setiosflags(ios::fixed | ios::showpoint) << setprecision(2)
        << c[i].first << endl;

    return 0;
}



Measured memory_bytes: 3212
#include <stdio.h>

#define NMAX 100
#define NIL -1


int L[NMAX];
int R[NMAX];
int P[NMAX];

void preOrder(int i) {
    if (i == NIL) {
        return;
    }
    printf(" %d",i);
    preOrder(L[i]);
    preOrder(R[i]);
}

void inOrder(int i) {
    if (i == NIL) {
        return;
    }
    inOrder(L[i]);
    printf(" %d",i);
    inOrder(R[i]);
}

void postOrder(int i) {
    if (i== NIL) {
        return ;
    }
    postOrder(L[i]);
    postOrder(R[i]);
    printf(" %d",i);
}

int main() {
    int n,id,left,right;
    scanf("%d",&n);
    for(int i=0;i<n;i++) {
        L[i]=NIL;
        R[i]=NIL;
        P[i]=NIL;
    }
    for(int i=0;i<n;i++) {
        scanf("%d %d %d",&id,&left,&right);
        if(left!=NIL){
            L[id]=left;
            P[left]=id;
        }
        if(right!=NIL){
            R[id]=right;
            P[right]=id;
        }
    }
    int root =0;
    for(int i=0;i<n;i++) {
        if (P[i]==NIL){
            root=i;
            break;
        }
    }
    printf("Preorder\n");
    preOrder(root);
    printf("\n");
    printf("Inorder\n");
    inOrder(root);
    printf("\n");
    printf("Postorder\n");
    postOrder(root);
    printf("\n");

    return 0;
}



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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	string str;
	cin >> str;
	for (auto&& i : str) {
		switch (i)
		{
		case '1':
			i = '9';
			break;
		case '9':
			i = '1';
			break;
		}
	}
	cout << str << "\n";
}

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


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

using namespace std;

using i64 = int64_t;
const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


signed main(){
    i64 n;
    cin >> n;
    vector<i64> a(n);
    vector<pair<i64,i64>> v;
    multiset<i64> s;
    for(i64 i = 0; i < n; ++i){
        cin >> a[i];
        v.emplace_back(a[i], i);
    }
    s.emplace(-1);
    s.emplace(n);
    s.emplace(-1);
    s.emplace(n);
    i64 ans = 0;
    sort(v.begin(), v.end(), greater<pair<i64,i64>>());
    for(auto& p : v){
        i64 val, pos;
        tie(val, pos) = p;
        s.emplace(pos);
        auto it = s.find(pos);
        i64 l1 = *(--it);
        i64 l2 = *(--it);
        it = s.find(pos);
        i64 r1 = *(++it);
        i64 r2 = *(++it);

        i64 v1 = 1L * abs(l2 - l1) * abs(pos - r1);
        i64 v2 = 1L * abs(l1 - pos) * abs(r2 - r1);
        ans += val * (v1 + v2);
    }

    cout << ans << endl;
}


Measured memory_bytes: 7536
A = input().split()
 
if (int(A[0]) == int(A[1])) and (int(A[1]) == int(A[2])):
  print("No")
elif (int(A[0]) != int(A[1])) and (int(A[1]) != int(A[2])) and(int(A[0]) != int(A[2])):
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FactorsOfFactorial solver = new FactorsOfFactorial();
        solver.solve(1, in, out);
        out.close();
    }

    static class FactorsOfFactorial {
        final long mod = (long) 1e9 + 7L;

        public void solve(int testNumber, FastReader fs, PrintWriter pw) {
            int n = fs.nextInt();
            long[] factors = new long[n + 1];
            for (int i = 2; i <= n; i++) {
                factorize(i, factors);
            }

            long ans = 1L;
            for (int i = 2; i < factors.length; i++) {
                if (factors[i] != 0) {
                    ans = ans * (factors[i] + 1) % mod;
                }
            }

            pw.println(ans);
        }

        private void factorize(int n, long[] factors) {
            for (int i = 2; i <= n; i++) {
                if (n % i == 0) {
                    while (n % i == 0) {
                        factors[i]++;
                        n /= i;
                    }
                }
            }
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
            st = null;
        }

        public FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }

        public FastReader(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
}



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

vector<vector<int> > g(100005);
vector<int> dist(100005);
vector<int> visit(100005);
vector<int> in_degree(100005);

void dfs(int a){
    visit[a] = 1;
    for(int b : g[a]){
        dist[b] = max(dist[b], dist[a]+1);
        --in_degree[b];
        if(in_degree[b] == 0){
            dfs(b);
        }
    }
}

int main(){
    int n,m;
    cin>>n>>m;
    for(int  i=1; i<=m; i++){
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        ++in_degree[y];
    }

    for(int i=1; i<=n; i++){
        if(!visit[i] && in_degree[i] == 0){
            dfs(i);
        }
    }

    int  maxi = 0;
    for(int i=1; i<=n; i++){
        maxi = max(maxi, dist[i]);
    }

    cout<<maxi<<endl;

}


Measured memory_bytes: 9984
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

class Program{
  public static void Main(){

    var input = Console.ReadLine().Split();
    int n = int.Parse(input[0]);
    int k = int.Parse(input[1]);
    var input2 = Console.ReadLine().Split();
    var l = new int[n];
    for(int i=0;i<n;i++){
      l[i] = int.Parse(input2[i]);
    }
    Array.Sort(l);
    int ans = 0;
    for(int i=n-1; i>=n-k; i--){
      ans += l[i];
    }
    Console.WriteLine(ans);
  }
}


Measured memory_bytes: 11092
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

std::string s;

int main(){
    std::cin >> s;
    if(s.length() % 2){
        printf("No\n");
        return 0;
    }
    for(int i = 0; i < s.length() / 2; i++){
        if(s[i*2] != 'h' || s[i*2+1] != 'i'){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
}


Measured memory_bytes: 256
from collections import defaultdict
from bisect import bisect_right
import sys
sys.setrecursionlimit(10**9)
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
class CountUp:
    def __init__(self, start=0):
        self.index = start-1

    def __call__(self):
        self.index += 1
        return self.index

N = int(input())
A = inpl()
ui = defaultdict(CountUp())
B = []
Ns = 0
for a in A:
    i = ui[a]
    if i >= Ns:
        Ns += 1
        B.append(1)
    else:
        B[i] += 1
B.sort()
C = []
prev = B[0]
n = 0
for b in B:
    if b == prev:
        n += 1
    else:
        C.append((prev,n))
        prev = b
        n = 1
else:
    C.append((prev,n))

f = []
S = 0
T = Ns
nc = 0
nxtc = C[0][0]
for i in range(1,N+1):
    if i == nxtc:
        n = C[nc][1]
        S += i*n
        T -= n
        nc += 1
        if nc < len(C):
            nxtc = C[nc][0]
        else:
            nxtc = None
    f.append(-(S//i + T))

#print(f)

for K in range(1,N+1):
    print(bisect_right(f,-K))

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

int main(){
    int N; cin >> N;
    string S; cin >> S;
    int ans=0, x=0;
    
    for(int i=0; i<N; i++){
        if(S[i]=='I'){
            x++;
            ans=max(ans,x);
        }
        else x--;
    }

    cout << ans << endl;

    return 0;
}

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

int len(char a[]){
  int i=0;

  while(a[i]!=0) i++;

  return i;
}

void sort(char a[],int n){
  int i,j;
  char c;

  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(a[j]<a[j-1]){
        c = a[j];
        a[j] = a[j-1];
        a[j-1] = c;
      }
    }
  }

}

void resort(char a[],int n){
  int i,j;
  char b;
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(a[j]>a[j-1]){
        b = a[j];
        a[j] = a[j-1];
        a[j-1] = b;
      }
    }
  }
}

int main(void){
  char a[1000];
  char b[1000];
  int i,n,m,c;

  scanf("%s %s",a,b);

  n = len(a);
  m = len(b);
  sort(a,n);
  resort(b,m);

  if(strcmp(a,b)<0) printf("Yes\n");
  else printf("No\n");

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;

vector<vector<int>> Factrization(int X);

int main(){
    int X, X1, X2, loop_n_B, X2_tmp;
    int A = 0, B = 0;
    vector<vector<int>> factors_;

    std::cin >> X;
    
    factors_ = Factrization(X);

    for(int i = 0; i < factors_.size(); i++ ){
    //    std::cout << factors_[i][0] << " " << factors_[i][1] << "\n";
    //因数分解のペアループ
        X1 = factors_[i][0];
        X2 = factors_[i][1];
    //    std::cout << X1 << "\n";
    //    std::cout << X2 << "\n";
        loop_n_B = (int)ceil(pow((float)X2,1.0/4.0))+1;
        //std::cout << pow((float)X,1.0/4.0) << "\n";
        //std::cout << loop_n_B << "\n";
        for(int i = -loop_n_B; i <= loop_n_B; i++){
            //B探索ループ
            X2_tmp = 5*(int)round(pow((float)i,4.0)) + 10*X1*(int)round(pow((float)i,3.0)) + 10*(int)round(pow(X1,2.0))*(int)round(pow((float)i,2.0)) + 5*(int)round(pow((float)X1,3.0))*i + (int)round(pow((float)X1,4.0));
        //    B = i^3;
        //    std::cout << B;
        //    std::cout << i << " " << X2_tmp << "\n";
            if(X2_tmp == X2){
                B = i;
                A = X1 + B; 
                goto print_answer;
            }
        }
    }
    print_answer:
    std::cout << A << " " << B;
}

vector<vector<int>> Factrization(int X){
    vector<vector<int>> factors = {};
    int n_loop, a, b;

    n_loop = (int)floor(sqrt((float)X));
    for(int i =1; i <= n_loop; i++){
        if(X%i == 0){
            a = i;
            b = X/i;
            factors.push_back({a, b});
        }
    }
    return factors;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<P> a(n);
    rep(i, n) cin >> a[i].first >> a[i].second;
    sort(a.begin(), a.end());

    ll ans = 0;
    int cnt = 0;
    for (auto k: a) {
        if (k.second + cnt <= m) {
            ans += k.first * k.second;
            cnt += k.second;
        } else {
            ans += k.first * (m - cnt);
            cnt += m - cnt;
        }
        if (cnt == m) break;
    }

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


Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include <math.h>
#define PAI 3.141592653589
using namespace std;
int main(){
	double r,mennseki,ennsyuu;
	cin>>r;
	mennseki=r*r*PAI;
	ennsyuu=2*PAI*r;
	printf("%.7lf %.7lf\n", mennseki, ennsyuu);

	return 0;
}


Measured memory_bytes: 3176
n,a,b = map(int,input().split())
s = list(input())
yosen = 0
gaikoku = 0
for i,si in enumerate(s):
    if si == 'a':
        if yosen < a+b:
            print('Yes')
            yosen += 1
        else:
            print('No')
    elif si == 'b':
        if yosen < a+b and gaikoku <b:
            print('Yes')
            yosen += 1
            gaikoku += 1
        else:
            print('No')
    else:
        print('No')


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

int main()
{
  	int r, g, b;
  	cin>>r>>g>>b;
  	int num = 10*g+b;
  	if(num % 4 == 0)
      	cout<<"YES";
  	else
      	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<int,int>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
#define YesNo(a) cout<<((a)?"Yes":"No")<<endl;
#define YESNO(a) cout<<((a)?"YES":"NO")<<endl;



int main(){
	
	ll N,M;
	cin >> N >> M;
	ll dp[(1<<N)];
	FOR(i,0,1<<N)dp[i] = INF;
	dp[0] = 0;
	vector<int> a(M),b(M),c(M,0);
	FOR(i,0,M){
		cin >> a[i] >> b[i];
		FOR(j,0,b[i]){
			ll x;
			cin >> x;
			x--;
			c[i] |= (1<<x);
		}
	}
	FOR(i,0,M){
		FORR(j,0,1<<N){
			dp[j|c[i]] = min(dp[j|c[i]],dp[j]+a[i]);
		}
	}
	if(dp[(1<<N)-1]==INF)dp[(1<<N)-1]=-1;
	cout << dp[(1<<N)-1] << endl;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll x, y, a, b, c; cin >> x >> y >> a >> b >> c;

    vector<ll> vp(a);
    for (ll i = 0; i < a; ++i) {
        cin >> vp[i];
    }

    vector<ll> vq(b);
    for (ll i = 0; i < b; ++i) {
        cin >> vq[i];
    }

    sort(vp.rbegin(), vp.rend());
    sort(vq.rbegin(), vq.rend());

    priority_queue<ll, vector<ll>, greater<ll>> p;
    priority_queue<ll, vector<ll>, greater<ll>> q;
    priority_queue<ll> r;

    for (ll i = 0; i < x; ++i) {
        p.push(vp[i]);
    }

    for (ll i = 0; i < y; ++i) {
        q.push(vq[i]);
    }

    for (ll i = 0; i < c; ++i) {
        ll R; cin >> R;
        r.push(R);
    }

    for (ll i = 0; i < c; ++i) {
        ll t = r.top(); r.pop(); //無色の最大値

        ll tp = p.top();
        ll tq = q.top();

        if (t < tp && t < tq) break;

//        if (tp == tq) {
//
//        }

        if (tp < tq) {
            p.pop();
            p.push(t);
        } else {
            q.pop();
            q.push(t);
        }
    }

    ll ans = 0;

    for (ll i = 0; i < x; ++i) {
        ll t = p.top(); p.pop();
        ans += t;
    }

    for (ll i = 0; i < y; ++i) {
        ll t = q.top(); q.pop();
        ans += t;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4724
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int h,w;
	cin >> h >> w;
	bool f[52][52]={};
	rep(i,0,h){
		rep(j,0,w){
			char c;
			cin >> c;
			if( c == '#' )
				f[i+1][j+1] = 1;
		}
	}
	/*
	rep(i,0,h+2){
		rep(j,0,w+2) cout << f[i][j];
	 	cout << endl;
	}
	*/	
	bool flag = 0;
	rep(i,1,h+1){
		rep(j,1,w+1){
			if( f[i][j] ){
				if( !f[i][j+1] && !f[i][j-1] && !f[i+1][j] && !f[i-1][j] ){
					flag = 1;
					break;
				}
			}
		}
		if( flag ) break;
	}
	
	if( flag ) No;
	else Yes;

	ret 0;
}


Measured memory_bytes: 256
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

CD=int(C*D/gcd(C,D))
Ac=A if A%C==0 else A+(C-A%C)
Ad=A if A%D==0 else A+(D-A%D)
Acd=A if A%CD==0 else A+(CD-A%CD)

Rc=(B-Ac)//C+1 if Ac>=A and Ac<=B else 0
Rd=(B-Ad)//D+1 if Ad>=A and Ad<=B else 0
Rcd=(B-Acd)//CD+1 if Acd>=A and Acd<=B else 0

print(B-A+1-(Rc+Rd-Rcd))

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int INF = 1000000007;
const ll MOD = 1000000007;

void solve_test()
{
    ll n;
    cin >> n;
    ll p10 = 1, p9 = 1, p8 = 1;
    for(int i=0; i<n; i++)
    {
        p10 = (p10*10) % MOD;
        p9 = (p9*9) % MOD;
        p8 = (p8*8) % MOD;
    }
    cout << (p10 + MOD - p9 + MOD + p8 - p9) % MOD;
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int tests;
    tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve_test();
    }
    return 0;
}


Measured memory_bytes: 3632
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

allenemy = sum(A)
for i in range(N):
    A[i] -= B[i]
    if A[i] < 0:
        A[i+1] += A[i]
        A[i] = 0
        if A[i+1] < 0:
            A[i+1] = 0
print(allenemy - sum(A))

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

using namespace std;

#define ll  long long
#define X   first
#define Y   second

#define all(x)  x.begin(),x.end()
#define sz(x)   (int)x.size()

#define pb      emplace_back
#define endl    "\n"

const ll    inf = 1e18;
const int   N   = 2e5 + 5;

typedef pair<int,int>   ii;

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

    int H;  cin >> H;
    int W;  cin >> W;
    int n;  cin >> n;

    cout << (n + max(W,H) - 1) / max(W,H) << endl;
}

Measured memory_bytes: 256