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

int N, M, Q;
int U[200000], V[200000];
vector< pair< int, int > > graph[100000];
int v[100000], in[100000];
bool live[200000];

void BFS()
{
  memset(v, -1, sizeof(v));
  queue< int > que;
  que.push(0);
  v[0] = 0;
  while(!que.empty()) {
    int p = que.front(); que.pop();
    for(auto to : graph[p]) {
      if(v[to.first] == v[p] + 1) {
        in[to.first]++;
      } else if(v[to.first] < 0) {
        v[to.first] = v[p] + 1;
        in[to.first]++;
        que.push(to.first);
      } 
    }
  }
}

int main()
{
  scanf("%d %d %d", &N, &M, &Q);
  for(int i = 0; i < M; i++) {
    scanf("%d %d", &U[i], &V[i]);
    --U[i], --V[i];
    graph[U[i]].emplace_back(V[i], i);
    graph[V[i]].emplace_back(U[i], i);
  }
  BFS();

  int halt = 0;
  
  for(int i = 0; i < Q; i++) {
    int R;
    scanf("%d", &R);
    live[--R] = true;
    if(v[U[R]] != v[V[R]]) {
      if(v[U[R]] > v[V[R]]) swap(U[R], V[R]);
      if(--in[V[R]] == 0) {
        queue< int > que;
        que.push(V[R]);
        while(!que.empty()) {
          int p = que.front(); que.pop();
          ++halt;
          for(auto to : graph[p]) {
            if(live[to.second]) continue;
            if(v[to.first] == v[p] + 1 && --in[to.first] == 0) {
              que.push(to.first);
            }
          }
          v[p] = 114514;
        }
      }    
    }
    printf("%d\n", halt);
  }
}

Measured memory_bytes: 14440
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;

int main() {
	int N, D;
	cin >> N >> D;
	
	vector<vector <int>> X(N, vector<int>(D));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < D; j++) {
			cin >> X[i][j];
		}
	}
	int ans = 0, check = 0;
	double count = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i+1; j < N; j++) {
			for (int k = 0; k < D; k++) {
				ans += (X[j][k] - X[i][k]) * (X[j][k] - X[i][k]);
			}
			count = sqrt(ans);
			if (count == ceil(count)) {
				check++;
			}
			ans = 0;
		}
	}
	
	cout << check << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
#include <climits>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
        // setw(6) << setfill('0')
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << "(" << v.first << ", " << v.second << ")";
    return ostr;
}

int64 powmod(int64 n, int64 count, int64 mod) {
    if (count == 0) return 1;
    if (count % 2 == 0) {
        int64 t = powmod(n, count / 2, mod);
        return t * t % mod;
    }
    return n * powmod(n, count - 1, mod) % mod;
}

int64 ncr(int64 n, int64 r, int64 mod) {
    int64 a;
    if (n < r) a = min(n, r - n);
    else a = min(n - r, r);

    int64 res = 1;
    rep(i, a) {
        res = res * (n - i) % mod;
        res = res * powmod(i + 1, mod - 2, mod) % mod;
    }

    return res;
}

int main() {
    int n; cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];

    vector<int> c(n);
    int _max = *max_element(all(v));
    rep(i, n) c[v[i]]++;

    if (v[0] != 0 || c[0] != 1) {
        cout << 0 << endl;
        exit(0);
    }

    // cout << m << endl;

    int64 ans = 1;
    reps(1, i, _max+1) {
        if (c[i] == 0) {
            cout << 0 << endl;
            exit(0);
        }

        rep(_, c[i]) {
            ans = ans * c[i-1] % 998244353;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  int minnum = 1001, maxnum = -1, a;
  for(int i = 0; i < N; i++) {
    cin >> a;
    minnum = min(a, minnum);
    maxnum = max(a, maxnum);
  }
  cout << maxnum - minnum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  while(n)
  {
      if(n % 10 == 7)
      {
          cout<<"Yes\n";
          return 0;
      }
      n /= 10;
  }
  cout<<"No\n";
  
  return 0;
}

Measured memory_bytes: 3624
// template version 1.6
// {{{ define basic macro
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
// varibable settings
#define int long long
#define INF 1000000000000000000LL
#define MOD 1000000007LL

#define infile "../test/sample-1.in"

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template<class T, size_t N> size_t sza(const T (&array)[N]) { return N; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T=int> T in() {T x; cin>>x; return (x);}
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

int solve(){
  int N,M;cin>>N>>M;
  int a[M]; rep(m, M) {cin>>a[m];}
  int num[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

  int dp[N+1];  // n本で作れる最大桁数
  fill(dp, dp+N+1, -1);
  dp[0] = 0;

  rep(n, 1, N+1){
    rep(m, M){
      if (n-num[a[m]]<0) continue;
      chmax(dp[n], dp[n-num[a[m]]]+1);
    }
  }
  dump_1d(dp, N+1);

  string res = "";
  sort(a, a+M, greater<int>());

  int r = N;
  rep(i, dp[N]){
    rep(m, M){
      if (r-num[a[m]]>=0 && dp[r-num[a[m]]]==dp[r]-1) {
        res += (char)('0'+a[m]);
        r -= num[a[m]];
        break;
      }
    }
  }
  cout << res << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 384
import numpy as np
N,C,K=map(int,input().split())
people = np.zeros(N)

for i in range(N):
    people[i]=int(input())
    
people=np.sort(people)

count=0
ride=C+1
ridetime=0
for i in range(N):
    if ridetime+K>=people[i] and ride<C:
        ride+=1
    else:
        count+=1
        ride=1
        ridetime=people[i]

print(count)
    


Measured memory_bytes: 14008
n = int(input())
s = input()
white = 0
black = 0
for i in range(n):
    if s[i] == ".":
        white += 1
ans = float("inf")
for j in range(n + 1):
    if white + black < ans:
        ans = white + black
    if j == n:
        break
    if s[j] == ".":
        white -= 1
    else:
        black += 1
print(ans)

Measured memory_bytes: 3500
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        System.out.println(a < b && b < c ? "Yes" : "No");
    }
}


Measured memory_bytes: 26260
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 1<<29
#define LLINF 1LL<<60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}
 
ll N, M;
 
int main() {
    cin >> N >> M;
    map<ll, ll> U;
    ll sum = 0, a;
    U[0] = 1;
    REP(i, N) {
        cin >> a; sum += a;
        if(U.find(sum % M) == U.end()) U[sum % M] = 0;
        U[sum % M]++;
    }
    ll ans = 0;
    for (auto u : U) {
        // cerr << u.first << " " << u.second << endl;
        ans += u.second * (u.second - 1) / 2;
    }
    cout << ans << endl;
 	return 0;
}

Measured memory_bytes: 4224
#!/usr/bin/env python

s = input()
p = input()
exists = False

sRing = []
iArray = []

pLetter = p[0]

for i in range(len(s)):
    if s[i] == pLetter:
        iArray.append(i)

for i in iArray:
    sNew = s[i:] + s[:i]
    sRing.append(sNew)
    
for x in sRing:
    if p in x:
        exists = True

if exists == True:
    print("Yes")
else:
    print("No")

    

Measured memory_bytes: 7452
#include <iostream>
#include <cmath>

using namespace std;

const double EPS = 1e-8;

int dcmp(double d) {
    if (fabs(d) < EPS) {
        return 0;
    }
    return d < 0? -1 : 1;
}

struct Vector {
    double x, y;
    Vector(double x=0, double y=0): x(x), y(y){
    }
};

typedef Vector Point;

double dot(const Vector& a, const Vector& b) {
    return a.x * b.x + a.y * b.y;
}

double cross(const Vector& a, const Vector& b) {
    return a.x * b.y - a.y * b.x;
}

Vector operator-(const Vector& a, const Vector& b) {
    return Vector(a.x - b.x, a.y - b.y);
}

int main() {
    Point points[4];
    int q;
    cin >> q;
    for (int kase = 0; kase < q; kase++) {
        for (int i = 0; i < 4; i++) {
            cin >> points[i].x >> points[i].y;
        }
        Vector v1 = points[1] - points[0];
        Vector v2 = points[3] - points[2];

        double c = cross(v1, v2);
        double d = dot(v1, v2);
        
        if (dcmp(d) == 0) {
            cout << 1 << endl;
        }
        else if (dcmp(c) == 0) {
            cout << 2 << endl;
        }
        else {
            cout << 0 << endl;
        }
    }
   
    return 0;
}

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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)

using namespace std;

const int N = 400010;

struct Box{
	int x, y;
}A[N];

struct Node{
	int num, id;

	bool operator < (const Node& B) const{
		return num < B.num;
	}
}B[N];

int n, m;
bool vis[N];

set<int> S;

int main(){
	scanf("%d", &n);
	int Mx = 0, Mn = 1e9;
	For(i, 1, n){
		scanf("%d%d", &A[i].x, &A[i].y);
		if(A[i].y < A[i].x) swap(A[i].x, A[i].y);
		Mx = max(Mx, A[i].y), Mn = min(Mn, A[i].x);
	}

	int xmax = Mn, ymin = Mx;
	For(i, 1, n){
		xmax = max(xmax, A[i].x);
		ymin = min(ymin, A[i].y);
	}
	long long ans1 = 1ll * (xmax - Mn) * (Mx - ymin);
	
	long long ans2 = 1e18;
	For(i, 1, n) B[++m] = (Node){A[i].x, i}, B[++m] = (Node){A[i].y, i}, S.insert(A[i].x);
	sort(B + 1, B + m + 1);
	For(i, 1, m){
		int x = B[i].id;
		ans2 = min(ans2, 1ll * (Mx - Mn) * (*S.rbegin() - B[i].num));
		S.erase(A[x].x), S.insert(A[x].y);
		if(vis[x]) break;
		vis[x] = true;
	}

	printf("%lld\n", min(ans1, ans2));
	return 0;
}

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

#define N_MAX 100002
#define M_MAX 200002

using namespace std;

int n, m;

struct Node
{
    int index;
    int color;
};

bool operator < (const Node &a, const Node &b)
{
    return make_pair(a.index, a.color) < make_pair(b.index, b.color);
}

struct Edge
{
    Node u;
    int cost;
};

map <int, vector <Edge> > edges[N_MAX];

struct Path
{
    Node finish;
    int dist;
};

bool operator < (const Path &a, const Path &b)
{
    return a.dist > b.dist;
}

priority_queue <Path> pq;

set <Node> visited;

vector <Edge> aux;

int main()
{
    cin >> n >> m;
    for(int i = 1; i <= m; i++)
    {
        int u, v, c;
        cin >> u >> v >> c;
        edges[u][c].push_back(Edge{Node{v, c}, 0});
        edges[v][c].push_back(Edge{Node{u, c}, 0});
    }
    for(auto it = edges[1].begin(); it != edges[1].end(); it++)
        pq.push(Path{Node{1, it->first}, 2});
    for(int i = 1; i <= n; i++)
        for(auto it = edges[i].begin(); it != edges[i].end(); it++)
        {
            edges[i][it->first].push_back(Edge{Node{i, 0}, 1});
            edges[i][0].push_back(Edge{Node{i, it->first}, 1});
        }
    while(!pq.empty())
    {
        Path t = pq.top();
        pq.pop();
        if(visited.find(t.finish) != visited.end())
            continue;
        visited.insert(t.finish);
        if(t.finish.index == n && t.finish.color > 0)
        {
            cout << t.dist / 2 << "\n";
            return 0;
        }
        aux = edges[t.finish.index][t.finish.color];
        for(Edge e : aux)
            if(visited.find(e.u) == visited.end())
                pq.push(Path{e.u, t.dist + e.cost});
    }
    cout << "-1\n";
    return 0;
}


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const ll MOD = 1e9+7;

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

	int a, b, c; cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);

	cout << a << ' ' << b << ' ' << c << '\n';

 	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	const int MAX = 101;
	int G[MAX][MAX] = {0};
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int u, d;
		cin >> u >> d;
		for (int j = 1; j <= d; j++)
		{
			int v;
			cin >> v;
			G[u][v] = 1;
		}
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (j != n)
				cout << G[i][j] << " ";
			else
				cout << G[i][j] << endl;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define mn(a,b) (a<b?a:b)
using namespace std;
string s;
int w,l,n,p;
int main()
{
	cin>>s,n=s.size();
	for(int i=0;i<n;i++)
		if(s[i]=='p')p++;
	w=mn(n/2,n-p),l=mn((n+1)/2,p);
	printf("%d\n",w-l),exit(0);
}

Measured memory_bytes: 512
d,n = gets.split.map(&:to_i)


cnt = 0
k = 1

d.times do 
    k *= 100
end
j = 0
m = k
while k != 0
    cnt += 1
    if cnt == n
        j = k
        break
    end
    k += m
end
puts j % (m * 100) == 0 ? j + m : j

Measured memory_bytes: 1788
/********************
=====================
**Code By-hardikdua**
=====================
*********************/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define vec vector
#define psb push_back
#define fst first
#define scd second
#define ins insert
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
int n,ut,va;
vector<vector<int>>g(100010);
vector<int>depth(100010),mxd(100010),par(100010);
void dfs(int v,int p) 
{
    par[v]=p;
    for(auto u : g[v])
        if (u!=p) 
		{
            depth[u]=depth[v]+1;
            dfs(u,v);
            mxd[v]=max(mxd[u]+1,mxd[v]);
        }
}
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);cin >> n >> ut >> va;
    rep(i,1,n) 
	{
        int a,b;
        cin>>a>>b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    dfs(va,-1);
    ll ans=(depth[ut]-1)/2;
    ll x=depth[ut];
    rep(i,0,ans) 
		ut=par[ut];
    cout<<ans+mxd[ut]+(x-1)%2<<'\n';
	return 0;
}

Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ar array
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int x, y;
  cin >> x >> y;
  for(int i=0; i<=x; i++) {
    if(((x-i)*2)+(i*4)==y){
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i <= n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

int main(){
  ll X;
  ll price;
  ll year;
  cin >> X;

  price = 100;
  year=0;
  while(1){
   if(price>=X){
     break;
   }
   price=price*1.01;
   year++;
  }
  cout << year << endl;
  return 0;
}


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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>

 

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

#define ic(n) int (n); cin>>(n);

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> P;






int main(){


	  
int one,two,three;//条件1,2,3条件を満たしていれば値を0に
	  one = 0 ; two = 0 ; three = 0;
	 ic(n);ic(m);ic(x);ic(y); 
	 int Z;
		 vector<int> X(n);
	 vector<int> Y(m);
	 rep(i,n){
		 cin>>X[i];
	   }
	 rep(i,m){
		 cin>>Y[i];
	   }
	   //次に条件2、条件3を確かめるために、XのMとYのmをとる。
	 SORT(X);SORT(Y);
	 int Max=X[n-1];
	 //ch(Max,"Max");
	 int Min=Y[0];
	 Z=Min;
	 ///ch(Min,"Min");
	 //まずは条件1を確かめる
	 if(x<Z&&Z<=y){
		 one = 1;
	   }

	 if(Max<Z){
		 two = 1;
	   }
	 if(Z>x){
		 three = 1 ;
	   }
	 if(1== one && 1==two && 1 == three){
	   cout << "No War"<<endl;
	   }
	 else{
		 cout << "War"<<endl;
	   }

}


	


Measured memory_bytes: 256
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
using namespace std;
bool my_compare(pair<ll, ll> a, pair<ll , ll> b) {
    // 基本はfirstで比較
    if(a.first != b.first){
         return a.first < b.first; // 昇順
        //return a.first > b.first; // 降順
    }

    // それ以外はsecondで比較
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        // どちらも同じ
        return true;
    }
}

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

    ll a,b,c,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>n>>m;
    vector<pair<ll,ll>> p(n);

    rep(i,n) {
        cin>>a>>b;
        p[i]=make_pair(a,b);
    }
    sort(p.begin(),p.end());
    ll d=0;
    ll mem;
    rep(i,n){
        sum+=p[i].first*p[i].second;
        d+=p[i].second;
        mem=i;
        if(d>=m) break;
    }
    sum-=(d-m)*p[mem].first;
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>
#include <sstream>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#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 chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

int main(){
    int H,W;
    cin >> H >> W;
    vector<string> C(H);

    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            char a;
            cin >> a;
            C.at(i) += a;
        }
    }

    for(int i = 0;i < H+2;i++){
        for(int j = 0;j < W+2;j++){
            if(i == 0 or i == H+1)
                cout << "#";
            else if(j == 0 or j == W+1)
                cout << "#";
            else
                cout << C.at(i-1).at(j-1);
        }
        cout << endl;
    }


    return 0;

}





    

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

int main(){
    int n;
    cin >> n;
    set<char> st;
    char tmp;
    for(int i = 0;i < n;i++){
        cin >> tmp;
        st.insert(tmp);
    }
    if(st.size() == 4){
        cout << "Four" << endl;
    }else{
        cout << "Three" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

int cnt[MAXSIZE];
int a[MAXSIZE];
int32_t main(){
	fastio();
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		cnt[a[i]]++;
	}
	int ans = 0;
	for(int i=1;i<=n;i++){
		bool ok = true;
		cnt[a[i]]--;
		for(int j=1;j*j<=a[i];j++){
			if(a[i]%j==0){
				if(cnt[j]||cnt[a[i]/j]){
					ok = false;
					break;
				}
			}
		}

		ans+=ok;
		cnt[a[i]]++;
	}
	cout<<ans;
}

Measured memory_bytes: 12840
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int i = 0;i < (int)(n);i++)

int main() {
char a[10];
REP(i,9){
cin >> a[i];
}
cout << a[0] << a[4] << a[8];
return(0);
}


Measured memory_bytes: 256
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define allr(v) v.begin(),v.end()
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
// #define pi 3.1415926535897932384626433832
#define mod 1000000007
//#define mod 998244353
#define inf 1000000000
#define pr1(a) cout << a << endl
#define pr2(a,b)cout << a <<  " " <<b<< endl
#define pr3(a,b,c) cout << a <<" " << b << " " << c << endl

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

int gcd(int a, int b){
    if(b==0)return a;
    return gcd(b,a%b);
}

vector<int> prefix_function(string s) {
    int n = (int)s.length();
    vector<int> pi(n);
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        //we will try to shorten the match string length until we revert to the beginning of match (index 1)
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
    return pi;
}
void solve(){

    int l,r,d;
    cin >> l >> r >> d;

    int ll = l/d;
    int rr = r/d;

    int ans = rr-ll;

    if(l%d==0 && r%d==0)ans++;
    cout << ans << endl;
} 

signed main() 
{   
    IOS;
    int t = 1;
    // cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


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

int n, m, dp[(int)1e5 + 1][2];
string str;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m >> str;
    reverse(str.begin(), str.end());
    set<pair<int, int>, decltype(&comp)> opt(&comp);
    dp[0][0] = 0, dp[0][1] = 0, opt.insert({0, 0});
	for(int i = 1; i <= n; i++){
		if(str[i] != '1'){
			if(!opt.size()){
				cout << "-1\n";
				return 0;
			}
			dp[i][0] = opt.begin() -> first + 1, dp[i][1] = opt.begin() -> second;
			opt.insert({dp[i][0], i});
		}
		if(i - m > -1) opt.erase({dp[i - m][0], i - m});
	}
	vector<int> mvs;
	int i = n;
	while(i > 0) mvs.push_back(i - dp[i][1]), i = dp[i][1];
	for(i = 0; i < (int)mvs.size() - 1; i++) cout << mvs[i] << " ";
	cout << mvs[(int)mvs.size() - 1] << "\n";
	return 0;
}

Measured memory_bytes: 3712
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: i32 = read();
    let v: Vec<usize> = read_vec();

    let mut four_count = 0;
    let mut two_count = 0;
    for elem in v {
        if elem % 4 == 0 {
            four_count += 1;
        } else if elem % 2 == 0 {
            two_count += 1;
        }
    }
    if two_count + four_count * 2 >= n {
        println!("Yes");
    } else if two_count == 0 && 2 * four_count + 1 >= n {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 8444
#![allow(unused_imports)]
#![allow(dead_code)]

use std::thread;
use std::io::{ self, Read };
use std::fmt;
use std::iter::Iterator;
use std::cmp::*;
use std::collections::*;
use std::str::*;

#[derive(Default)]
struct Input {
    buf: Vec<String>
}

impl Input {
    fn new() -> Input {
        Input { buf: Vec::new() }
    }

    fn read<T: FromStr>(&mut self) -> T 
    where <T as FromStr>::Err: fmt::Debug {
        self.next().unwrap().parse::<T>().unwrap()
    }

    fn read_bytes(&mut self) -> Vec<u8> {
        self.next().unwrap().into_bytes()
    }

    fn read_n<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where <T as FromStr>::Err: fmt::Debug {
        let mut v = Vec::new();
        for _ in 0..n { v.push(self.read::<T>()); }
        v
    }
}

impl Iterator for Input {
    type Item = String;
    fn next(&mut self) -> Option<String> {
        while self.buf.is_empty() {
            let mut s = String::new();
            let _res = io::stdin().read_line(&mut s);
            self.buf = s.split_whitespace().map(|s| s.to_owned()).collect::<Vec<_>>();
            self.buf.reverse();
        }
        self.buf.pop()
    }
}

fn f(x: i64) -> i64 {
    if x == 0 { 0 } else { 1 + f(x / 10) }
}

fn run() {
    let mut ip = Input::new();
    let n = ip.read::<i64>();
    let s = (n as f64).sqrt();
    let mut y = 1i64 << 40;
    for x in 1..(s as i64) + 1 {
        if n % x == 0 {
            y = min(y, max(x, n / x));
        }
    }

    println!("{}", f(y));
}

fn main() {
    let _ = thread::Builder::new()
        .stack_size(10 * 1024 * 1024)
        .spawn(run).unwrap()
        .join();
}

Measured memory_bytes: 8572
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<queue>



using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int INF=1001001001;



int main(){
	while(1){
		vector<pair<int,int> > edge[102];//[?§????] <??????????????????>
		int N,K;
		int map[102];//????????°????????????????????¢
		scanf("%d %d",&N,&K);
		if(N==0&&K==0)break;
		rep(i,K){
			int type;
			scanf("%d",&type);
			if(type==0){//??¨????\¨
				int s,g;
				scanf("%d %d",&s,&g);
				s--;g--;
				priority_queue< pair<int,int>, vector< pair<int,int> >, greater< pair<int,int> > > q;
				rep(i,N)map[i]=INF;
				map[s]=0;
				q.push( make_pair(0,s) );
				while(!q.empty()){
					pair<int,int> p=q.top();
					q.pop();
					int c=p.second;
					if(map[c]<p.first) continue;
					rep(i,edge[c].size()){
						pair<int,int> e=edge[c][i];
						if(map[e.first]>map[c]+e.second){
							map[e.first]=map[c]+e.second;
							q.push( make_pair(map[e.first],e.first));
						}
					}
				}
				if(map[g]==INF)map[g]=-1;
				printf("%d\n",map[g]);
			}else{
				int a,b,c;
				scanf("%d %d %d",&a,&b,&c);
				a--;b--;
				edge[a].push_back(make_pair(b,c));
				edge[b].push_back(make_pair(a,c));
			}
		}
	}
}

Measured memory_bytes: 1068
#include <bits/stdc++.h>
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,zero,b)
#define ALL(c) c.begin(),c.end()
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int LL
#define zero 0LL
using namespace std;
template<typename T> inline void maximize(T &a,T b){a=max(a,b);}
template<typename T> inline void minimize(T &a,T b){a=min(a,b);}
template<typename T> inline bool middle(T a,T b,T c){return b<=a && a<=c;}
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
inline void outputVI(VI x){REP(i,SI(x)){cout << three(i," ","") << x[i];}OUT("");}
const int SIZE=1e6+1000;
const int SIZE2=5010;
const int SIZE3=400;
const LL p=7+1e9;
const LL INF=1LL<<60;
const long double EPS=1e-7;
string S;
ut N,M,K,X,L,W,H;
// ut A,B,C,D,E,F,G,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE],nums[SIZE],maps[SIZE2][SIZE2],answer=zero;

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

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

LL solve(){
	cin >> N >> K;
	VI A;
	REP(i,N){

		int x;
		cin >> x;
		A.PB(x);
	}
	sort(ALL(A));
	VI B;
	int now=0;
	REP(i,N){
		now++;
		if(i==N-1 || A[i]!=A[i+1]){
			B.PB(now);
			now=0;
		}
	}
	sort(ALL(B),greater<LL>());
	while(SI(B)>K){
		answer+=B.back();
		B.pop_back();
	}
	return answer;
}
signed main(){
	OUT(solve());
//	solve();
	return 0;
}

Measured memory_bytes: 29168
#include<bits/stdc++.h>
using namespace std;
string K;
int D;
int mod=1e9+7;
vector<vector<vector<int>>>dp;
int f(int i,long long sum,bool check)
{
    if(i==K.size())
    {
        if(sum==0)
        {
            return 1;
        }
        return 0;
    }
    if(dp[i][sum][check]!=-1)
        return dp[i][sum][check];
    int lmt=9;
    if(check)
    {
        lmt=K[i]-'0';
    }
    long long ans=0;
    for(int d=0;d<=lmt;d++)
    {
        if(check&&(d==lmt))
            ans=(ans+f(i+1,(sum+d)%D,true))%mod;
        else ans=(ans+f(i+1,(sum+d)%D,false))%mod;
    }
    return dp[i][sum][check]=ans;
}

int main(){
    cin>>K;
    cin>>D;
    dp.resize(K.size()+1,vector<vector<int>>(D+1,vector<int>(2,-1)));
    int ans=f(0,0,true);
    ans--;
    if(ans==-1)
        cout<<mod-1;
    else cout<<ans;
}


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

int CalcPoint(int P, int R, int S, char c) {
	switch (c) {
	case 'r':
		return P;
	case 's':
		return R;
	case 'p':
		return S;
	}
}

int main() {
	int N, K, R, S, P;
	cin >> N >> K >> R >> S >> P;
	string T;
	cin >> T;
	int point = 0;
	for (int i = 0; i < K; i++) {
		int j = i;
		int renzoku = 1;
		while (j < N) {
			if (j + K < N) {
				if (T[j] == T[j + K]) renzoku++;
				else {
					point += (renzoku + 1) / 2 * CalcPoint(P, R, S, T[j]);
					renzoku = 1;
				}
			}
			else point += (renzoku + 1) / 2 * CalcPoint(P, R, S, T[j]);
			j += K;
		}

	}
	cout << point << endl;
}


Measured memory_bytes: 512
import math
n = int(input())
s = [0 if i == "W" else 1 for i in list(input())]
cnt = 0
c = 1
for i in range(n * 2):
    if (s[i] + cnt) % 2 != 0:
        cnt += 1
    else:
        c = (c * (cnt if cnt != 0 else 1)) % (10 ** 9 + 7)
        cnt -= 1
    if cnt < 0:
        print(0)
        exit()
if cnt != 0:
    print(0)
else:
    print((c * math.factorial(n)) % (10 ** 9 + 7))

Measured memory_bytes: 61552
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(), (x).rend()
#define pll pair<long long, long long>
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
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;}
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin >> n;
  ll count=0;
  rep(i,n){
    ll d1;
    ll d2;
    cin>>d1>>d2;
    if(d1==d2) count++;
    else count=0;
    if(count==3){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn=1e5+5;
int a[150000];
int n,k;
int judge(int s)
{
    while(s!=0)
    {
        if(a[s%10])
            return 0;
        s/=10;
    }
    return 1;
}
int main()
{
    cin>>n>>k;
    for(int i=1;i<=k;i++)
    {
        int aa;
        cin>>aa;
        a[aa]++;
    }
    int s;
    for(int i=n;;i++)
    {
        if(judge(i))
        {
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
/// 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 long long ll;
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 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
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
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;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

 
string s;

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
	
	int n;
	cin >> n;
	cin >> s;
	int ans = 1;
	for(int i=1;i<n;i++){
		if(s[i]!=s[i-1])ans++;
	}        
	cout << ans << endl;


return 0;
}
///....


Measured memory_bytes: 512
//#include<bits/stdc++.h>	// 全てのヘッダーファイルをinclude
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<utility>	// wrap,pair
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR (i,n) for(int i=n;i>0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
const int MOD{ int(1e9 + 7) };	// int 1000000007
const int inf{ int(1e9) };	// inf = 1000000000 // 1e9 はdouble型
using namespace std;
typedef long long ll;

// 最大公約数（ユークリッドの互除法）
int GCD(int x, int y) {
	if (x > y) {
		swap(x, y);
	}
	int r = y % x;
	while (r != 0) {
		y = x;
		x = r;
		r = y % x;
	}
	return x;
}

// 最小公倍数
int LCM(int x, int y) {
	ll gcd = GCD(x, y);
	return x * y / gcd;
}

// 素数判定(素数ならtrue,合成数ならfalse)
bool IsPrime(int num) {
	if (num < 2) return false; // 0,1
	else if (num == 2) return true;	// 2
	else if (num % 2 == 0) return false; // 偶数

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false; // 割り切れたら素数ではない
	}
	return true; // 全部通ったら素数
}

// pairをsecond基準で昇順sort
// sort(vector_name.begin(),vector_name.end(),compare_by_b);
bool compare_by_b(pair<int, int>a, pair<int, int>b) {
	if (a.second != b.second) return a.second < b.second;
	else return a.first < b.first;
}

// 桁数を返す：unsigned(-の値をとらない)
unsigned Digit(unsigned num) {
	return log10(num) + 1;
}

// ----------------------------------------------------------------

int main(void) {

	ll L, R;
	cin >> L >> R;
	ll h = R - L;

	if (h >= 2019) {
		cout << 0 << endl;
	}
	else {
		ll tmp = inf;
		for (ll i = L; i < R; i++) {
			for (ll j = i + 1; j <= R; j++) {
				tmp = min(tmp, (i % 2019)*(j % 2019) % 2019);
				if (tmp == 0) break;
			}
		}
		cout << tmp << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
#define int long long int
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
lli dp[1005][1 << 13] = {};
signed main()
{
  int n, m;
  cin >> n >> m;
  vector<lli> a(m), b(m);
  vector<lli> c(m);
  rep(i, 1005) rep(j, 1 << n) dp[i][j] = 1e18;
  rep(i, m)
  {
    cin >> a[i] >> b[i];
    rep(j, b[i])
    {
      int t;
      cin >> t;
      t--;
      c[i] |= 1 << t;
    }
  }
  dp[0][0] = 0;
  rep(i, m) rep(j, 1 << n)
  {
    chmin(dp[i + 1][j], dp[i][j]);
    chmin(dp[i + 1][j | c[i]], dp[i][j] + a[i]);
  }
  cout << (dp[m][(1 << n) - 1] < 1e9 ? dp[m][(1 << n) - 1] : -1) << endl;
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}


Measured memory_bytes: 63360
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

typedef long long ll;

ll dp[1000000 + 100][2];

int main() {
	string s;
	cin >> s;
	reverse(s.begin(), s.end());

	for (int i = 0; i <= 1000000 + 10; i++)dp[i][0] = 1145141919810, dp[i][1] = 1145141919810;
	dp[0][0] = 0;
	for (int i = 0; i < s.size(); i++) {
		for (int j = 0; j < 2; j++) {
			if (dp[i][j] == 1145141919810)continue;
			dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + (10 - (s[i] - '0' + j)));
			if (s[i] - '0' + j <= 9)dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + (s[i] - '0' + j));
		}
	}
	cout << min(dp[s.size()][0], dp[s.size()][1] + 1) << endl;
	return 0;
}

Measured memory_bytes: 17012
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//
        int a, b, c, k;
        cin >> a >> b >> c >> k;

        int res = max({a, b, c});
        for (int i = 0; i < k; i++)
        {
                res *= 2;
        }

        cout << res+a+b+c-max({a,b,c}) << endl;

        return 0;
}


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

int main(){
  int N;
  cin >> N;
  if(N<400) cout << "8" <<endl;
  else if(N<600) cout << "8" << endl;
  else if(N<800) cout << "7" << endl;
  else if(N<1000) cout << "6" << endl;
  else if(N<1200) cout << "5" << endl;
  else if(N<1400) cout << "4" << endl;
  else if(N<1600) cout << "3" << endl;
  else if(N<1800) cout << "2" << endl;
  else cout << "1" << endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> b(n-1);
  for(int i=0; i<n-1; i++){
    cin >> b.at(i);
  }
  int ans=0;
  ans += b.at(0);
  ans += b.at(n-2);
  for(int i=0; i<n-2; i++){
    ans += min(b.at(i), b.at(i+1));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#coding: UTF-8
import sys

H, W = map(int, input().split())
table = [[0]*(W+1) for i in range(H+1)]
# list = [[0 for i in range(W+1)] for j in range(H+1)]

for row in range(H):
    pre_table = list(map(int, input().split()))
    for col in range(W):
        table[row][col] = pre_table[col]

for row in range(H):
    for col in range(W):
        table[row][W] += table[row][col]

for col in range(W+1):
    for row in range(H):
        table[H][col] += table[row][col]

for row in range(H+1):
    print("%d"%(table[row][0]), end="")
    for col in range(1, W+1):
        print(" %d"%(table[row][col]), end = "")
    print()


Measured memory_bytes: 6252
#include <stdio.h>
#include <stdlib.h>

int main(){
	int n;
	int *R = NULL;
	int i,j;
	int max = - 1000000000;
	int min;
	int temp;
	scanf("%d",&n);
	R = (int *)malloc(4*n);
	for(i=0;i<n;i++){
		scanf("%d",&R[i]);
	}
	min = R[0];
	for(j=1;j<n;j++){
		temp = R[j] - min;
		if(temp > max){
			max = temp;
		}
		if(R[j] < min){
			min = R[j];
		}
	}
	printf("%d\n",max);
	free(R);
	return 0;
}

Measured memory_bytes: 1152
#include<cstdio>
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a==b&&a!=c||a==c&&a!=b||c==b&&c!=a)
	printf("Yes\n");
	else
	printf("No\n");
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25


int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> s(h, vector<int>(w));
    rep(i, h){
        rep(j, w){
            char t; cin >> t;
            if(t == '.'){
                s[i][j] = 0;
            }else{
                s[i][j] = 1;
            }
        }
    }
    vector<vector<int>> l(h, vector<int>(w)), r(h, vector<int>(w)), u(h, vector<int>(w)), d(h, vector<int>(w));
    rep(i, h){
        rep(j, w){
            if(s[i][j] == 1){
                l[i][j] = 0;
                u[i][j] = 0;
            }else{
                if(j == 0){
                    l[i][j] = 1;
                }else{
                    l[i][j] = l[i][j-1] + 1;
                }
                if(i == 0){
                    u[i][j] = 1;
                }else{
                    u[i][j] = u[i-1][j] + 1;
                }
            }
        }
    }
    for(int i = h-1; i >= 0; i--){
        for(int j = w-1; j >= 0; j--){
            if(s[i][j] == 1){
                r[i][j] = 0;
                d[i][j] = 0;
            }else{
                if(j == w-1){
                    r[i][j] = 1;
                }else{
                    r[i][j] = r[i][j+1] + 1;
                }
                if(i == h-1){
                    d[i][j] = 1;
                }else{
                    d[i][j] = d[i+1][j] + 1;
                }
            }
        }
    }
    int ans = 0;
    rep(i, h){
        rep(j, w){
            ans = max(ans, l[i][j]+r[i][j]+u[i][j]+d[i][j]-3);
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 78720
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;

int main(){
    int n; cin >>n;
    vector< vector<int> > v(n, vector<int>());
    REP(i, n){
        int s, nn; cin >>s >>nn; s--;
        REP(j, nn){
            int e; cin >>e; e--;
            v[s].push_back(e);
        }
    }

    int c; cin >>c;
    REP(i, c){
        int s, e, t; cin >>s >>e >>t; s--; e--;
        queue<P> open;
        open.push( P(s, t) );
        vector<int> closed(n, -1);

        while(!open.empty()){
            P now = open.front(); open.pop();
            int place = now.first, ttl = now.second;
            if(ttl <= 0 || ttl <= closed[place]) continue;
            closed[place] = ttl;
            int s = v[place].size();
            REP(i, s) open.push( P(v[place][i], ttl - 1) );
        }
        if(closed[e] == -1) cout <<"NA" <<endl;
        else cout <<t - closed[e] + 1 <<endl;
    }
    return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >>s;
    bool a=true,b=true;
    set<string> se;
    // s.insert({"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "12"});
    se.insert("01");
    se.insert("02");
    se.insert("03");
    se.insert("04");
    se.insert("05");
    se.insert("06");
    se.insert("07");
    se.insert("08");
    se.insert("09");
    se.insert("10");
    se.insert("11");
    se.insert("12");
    if(se.count(s.substr(0,2))==0) a=false;
    if (se.count(s.substr(2,2))==0) b=false;
    if(a && b) cout << "AMBIGUOUS" << endl;
    else if(b) cout << "YYMM" << endl;
    else if(a) cout << "MMYY" << endl;
    else cout << "NA" << endl;

    return 0;
}

Measured memory_bytes: 256