akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}

vector<vector<int>>g;
vector<ll>ans;
void dfs(int v,int p = -1) {
    for(int u :g[v]) {
        if(u==p) continue;
        ans[u] += ans[v];
        dfs(u,v);
    }
}
int main() {
    int n,q;
    cin >> n >> q;
    g.resize(n);
    ans.resize(n);
    rep(i,n-1) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep(i,q) {
        int p,x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }
    dfs(0);
    rep(i,n) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 24320
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
counter = 0
for i in range(N):
    counter += min(A[i],B[i])
    if B[i]>A[i]:
        remain = B[i] - A[i]
        counter += min(A[i+1],remain)
        A[i+1] -= remain
        if A[i+1] < 0:
            A[i+1] = 0
print(counter)

Measured memory_bytes: 82020
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, K,W, H, Q, X, Y;
  ll ans;
  string S, T;
  cin >> N;
  vector<string> w;
  rep(i, N){
    cin >> S;
    w.push_back(S);
  }
  rep(i, N-1){
    if (w[i][w[i].length()-1] != w[i+1][0]){
      cout << "No" << endl;
      return 0;
    }
  }
  rep(i, N-1){
    rep_s(j, i+1, N){
      if (w[i] == w[j]){
        cout <<"No" << endl;
        return 0;  
      }
    }
  }
  cout <<"Yes" << endl;
  return 0;
  
}


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

ll d[200001];
int main() {
	int n; scanf("%d", &n);
	unordered_map<ll, vector<int>>mp;
	mp[0].push_back(0);
	rep(i, n) {
		scanf("%lld", &d[i + 1]);
		d[i + 1] += d[i];
		mp[d[i + 1]].push_back(i + 1);
	}
	int Max = 0;
	for (auto&p : mp) {
		Max = max(Max, *p.second.rbegin() - *p.second.begin());
	}
	printf("%d\n", Max);
}

Measured memory_bytes: 22028
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int N; cin >> N;
    vi A(N - 1), B(N - 1), C(N - 1);
    REP(i,N-1){
        cin >> A[i] >> B[i] >> C[i];
        A[i]--; B[i]--;
    }
    int Q, K; cin >> Q >> K;
    K--;
    vi X(Q), Y(Q); 
    REP(i,Q){
        cin >> X[i] >> Y[i];
        X[i]--; Y[i]--;
    }

    vvi es(N);
    map<pii, int> cost;
    REP(i,N-1) {
        es[A[i]].push_back(B[i]);
        cost[pii(A[i], B[i])] = C[i];
        es[B[i]].push_back(A[i]);
        cost[pii(B[i], A[i])] = C[i];
    }

    queue<int> que;
    que.push(K);
    vb vis(N, false);
    vl dist(N, LINF);
    dist[K] = 0;
    while(!que.empty()) {
        int x = que.front(); que.pop();
        vis[x] = true;

        for(int nx : es[x]) {
            if (vis[nx]) continue;

            dist[nx] = min(dist[nx], dist[x] + cost[pii(x, nx)]);
            que.push(nx);
        }
    }

    REP(i,Q) {
        ll ans = dist[X[i]] + dist[Y[i]];
        cout << ans << endl;
    }

    return 0;
}

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

int main() {

	string a, b;
	cin >> a >> b;

	if (a == "H")
		cout << b << endl;
	else {
		if (b == "H")
			cout << "D" << endl;
		else
			cout << "H" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))
J = [list(map(int, input().split())) for _ in range(M)]

res = {}
for n in range(1, N+1):
    res[n] = True

for j in J:
    n1 = j[0]
    n2 = j[1]
    h1 = H[n1-1]
    h2 = H[n2-1]
    if h1 < h2:
        if res[n1]:
            res[n1] = False
    elif h2 < h1:
        if res[n2]:
            res[n2] = False
    else:
        if res[n1]:
            res[n1] = False
        if res[n2]:
            res[n2] = False

l = 0
for v in res.values():
    if v:
        l+=1
print(l)


Measured memory_bytes: 42668
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		char c = in.readLine().charAt(0);
		++c;
		System.out.println(c);
	}


	void calc() {
	}

	void showResult() {
	}
}


Measured memory_bytes: 19924
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

int kaibun(string s){
    rep(i,s.size()){
        if(s[i] != *(s.end()-i-1))return 0;
    }

    return 1;
}


void solve() {
    ll a, b, c, d, e , m, n, k, x, y, l,r, h, w;
    string s, t;
    ll ans = 0;
    double dans = 0;
    string sans = "Yes";
    vector<ll> ar;
    vector<string> sr;
    vector<vector<char>> arr;

    int ch;
    cin >> s;

    int _a = kaibun(s);
    int _b = kaibun(s.substr(0,((s.size()-1)/2)));
    int _c =  kaibun(s.substr(((s.size()+3)/2)-1));


    ch = _a * _b * _c;
    if(ch==1)sans = "Yes";
    else sans = "No";


    // std::cout << ans << endl;

    std::cout << sans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

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

using namespace std;

int main()
{
    //system("chcp 65001");

    char S[3];
    int i,ans = 700;
    for(i = 0;i <= 2;i++)
    {
        cin >> S[i];
        if(S[i] == 'o')
        {
            ans += 100;
        }
    }

    cout << ans;

    return 0;
}

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

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

  long long cap = 1001001001001001;
  for (int i = 0; i < 5; i++) {
    long long c; cin >> c;
    cap = min(cap, c);
  }
  cout << (n + cap - 1) / cap + 4 << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
const int MODU = 1e9+7;
const int N = 1e5+10;
 
void solve() {
		
}
 
int main() {
	const double PI = 2*3.1415926;
	cout << setprecision(12);
	int r;
	cin >> r;
	cout << PI * r << endl; 
	return 0;
}

Measured memory_bytes: 3784
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int n; cin >> n;
    vector<LL> a(n);
    REP(i,n) cin >> a[i];

    LL cost1 = 0, cost2 = 0;
    LL sum1 = 0, sum2 = 0;

    dump("pnp")

    REP(i,n)
    {
        if(i % 2 == 0)
        {
            if(sum1 +a[i] <= 0)
            {
                cost1 +=  -1 * (sum1 + a[i]) + 1;
                sum1 = 1;
            }
            else
            {
                sum1 += a[i];
            }

        }
        else
        {
            if(sum1 + a[i] >= 0)
            {
                cost1 += sum1 + a[i] + 1;
                sum1 = -1;
            }
            else
            {
                sum1 += a[i];
            }
        }

        dump(sum1)
        dump(cost1)
    }

    dump("npn")

    REP(i,n)
    {
        if(i % 2 != 0)
        {
            if(sum2 +a[i] <= 0)
            {
                cost2 +=  -1 * (sum2 + a[i]) + 1;
                sum2 = 1;
            }
            else
            {
                sum2 += a[i];
            }

        }
        else
        {
            if(sum2 + a[i] >= 0)
            {
                cost2 += sum2 + a[i] + 1;
                sum2 = -1;
            }
            else
            {
                sum2 += a[i];
            }
        }
        dump(cost2)
    }

    cout << min(cost1,cost2) << endl;



}


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

use itertools::Itertools;
use proconio::*;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let s: String = read!();
    let t: String = read!();

    let s = s.chars().collect_vec();
    let t = t.chars().collect_vec();

    let mut ans = U_INF;

    for i in 0..s.len() {
        let s = &s[i..];
        if s.len() < t.len() {
            break;
        }

        let mut tmp = 0;

        for j in 0..t.len() {
            if s[j] != t[j] {
                tmp += 1;
            }
        }

        ans = (ans).min(tmp)
    }

    println!("{}", ans);
}


Measured memory_bytes: 2168
#coding:utf-8
 
import heapq
 
N, M = map(int, input().split())
invA = []
for a in map(int, input().split()):
    heapq.heappush(invA, -1*a)
for m in range(M):
    heapq.heappush(invA, heapq.heappop(invA)/2)
total = -1*sum(map(int, invA))
 
print(total)

Measured memory_bytes: 14180
// #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(), c_end=c.end(); it!=c_end; ++it)

// ------------------- include, typedef, define END. -------------------

void solve(double time500, double time1000){
	pair<double, double> timeList[7] = {
		MP(35.50,71.00),MP(37.50,77.00),MP(40.00,83.00),MP(43.00,89.00),
		MP(50.00,105.00),MP(55.00,116.00),MP(70.00,148.00)};
	string rank[7] = { "AAA", "AA", "A", "B", "C", "D", "E" };
	for (int i = 0; i < 7; i++){
		if (time500 < timeList[i].first && time1000 < timeList[i].second){
			cout << rank[i] << endl;
			return;
		}
	}
	cout << "NA" << endl;
	return;
}

int main(){
	double time500 = 0.0, time1000 = 0.0;
	while (cin >> time500 >> time1000){
		solve(time500, time1000);
	}
	return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int a,b,c,k,s,ans=0;
    cin>>k>>s;
    for(a=0;a<=k;a++)
        for(b=0;b<=k;b++)
        {
            c=s-a-b;
            if(c>=0 && a+b+c==s && c<=k)ans++;
        }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
ll r,g,b;
cin >> r >> g >> b;
cout << ((100 * r + 10 * g + b) % 4 == 0 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>

using namespace std;

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

  vector<int> a(m);
  vector<int> pri(50001,1000000000);

  for(int i=0;i<m;i++){
    cin>>a[i];
    pri[a[i]]=1;
    if(n == a[i]){
      cout << 1 << endl;
      return 0;
    }
  }
  int ans=1;
  int a_max=*max_element(a.begin(),a.end());
  while( 1 ){
    for(int i=0;i<m;i++){

      for(int j=1;j<=ans*(a_max) && j<=50000;j++){
        if(a[i]+j > 50000) break;
        if( pri[j] == ans ){
          //cout << "a[i]:" << a[i] << ", j:" << j << endl;
          if( pri[ a[i]+j ] > 1 + pri[j] ){
            pri[ a[i]+j ] = 1 + pri[j];
          }
          if( a[i]+j == n){
            cout << pri[ a[i]+j ] << endl;
            return 0;
          }
        }


      }

    }
    ans++;
    //cout << ans << endl;
  }



  return 0;
}



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

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

  double ans = l*l*l /27;

  cout << fixed << setprecision(12) << (double) l*l*l/27;

  return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
visited = [0]
for _ in range(n):
    now = a[visited[-1]]-1
    visited.append(now)

if k < n:
    print(visited[k]+1)
else:
    p = visited.index(visited[-1])
    loop = visited[::-1][1:].index(visited[-1])+1
    x = (k-p-1)%loop
    print(visited[p+x+1]+1)


Measured memory_bytes: 32332
import java.nio.Buffer;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Vector;

public class Main {
    public static Scanner r=new Scanner(System.in);
    public static void main(String[] args) {
        int n=r.nextInt();
        long sum=0;
        long cur=0;
        for(int i=1;i<=n;++i){
            cur+=i;
            sum+=cur;
        }
        for(int i=0;i<n-1;++i){
            int x,y;
            x=r.nextInt()-1;
            y=r.nextInt()-1;
            int a=Math.min(x,y);
            int b=Math.max(x,y);
            sum-=(a+1)*(long)(n-b);
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 50256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
ll n,x;
vector<ll> y;

ll gcd(ll n, ll m){
    if(m<n)return gcd(m,n);
    ll r;
    while(r=n%m){
        n=m;
        m=r;
    }
    return m;
}

int main(void) {
    cin >> n >> x;
    rep(i,n){
        ll tmp;
        cin >> tmp;
        y.push_back(tmp);
    }
    y.push_back(x);
    sort(y.begin(),y.end());
    ll res=y[1]-y[0];
    for(int i=2;i<n+1;i++){
        res = gcd(res,y[i]-y[i-1]);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1400
import sys

N = int(sys.stdin.readline())
vlist = sorted(list(map(int, sys.stdin.readline().split())))

for i in range(0, N-1):
  newv = (vlist[0] + vlist[1])/2
  del vlist[:2]
  vlist = sorted([newv] + vlist)
  
print(vlist[0])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
 
const i64 MOD = 1e9 + 7;
 
int main()
{
  i64 n;
  cin >> n;
  vector<i64> a(n);
  for (i64 i = 0; i < n; i++)
    cin >> a[i];
  i64 ans = 0, bit = 1;
  for (i64 i = 0; i < 60; i++)
  {
    i64 cnt[2] = {};
    for (i64 j = 0; j < n; j++)
      if (a[j] & (1LL << i))
        cnt[1]++;
      else
        cnt[0]++;
    (ans += (cnt[0] * cnt[1]) % MOD * bit % MOD) %= MOD;
    (bit *= 2) %= MOD;
  }
  cout << ans << endl;
  return 0;
}

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


int main(){
  int H,W;
  cin >> H >> W;

  string Canvas[H+1];
  for(int i=0;i<H;i++){cin >> Canvas[i];}

  bool ans = true;
  char u,d,l,r;
  for(int y=0;y<H;y++)for(int x=0;x<W;x++){
    x==0 ? l='.' : l=Canvas[y][x-1];
    x==W ? r='.' : r=Canvas[y][x+1];
    y==0 ? u='.' : u=Canvas[y-1][x];
    y==H ? d='.' : d=Canvas[y+1][x];
    if(Canvas[y][x]=='#'){
      if(l=='.' && r=='.' && u=='.' && d=='.'){
        ans=false;
        break;
        }
    }
  }
  //for(int i=0;i<H;i++){cout<<Canvas[i]<<endl;}

  cout << (ans ? "Yes" : "No") << endl;
}


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

n,m = map(int,input().split())
li = [list(map(int,input().split())) for _ in range(m)]

ans = 0
now = -1

li.sort(key = lambda x:x[1])

for i in range(m):
    if li[i][0] <= now and li[i][1] > now:
        pass
    else:
        ans += 1
        now = li[i][1] - 1

print(ans)


Measured memory_bytes: 29152
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    int N;
    cin >> N;
    i64 S = 0;
    i64 M = 1e14;
    bool equals = true;
    for(int i = 0; i < N; i++) {
        i64 a, b;
        cin >> a >> b;
        S += a;
        if(a > b) M = min(M, b);
        if(a != b) equals = false;
    }
    if(equals) M = S;
    cout << S - M << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  
  cin >> a >> b >> c >> d;
  
  
  if(a+b>c+d)cout<<"Left"<<endl;
  else if(a+b<c+d)cout<<"Right"<<endl;
  else cout<<"Balanced"<<endl;
  
}

Measured memory_bytes: 3596
/*----------------by syr----------------*/
/*

         iii                  ii
     rBQBBBBBBE       BBR iBBBBQBBL     XBBBBBBQBBBBB
   iBBQJ    7BBB      BBsSBBr   BBQ      i      cBBB
  rBBU       iBBw     BBBQi     HBBi           KBBi
  BBH         BB5    iBBB       isL          wBB5
 GBB         iBBi    6BB                   iBBB
 BBQ         BQB     BBD                  QBBi
 BBB        BQB     iQBi                1BBv
 sBBg     wBBB      QBB               iBBB
  7BBBBBBBBBi       BBR              wBBBBBBBBBBBBB
     irvi           ii               ii    i i iii
                i5U
               BBB
               BB7
              1BB
      iPBBBBBKBBR    JBR1       rQBO   BR  UBQP  iBBQi
    7BBBGs7sXBBBi     QBBr     gBBE   rBB BB2BB7HBZQBB
   QBBi      sBQ       BBB   iBBB     SQBBR  BBBB  cBQ
  gBQ        BBg        BBB KBBi      MBBH   BBB   BBs
 iBBv       iBBi         QBBBL        BBR   pBB   iBB
 pBB        BBB         iBBBB        iBB    BBL   KBB
 MBB       BBBR        BBB JBBi      DBR   iBQ    BBL
 GBB     7BBBB2      PBBH   BBBi     BQr   DBB   iBB
  BQBXwgBBP BB7    1BBB      BBQ7   1BB    BBc   BBB
   2BBBBw   BB    EBBS        QBBi  HBa   iBB    BB7
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;
const int maxn = 2e5 + 5;

int n, m;
pii a[maxn];
vector<pii> vec;

int main(){
	scanf("%d%d", &n, &m);
	FOR(i, 0, n){
		int l, r;
		scanf("%d%d", &l, &r);
		a[i] = MP(l, r);
	}
	sort(a, a + n);
	priority_queue<pii, vector<pii>, greater<pii> > q;
	FOR(i, 0, n){
		q.PH(MP(a[i].snd, i));
		while(q.size() > a[i].fst){
			pii j = q.top();
			vec.PB(j);
			q.pop();
		}
	}
	sort(vec.begin(), vec.end());
	int cnt = 0;
	for(int i = vec.size() - 1; i >= 0; --i){
		//printf("cnt = %d m = %d n = %d sz = %d\n", cnt, m, n, vec.size());
		if(cnt >= m - vec[i].fst + 1 || m - cnt <= n - vec.size()) continue;
		++cnt;
	}
	printf("%d\n", vec.size() - cnt);
	return 0;
}



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

using namespace std;

int main() {
	string integr;
	cin >> integr;

	if (integr.find("000") != string::npos) { cout << "Yes"; return 0; }
	if (integr.find("111") != string::npos) { cout << "Yes"; return 0; }
	if (integr.find("222") != string::npos) { cout << "Yes"; return 0; }
	if (integr.find("333") != string::npos) { cout << "Yes"; return 0; }
	if (integr.find("444") != string::npos) { cout << "Yes"; return 0; }
	if (integr.find("555") != string::npos) { cout << "Yes"; return 0; }
	if (integr.find("666") != string::npos) { cout << "Yes"; return 0; }
	if (integr.find("777") != string::npos) { cout << "Yes"; return 0; }
	if (integr.find("888") != string::npos) { cout << "Yes"; return 0; }
	if (integr.find("999") != string::npos) { cout << "Yes"; return 0; }
	cout << "No" << endl;
	return 0;
}

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

int main(){
	ll n,m;
	cin >> n >> m;
	
	vector<pair<ll,ll>> ab;
	priority_queue<ll> pq;

	for(ll i=0;i<n;i++) {
		ll a,b;
		cin >> a >> b;
		ab.push_back(make_pair(a,b));
	}

	sort(ab.begin(), ab.end());

	ll ans = 0;
	// 後ろから見ていく
	int j = 0;
	for(ll i=1;i<=m;i++) {
		// 今選べる仕事をすべてpush
		while(j < n and ab[j].first <= i) {
			pq.push(ab[j].second);
			j++;
		}
		// queueの中から取れる一番いい仕事を
		if(!pq.empty()) {
			ans += pq.top();
			pq.pop();
		}
	}

	cout << ans << endl;
}

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

int BFS(int H,int W,vector<vector<char> >& ch){//幅優先探索
    int ans = -1;//最大経路数

    const int non = -1;

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

    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            if(ch[i][j] == '#') continue;//#には立てないから飛ばす

            vector<vector< int> > dist(H,vector<int>(W,non));

            queue<pair<int,int> > q;
            q.push(make_pair(i,j));//i,jをスタートにセット

            dist[i][j] = 0;

            while(!q.empty()){
                int vx = q.front().second;
                int vy = q.front().first;

                q.pop();

                for(int k = 0;k < 4; ++k){
                    int nx = vx + dx[k];
                    int ny = vy + dy[k];

                    if(nx < 0 || nx >= W || ny < 0 || ny >= H) continue;

                    if(ch[ny][nx] == '#') continue;

                    if(dist[ny][nx] == non){
                        dist[ny][nx] = dist[vy][vx] + 1;
                        q.push(make_pair(ny,nx));
                    }
                }
            }

            for(int ii = 0; ii < H; ++ii){
                for(int jj = 0; jj < W; ++jj){
                    if(dist[ii][jj] != non)
                        ans = max(ans,dist[ii][jj]);
                        //cout << dist[ii][jj] << endl;
                }
            }
        }
    }

    return ans;
}//幅優先探索

int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char> > ch(h,vector<char>(w,'0'));

    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            cin >> ch[i][j];
        }
    }

    cout << BFS(h,w,ch) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

bool memo[100001] = {};

int main() {
  int x;
  cin >> x;
  REP(i, 6) { memo[100 + i] = true; }
  FOR(i, 106, 100001) {
    REP(j, 6) { memo[i] = memo[i] || memo[i - 100 - j]; }
  }

  if (memo[x]) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 384
#include<stdio.h>
#define MAXLEN 150
int arr[4][MAXLEN];
int dp[4][MAXLEN];
int max(int a,int b)
{
	return a > b ? a : b;
}
 int main(void)
 {
 	int i,j,nCol;
 	scanf("%d",&nCol);
 	for(i=1;i<=2;i++)
 	{
 		for(j=1;j<=nCol;j++)
 		{
 			scanf("%d",&arr[i][j]);
		} 
	}
	 for(i=nCol;i>=1;i--)
	 {
	 	for(j=2;j>=1;j--)
	 	{
	 		dp[j][i]=max(dp[j][i+1],dp[j+1][i])+arr[j][i];
		 }
	}
	 printf("%d",dp[1][1]);
 	return 0;
  } 

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


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

bool solve(vector<ll> a, ll n){
	if (a[n] == 1) { return false; }
	if (a[1] == 0) { return false; }
	repn(i, n - 1) { if (a[i] != a[n - i]) { return false; } }
	return true;
}



int main() {

	string S;
	cin >> S;

	string ans = "Yes";

	if (S[0] == S[1] && S[1] == S[2]) { ans = "No"; }

	cout << ans;

	
	
	system("PAUSE");

}





Measured memory_bytes: 504
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <queue>
using namespace std;

int main(){
string s;
int n,m,x,y;
while(cin>>n && n!=0){
int c=0;
int ma[22][22]={0};
for(int aa=0;aa<n;aa++){
cin>>x>>y;
ma[x][y]=1;
}
cin>>m;
int nx=10,ny=10,w;
for(int aa=0;aa<m;aa++){
cin>>s>>w;
if(s=="N"){
while(w>0){
ny++;
if(ma[nx][ny]==1){
ma[nx][ny]=0;
c++;
}
w--;
}
}
if(s=="S"){
while(w>0){
ny--;
if(ma[nx][ny]==1){
ma[nx][ny]=0;
c++;
}
w--;
}
}
if(s=="E"){
while(w>0){
nx++;
if(ma[nx][ny]==1){
ma[nx][ny]=0;
c++;
}
w--;
}
}

if(s=="W"){
while(w>0){
nx--;
if(ma[nx][ny]==1){
ma[nx][ny]=0;
c++;
}
w--;
}
}

}

if(n==c)cout<<"Yes"<<endl;
else cout<<"No"<<endl;

}
return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

int my_sort(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

int main(int argc, void **arg)
{
    long long n, k;
    int h[100000];
    int i;

    scanf("%lld %lld", &n, &k);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &h[i]);
    }

    qsort(h, n, sizeof(int), my_sort);

    for (i = 0; i < n; i++)
    {
        if( h[i] < k ) {
            break;
        }
    }
    printf("%d\n", i);

    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    string s;
    cin >> s;
    stack<char> data;
    rep(i,0,s.size()){
        if(s[i]!='B'){
            data.push(s[i]);
        }else{
            if(data.empty()){
                continue;
            }else{
                data.pop();
            }
        }
    }
    stack<char> ans;
    while(!data.empty()){
        ans.push(data.top());
        data.pop();
        
    }
    while(!ans.empty()){
        cout<<ans.top();
        ans.pop();
    }
    cout<<endl;

  return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
struct edge{int to,nxt;}e[N<<1];
int head[N],tot=1;
void adde(int x,int y){e[tot]=(edge){y,head[x]};head[x]=tot++;}
int fa[N],k,dep[N],ans=0;
int dfs(int u)
{
    int mx=dep[u];
    for(int i=head[u];i;i=e[i].nxt)
        dep[e[i].to]=dep[u]+1,mx=max(mx,dfs(e[i].to));
    if(fa[u]!=1&&mx-dep[u]==k-1){ans++;return 0;}
    return mx;
}
int main()
{
    int n;scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)scanf("%d",&fa[i]);
    for(int i=2;i<=n;i++)adde(fa[i],i);
    if(fa[1]!=1)ans++,fa[1]=1;
    dfs(1);
    printf("%d\n",ans);
}


Measured memory_bytes: 16000
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int>score;
	vector<int>vscore;
	int total = 0;
	for (int i = 0; i < n; i++) {
		int si;
		cin >> si;
		score.push_back(si);
		total += si;
		if (si % 10 != 0)vscore.push_back(si);
	}
	sort(score.begin(), score.end());
	sort(vscore.begin(), vscore.end());
	
	int max=total;
	if (total % 10 == 0) {
		if (vscore.size()!=0) {
			max = total - vscore[0];
		}
		else max = 0;
	}

	cout << max << endl;

	return 0;

	
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long

const int MOD =  1000000007;
const int IINF = INT_MAX;
const ll INF = 1LL << 60;


int main() {
    int n; cin >> n;
    int cnt = 0;
    ll sum = 0;
    ll mi = INF;
    for(int i = 0; i < n; i++){
        ll a; cin >> a;
        mi = min(abs(a), mi);
        sum += abs(a);
        if(a < 0) cnt++;
    }

    if(cnt & 1) cout << sum - mi * 2 << endl;
    else cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3512
#include<iostream>
#include<vector>
#include<string>

int judge(int i, int j, int w, int h, const std::vector<std::string> &s) {

	int res = 0;
	if (i - 1 >= 0 && s[i - 1][j] == '#')res++;
	if (i + 1 < h && s[i + 1][j] == '#')res++;
	if (j - 1 >= 0 && s[i][j - 1] == '#')res++;
	if (j + 1 < w && s[i][j + 1] == '#')res++;

	if (res)return 0;
	else return 1;

}


int main() {

	int h, w;
	std::cin >> h >> w;

	std::vector<std::string> s(h);
	for (int i = 0; i < h; i++)std::cin >> s[i];
	
	int res = 0;
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			if (s[i][j] == '#') res += judge(i,j,w,h,s);
		}
	}

	std::cout << (res ? "No" : "Yes") << std::endl;
	}

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

int main(){
  int A,B,C,X,Y;
  cin>>A>>B>>C>>X>>Y;
  int ans(1e9);
  ans=min(ans,min(X,Y)*2*C+abs(X-Y)*2*C); 
  ans=min(ans,A*X+B*Y);
  if (X>Y) ans=min(ans,2*C*Y+(X-Y)*A);
  else ans=min(ans,2*C*X+(Y-X)*B);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

c1 = 0
for i in range(X+1, N):
    if i in A:
        c1 += 1
c2 = 0
for i in range(X-1, 0, -1):
    if i in A:
        c2 += 1

print(c1 if c1 < c2 else c2)


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

ll mp[111111];

int main(){
	
	ll n,m;cin >> n >> m;
	REP(i,n)cin >> mp[i+1];
	REP(i,n)mp[i+1] += mp[i];
	REP(i,n+1)mp[i] %= m;
	
	map<ll,ll> seica;
	REP(i,n+1)seica[mp[i]]++;
	
	ll ans = 0;
	for(auto it = seica.begin();it != seica.end();it++){
		ans += (it->SE)*(it->SE - 1) / 2;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int t=0,n=0;
  string s;
  cin>>s;
  for(int i=0;i<3;i++)
  {
  	if(s[i]=='R'){
  	t++;
  	n++;}
  	else
  	t=0;
  }
  if(t==0)
  cout<<n;
  else
  cout<<t;
  return 0;
}

Measured memory_bytes: 3620
#include<cstdio>

using namespace std;

char map[105][105];
int n, m;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

void dfs(int x, int y)
{
    char tmp = map[x][y];
    map[x][y]='.';
    for(int i=0; i<4; i++)
    {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(nx>=0 &&nx<n && ny>=0 &&ny<m && map[nx][ny]==tmp)
            dfs(nx, ny);
    }

}


int main()
{
    while(scanf("%d%d", &n, &m)!=EOF)
    {
        if(n==0 && m==0) break;
        for(int i=0; i<n; i++)
            scanf("%s", map[i]);
            int res=0;
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++)
            {
               if(map[i][j]!='.')
               {
                   dfs(i, j);
                   res++;
               }
            }
        printf("%d\n", res);
    }

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  long long int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (i % 3 != 0 && i % 5 != 0) ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
  int A,B,T;
  cin >> A >> B >> T;
  
  int sum =0;
  for(int i=1;i*A<T+0.5;i++){
    sum += B;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

int main(void){
    string str;
    cin >> str;
    for(int i=0; i<3; i++){
        char temp=str[i];
        if(temp=='1')str[i]='9';
        else if(temp=='9')str[i]='1';
    }
    cout << str << endl;
    return 0;
}

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

void solve(long long N, vector<long long> W)
{
    long long ans = 1000000000;
    for (int i = 0; i < N; i++)
    {
        long long s1 = accumulate(W.begin(), W.begin() + i, 0LL);
        long long s2 = accumulate(W.begin() + i, W.end(), 0LL);
        ans = min(ans, abs(s1 - s2));
    }
    cout << ans << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> W(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &W[i]);
    }
    solve(N, std::move(W));
    return 0;
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N,M = II()
a = [0]*M
b = [0]*M
c = []
x = []
for i in range(M):
    a[i],b[i] = II()
    new_c = III()
    c.append(new_c)
    k = 0
    for c1 in new_c:
        k += 2**(c1-1)
    x.append(k)

dp = [-1]*(2**N)
dp[0] = 0
for i in range(M):
    if dp[x[i]]==-1:
        dp[x[i]] = a[i]
    else:
        dp[x[i]] = min(dp[x[i]], a[i])
    for j in range(2**N-1):
        if dp[j]==-1:
            continue
        else:
            if dp[j|x[i]]==-1:
                dp[j|x[i]] = dp[j] + dp[x[i]]
            else:        
                dp[j|x[i]] = min(dp[j|x[i]], dp[j] + dp[x[i]])

print(dp[2**N-1])

Measured memory_bytes: 43884
using System;

class Program
{
    static void Main(string[] args)
    {
        var inp = Console.ReadLine().Split(' ');
        var syainNum = Console.ReadLine().Split(' ');       
        int[] buka = new int[int.Parse(inp[0])];

        for(int idx = 0; idx < buka.Length; idx++)
        {
            buka[idx] = 0;
        }

        for (int idx = 0; idx < syainNum.Length; idx++)
        {
            buka[int.Parse(syainNum[idx]) - 1]++;
        }

        for (int idx = 0; idx < buka.Length; idx++)
        {
            Console.WriteLine(buka[idx].ToString());
        }
    }
}

Measured memory_bytes: 41812
N, A, B, C, D = map(int, input().split())
S = input()

for i in range(A, max(C, D)):
    if S[i-1:i+1] == '##':
        print('No')
        exit(0)

if C < D:
    print('Yes')
    exit(0)

for i in range(B-1, D):
    if S[i-1:i+2] == '...':
        print('Yes')
        exit(0)
print('No')


Measured memory_bytes: 3572
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e17;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14

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

	string va = "";
	int j = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == t[j]){
			j++;
		}
	}
	for(; j < n; j++)
		s += t[j];
	cout << s.size() << endl;
}


Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::Usize1;

#[derive(Clone, Debug)]
struct Adjacent {
    to: usize,
}

#[derive(Debug)]
struct Graph {
    n: usize,
    links: Vec<Vec<Adjacent>>,
}

impl Graph {
    fn new(n: usize) -> Graph {
        Graph {
            n,
            links: vec![vec![]; n],
        }
    }

    fn add_edge(&mut self, from: usize, to: usize) {
        self.links[from].push(Adjacent { to });
        self.links[to].push(Adjacent { to: from });
    }
}


fn dfs(v: usize, p: usize, g: &Graph, aaa: &Vec<u64>, state: &mut Vec<u64>, ans: &mut Vec<u64>) {
    let i = state.binary_search(&&aaa[v]).unwrap_or_else(|x| x);
    let pushed = i == state.len();
    let mut backup_a = 0;
    if pushed {
        state.push(aaa[v]);
    } else {
        backup_a = state[i];
        state[i] = aaa[v];
    }
    ans[v] = state.len() as u64 - 1;

    for adj in &g.links[v] {
        if adj.to == p { continue; }
        dfs(adj.to, v, g, aaa, state, ans);
    }

    if pushed {
        state.pop();
    } else {
        state[i] = backup_a;
    }
}

#[fastout]
fn main() {
    input! {
        n: usize,
        aaa: [u64; n],
        uv: [(Usize1, Usize1); n - 1],
    }

    let mut g = Graph::new(n);
    for (u, v) in uv { g.add_edge(u, v); }

    let mut state = vec![0u64];
    let mut ans = vec![0u64; n];

    dfs(0, n, &g, &aaa, &mut state, &mut ans);

    for v in ans {
        println!("{}", v);
    }
}


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

int main(){
    ll N; cin >> N;
    vector <pair<ll,ll>> A(N+1);
    rep(i,N){
        ll x,y; cin >> x >> y;
        A[i]=make_pair(x,y);
    }
    
    double sum=0;
    for (ll i=1; i<N; i++){
        for (ll j=i+1; j<=N; j++){
            sum+=sqrt ( pow(A[i].first-A[j].first,2) + pow(A[i].second-A[j].second,2) );
        }
    }
    
    double cnt=0;
    rep(i,N-1) cnt+=i;
    
    double ans=sum*(N-1)/cnt;
    cout << fixed << setprecision(10) << ans;
    
}

Measured memory_bytes: 256
#include <iostream>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
using ll = long long;

using namespace std;



int main() {
    ll x,k,d;
    cin>>x>>k>>d;
    if(x>0) {
        if(k<=x/d) {x -= k*d;}
        else {
            k -= x/d;
            x -= (x/d)*d;
            if(k%2) x -= d;
        }
    } else {
        if(k<=-x/d) {x += k*d;}
        else {
            k -= -x/d;
            x += (-x/d)*d;
            if(k%2) x += d;
        }
    }
    cout<<abs(x)<<endl;

    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int a[200005];
map<int, int> freq;

int main() {
    int n, maxim = INT_MIN;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        freq[a[i]]++;
    }
    for(int i = 1; i <= n; i++) {
        maxim = max(maxim, freq[a[i]]);
    }
    if(maxim == 1) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, m;
	string a, b; cin >> n >> m >> a >> b;
	ll lcm = (ll)n / __gcd(n, m) * m;
	
	for(ll i = 0, j = 0; i < lcm && j < lcm; i += lcm / n){
		while(j <= i){
			if(i == j && a[i / (lcm / n)] != b[j / (lcm / m)]){
				cout << -1 << endl;
				return 0;
			}
			j += lcm / m;
		}
	}
	cout << lcm << endl;
	
	return 0;
}

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

#define lint long long
#define P pair<int, int>


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

int extgcd(int a, int b, int& x, int& y){
    int d = a;
    if(b != 0){
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1; y = 0;
    }
    return d;
}



int main(){
    int N;
    cin >> N;
    
    int A[N];
    
    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }
    
    int ans = A[0];
    
    for(int i = 1; i < N; ++i){
        ans = gcd(ans, A[i]);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
double s,a,left,right;
double b;
string str;
int main () {
	cin>>str;
	if(str=="Sunny") printf("Cloudy\n");
	if(str=="Cloudy") printf("Rainy\n");
	if(str=="Rainy") printf("Sunny\n");
	return 0;
}

Measured memory_bytes: 256
n, y = map(int, input().split())

target = y - n * 1000
flag = 0
for i in range(n+1):
    b_4000 = (target - 9000 * i)
    if b_4000 % 4000 == 0 and b_4000 // 4000 >= 0:
        if n-i-b_4000//4000 >= 0:
            c = i
            b = b_4000 // 4000
            flag = 1
            break

if flag:
    print(c, b, n-b-c)
else:
    print('-1 -1 -1')

Measured memory_bytes: 3060