akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	Yn(s==t.substr(0,t.size()-1));
}



Measured memory_bytes: 3612
card = {}
card['a'] = input()
card['b'] = input()
card['c'] = input()

turn = 'a'
while True:
    if len(card[turn]) == 0:
        print(turn.upper())
        break
    nextturn = card[turn][0]
    card[turn] = card[turn][1:]
    turn = nextturn


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

int main(){
  long long n,d,a,b;
  int ans=0;
  cin>>n>>d;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    if(a*a+b*b<=d*d) ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3600
import numpy as np
n,d = list(map(int,input().split()))
t = np.array([list(map(int,input().split())) for i in range(n)])
cnt = 0

for i in range(n):
	for h in range(n):
		x = (sum((t[i]-t[h])**2))**0.5
		if x % 1 == 0:
			cnt += 1
			
print(int((cnt-n)/2))

Measured memory_bytes: 13096
N =int(input())
List = list(map(int, input().split()))
flag = True
res = 0
while flag:
  for i in range(N):
    if List[i] % 2 == 1:
      flag = False
      break
    else:
      List[i] = List[i]//2
  if flag:
    res += 1
print(res)

Measured memory_bytes: 9064
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int ans[10002];
  for(int i=0;i<10002;i++)ans[i]=0;
  for(int x=1;x<=100;x++){
  	for(int y=1;y<=100;y++){
    	for(int z=1;z<=100;z++){
        	int p=x*x+y*y+z*z+x*y+y*z+z*x;
          	if(p>10000)continue;
          	else ans[p]++;
        }
    }
  }
  for(int i=1;i<=n;i++)cout<<ans[i]<<endl;
}

Measured memory_bytes: 3664
#include<iostream>
using namespace std;
int main() {
	int a, b, c, x, y, z;
	while (cin >> a >> b) {
		y = a;
		z = b;
		if (a < b) {
			x = a;
			a = b;
			b = x;
		}
		while (b > 0) {
			x = a;
			a = b;
			b = x%b;
		}
		c = (y / a)*(z / a)*a;
		cout << a << " " << c << endl;
	}
	return 0;
}

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

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

using ll = long long;

int main(){
  int N; cin>>N;
  vector<ll> A(N),B(N),C(N);
  rep(i,N)cin>>A.at(i);
  rep(i,N)cin>>B.at(i);
  rep(i,N)cin>>C.at(i);
  sort(begin(A),end(A));
  sort(begin(C),end(C));
  ll res = 0;
  rep(i,N){
    auto ia = lower_bound(begin(A),end(A),B.at(i));
    ll la = distance(begin(A),ia);
    auto ic = upper_bound(begin(C),end(C),B.at(i));
    ll lc =distance(ic,end(C));
    res += la*lc;
  }
  cout<<res<<endl;
}

Measured memory_bytes: 2560
#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#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 int_fast64_t 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":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll 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 modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

int N, ans = 0;
ll A[200000];
bool B[200000] = {false};

int main() {
    scanf("%d", &N);
    REP(i, N) scanf("%d", A+i);
    sort(A, A+N);
    for(int i=N-1; i>=0; i--) {
        int p = 0;
        while(A[i] >= 1LL<<p) p++; 
        ll x = (1LL<<p) - A[i];
        int j = lower_bound(A, A+N, x) - A;
        if(B[i]) continue;
        if(j < i && A[j] == x && !B[j]) {
            B[j] = true;
            A[j]--;
            ans++;
        }
    }
    printf("%d", ans);
	return 0;
}

Measured memory_bytes: 1920
#include <iostream>

using namespace std;

int main(void)
{
    int N, M, X, Y;
    int x, y;

    cin >> N >> M >> X >> Y;

    int max_x = 0;
    for (int i = 0; i < N; i++) {
        cin >> x;
        if (i == 0 || max_x < x) {
            max_x = x;
        } 
    }

    int min_y = 0;
    for (int i = 0; i < M; i++) {
        cin >> y;
        if (i == 0 || min_y > y) {
            min_y = y;
        }
    }

    for (int i = X+1; i <= Y; i++) {
        if (i > max_x && i <= min_y) {
            cout << "No War" << endl;
            return 0;
        }
    }

    cout << "War" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <stack>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#define esp 1e-9
#define INF 0x3f3f3f3f
#define Pi acos(-1.0)
const int maxn = 3*1e6;
typedef long long ll;
using namespace std;

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

    if(a<=0 && b>=0)
        printf("Zero\n");
    else if(a>0 && b>0)
        printf("Positive\n");
    else if(a<0 && b<0)
    {
        if((b-a)%2)
            printf("Positive\n");
        else
            printf("Negative\n");
    }
    return 0;
}

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

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

    int L, R, d;
    cin>>L>>R>>d;
    int ans = 0;
    for (int i=L; i<=R; i++){
        if (i%d==0) ans++;
    }
    cout<<ans<<endl;

    return 0;
}


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

// 型名の省略
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> P;
typedef pair<lint, lint> Plint;
 
const int MOD = 1e9+7;
const int INF = 1<<18;
const lint INFLINT = 1LL<<60;
const double PI=acos(-1.0);
 
// cinとcoutの高速化
#define endl "\n"
struct cinacc{cinacc(){cin.tie(0);ios::sync_with_stdio(false);}}cinaccc;
struct coutacc{coutacc(){cout.setf(ios::fixed);cout.precision(12);}}coutaccc;
 
// 繰り返し
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define reps(i,n) for(lint i=0;i<=(lint)(n);i++)
#define rrep(i,n) for(lint i=(lint)(n)-1;i>0;i--)
#define rreps(i,n) for(lint i=(lint)(n)-1;i>=0;i--)

#define pb push_back

#define ALL(s) (s.begin(), s.end())
#define SZ(s) (s.size())

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

// Union-Find-Tree
class UnionFind {
	vector<int> par;
	UnionFind(int n):par(n){rep(i,n)par[i]=i;}
	int root(int x){if(par[x]==x)return x;return par[x]=root(par[x]);}
	void unite(int x,int y){int rx=root(x);int ry=root(y);if(rx==ry)return;par[rx]=ry;}
	bool same(int x,int y){return root(x)==root(y);}
};

// Final Weapon!
// #define int lint

int main() {
    lint x, ans = 0;
    lint num = 0;
    cin >> x;
    for(lint i = 1; i <= INF; i++) {
        for(lint j = 2; j <= INF; j++) {
            num = pow(i, j);
            if(num > x) break;
            chmax(ans, num);
        }
    }
    
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,d;
  cin>>m>>d;
  int result = 0;
  for(int j=1;j<=m;++j){
    for(int i=11;i<=d;++i){
      int a = i%10;
      int b = i/10;
      if(a*b==j&&a>1&&b>1){
        result ++;
        //cout<<j<<" "<<i<<endl;
      }
    }    
  }

  cout<<result<<endl;
  return 0;
}

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

int main()
{
ll k , n ;
cin >> k >> n ;
if(k%2==0){
  cout << k/2 << ' ';
  rep(i,n-1)cout << k << ' ';
  cout << endl;
}
else{
  vector<ll> v;
  rep(i,n)v.push_back(k/2+1);
  ll s=n-1;
  rep(i,n/2){
    v[s]--;
    if(v[s]==0)s--;
    else{
      for(ll j=s+1;j<n;j++)v[j]=k;
      s=n-1;
    }
  }
  rep(i,n){
    if(v[i]==0)break;
    cout << v[i] << ' ';
  }
  cout << endl;
}
return 0;
}

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

using namespace std;
double condition = 0.0;

bool kaibun(string S, int start, int length)
{
	string tmp1, tmp2;
	tmp1 = S.substr(start, length);
	tmp2 = tmp1;
	reverse(tmp2.begin(), tmp2.end());
return tmp1 == tmp2;
}

void func()
{
	string S;
	cin >> S;


	int l = S.length();
	if (kaibun(S,0,l)
		&& kaibun(S, 0, (l-1)/2)
		&& kaibun(S, (l + 3) / 2  - 1, l- (l + 3) / 2 + 1))
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\n";
	}
}

int main() {
//	while(1)
	func();
	return 0;
}


Measured memory_bytes: 3096
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <climits>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

#define fast_cin() ios_base::sync_with_stdio(false)

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

const int max_N = 1e5 + 10;
ll A[max_N], B[max_N];

int main()
{
	fast_cin();
	int N;
	cin >> N;
	for (int i = 1; i <= N; ++i) {
		cin >> A[i] >> B[i];
	}

	ll res = 0;
	for (int i = N; i >= 1; --i) {
		A[i] += res;
		res += (B[i] - A[i] % B[i]) % B[i];
	}

	cout << res << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    int n;
    cin >> n;
    int cnt = 0;
    for (i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (i % 2 == 1 && x % 2 == 1) cnt++;
    }
    cout << cnt << endl;
}

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

int main(){
  std::string S;
  int Q;
  std::cin >> S;
  std::cin >> Q;

  int even_odd = 0;
  for(int i = 0; i < Q; ++i){
    int T;
    std::cin >> T;
    if(T == 1){
      even_odd ^= 1;
      continue;
    }
    else if(T == 2){
      int F;
      char C;
      std::cin >> F;
      std::cin >> C;
      if(even_odd == 0){
        if(F == 1){
          S.insert(0,1,C);
          continue;
        }
        else if(F == 2){
          S.push_back(C);
        }
      }
      else{
        if(F == 1){
          S.push_back(C);
          continue;
        }
        else if(F == 2){
          S.insert(0,1,C);
        }
      }
    }
  }
  if(even_odd == 0){
    std::cout << S << std::endl;
  }
  else{
    for(int i = 0; i < S.length(); ++i){
      std::cout << S[S.length()-i-1];
    }
    std::cout << std::endl;
  }
  return 0;
}

Measured memory_bytes: 900
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    string s;cin>>s;
    int lw=0;
    int re=0;
    rep2(i,1,n)if(s[i]=='E')re++;
    int m=inf;
    rep(i,n){
        m=min(m,lw+re);
        if(i==n-1)break;
        if(s[i]=='W')lw++;
        if(s[i+1]=='E')re--;
    }
    cout<<m<<endl;
}

Measured memory_bytes: 3900
# -*- coding: utf-8 -*-
"""
Created on Mon Mar  2 06:12:32 2020

@author: naoki
"""
from collections import deque
import time
start = time.time()
time_all = []
part_time1 = 0
part_time2 = 0
#with open('C:/Users/naoki/Desktop/Atcoder/input.txt') as f:
#    N ,M ,K = map(int,f.readline().split())
#    A = [list(map(int,f.readline().split())) for _ in range(M)]
#    C = [list(map(int,f.readline().split())) for _ in range(K)]
    
time_all.append(time.time()-start)

N ,M ,K = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(M)]
C = [list(map(int,input().split())) for _ in range(K)]
connection = [[] for i in range(N)]
seen = [False]*N
label = [0]*N
todo = deque()
num = 0
minus = [0]*N

time_all.append(time.time()-start)
 
for pair in A:
    connection[pair[0]-1] += [(pair[1]-1)]
    connection[pair[1]-1] += [(pair[0]-1)]
    minus[pair[0]-1] -= 1
    minus[pair[1]-1] -= 1

time_all.append(time.time()-start)
count = 0
for k in range(N):
    time1 = time.time()
    num+=1
    if seen[k] == False:
        H = k
    else:
        continue
    todo += [(H)]
    seen[H] = True
    group = []
    part_time1 += time.time() - time1
    while not len(todo) == 0:
        current = todo.pop()
        label[current] = num
        group += [current]
        for i in connection[current]:
            count+=1
            if seen[i] == False:
                todo += [i]
                seen[i] = True
#print(count)
time_all.append(time.time()-start)

for pair in C:
    if label[pair[0]-1] == label[pair[1]-1]:
        minus[pair[0]-1] -= 1
        minus[pair[1]-1] -= 1
accompany = {i:0 for i in range(1,num+1)}
for i in range(N):
    accompany[label[i]] += 1
    
time_all.append(time.time()-start)

print(" ".join(map(lambda x,y : str(accompany[x]+y-1), label, minus)))

time_all.append(time.time()-start)

#print(time_all)


Measured memory_bytes: 130384
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
int a[M];
 main()

{

    int n,l;
    scanf("%lld%lld",&n,&l);
    vector<int>ses;
    f(i,1,n)
    {
        scanf("%lld",&a[i]);
    }
    int flag=0;
    for(int i=1;i<n;i++)
    {
        int sum=a[i]+a[i+1];
        if(sum>=l)
        {
            flag=i;
        }
    }
    if(flag==0)
    {
        printf("Impossible\n");
        return 0;
    }
    printf("Possible\n");
    for(int i=1;i<flag;i++)
    {
        printf("%lld\n",i);
    }
    for(int i=n-1;i>flag;i--)
    {
        printf("%lld\n",i);
    }
    printf("%lld\n",flag);
    return 0;

}



































Measured memory_bytes: 4484
fun main(args: Array<String>) {
  val (N, K) = readInts()
  val x = readInts()

  var min = Int.MAX_VALUE
  for (i in 0 until N) {
    val l = x[i]
    val r = x.getOrNull(i + K - 1) ?: break
    val d = when {
      r < 0 -> l * -1
      l < 0 -> Math.min(l * -2 + r, l * -1 + r * 2)
      else -> r
    }
    min = Math.min(min, d)
  }
  println(min)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 49836
#include <stdio.h>
 
int main(void){
 
    int x, y, q, r;
    long long int a,b,z;
 
    while(scanf("%lld %lld", &a, &b)!=EOF){
 
    x = a;
    y = b;
 
    if(x < 0) x = -x;
    if(y < 0) y = -y;
    for(;;){
        q = x/y;
        r = x - q*y;
        if(r == 0) break;
        x = y;
        y = r;
    }
    z=a*b/y;
    printf("%d %lld\n",y,z);
    }
    return 0;
}


Measured memory_bytes: 2056
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long mod = (long)Math.pow(10,9)+7;
        int n = sc.nextInt();
        int m = sc.nextInt();
        boolean[] brokes = new boolean[n+1];
        for(int i = 0; i < m; i++){
            brokes[sc.nextInt()] = true;
        }
        long[] dp = new long[n+1];
        dp[0] = 1;
        for(int i = 1; i <= n; i++){
            if(brokes[i]){
                continue;
            }else if(i == 1){
                dp[i] = dp[i-1]%mod;
            }else{
                dp[i] = dp[i-2]%mod + dp[i-1]%mod;
                dp[i] %= mod;
            }
        }
        System.out.println(dp[n]%mod);
    }
}

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

const long N = 100;
const long INFTY = (1<<21);

long n, M[N + 1][N + 1];
long d[N + 1];

void bfs(long s){
	queue<long> q;
	q.push(s);
	for (long i = 1; i <= n; i++) d[i] = INFTY;
	d[s] = 0;
	long u;
	while (!q.empty()){
		u = q.front();
		q.pop();
		for (long v = 1; v <= n; v++){
			if (M[u][v] == 0) continue;
			if (d[v] != INFTY) continue;
			d[v] = d[u] + 1;
			q.push(v);
		}
	}
	for (long i = 1; i <= n; i++){
		cout << i << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
	}
}

int main(){
	long u, k, v;
	cin >> n;
	for (long i = 1; i <= n; i++){
		for (long j = 1; j <= n; j++){
			M[i][j] = 0;
		}
	}
	for (long i = 0; i < n; i++){
		cin >> u >> k;
		for (long j = 0; j < k; j++){
			cin >> v;
			M[u][v] = 1;
		}
	}

	bfs(1);

	return 0;
}

Measured memory_bytes: 1280
n,x = map(int,input().split())
l = list(map(int,input().split()))
count = 0
for i in range(n-1):
  if l[i]>x:
    count += (l[i]-x)
    l[i] -= (l[i]-x)
  if l[i]+l[i+1]>x:
    count += (l[i]+l[i+1]-x)
    l[i+1] -= (l[i]+l[i+1]-x)
print(count)

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

const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, M, ans=0, tmp=0;
vector<vector<ll>> G, H;
vector<ll> d;

void bfs(ll id) {
    queue<ll> Q;
    Q.push(id);
    while(!Q.empty()) {
        ll num = Q.front();
        Q.pop();
        for(int i=0;i<G[num].size();i++) {
            if(d[G[num][i]]==INF) {
                d[G[num][i]]=0;
                Q.push(G[num][i]);
            }
        }
    }
}

signed main(){
    cin >> N >> M;
    G.resize(N+M);
    H.resize(N);
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        for(int j=0;j<a;j++) {
            ll l;
            cin >> l;
            l += N-1;
            G[i].push_back(l);
            G[l].push_back(i);
        }
    }
    d.resize(N+M, INF);
    bfs(0);
    for(int i=0;i<N;i++) {
        ans = max(ans, d[i]);
    }
    if(ans==INF) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 16424
#include<stdio.h>
int main()
{
    int num,x,y=0;
    scanf("%d",&num); 
    int copy=num;
  //  printf("%d",copy);
    while(copy>0)
    {
        x = copy%10;  
        y = y*10+x*10;  
        copy=copy/10;
    }
    y=y/10;
   // printf("%d",y);
    if(num==y)
    {
        printf("Yes");
    }
    if(num!=y)
    {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
int n;
int main(){
	cin >> n;
	cout << n*n*n;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class T>
void dump(vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		cout << vec[i];
		if(i+1<vec.size())cout << ' ';
		else cout << endl;
	}
	return;
}
int N,M;
vector<int> g[100100];
bool used[100100];
int col[100100];
bool flag;
int k;
void dfs(int v,int c){
	used[v] = true;
	k++;
	col[v] = c;
	for(int i=0;i<g[v].size();i++){
		int u = g[v][i];
		if(used[u]){
			if(col[u]==col[v])flag = false;
		}else{
			dfs(u,1-c);
		}
	}
	return;
}
int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){
		int u,v;
		cin >> u >> v;
		u--;
		v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	memset(used,false,sizeof(used));
	ll ans = 0ll;
	ll X = 0ll, Y = 0ll ,Z = 0ll;
	for(int i=0;i<N;i++){
		if(!used[i]){
			k = 0;
			flag = true;	
			dfs(i,0);
			if(k==1){
				ans++;
				Z++;
			}else{
				if(!flag){
					ans++;
					Y++;
				}else{
					ans+=2;
					X++;
				}
			}
		}
	} 
	/*cout << ans << endl;
	cout << X << endl;
	cout << Y << endl;
	cout << Z << endl;*/
	ans += 2ll*X*(X-1ll);
	ans += Y*(Y-1ll);
	ans += 2ll*X*Y;
	ans += Z*(Z-1ll);
	ans += 2ll*Z*((ll)N-Z);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 10112
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        String s = sc.next();
        Boolean flag = true;

        for(int i =0;i<s.length();i++){
            if(i==a){
                if(s.charAt(i)!='-'){
                    flag = false;
                }
            }else{
                if(!(s.charAt(i)>=48 && s.charAt(i)<=57)){
                    flag = false;
                }
            }
        }
        
        if(flag){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
    }
}


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

int N;
string S;

int main() {
  cin >> N;
  cin >> S;
  rep(i, S.size()) {
    cout << (char)((((int)S[i] + N - ((int)('A'))) % 26 + ((int)('A')))) << flush;
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cassert>
#include<ctime>
#include<climits>
#include<queue>
#include<fstream>
#include<deque>
#include<iomanip>
#include<list>
#include<stack>
#include<sstream>
#include<string>
#include<cctype>
#include<cstdio>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-10
#define F first
#define S second
#define all(n) n.begin(),n.end()
#define pb push_back
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define INF (1<<27)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int MAX = 1000010;
bool prime[MAX+2];
  
  
  
  
class AOJ2048{
private:
  int a,b;
  vector<int> A,B;
public:
  AOJ2048(int a,int b):a(a),b(b){}
     
   
  
  vector<int> div(int num){
    vector<int> vec;
    for(int i=2;i<=sqrt(num);i++){
      if(num%i == 0){
    vec.pb(i);
    //cout << "pre " << num << endl;
    while(num%i == 0)
      num = num/i;
    //cout << "after " << num << endl << endl;
    if(num == 1)break;
      }
    }
    if(num != 1)vec.pb(num);
    // rep(i,vec.size()){
    //cout <<"vec = " << vec[i] << endl;
    // }
    return vec;
  }
  
  void run(){
     
    A = div(a);
    B = div(b);
    ll totalA,totalB;
    totalA = totalB = 0;
    int maxa,maxb;
    maxa=maxb=0;
    rep(i,A.size()){
      if(prime[A[i]]){
    maxa = max(maxa,A[i]);
    totalA += A[i];
      }
      //cout << "a = " << A[i] << endl;
    }   
  
    rep(i,B.size()){
      if(prime[B[i]]){
      maxb = max(maxb,B[i]);
      totalB += B[i];
      }
    }   
    totalA -= maxa;
    maxa -= totalA;
    totalB -= maxb;
    maxb -= totalB;
    if(maxa > maxb){
      cout << 'a' << endl;
    }
    else cout << 'b' << endl;
  
  }
  
  
};
  
void eratos(){
  rep(i,MAX+1)prime[i] = false;
  for(int i=3;i<=MAX;i+=2)prime[i] = true;
  prime[2] = true;
  int lim = (int)sqrt((double)MAX)+1;
  for(int i=3;i<=lim;i+=2){
    if(!prime[i])continue;
    for(int j=i+i;j<=MAX;j+=i)prime[j] = false;
  }
}
  
int main(){
  int Aa,Ba;
    eratos();
    
    while(true){
      cin >> Aa >> Ba;
      if(Aa+Ba == 0)break;
      AOJ2048 ans = AOJ2048(Aa,Ba);
      ans.run();
    }
return 0;
}

Measured memory_bytes: 2184
#include<iostream>
#include<algorithm>
#include<cmath>
#include <numeric>
#include <string>
using ll = long long;
using namespace std;

int main()
{
	ll n;

	cin >> n;
	string ans = "";
	while (n != 0) {
		if (n % 2 != 0) {
			n--;
			ans = "1" + ans;
		}
		else {
			ans = "0" + ans;
			
		}
		n /= -2;
	}

	if (ans == "") {
		ans = "0";
	}

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


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

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int dx = x2 - x1;
  int dy = y2 - y1;
  int x3 = x2 - dy;
  int y3 = y2 + dx;
  int x4 = x1 - dy;
  int y4 = y1 + dx;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}


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

#define MAX 100000

vector<int> G[MAX];
int N;
bool visited[MAX];
int prenum[MAX], parent[MAX], lowest[MAX], timer;

void dfs( int current, int prev ) {
  // ノード current を訪問した直後の処理
  prenum[current] = lowest[current] = timer;
  timer++;

  visited[current] = true;

  int next;

  for ( int i = 0; i < G[current].size(); i++ ) {
    next = G[current][i];
    if ( !visited[next] ) {
      // ノード current からノード next へ訪問する直前の処理
      parent[next] = current;

      dfs( next, current );

      // ノード next の探索が終了した直後の処理
      lowest[current] = min( lowest[current], lowest[next] );
    } else if ( next != prev ) {
      // エッジ current -> next が Back-edge の場合の処理
      lowest[current] = min( lowest[current], prenum[next] );
    }
  }
  // ノード current の探索が終了した直後の処理
}

void art_points() {
  for ( int i = 0; i < N; i++ ) visited[i] = false;
  timer = 1;
  // lowest の計算
  dfs(0, -1);  // 0 == root

  set<int> ap;
  int np = 0;
  for ( int i = 1; i < N; i++ ) {
    int p = parent[i];
    if ( p == 0 ) np++;
    else if ( prenum[p] <= lowest[i] ) ap.insert(p);
  }
  if ( np > 1 ) ap.insert(0);
  for ( set<int>::iterator it = ap.begin(); it != ap.end(); it++ )
    cout << *it << endl;
}

int main() {
  int m;
  cin >> N >> m;

  for ( int i = 0; i < m; i++ ) {
    int s, t;
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  art_points();

  return 0;
}


Measured memory_bytes: 6880
#include<bits/stdc++.h>
// using namespace std;
typedef long long ll;
const int mod=1e9+9;
const int N=1e5+5;

int n,m;
int h[N];
bool yes[N];

int main()
{
    // ios::sync_with_stdio(false);std::cin.tie(0);cout.tie(0);                           
    // freopen("a.in","r",stdin);
    // int T;scanf("%d",&T);while(T--){
    // while(~scanf("%d%d%d",&n,&p,&c)){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d",&h[i]),yes[i]=1;
    for(int i=1,u,v;i<=m;i++)
    {
        scanf("%d%d",&u,&v);
        if(h[u]==h[v]) yes[u]=yes[v]=0;
        else if(h[u]>h[v]) yes[v]=0;
        else yes[u]=0;
    }
    int ans=0;
    for(int i=1;i<=n;i++) if(yes[i]) ans++;
    printf("%d\n",ans);
    // }
    return 0;
}

Measured memory_bytes: 4356
q, h, s, d = map(int, input().split())
n = int(input())
one = [q*4, h*2, s]
one.sort()
cost = 0
if one[0]*2>d:
    cost += d*(n//2)
    n %= 2
cost += one[0]*int(n)
n -= int(n)
if n==0:
    print(cost)
else:
    n *= 100
    x = []
    x.append(q*(n//25))
    x.append(s*(n//50)+q*((n%50)//25))
    print(min(x)+cost)

Measured memory_bytes: 61912
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int h,w;
    cin>>h>>w;
    vector<vector<int>> a(h,vector<int>(w,0));
    vector<int> b(w,0);
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int s;
            cin>>s;
            a[i][j]=s;
        }
    }
    for(int i=0;i<w;i++){
        int s;
        cin>>s;
        b[i]=s;
    }
    vector<int> ans(h,0);
    for(int i=0;i<h;i++){
        int num=0;
        for(int j=0;j<w;j++){
            num+=a[i][j]*b[j];
        }
        ans[i]=num;
    }
    for(int i=0;i<h;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3204
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include <algorithm>
#include <functional>

using namespace std;

int main (void){
    int N,D;
    cin >> N >> D;

    int s = 1+(D*2);
    int n = N/s;
    if(N%s != 0) n++;
    cout << n << endl;
    return 0; 
}

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

int main()
{

    int n;
    cin >> n;

    vector <string> v;
    for(int i=0 ; i < n; i++)
    {
        string s;
        cin >> s;
        v.push_back(s);
    }
    cout << "AC x " <<count(v.begin(),v.end(),"AC") << "\n";
    cout << "WA x " << count(v.begin(),v.end(),"WA") << "\n";
    cout << "TLE x " << count(v.begin(),v.end(),"TLE") << "\n";
    cout << "RE x " << count(v.begin(),v.end(),"RE") << "\n";
}


Measured memory_bytes: 7456
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<cstdlib>
//#include<cmath>
//#include<algorithm>
//#include<vector>
//#include<queue>
//#include<stack>
//#include<map>
//#include<set>
using namespace std;
#define SC scanf
#define PR printf
#define pb push_back
#define mp make_pair
#define SZ(v) ((int)(v).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define db double
#define ldb long double
#define uint unsigned
#define ll long long
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef pair<pii,pii> ppp;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef map<int,int> mii;
const int INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const int xx[4]={1,-1,0,0};
const int yy[4]={0,0,1,-1};
int inline nextin(){
	int t;
	if(scanf("%d",&t)!=1)exit(0);
	return t;
}
int inline in(){
	int x=0,c;
	for(;(uint)((c=getchar())-'0')>=10;){
		if(c=='-')return -in();
		if(!~c)throw ~0;
	}
	do{
		x=(x<<3)+(x<<1)+(c-'0');
	}while((uint)((c=getchar())-'0')<10);
	return x;
}
bool dislike[10];
int main(){
    cin.sync_with_stdio(false);cin.tie(0);
	int n;
	int k;
	cin>>n>>k;
	rep(i,k){
		int x;
		cin>>x;
		dislike[x]=true;
	}
	for(int i=n;i<100000;i++){
		string S=to_string(i);
		rep(j,SZ(S)){
			if(dislike[S[j]-'0']){
				goto E;
			}
		}
		cout<<i<<endl;
		break;
		E:;
	}
	return 0;
}

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

int main() {

    int n, k; cin >> n >> k;
    vector<int> num(n, 0);
    for (int i = 0; i < k; i++) {
        int d; cin >> d;
        for (int j = 0; j < d; j++) {
            int a; cin >> a;
            num[--a]++;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (num[i] == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
=begin
N
P1 P2 ... Pn
Q1 Q2 ... Qn
=end

require "set"

n = gets.chomp.to_i
ps = gets.chomp.split(" ").map(&:to_i)
qs = gets.chomp.split(" ").map(&:to_i)

candidates = n.times.map {|i| i + 1}.to_set

def order_num(candidates, targets, smaller)
  if targets.count == 0
    return 1
  end

  result = nil

  if smaller
    prod = 1
    (1..(candidates.count)).each do |i|
      prod = prod * i
    end

    result = prod
  else
    target = targets.first

    o1 = order_num(candidates.dup.delete(target), targets[1..-1], false)
    
    o2 = 0
    candidates.select {|c| c < target}.each do |c|
      o2 += order_num(candidates.dup.delete(c), targets[1..-1], true)
    end

    result = o1 + o2
  end

  # p [candidates, targets, smaller, result]
  result
end

a = order_num(candidates.dup, ps, false)
b = order_num(candidates.dup, qs, false)

# p a
# p b

p((a-b).abs)


Measured memory_bytes: 3964
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String[] line = br.readLine().split(" ");
      int n     = Integer.parseInt(line[0]);
      int qTime = Integer.parseInt(line[1]);
      Queue<Process> queue = new Queue<>(n*2);

      for(int i=0; i!=n; i++) {
        line = br.readLine().split(" ");
        queue.enQueue( new Process(line[0], Integer.parseInt(line[1])) );
      }

      int usingTime = 0;
      Process proc;
      StringBuilder result = new StringBuilder(n*5);

      while(!queue.isEmpty()) {
        proc = queue.deQueue();
        proc.pTime -= qTime;

        if(proc.pTime < 1) {
          usingTime += qTime + proc.pTime;
          result.append(proc.name).append(" ").append(usingTime).append("\n"); 
        } else {
          usingTime += qTime;
          queue.enQueue(proc);
        }
      }

      System.out.print(result);
    }
  }
}

class Process {
  final String name;
  int pTime;

  public Process(String name, int time) {
    this.name = name;
    this.pTime = time;
  }
}

class Queue<E> {

  private Object[] queue;
  private int head;
  private int tail;
  private int max;

  public Queue(int capacity) {
    queue = new Object[capacity];
    head = tail = 0;
    max  = queue.length;
  }

  boolean isEmpty() {
    return head == tail;
  }
  boolean isFull() {
    return head == (tail + 1) % max;
  }

  void enQueue(E x) {
    if(isFull()) System.out.println("queue is full!");

    queue[tail] = x;
    if(tail+1 == max) tail = 0;
    else tail++;
  }
  @SuppressWarnings("unchecked")
  E deQueue() {
    if(isEmpty()) {
      System.out.println("queue is empty!");
      throw new IllegalStateException("queue is empty!");
    }

    E ret = (E)queue[head];

    if(head+1 == max) head = 0;
    else head++;

    return ret;
  }
}


Measured memory_bytes: 56612
N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))
X = 0
Y = 0
for i in range(N):
    if V[i] > C[i]: 
        X = X + V[i]
        Y = Y + C[i]
       
print(X - Y)

Measured memory_bytes: 3060
x, y = list(map(int, input().split()))
group1 = [1,3,5,7,8,10,12]
group2 = [4,6,9,11]
group3 = [2]

if x in group1 and y in group1 or x in group2 and y in group2 or x in group3 and y in group3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#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++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int abc(string s,int itr){
    int flag = 0;
    if (s[itr] =='A' && s[itr+1] == 'B' && s[itr+2] == 'C'){
        flag = 1;
    }
    return flag;
}
int main()
{
    int N;
    string S;
    cin >> N >> S;

    int count = 0;
    REP(i, N-2){
        count += abc(S,i);
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=16;
const ll inf=1e18;
const ll mod=1e9+7;

ll a[MX][MX], n;
ll dp[1<<20];

int main()
{
    FasterIO;

    cin>>n;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            cin>>a[i][j];
        }
    }

    for(int mask=0; mask<(1<<n); mask++)
    {
        for(int i=0; i<n; i++)
        {
            if(mask&(1<<i))
            {
                for(int j=i; j<n; j++)
                {
                    if(mask&(1<<j)) dp[mask]+=a[i][j];
                }
            }
        }
    }

    for(int mask=1; mask<(1<<n); mask++)
    {
        for(int msk=mask; msk>0; msk=(mask&(msk-1)))
        {
            dp[mask]=max(dp[mask], dp[msk]+dp[mask^msk]);
        }
    }
    cout<<dp[(1<<n)-1]<<endl;
    return 0;
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1


struct box{
    int y;
    int x;
}
;

int main() {

    int h,w,d;
    int a[303][303];
    int q;
    int l,r;

    int spend[100000] = {};

    box b[100000];
    Scd3(h,w,d);
    Rep(i,h){
        Rep(j,w){
            Scd(a[i][j]);
            b[a[i][j]] = {i,j};
        }
    }

    for ( int i = d+1; i <= w*h; i++){
        spend[i] += abs(b[i].x - b[i-d].x) + abs(b[i].y - b[i-d].y) + spend[i-d];
    //    printf ("%d->%d (%d)\n", i%d, i, spend[i]);
    }

    Scd(q);
    Rep(i,q){
        Scd2(l,r);
        if( l != r )
        printf ("%d\n", spend[r] - spend[l]);
        else
        printf ("%d\n", 0);
    }
    return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
 
constexpr int INF = 1e9;
constexpr int MOD = 1e9+7;

int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll l = 0,r = 1e9,m;
    while(r > 1 && l < r){
        m = (l+r)/2;
        ll cnt = 0;
        for(int i = 0; i < n; i++) cnt += (a[i]-1)/m;
        if(k < cnt) l = m+1;
        else r = m-1;
    }
    r = max(1ll,r-2);
    while(1){
        ll cnt = 0;
        for(int i = 0; i < n; i++) cnt += (a[i]-1)/r;
        if(cnt <= k){
            cout << r << endl;
            return 0;
        }else r++;
    }
}

Measured memory_bytes: 4784
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <cstring>
#include <iterator>
#include <typeinfo>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int MOD=1e9+7;
const int INF=1e9+7;
const double PI=3.141592653589793238462643383279;
//
int N;
int A[2][100];
int DP[2][100];
int main(){
  cin>>N;
  FOR(i,0,2){
    FOR(j,0,N){
      cin>>A[i][j];
    }
  }
  DP[0][0]=A[0][0];
  FOR(i,1,N){
    DP[0][i]=DP[0][i-1]+A[0][i];
  }
  DP[1][0]=DP[0][0]+A[1][0];
  FOR(i,1,N){
    DP[1][i]=max(DP[0][i]+A[1][i],DP[1][i-1]+A[1][i]);
  }
  cout<<DP[1][N-1]<<endl;
  return 0;
}


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

int main()
{
  int N,K,count=0;
  cin >> N >> K;
  int d[K], A[K][N], ans[N]={};
  for (int i = 0; i < K; i++)
  {
    cin >> d[i];
    for (int j = 0; j < d[i]; j++)
    {
      cin >> A[i][j];
      ans[A[i][j]-1]++;
    }
    
  }
  for (int i = 0; i < N; i++)
  {
    if (ans[i]==0) count++;
    
  }
  cout << count;
    }


Measured memory_bytes: 3616
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}


int main(){
    int N;
    cin>> N;
    int A[N+1], B[N];
    rep(i,N+1)cin >> A[i];
    rep(i,N)cin >> B[i];

    long long ans = 0;
    rep(i,N){
        if(B[i] >= A[i]){
            B[i] = B[i]-A[i];
            if(B[i] >= A[i+1]){
                ans += A[i]+ A[i+1];
                A[i+1] = 0;
            }else{
                A[i+1]-= B[i];
                ans += A[i]+B[i];

            }
        }else{
            ans += B[i];
        }
    }

    cout << ans << endl;


}

Measured memory_bytes: 4396
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll inf = (1LL << 60LL);
const int maxn = 1e5 + 10;
int n, m;
int arr[maxn][3];
vector<pair<int, int> > v[maxn];
string ret[maxn];
string toStr(int &num){
    int tmp = num;
    string rr = "";
    while(tmp){
        rr += (tmp % 10) + '0';
        tmp /= 10;
    }
    reverse(rr.begin(), rr.end());
    return rr;
}
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    int mxx = 0;
    for(int i = 0; i < m; i ++){
        cin >> arr[i][0] >> arr[i][1];
        v[arr[i][0]].push_back(make_pair(arr[i][1], i));
        mxx = max(mxx, arr[i][0]);
    }
    for(int i = 0; i <= mxx; ++i){
        if(!v[i].empty()){
            sort(v[i].begin(), v[i].end());
            for(int j = 0; j < (int)v[i].size(); j ++){
                ret[v[i][j].second] = toStr(i);
                while(ret[v[i][j].second].size() < 6){
                    ret[v[i][j].second].insert(0, "0");
                }
                int t = j + 1;
                ret[v[i][j].second] += toStr(t);
                while(ret[v[i][j].second].size() < 12){
                    ret[v[i][j].second].insert(6, "0");
                }
            }
        }
    }
    for(int i =0 ; i < m; i ++){
        cout << ret[i] << endl;
    }
    
    return 0;
}


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

using namespace std;
typedef long long ll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

const ll inf = 1000000000000000000LL;

ll pw(ll x, ll y) {
	ll s = 1;
	for (int i = 0; i < y; i ++) {
		if (inf/x < s) return inf;
		s *= x;
	}
	return s;
}

ll ff(ll x, ll y) {
	ll le = 1, ri = x;
	while (le <= ri) {
		ll mi = (le+ri)/2;
		if (pw(mi, y) > x) ri = mi-1;
		else le = mi+1;
	}
	return ri;
}

int main() {
	ll N, A;
	cin >> N >> A;
	ll S = N;
	for (ll n = 1; n <= 40; n++) {
		// find N^(1/(n+1))
		ll le = ff(N, n+1);
		ll ri = le+1;
		for (int m = 0; m <= n; m++) {
			ll T = 0;
			ll U = 1;
			for (int i = 0; i < m; i ++) {
				T += le;
				U *= le;
			}
			for (int i = m; i < n; i ++) {
				T += ri;
				U *= ri;
			}
			if (N%U == 0) T += N/U; else T += N/U+1;
			T += A*n;
			S = min(S, T);
		}
	}
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
rc = [[0, 0]]+[list(map(int, input().split())) for i in range(n)]
m = [[0]*(n+1) for _ in range(n+1)]

for l in range(2, n+1):
    for i in range(1, n-l+2):
        j = i+l-1
        m[i][j] = 2**64
        for k in range(i, j):
            m[i][j] = min([
                m[i][j],
                m[i][k]+m[k+1][j]+rc[i][0]*rc[k+1][0]*rc[j][1]
            ])
print(m[1][n])



Measured memory_bytes: 5720