akhauriyash/Code-Regression huggingface dataset:
### constant

H = 4
W = 8
HW = H * W

### main

gl = []
for y in (0...H)
  for x in (0...W)
    id = y * W + x
    gl[id] = (x < W - 1) ? (y + 1) * 10 + (x + 1) : 0
  end
end
#p gl

n = gets.to_i

n.times do
  gets

  flds = []
  H.times do
    flds += [0] + gets.split.map(&:to_i)
  end
  #p $flds

  gaps = []
  for i in (0...HW)
    next if i % W == 0
    if flds[i] % 10 == 1
      y = flds[i] / 10 - 1
      flds[y * W] = flds[i]
      flds[i] = 0
      gaps << i
    end
  end
  #p flds
  #p gaps

  used = {}
  used[flds] = true
  q = [[0, flds, gaps]]
  gd = nil

  while ! q.empty?
    ud, uflds, ugaps = q.shift

    if uflds == gl
      gd = ud
      break
    end

    vd = ud + 1

    for gi in (0...H)
      vgaps = ugaps.clone
      vgapi = vgaps[gi]

      vflds = uflds.clone
      c = vflds[vgapi - 1] + 1
      vid = vflds.index(c)
      next if vid.nil?

      vflds[vgapi] = c
      vflds[vid] = 0
      vgaps[gi] = vid

      if ! used[vflds]
        used[vflds] = true
        q << [vd, vflds, vgaps]
      end
    end
  end

  puts (gd || -1)
end

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

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int h, w, n;
    cin >> w >> h >> n;
    vector<vector<int>> vvi(w+1, vector<int>(h+1, 0));
    int x, y, a;
    int sum = 0;
    for(int i = 0; i < n; ++i)
    {
        cin >> x >> y >> a;
        if (a == 1) {
            for (int i = 0; i < x; ++i)
            {
                for (int j = 0; j <= h; ++j)
                {
                    vvi[i][j] = 1;
                }
            }
        } else if (a == 2) {
            for (int i = w; i > x; --i)
            {
                for (int j = 0; j <= h; ++j)
                {
                    vvi[i][j] = 1;
                }
            }
        } else if (a == 3) {
            for (int i = 0; i <= w; ++i)
            {
                for (int j = 0; j < y; ++j)
                {
                    vvi[i][j] = 1;
                }
            }
        } else {
            for (int i = 0; i <=w; ++i)
            {
                for (int j = h; j > y; --j)
                {
                    vvi[i][j] = 1;
                }
            }
        }
    }
    for (int i = 0; i < w; ++i)
    {
        for (int j = 0; j < h; ++j)
        {
            if (vvi[i][j] == 0 && vvi[i+1][j] == 0 && vvi[i][j+1] == 0 && vvi[i+1][j+1] == 0) ++sum;
        }
    }
    cout << sum << endl;

    return 0;
}

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

#define ll long long
#define N 100005
#define mod 1000000007


int main() 
{
    int i,j,k,S,n=0;
    
    cin>>k>>S;
    
    for(i=0;i<=k;i++)
    {
        for(j=0;j<=k;j++)
        {
            if(i+j <= S && i+j >= S-k)
            n++;
        }
    }
    cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
cnt = 0
on = [0] * n
for i in range(k):
    d = int(input())
    a = list(map(int,input().split()))
    
    for j in a:
        on[j - 1] += 1

for l in on:
    if l == 0:
        cnt += 1

print(cnt)

Measured memory_bytes: 9132
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (int)(n);i++)
typedef long long ll;
using namespace std;
int main() {
	int w, h, x, y;
	cin >> w >> h >> x >> y;
	if (2 * x == w && 2 * y == h) {
		cout << double(w) * double(h) / 2 << " " << '1' << endl;
	}
	else {
		cout << double(w) * double(h) / 2 << " " << '0' << endl;
	}
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n)cin >> d[i];
    sort(d.begin(), d.end());
    int left, right;
    left = d[d.size()/2 -1];
    right = d[d.size()/2];
    cout << right - left << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll a,b,c,d;
	cin>>a>>b>>c>>d;

	bool flg = true;
	while(1)
	{
		c-=b;
		if (c<=0)
			break;
		a-=d;
		if (a<=0)
		{
			flg = false;
			break;
		}
	}

	if (flg)
		cout<<"Yes";
	else
		cout<<"No";
}

Measured memory_bytes: 3636
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}

int n,a[101010];

signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

   cin >> n;
   for(int i=1;i<=n;i++){
      cin >> a[i];
   }
   sort(a+1,a+n+1);
   int l = (n)/2;
   int r = l+1;

   if(a[l]!=a[r]){
      cout << a[r]-a[l] << endl;
   }
   else {
      cout << 0 << endl;
   }



return 0;
}
///....


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
#define int long long int
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll MOD = 1e9+7;
const ll inf = 1e18;
const ll p = 998244353;
vector<int> visited;
vector<int> group;
vector<vector<int> > adj;
void dfs(int s,int count)
{
	if(visited[s])return;
	visited[s]=1;
	group[s]=count;
	for(int i=0;i<sz(adj[s])-1;i++)
	{
		if(!visited[adj[s][i]])
		dfs(adj[s][i],count);
	}
}
//matrix of 1 and 0 ,1 island count the number of groups of islands
//dp bitmask implementation
// 4 more dp problems
signed main() 
{
 int n,k;
 cin>>n>>k;
 int a[n+1];
 for(int i=1;i<=n;i++)
 cin>>a[i];
 int dp[n+1][k+1];
 int pref[n+1][k+1];
 for(int i=0;i<=n;i++)
 {
 	for(int j=0;j<=k;j++)
 	{
 	pref[i][j]=0;
 	dp[i][j]=0;	
    }
 }
 for(int i=0;i<=n;i++)
 {
 dp[i][0]=1;
 pref[i][0]=1;	
 }
 for(int i=1;i<=n;i++)
 {
 	for(int j=1;j<=k;j++)
 	{
 	 pref[i-1][j]=(pref[i-1][j-1]+dp[i-1][j])%MOD;
 	 pref[i-1][j]=pref[i-1][j]%MOD;
 	  if(j<=a[i])
	  dp[i][j]=pref[i-1][j];
	  else
	  dp[i][j]=pref[i-1][j]-pref[i-1][j-a[i]-1];
	  if(dp[i][j]<0)dp[i][j]+=MOD;
	  dp[i][j]%=MOD;
	  //cout<<dp[i][j]<<" ";	
	}
	//cout<<endl;
 }
 cout<<dp[n][k]<<endl;
}

Measured memory_bytes: 161372
N = int(input())
S = '0'
S += input()
R_count = 0
G_count = 0
B_count = 0
for i in range(1, N + 1):
  if S[i] == 'R':
    R_count += 1
  if S[i] == 'G':
    G_count += 1
  if S[i] == 'B':
    B_count += 1
res = R_count * G_count * B_count
for i in range(1, N + 1):
  for j in range(i + 1, N + 1):
    if 2 * j - i > N:
      break
    temp = []
    temp += S[i] + S[j] + S[2 * j - i]
    temp.sort()
    if temp[0] == 'B' and temp[1] == 'G' and temp[2] == 'R':
      res -= 1
print(res)

Measured memory_bytes: 68524
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define llg long long 
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,mid,ans,x;
int main()
{
	cin>>x;
	x*=2;
	llg l=1,r=1e9;
	while (l<=r)
	{
		mid=(l+r)>>1;
		llg val=mid*mid+mid;
		if (val>=x) {r=mid-1,ans=mid;} else l=mid+1;
	}
	cout<<ans;
	return 0;
}


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

using namespace std;

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

const int mod = 109;
int value[mod];
int cnt[mod];

int main(){
  while(int n = getInt()){
    int ans = -1;
    const int n2 = n / 2;

    for(int i = 0; i < mod; i++){
      value[i] = -1;
      cnt[i] = 0;
    }

    for(int i = 0; i < n; i++){
      int a = getInt();
      int m = a % mod;
      if(value[m] == -1) value[m] = a;
      if(++cnt[m] > n2) ans = a;
    }

    if(ans == -1)
      puts("NO COLOR");
    else
      printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 836
N = int(input())
a = list(map(int,input().split()))
count = 0

if N != 2:
    for i in range(1,N-1):
        if a[i] == a[i-1]:
            a[i] = a[i+1] + 1
            count = count + 1
else:
    if a[0] == a[1]:
        a[0] = a[1]+1
        count = count + 1

if a[N-2] == a[N-1]:
    count = count + 1

print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
 
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define int         ll int
#define float       double
#define	endl		'\n'
#define maxpq       priority_queue<ll>
#define minpq       priority_queue<ll, vector<ll>, greater<ll> >
#define mii         map<int,int>
#define msi         map<string,int>
#define mis         map< int, string>
#define mpi         map<pair< int, int>, int>
#define pii         pair< int, int>
#define vi          vector< int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define EPS         1e-9
#define INF         1e18
#define PI          3.14159265358979323846
#define MAXI        1000000
#define what_is(x)  cerr << #x << " is " << x << endl;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
#define N 100005
int modexp(int x,int n){
	x%=hell;
	int res=1;
	while(n>0){
		if(n&1) res=res*x%hell;
		x=x*x%hell;
		n/=2;
	}
	return res;
}

signed main()
{
	fast;
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int arr[n];
		int i,j,k;
		int num=0;
		for(i=0;i<=n-1;i++)
		{
			cin>>arr[i];
			if(i%2==0&&arr[i]%2!=0) num++;
		}
		cout<<num<<endl;
	}
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

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

  if(k>(n-1)*(n-2)/2) { cout<<-1<<endl; return 0; }

  vector<pi>result;
  rep(i, n-1)result.push_back({1, 2+i});

  int counter = (n-1)*(n-2)/2;
  for(int i=2;i<=n;i++)for(int j=i+1;j<=n;j++){
    if(counter==k)break;
    result.push_back({i, j});
    counter--;
  }

  cout<<result.size()<<endl;
  for(auto p: result)cout<<p.first<<' '<<p.second<<endl;

  return 0;
}

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

using namespace std;

int main(void){
  
  string S;
  int A_Position = 0;
  int Z_Position = 0;
  int A_count = 0;
  int Z_count = 0;
  int S_length = 0;
  int ans = 0;
    
    cin >> S;
  S_length = S.length();
  Z_count = S_length - 1;

  while( S[A_count] != 'A' ){
    A_count++;
  }
  A_Position = A_count;

  while( S[Z_count] != 'Z' ){
    Z_count--;
  }
  Z_Position = Z_count;

  ans = Z_Position - A_Position + 1;

  cout << ans;

  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define SORT(i) sort((i).begin(),(i).end())
#define INF 2000000000
constexpr ll mod = 1e9 + 7;

int coudp[100001];

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

	int mid;
	if (N % 2 == 0) {
		mid = N / 2 - 1;
	}
	else {
		mid = N / 2;
	}
	int ans = 0;
	for (int i = 0;i < N;++i) {
		set<char>st{};
		for (int j = i + 1;j < N;++j) {
			for (int k = 0;k <= i;++k) {
				if (s[k] == s[j]) {
					if (!st.count(s[k])) {
						st.insert(s[k]);
					}
				}
			}
		}
		ans = max(ans, (int)st.size());
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int AMAX = 1e5;
ll cnt[AMAX + 1];
int main(){
    int N;
    ll K;
    cin >> N >> K;
//    ll large = 1e10;
//    vector<long long> hairetsu(large);
//    int a,b;
    for(int i = 0;i<N;i++){
        int a,b;
        cin >> a >> b;
        cnt[a] += b;
    }
    for(int ans = 1;ans <= AMAX; ++ans){
        if(K <= cnt[ans]){
            cout << ans << endl;
            break;
        }
        K -= cnt[ans];
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll x;cin>>x;
    for(ll i=1;i<=sqrt(x);i++){
        if(x%i!=0)continue;
        for(ll a=(ll)0;a<=(ll)300;a++){
            ll b=a-i;
            ll A=a*a*a*a*a;
            ll B=b*b*b*b*b;
            ll jud=A-B;
            if(jud==x){
                cout<<a<<" "<<b<<endl;
                return 0;
            }
            ll j=x/i;
            b=a-j;
            A=a*a*a*a*a;
            B=b*b*b*b*b;
            jud=A-B;
            if(jud==x){
                cout<<a<<" "<<b<<endl;
                return 0;
            }
        }
    }
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    int a,b,sum=1,ans=0;cin>>a>>b;

    while (sum<b) {
        ans++;
        sum=sum+a-1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;

const int INF = 1001001001;

int main()
{
  int H, N, maxa, ans;
  int na, nb;
  cin >> H >> N;
  vector<int> A(N), B(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i) >> B.at(i);
    if(i == 0 || maxa < A.at(i)){
      maxa = A.at(i);
    }
  }
  
  vector<int> dp(H+maxa, INF);
  dp.at(0) = 0;
  for(int i = 1; i < H+maxa; i++){
    for(int j = 0; j < N; j++){
      na = A.at(j);
      if(i < na) continue;
      nb = B.at(j);
      dp.at(i) = min(dp.at(i), dp.at(i-na)+nb);
    }
    if(i >= H){
      if(i == H || ans > dp.at(i)) ans = dp.at(i);
    }
  }
  cout << ans << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;
template <typename T>
T gcd(T a,T b){ // greatest common divisor
    if(b == 0) return a;
    return gcd(b,a%b);
}
template <typename T>
T lcm(T a,T b){ // least common multiple
    T g = gcd(a,b);
    return a / g * b;
}
int main(){
    int N;
    cin >> N;
    long long T[N];
    long long ans = 1;
    for(int i = 0; i < N; i++){
        cin >> T[i];
        ans = lcm(T[i], ans);
    }
    cout << ans << endl;   

    return 0;
}

Measured memory_bytes: 256
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if a == b:
    print("YES")
elif v<=w:
    print("NO")
else:
    if -(-abs(b-a)//(v-w)) <= t:
        print("YES")
    else: print("NO")

Measured memory_bytes: 9180
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<string> vstring;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

//aのb乗をmodで割った余りを求める
llint power(llint a, llint b) {
	if (b == 1)return a;
	if (b == 0)return 1;
	llint tmp = power(a, (llint)b / 2);
	tmp *= tmp;
	tmp %= mod;
	if (b % 2 == 1) {
		tmp *= a;
		tmp %= mod;
	}
	return tmp;
}

int main() {
	int a, b;
	cin >> a >> b;
	Yes(a == b);
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef pair < int , int > Pi;
vector < int > order;
vector < int > G[10005];
vector < int > NG[10005];
vector < int > rev[10005];
vector < int > Nrev[10005];
bool flag[10005] = {};
int cmp[10005];
int N, M;
void dfs(int v)
{
    if(flag[v]) return;
    flag[v] = true;
    for(int i = 0; i < G[v].size(); i++) dfs(G[v][i]);
    order.push_back(v);
    return;
}
void rdfs(int v, int c)
{
    if(~cmp[v]) return;
    cmp[v] = c;
    for(int i = 0; i < rev[v].size(); i++) rdfs(rev[v][i], c);
    return;
}
int main()
{
    int NN = 0;
    int S[100005], T[100005];
    memset(cmp, -1, sizeof(cmp));
    cin >> N >> M;
    for(int i = 0; i < M; i++) {
        cin >> S[i] >> T[i];
        G[S[i]].push_back(T[i]);
        rev[T[i]].push_back(S[i]);
    }
    for(int i = 0; i < N; i++) dfs(i);
    reverse(order.begin(), order.end());
    for(int i = 0; i < N; i++) {
        if(cmp[order[i]] == -1) {
            rdfs(order[i], NN);
            NN++;
        }
    }
    set < Pi > st;
    for(int i = 0; i < M; i++) {
        int a = cmp[S[i]], b = cmp[T[i]];
        if(a != b && st.find(Pi(a, b)) == st.end()) {
            st.insert(Pi(a, b));
            NG[a].push_back(b);
            Nrev[b].push_back(a);
        }
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < G[i].size(); j++) {
            rev[i].push_back(G[i][j]);
        }
    }
    int cnt = 0;
    memset(cmp, -1, sizeof(cmp));
    for(int i = 0; i < N; i++) {
        if(cmp[i] == -1) {
            rdfs(i, cnt);
            cnt++;
        }
    }
    int acnt = 0, bcnt = 0;
    for(int i = 0; i < NN; i++) {
        if(NG[i].size() == 0) acnt++;
        if(Nrev[i].size() == 0) bcnt++;
    }
    if(NN == 1) cout << 0 << endl;
    else cout << cnt - 1 + max(acnt - cnt + 1, bcnt - cnt + 1) << endl;

    return (0);
}

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

int main(){
  int n,m; cin>>n>>m;
  vector<vector<int>> tree(n);
  for(int i=0;i<m;i++){
    int x,y,z; cin>>x>>y>>z;
    x--; y--;
    tree[x].push_back(y);
    tree[y].push_back(x);
  }
  vector<bool> vis(n,false);
  int ans=0;
  for(int j=0;j<n;j++){
    if(vis[j]) continue;
    vis[0]=true;
    queue<int> que;
    que.push(j);
    ans++;
    while(!que.empty()){
      int a=que.front();
      que.pop();
      for(int i=0;i<tree[a].size();i++){
        if(vis[tree[a][i]]) continue;
        que.push(tree[a][i]); vis[tree[a][i]]=true;
      }
    }
  }
  cout<<ans<<endl;
} 

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

using namespace std;
#define ll  long long
#define db long double
#define pb push_back
#define all(a) a.begin(),a.end()
#define f(i,l,u) for(ll i=l;u<u;i++)
#define lb lower_bound
#define ub upper_bound
int main() {
    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        
        char a;
        cin>>a;
        ll y=a;
        if(a<=90)
        cout<<'A';
        else
        cout<<'a';
        
        
        
        
    }
    
    
    
    
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);


int main(){
  int n,k;
  cin >> n >> k;
  vector<int>a(n);
  rep(i,n)cin >> a[i];
  int left,right;
  rep(i,n){
    if(a[i]==1){
      left=i;
      right=n-1-left;
    }
  }
  int ans=0;
  ans+=(left+k-2)/(k-1);
  right-=ans*(k-1)-left;
  if(right>0);
  ans+=(right+k-2)/(k-1);
  
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
#include <set>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };
const double PI = 3.14159265358979323846;


int main() {
	
	ll x;
	cin >> x;
	vector<ll> beki(201);
	rep(i, 201) {
		beki.at(i) = pow(i, 5);
	}
	ll a;
	ll b;
	bool c = false;
	rep(i, 201) {
		rep(j, 201) {
			a = beki.at(i);
			b = beki.at(j);
			if ((a - b) == x) {
				cout << i << ' ' << j << endl;
				c = true;
				break;
			}
			else if ((a + b) == x) {
				cout << i << ' ' << j * (- 1) << endl;
				c = true;
				break;

			}
		}
		if (c == true) {
			break;
		}
	}

	
	return 0;
	
}



Measured memory_bytes: 4108
#include <stdio.h>

void check_parent(int i, int a[], int n){
    if(i-1<0) return;
    printf("parent key = %d,",a[(i-1)/2]);
    printf(" ");
}

void left_key(int i, int a[], int n){
    if(i*2+1>=n) return;
    printf("left key = %d,",a[i*2+1]);
    printf(" ");
}

void right_key(int i, int a[], int n){
    if(i*2+2>=n) return;
    printf("right key = %d,",a[i*2+2]);
    printf(" ");
}
int main()
{
    int n;
    scanf("%d",&n);
    int a[n];
    for(int i = 0; i<n; i++){
        scanf("%d",&a[i]);
    }
    for(int i = 0; i < n; i++){
        printf("node %d: ",i+1);
        printf("key = %d, ",a[i]);
        check_parent(i,a,n);
        
        left_key(i,a,n);
        right_key(i,a,n);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2600
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stdlib.h>
#include <list>
#include <queue>
#include <map>
#include <stack>
#include <set>
#define inf 0x3f3f3f3f
#define PI acos(double(-1))
using namespace std;

typedef long long ll;
const int maxn=1e5+10;
char s1[maxn],s2[maxn];

int main()
{
    scanf("%s%s",s1,s2);
    int len1=strlen(s1);
    int len2=strlen(s2);
    if(len1<len2)
        printf("LESS\n");
    else if(len1>len2)
        printf("GREATER\n");
    else
    {
        for(int i=0;i<len1;i++)
        {
            if(s1[i]<s2[i])
            {
                printf("LESS\n");
                return 0;
            }
            else if(s1[i]>s2[i])
            {
                printf("GREATER\n");
                return 0;
            }
        }
        printf("EQUAL\n");
    }
    return 0;
}


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

int main(){
    char d[11];
    scanf("%s", d);
    char h[] = "2019/04/30";

    if(strcmp(d, h) <= 0){
        printf("Heisei\n");
    }else{
        printf("TBD\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    long long N,K,a,b;
    cin>>N>>K;
    if(N%K==0)
    {
        cout<<0<<endl;
    }
    else
    {
         a=N%K;
         b=abs(K-a);
         if(a<b)
         {
             cout<<a<<endl;
         }
         else
         {
             cout<<b<<endl;
         }
    }
    return 0;
}


Measured memory_bytes: 3384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

const int N = 1e3+3;


int cnt[N][N];
pair< int, int > edge[N*200];
int n, m;
vector<int> g[N];

#define u first
#define v second

bool kappa[N][N];

void dothething(int root) {
	vector< pair<int, int> > lel;
	queue< pair<int, int> > q;
	int k = 0;
	for (auto c : g[root]) {
		k++;
		q.push({c, k});
		lel.push_back({c, k});
		kappa[c][k] = 1;
		cnt[root][c] = 1;
	} 
	while (q.empty() == false) {
		int u = q.front().u;
		int e = q.front().v; q.pop();
		for (auto v : g[u]) {
			if (v == root) continue;
			if (cnt[root][v] == 2) continue;
			if (!kappa[v][e]) {
				lel.push_back({v, e});
				kappa[v][e] = 1;
				cnt[root][v]++;
				q.push({v, e});
			}
		}
	}
	for (auto i : lel) {
		kappa[i.u][i.v] = 0;
	}
}

signed main() {
	memset(cnt, 0, sizeof(cnt));
	memset(kappa, 0, sizeof(kappa));
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++) {
		scanf("%d%d", &edge[i].u, &edge[i].v);
		g[edge[i].u].push_back(edge[i].v);
	}
	for (int i = 1; i <= n; i++) {
		dothething(i);
	}
	for (int i = 1; i <= m; i++) {
		// cout << cnt[edge[i].u][edge[i].v] << '\n';
		if (cnt[edge[i].u][edge[i].v] == 1) {
			if (cnt[edge[i].v][edge[i].u] >= 1) {
				cout << "diff\n";
			}
			else {
				cout << "same\n";
			}
		} 
		else {
			if (cnt[edge[i].v][edge[i].u] >= 1) {
				cout << "same\n";
			}
			else {
				cout << "diff\n";
			}
		}
	}
}

Measured memory_bytes: 9344
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int l = sc.nextInt();
    int r = sc.nextInt();
    int d = sc.nextInt();
    
    int ans = 0;
 
    for(int i = l ; i <= r ; ++i){
      if(i%d == 0){
        ans++;
      }
    }
    
    System.out.println(ans);
    
  }
}

Measured memory_bytes: 35652
#include <bits/stdc++.h>
using namespace std;
//#define int long long
typedef pair<int,int> ii;
typedef tuple<int,int,int> iii;
#define ll long long
#define iiMPQ priority_queue<ii,vector<ii>,greater<ii> >
#define MPQ priority_queue<int,vector<int>,greater<int> >
#define PQ priority_queue<int>
#define iiPQ priority_queue<ii>
#define US unordered_set<int>
#define UMS unordered_multiset<int>
#define UM unordered_map<int>
#define ST stack<int>
#define MS multiset<int>
#define scan(n) cin>>n
#define scann(a,b) cin>>a>>b
#define scannn(a,b,c) cin>>a>>b>>c
#define print(n) cout<<n
#define println(n) cout<<n<<"\n"
#define first fi
#define second se
#define REP(i,n) for(int i=0;i<n;++i)
 
void m1(){
  int n,k;
  scann(n,k);
  int arr[n+5];
  REP(i,n)scan(arr[i]);
  sort(arr,arr+n);
  int res = 0;
  for(int i=0;i<k;++i) res += arr[i];
  print(res);
}
/* 
void m2(){
  int t; scan(t);
  while(t--) m1();
}
*/
 
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //freopen("in.txt","r",stdin);
  m1();
  //m2();
}

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


def main():
    """Function."""
    s = str(input())

    N = s.count("N")
    W = s.count("W")
    S = s.count("S")
    E = s.count("E")

    ns_flag = -1
    if N == 0 and S == 0:
        ns_flag = 1
    elif N == 0 and S != 0:
        ns_flag = -1
    elif N != 0 and S == 0:
        ns_flag = -1
    else:
        ns_flag = 1

    we_flag = -1
    if W == 0 and E == 0:
        we_flag = 1
    elif W == 0 and E != 0:
        we_flag = -1
    elif W != 0 and E == 0:
        we_flag = -1
    else:
        we_flag = 1

    if ns_flag == -1 or we_flag == -1:
        print("No")
    else:
        print("Yes")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int H = Integer.parseInt(scanner.next());
        int N = Integer.parseInt(scanner.next());
        int A = 0;
        for (int i = 0; i < N; i++) {
            A += Integer.parseInt(scanner.next());
        }
        System.out.println(H <= A ? "Yes" : "No");
    }

}


Measured memory_bytes: 47024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>

namespace IO {
    template <typename _T>
    inline bool read (_T& x) {
        x = 0;
        _T y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return false;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        x *= y;
        return true;
    }

    template <typename _T>
    inline _T input () {
        _T x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return 0;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        x *= y;
        return x;
    }
};
using namespace IO;

using std::pair;

#define reg register
#define MAX_N 6007
#define pii pair<int, int>
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for(int i = l; i <= r; ++i)
#define lep(i, l, r) for(int i = l; i < r; ++i)
#define irep(i, r, l) for(int i = r; i >= l; --i)
#define ilep(i, r, l) for(int i = r; i > l; --i)
typedef long long ll;

int N, M, top;
int a[MAX_N], b[MAX_N], s[MAX_N];
int L[MAX_N], R[MAX_N];
char str[MAX_N];
pii p[MAX_N];

inline void init () {
    rep (i, 1, M) s[i] = s[i - 1] + b[i];
    L[0] = -1e9;
    rep (i, 1, M) L[i] = (b[i] == 1) ? i : L[i - 1];
    R[M + 1] = 1e9;
    irep (i, M, 1) R[i] = (b[i] == 1) ? i : R[i + 1];
}

inline bool has (int l, int r) { return s[r] - s[l - 1] > 0; }

inline int work (int d) {
    int flp = 0;
    top = 0;
    rep (i, N + 1, N * 2) if (a[i] != b[i + d]) {
        flp++;
        int l = i + d, r = i;
        if (l > r) std::swap(l, r);
        if (!has(l, r)) {
            p[++top] = pii(l - L[l], R[r] - r);
        }
    }
    std::sort(p + 1, p + top + 1);
    int mxr = 0, mn = 1e9;
    irep (i, top, 0) {
        mn = std::min(mn, p[i].first + mxr);
        mxr = std::max(mxr, p[i].second);
    }
    // printf("%d %d\n", d, flp);
    return std::abs(d) + flp + mn * 2;
}

inline void solve () {
    // return printf("%d\n", work(-1)), void();
    int res = 1e9;
    rep (i, -(N - 1), N - 1) {
        res = std::min(res, work(i));
    }
    printf("%d\n", res == 1e9 ? -1 : res);
}

int main () {
#ifdef LOCAL
    FIN("in");
#endif
    scanf("%s", str + 1);
    N = strlen(str + 1);
    rep (i, 1, N) a[i] = str[i] - '0';
    scanf("%s", str + 1);
    rep (i, 1, N) b[i] = str[i] - '0';
    M = 3 * N;
    rep (i, N + 1, 2 * N) b[i] = b[i - N], a[i] = a[i - N];
    rep (i, 2 * N + 1, M) b[i] = b[i - N], a[i] = a[i - N];
    init();
    rep (i, 1, N) if (a[i] && !has(1, N)) return puts("-1"), 0;
    solve();
    return 0;
}


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

const int depth = 17;
class SegTree {
public:
	int data[1<<(depth+1)];
	SegTree() { for (int i = 0; i < (1<<(depth+1)); i++) data[i] = 0; }
	void add(int pos, int x) {
		pos = (1<<depth) - 1 + pos;
		data[pos] += x;
		while (pos > 0) {
			pos = (pos - 1) / 2;
			data[pos] += x;
		}
	}
	int getSum(int l, int r, int a = 0, int b = (1 << depth), int id = 0) {
		if (b <= l || a >= r) return 0;
		if (l <= a && b <= r) { return data[id]; }
		int u = getSum(l, r, a, a + (b - a) / 2, id * 2 + 1);
		int v = getSum(l, r, a + (b - a) / 2, b, id * 2 + 2);
		return u + v;
	}
};

SegTree seg;
int n, q;
int com, x, y;

int main() {
	cin >> n >> q;
	for (int i = 0; i < q; i++) {
		cin >> com >> x >> y;
		if (com == 0) { seg.add(x, y); }
		else { cout << seg.getSum(x, y + 1) << endl; }
	}
	return 0;
}

Measured memory_bytes: 4112
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  string s,t;
  cin>>s>>t;
  for (int i(0);i<s.size();i++){
    bool flag = true;
    for (int j(0);j<s.size();j++){
      int now = (i+j>=s.size() ? i+j-s.size() : i+j);
      if (s[now] != t[j]){
        flag = false;
      }
    }
    if (flag == true){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}



Measured memory_bytes: 256
function BFS(X,Y){
   var dx=[0,-1,1,0];
   var dy=[-1,0,0,1];
   var cnt=0;
   var bfs=[[X,Y,cnt,1]];
   var obj={};
   var memo=[];
   for(var i=0;i<=1000;i++){
      memo[i]=[];
      for(var j=0;j<=1000;j++){
         memo[i][j]=0;
      }
   }
   memo[X][Y]=0;
   while(true){
      var leaf=bfs.shift();
      var x=leaf[0];
      var y=leaf[1];
      var c=leaf[2];
      var s=leaf[3];
      if(s===power+1){cnt=c;break;}
      for(var i=0;i<4;i++){
         var xx=x+dx[i];
         var yy=y+dy[i];
         var ss=s;
         if(xx<0 || yy<0 || xx>=hw[1] || yy>=hw[0])continue;
         if(YX[yy][xx]=="X")continue;
         if(YX[yy][xx]===""+ss)ss++;
         if(memo[xx][yy]>=ss)continue;
         memo[xx][yy]=ss;
         bfs.push([xx,yy,c+1,ss]);
      }
   }
   return cnt;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var hw=(Arr.shift()).split(" ").map(Number);
var power=hw[2];
var YX=[];
var start=[];
for(var i=0;i<hw[0];i++){
var arr=(Arr.shift()).split("");
if(arr.indexOf("S")!=-1)start=[arr.indexOf("S"),i]
YX.push(arr);
}
var ans=BFS(start[0],start[1]);
console.log(ans);

Measured memory_bytes: 62064
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&... tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&... args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 2010


int main() {
  int N, V[SIZE], C[SIZE];
  int ans = 0;

  cin >> N;

  for (int i = 0; i < N; i++) cin >> V[i];
  for (int i = 0; i < N; i++) cin >> C[i];

  for (int i = 0; i < N; i++) {
    ans += max(0, V[i] - C[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;


int main(){
    int N, M; cin >> N >> M;
    vector<int> A(M);
    vector<pair<int, ll>> keys;
    rep(i,M){
        int a, b; cin >> a >> b;
        int to = 0;
        rep(j,b){
            int c; cin >> c;
            c--;
            to |= 1 << c; 
        }
        keys.emplace_back(to, a);
    }

    vector<ll> dp(1<<N, INF);
    dp[0] = 0;

    rep(i,1<<N){
        rep(j,M){
            int to = i | keys[j].first;
            dp[to] = min(dp[to], dp[i]+keys[j].second);
        }
    }

    int ans = -1;
    if (dp.back() != INF) ans = dp.back();
    cout << ans << endl;
}

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

int main(){
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int ans;
    if(m1-m2<0){
        ans = (h2-1-h1) * 60 + (m2+60-m1);
    }else{
        ans = (h2-h1) * 60 + (m2-m1);
    }
    cout << ans-k << endl;
    return 0;
}

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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);

void header() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

void solve() {
    int s, w;
    cin >> s >> w;
    if (s <= w) cout << "unsafe\n";
    else cout << "safe\n";
}

int main() {
	header();
	solve();
	return 0;
}


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

int main() {
	int n,k,x,y;
  	cin >> n >> k >> x >> y;
  
  	if(n > k) {
  	cout << k * x + y * (n - k) << endl;
    }else {
    cout << n * x << endl;
    }
}

Measured memory_bytes: 256
N, Y = map(int, input().split())
x, y, z = -1, -1, -1

for a in range(N + 1):
    for b in range(N + 1 - a):
        c = N - a - b
        
        if(10000 * a + 5000 * b + 1000 * c == Y):
            x, y, z = a, b, c
            break
print(x, y, z)

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

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

    string s;
    cin >> s;

    vector<int> pref(n, 0), suff(n, 0);

    for (int i = 1; i < n; i++) {
        pref[i] = pref[i-1] + (s[i-1] == 'W');
    }
    for (int i = n-2; i >= 0; i--) {
        suff[i] = suff[i+1] + (s[i+1] == 'E');
    }

    int ans = 1e8;
    for (int i = 0; i < n; i++) {
        ans = min(ans, pref[i] + suff[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 6152
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

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

int main()
{
  string s, t;
  cin >> s >> t;

  ll **dp = new ll *[s.length() + 1];
  FOR(i, 0, s.length())
  {
    dp[i] = new ll[t.length() + 1];
    FOR(j, 0, t.length())
    {
      dp[i][j] = 0;
    }
  }

  FOR(i, 1, s.length())
  {
    FOR(j, 1, t.length())
    {
      if (s[i - 1] == t[j - 1])
      {
        chMax(dp[i][j], dp[i - 1][j - 1] + 1);
      }
      else
      {
        chMax(dp[i][j], dp[i - 1][j]);
        chMax(dp[i][j], dp[i][j - 1]);
      }
    }
  }

  stack<char> ss;
  ll i = s.length(), j = t.length();
  while (i != 0 && j != 0)
  {
    if (dp[i - 1][j - 1] < dp[i][j] && dp[i - 1][j] < dp[i][j] && dp[i][j - 1] < dp[i][j])
    {
      ss.push(s[i - 1]);
      i--, j--;
    }
    else if (dp[i][j] == dp[i - 1][j])
    {
      i--;
    }
    else
    {
      j--;
    }
  }

  while (!ss.empty())
  {
    cout << ss.top();
    ss.pop();
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 70656
#include "bits/stdc++.h"

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define vi vector<int>

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cerr << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define debug(...) CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) (__VA_ARGS__)

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

const int MAX_N = 100005;

ll num[51];
ll paty[51];

ll f(int L, ll x) {
  if (L == 0) return 1;
  if (x == 1) return 0;
  if (x == num[L]/2) return paty[L]/2;
  if (x == num[L]/2 + 1) return paty[L]/2 + 1;
  if (x == num[L] || x == num[L] - 1) return paty[L];
  if (x > num[L]/2+1) return paty[L]/2+1+f(L-1, x - num[L]/2 - 1);
  return f(L-1, x-1);
}

void Main() {
  int n; ll x;
  cin >> n >> x;
  num[0] = 1;
  rep(i, n) num[i+1] = num[i]*2 + 3;
  paty[0] = 1;
  rep(i, n) paty[i+1] = paty[i]*2 + 1;
  cout << f(n, x) << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(double x){
  printf("%.15f",x);
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N, T[100], V[100], mx[50000];
int main(){
  double res=0;
  int all, i, j;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(T[Lj4PdHRW]);
    }
  }
  {
    int KL2GvlyY;
    for(KL2GvlyY=0;KL2GvlyY<N;KL2GvlyY++){
      rd(V[KL2GvlyY]);
    }
  }
  all = 0;
  for(i=0;i<N;i++){
    for(j=0;j<2*T[i];j++){
      mx[all] = 2*V[i];
      if(i&&j==0){
        chmin(mx[all], 2*V[i-1]);
      }
      all++;
    }
  }
  mx[0] = mx[all] = 0;
  for(i=1;i<all;i++){
    chmin(mx[i], mx[i-1]+1);
  }
  for(i=all-1;i;i--){
    chmin(mx[i], mx[i+1]+1);
  }
  for(i=1;i<all+1;i++){
    res += mx[i-1]+mx[i];
  }
  res /= 8;
  wt_L(res);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20171023-1 [beta]

// --- original code ---
// int N, T[100], V[100];
// int mx[50000];
// {
//   int i, j, all;
//   double res = 0;
// 
//   rd(N,T(N),V(N));
// 
//   all = 0;
//   rep(i,N){
//     rep(j,2T[i]){
//       mx[all] = 2V[i];
//       if(i&&j==0) mx[all] <?= 2V[i-1];
//       all++;
//     }
//   }
//   mx[0] = mx[all] = 0;
// 
//   rep(i,1,all) mx[i] <?= mx[i-1]+1;
//   for(i=all-1;i;i--) mx[i] <?= mx[i+1]+1;
// 
//   REP(i,1,all+1) res += mx[i-1]+mx[i];
//   res /= 8;
//   wt(res);
// }


Measured memory_bytes: 384
#include<string.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
#include<set>
#define lli long long int
#define ULTRA_INSTINCT ios_base::sync_with_stdio(false); cin.tie(0)
#define fo(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int MAXI = 2e5 + 5;

vector<int >g[MAXI];
int visi[MAXI];
int sz = 0;
void dfs(int node){
    visi[node] = 1;
    sz++;
    for(int to : g[node]){
        if(visi[to] ==0){
            dfs(to);
        }
    }
}

void solve(){

    int  n , m;
    cin>>n>>m;
    int l,r;
    set<pair<int,int > >st;
    fo(i,m){
        cin>>l>>r; --l,--r;
        if(st.find(make_pair(l,r)) == st.end()){
            st.insert(make_pair(l,r));
            st.insert(make_pair(r,l));
            g[l].push_back(r);
            g[r].push_back(l);
        }   
    }
    int ans = 1;
    fo(i,n){
        if(visi[i] == 0){
            sz = 0;
            dfs(i);
            ans = max(ans , sz);
        }
    }
    cout<<ans<<endl;




}

int main(){
    ULTRA_INSTINCT;
    int t =1;
    // cin>>t;
    while(t--){
        solve();
    }

    return 0;
}

Measured memory_bytes: 40268