akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=100000 +117;
const int MM=1000000 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.cpp.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n,q,mod;
int e[NN][3]={};
int kd[2][MM]={};
int fa[NN*6]={};
void initi(int n){
	for(int i=1;i<=n;++i)fa[i]=i;
}
int getfa(int x){
	return x==fa[x]?x:fa[x]=getfa(fa[x]);
}
bool link(int x,int y){
	if(getfa(x)==getfa(y))return false;
	fa[fa[x]]=fa[y];
	return true;
}
bool check(int x,int y){
	return getfa(x)==getfa(y);
}
int main(){
	//open();
	n=read();
	m=read();
	q=read();
	mod=read();
	int g=mod;
	for(int i=1;i<=m;++i){
		int x=read(),y=read(),c=read();
		e[i][0]=x,e[i][1]=y,e[i][2]=c;
		g=__gcd(g,abs(e[1][2]-e[i][2]));
	}
	mod=__gcd(mod,3*g);
	int z=e[1][2]%g;
	int mi=1;
	for(int i=1;i<=mod;++i){
		kd[0][(LL)mi*z%mod]=1;
		mi=mi*4%mod;
	}
	mi=2;
	for(int i=1;i<=mod;++i){
		kd[1][(LL)mi*z%mod]=1;
		mi=mi*4%mod;
	}
	initi(n*6+5);
	for(int i=1;i<=m;++i){
		e[i][2]=(e[i][2]-z)/g;
		for(int a=0;a<=1;++a)for(int b=0;b<=2;++b){
			int c=a^1,d=(b*2+e[i][2])%3;
			link(e[i][0]*6+a*3+b,e[i][1]*6+c*3+d);
			link(e[i][1]*6+a*3+b,e[i][0]*6+c*3+d);
		}
	}
	for(int i=1;i<=q;++i){
		int s=read(),t=read(),r=read();
		bool ok=0;
		for(int b=0;b<=2;++b){
			int fin=(z+r+3*g-b*g)%mod;
			if(kd[0][fin]){
				ok|=check(t*6+0*3+0,s*6+b);
			}
			if(kd[1][fin]){
				ok|=check(t*6+0*3+0,s*6+3+b);
			}
		}
		if(ok)printf("YES\n");
		else printf("NO\n");
	}
	close();
	return 0;
}

Measured memory_bytes: 10240
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cmath"
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll AA, BB, CC;

  std::cin >> AA>> BB>> CC;

  ll c_num;

  if (AA + BB + 1 >= CC) {
    c_num = CC;
  }else{
    c_num = AA + BB + 1;
  }

  std::cout << c_num+BB << '\n';


}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    W,a,b=map(int,input().split())
    if a<=b<=a+W or a<=b+W<=a+W or b<=a<=b+W or b<=a+W<=b+W:
        print(0)
    else:
        if a<b:
            print(b-(a+W))
        else:
            print(a-(b+W))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
s = input()
counter_A = 0
counter_Z = 0
for i in s:
    if i == 'A':
        break
    else:
        counter_A += 1
for i in s[::-1]:
    if i == 'Z':
        break
    else:
        counter_Z += 1
print(len(s) - counter_A - counter_Z)


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

int main(void){
    bool ab[26] = {false};
    char input;
    
    while((cin >> input)){
        if(!(input >= 'a' && input <= 'z')){
            break;
        }
        if(ab[input - 'a'] == true){
            cout << "no" << endl;
            return 0;
        }
        ab[input - 'a'] = true;
    }
    
    cout << "yes" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

int main(){
    int N,M;
    cin>>N>>M;
    priority_queue<int> job;

    rep(i,0,N){
        int tmpi;
        cin>>tmpi;
        job.push(tmpi);
    }

    rep(i,0,M){
        int tmpi=job.top();
        tmpi=floor(tmpi/2);
        job.pop();
        job.push(tmpi);
    }

    ll ans=0;
    rep(i,0,N){
        ans+=job.top();
        job.pop();
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

const int MAX_N = 200000;
int64_t n, x;
int pos[MAX_N];
uint64_t pre_sum[MAX_N+1];

__int128 e(uint64_t i, uint64_t x)
{
  if (i == 1) return (__int128)5*x;
  return (__int128)(2*i + 1) * x;
}

int ceil(int x, int y)
{
  if (x % y == 0) return x/y;
  return x/y + 1;
}

int main()
{
  cin >> n >> x;
  for (int i = 0; i < n; ++i) cin >> pos[i];

  pre_sum[0] = 0;
  for (int i = 0; i < n; ++i) {
    pre_sum[i+1] = pre_sum[i] + pos[i];
  }

  __int128 min_e = ULLONG_MAX;
  for (int k = 1; k <= n; k++) {
    __int128 total_e = (n+k) * x;
    for (int i = n-1; i >= 0; i -= k) {
      int l = max(0, i-k+1);
      total_e += e(ceil(n-i, k), pre_sum[i+1] - pre_sum[l]);
    }
    min_e = min(min_e, total_e);
  }

  cout << (uint64_t)min_e << endl;

  return 0;
}


Measured memory_bytes: 2560
H, W = map(int, input().split())
sh, sw = map(int, input().split())
gh, gw = map(int, input().split())

sh += 1
sw += 1
gh += 1
gw += 1
s = sh*3000+sw
g = gh*3000+gw

S = [0]*(H+4)
S[0] = '*'*(W+4)
S[1] = '*'*(W+4)
S[-2] = '*'*(W+4)
S[-1] = '*'*(W+4)
for h in range(2,H+2):
  S[h] = '**' + input() + '**'

visited = [[float('inf')]*(W+4) for _ in range(H+4)]
dh1 = [0,1,0,-1]
dw1 = [1,0,-1,0]
dh2 = [2,2,2,2,2,1,1,1,1,0,0,-1,-1,-1,-1,-2,-2,-2,-2,-2]
dw2 = [-2,-1,0,1,2,-2,-1,1,2,-2,2,-2,-1,1,2,-2,-1,0,1,2]

from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
d = []
heapify(d)
heappush(d,s)
ans = float('inf')
while len(d)>0:
  a = heappop(d)
  cnt,a1 = divmod(a,10**7)
  h,w = divmod(a1,3000)
  if cnt>=ans:
    break
  visited[h][w] = cnt
  for i in range(4):
    h1 = h+dh1[i]
    w1 = w+dw1[i]
    if (h1,w1)==(gh,gw):
      ans = cnt
    if S[h1][w1]=='.':
      if visited[h1][w1]>cnt:
        visited[h1][w1]=cnt
        heappush(d,cnt*(10**7)+h1*3000+w1)
  for i in range(20):
    h2 = h+dh2[i]
    w2 = w+dw2[i]
    if (h2,w2)==(gh,gw):
      ans = cnt+1
    if S[h2][w2]=='.':
      if visited[h2][w2]>cnt+1:
        visited[h2][w2]=cnt+1
        heappush(d,(cnt+1)*(10**7)+h2*3000+w2)
ans = ans if ans<float('inf') else -1
print(ans)

Measured memory_bytes: 93936
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;
signed main(){
  int n,h;
  cin >> n >> h;
  vector<P> katana(n);
  int amax = 0;
  int bmax = 0;
  int key = 0;
  rep(i,n){
    int a,b;
    cin >> a >> b;
    katana[i] = make_pair(b,a);
  }
  sort(katana.begin(),katana.end());
  reverse(katana.begin(),katana.end());
  rep(i,n){
    if(amax < katana[i].second){
      amax = katana[i].second;
      bmax = katana[i].first;
      key = i;
    }
  }
  //cout << amax << " " << bmax << endl;
  int count = 0;
  int ans = 0;
  while(h > bmax){
    if(count != key && katana[count].first >= amax){
      h -= katana[count].first;
      ans++;
    }
    count++;
    if(count == n) break;
  }
  if(h > 0){
    if(h - bmax <= 0){
      ans++;
    }
    else{
      if((h-bmax) % amax == 0){
        ans += (h-bmax)/amax;
      }
      else{
        ans += (h-bmax)/amax + 1;
      }
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
	int N;
	cin >> N;
	int h[100];
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	int ans = 0;
	bool flag = 0;
	for (int i = 0; i < 100; i++) {
		flag = false;
		for (int j = 0; j < N; j++) {
			if (h[j] > 0) {
				h[j]--;
				flag = true;
			}
			else if (flag == true) {
				flag = false;
				ans++;
			}
		}
		if (flag == true) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc055/tasks/abc055_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, t = 0;
    cin >> n >> m;
    if (n <= m / 2) {
        t = (m / 2 - n) / 2;
        cout << n + t << endl;
    } else {
        cout << m / 2 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);  //"for float-base problem"
  int N;
  cin >> N;
  vector<long double> vec(N);
  REP(i, N) cin >> vec.at(i);
  sort(vec.begin(), vec.end());
  REP(i, N - 1) { vec.at(i + 1) = (vec.at(i) + vec.at(i + 1)) / 2; }

  cout << vec.at(N - 1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	int n;
	cin >> n;
	
	vector<int> a(n);
	int ans=0;
	for(int i=0; i<n; i++){
		cin >> a.at(i);
	}
	sort(a.begin(), a.end());
	int tmp=a.at(0);
	int cnt=1;
	for(int i=1; i<n; i++){
		if(tmp==a.at(i)){
			cnt++;
		}else{
			if(cnt%2!=0){
				ans++;
			}
			tmp=a.at(i);
			cnt=1;
		}
	}
	if(cnt%2!=0){
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
l=[0]*(n)
l1=[0]*(n)
for i in range(n):
    l[a[i]-1]+=1
    
for i in range(n):
    if l[i]>=2:
        l1[i]+=l[i]*(l[i]-1)//2

l1sum=sum(l1)
for i in range(n):
    if l[a[i]-1]-1>=2:print(l1sum-l1[a[i]-1]+ (l[a[i]-1]-1)*(l[a[i]-1]-2)//2)
    else:print(l1sum-l1[a[i]-1])

Measured memory_bytes: 26140
N = int(input())

A = tuple( map(int, input().split()) )

dict_ = {}

ans = 0
for i in range(N):
  k = (i+1) - A[i]
  if k in dict_:
    ans += dict_[k]
  ad = (i+1) + A[i]
  if ad in dict_:
    dict_[ad] = dict_[ad] + 1
  else:
    dict_[ad] = 1

print(ans)


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

int q;

bool input() {
	cin >> q;
	if(q == -1)
		return false;
	return true;
}

double solve() {
	double x = (double)q / 2;
	while(fabs(x * x * x - q) >= 0.00001 * q) {
		x = x - (x * x * x - q) / (3 * x * x);
	}

	return x;
}

int main(void) {
	while(input())
		printf("%.6f\n", solve());
}

Measured memory_bytes: 1192
import math
import itertools

N, D = [int(n) for n in input().split()]
X = []
for i in range(N):
    X.append([int(m) for m in input().split()])

def get_distance(p1, p2):
    d2 = 0
    for i in range(D):
        d2 += (p1[i] - p2[i])**2
    return math.sqrt(d2)

count = 0
for i, j in itertools.combinations(range(N), 2):
    if get_distance(X[i], X[j]).is_integer():
        count += 1

print(count)

Measured memory_bytes: 9108
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first) {
        return a.first < b.first;
    } else {
        return a.second < b.second;
    }
}

int main() {
    int N, K;
    string S;
    cin >> N >> K;
    cin >> S;
    int count = 0;
    int huko = 0;
    int hazi = 0;
    rep(i, 0, N) {
        if(i == 0) {
            if(S[i] == 'L') {
                count++;
                huko++;
                hazi++;
            }
        }
        if(i == N - 1) {
            if(S[i] == 'R') {
                count++;
                huko++;
                hazi++;
            }
        }
        if(i != N - 1) {
            if(S[i] == 'R' && S[i + 1] == 'L') {
                count++;
                huko++;
                huko++;
            }
        }
    }
    //  cout << "count:" << count << ",huko:" << huko << endl;
    if(count == 1) {
        cout << N - 1 << endl;

    } else if(count - 2 >= K) {
        //  cout << "aaaa" << endl;
        cout << N - huko + 2 * K << endl;
    } else {
        //  cout << "bbbb" << endl;
        int p = 2;
        if(hazi == 2) {
            p = 1;
        }
        cout << N - huko + 2 * (count - 2) + p << endl;
    }
}

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

struct Point {
	double x, y;
};

void koch(int n, Point a, Point b) {
	if (n == 0) return ;
	Point s, t, u;
	double th = M_PI * 60.0 / 180.0;

	s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
	s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
	t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
	t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
	u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) +s.x;
	u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) +s.y;

	koch(n-1, a, s);
	printf("%.8f %.8f\n", s.x, s.y);
	koch(n-1, s, u);
	printf("%.8f %.8f\n", u.x, u.y);
	koch(n-1, u, t);
	printf("%.8f %.8f\n", t.x, t.y);
	koch(n-1, t, b);

}

int main() {
	Point a, b;
	int n;

	scanf("%d", &n);

	a.x = 0;
	a.y = 0;
	b.x = 100;
	b.y = 0;
	printf("%.8f %.8f\n", a.x, a.y);
	koch(n, a, b);
	printf("%.8f %.8f\n", b.x, b.y);


	return 0;
}


Measured memory_bytes: 3204
#include <iostream>

const int MAX_N = 100;

int main(void) {
  int Adj[MAX_N + 1][MAX_N + 1] = {0};
  
  int n = 0;

  std::cin >> n;

  for (int i = 1; i <= n; i++) {
    int u = 0;
    int k = 0;
    
    std::cin >> u;
    std::cin >> k;

    for (int j = 0; j < k; j++) {
      int v = 0;
      
      std::cin >> v;
      
      Adj[i][v] = 1;
      //      Adj[v][i] = 1;
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      std::cout << Adj[i][j];

      if (j < n) {
	std::cout << " ";
      } else {
	std::cout << std::endl;
      }
    }
  }

  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll H, W, N;
    cin >> H >> W >> N;
    ll a = (H+N-1)/ H;
    ll b = (W+N-1)/W;
    print(min(a,b));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

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

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;

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;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    else return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

int INF = 1e9+7;

template<class T>
void dcomb(T n,T m, string s){
    if(n==0) cout << s << endl;
    else {
        for(T i=0; i<m; ++i){
            dcomb(n-1,m,s+to_string(i));
        }
    }
}

int main(){
    int n;
    cin >> n;
    Graph g(n);
    rep(i,n-1){
        int u,v,w;
        cin >> u >> v >> w;
        u -=1;
        v -=1;
        g[u].pb(Edge(v,w));
        g[v].pb(Edge(u,w));
    }
    vector<int> ans(n,INF);
    queue<int> que;
    que.push(0);
    ans[0] = 0;
    while (!que.empty()){
        int v = que.front();
        que.pop();
        for(Edge nv : g[v]){
            if(ans[nv.to]<1e9){
                continue;
            }
            if(nv.weight%2==0){
                ans[nv.to] = ans[v];
            }
            else{
                ans[nv.to] = abs(ans[v]-1);
            }
            que.push(nv.to);
        }
    }
    rep(i,n){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 6784
N, K = map(int, input().split())
kashi = [0] * N
cnt = 0

for i in range(K):
    d = int(input())
    A = [0] * d
    A = list(map(int,input().split()))
    for j in range(d):
        kashi[A[j]-1] += 1

for k in range(N):
    if kashi[k] == 0:
        cnt += 1

print(cnt)

Measured memory_bytes: 9204
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

const int MAX_M = 100;
const int MAX_A = 50;
const int MAX_SILVERS = MAX_M * MAX_A + 10;
const ll INF = LONG_LONG_MAX / 2;

// {to, money, time}
vector<vector<tuple<int, int, int>>> edges;

// dp[pos][money] = minimum time
vector<vector<ll>> dp;

void solve(const int N, const int M, const int S) {
    // {time, pos, money}
    priority_queue<
        tuple<ll, int, int>,
        vector<tuple<ll, int, int>>,
        greater<tuple<ll, int, int>>> que;

    que.push({0, 0, S});

    while (!que.empty()) {
        ll cur_time;
        int cur_pos, cur_money;
        tie(cur_time, cur_pos, cur_money) = que.top();
        que.pop();
        // printf("cur_time: %lld, cur_pos: %d, cur_money: %d\n", cur_time, cur_pos, cur_money);

        for (auto &edge : edges[cur_pos]) {
            ll to_time;
            int to_pos, to_money;
            tie(to_pos, to_money, to_time) = edge;
            ll cand_time = dp[cur_pos][cur_money] + to_time;
            ll cand_money = cur_money + to_money;
            if (cand_money < 0 || cand_money > MAX_SILVERS) {
                continue;
            }
            if (cand_time < dp[to_pos][cand_money]) {
                dp[to_pos][cand_money] = cand_time;
                que.push({cand_time, to_pos, cand_money});
            }
        }
    }
}

int main(void) {
    int N, M, S;
    cin >> N >> M >> S;

    if (S > MAX_SILVERS) {
        S = MAX_SILVERS;
    }

    edges.resize(N);

    for (int i = 0; i < M; i++) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--;
        v--;
        edges[u].push_back({v, -a, b});
        edges[v].push_back({u, -a, b});
    }

    for (int i = 0; i < N; i++) {
        int c, d;
        cin >> c >> d;
        edges[i].push_back({i, c, d});
    }

    dp.resize(N, vector<ll>(MAX_SILVERS + 1, INF));
    dp[0][S] = 0;

    solve(N, M, S);

    // for (int i = 0; i < N; i++) {
    //     for (int j = 0; j < 50; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // cout << endl;

    for (int i = 1; i < N; i++) {
        ll ans = INF;
        for (int j = 0; j <= MAX_SILVERS; j++) {
            chmin(ans, dp[i][j]);
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 9408
import itertools
N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
answer_list=list(itertools.permutations(range(1,N+1)))
P_num=answer_list.index(tuple(P))
Q_num=answer_list.index(tuple(Q))
print(abs(P_num-Q_num))

Measured memory_bytes: 8052
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <numeric>
#include <string>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
#define ullrep(i, a, b) for(ull i = (a); i < (b); ++i )
#define ullrrep(i, a, b) for(ull i = (a); i > (b); --i )
#define ullREP(i, a, b) for(ull i = (a); i <= (b); ++i )
#define ullRREP(i, a, b) for(ull i = (a); i >= (b); --i )

int N;
char A[600][600];
int main() {
    cin >> N;
    rep(i, 0, N)
    rep(j, 0, N) {
        char x;
        cin >> x;
        A[N+i][N+j] = x;
        A[i][N+j] = x;
        A[N+i][j] = x;
        A[i][j] = x;
//        A[N-(i+1)][N+j] = x;
//        A[N-(i+1)][N-(j+1)] = x;
//        A[N+i][N-(j+1)] = x;
    }
    ll cnt = 0;
    rep(offset, 0, N)
    {
        bool flag = true;
        rep(i, 0, N) {
            rep(j, i+1, N) {
                if(A[N+i-offset][N+j] != A[N+j-offset][N+i]) {
                    i = N+1;
                    j = N+1;
                    flag=false;
                }
            }
        }
        if(flag) {
            cnt++;
        }
    }
    cout << cnt*N << endl;
}

Measured memory_bytes: 640
Q = int(input())

p = [True] * (10 ** 5 + 1)
p[0] = p[1] = False
for i in range(2, 10 ** 5 + 1):
    for j in range(2 * i, 10 ** 5 + 1, i):
        p[j] = False

pp = [0] * (10 ** 5 + 1)
for i in range(1, 10 ** 5 + 1):
    pp[i] = int(p[i] and p[(i + 1) // 2]) + pp[i - 1]

res = 0
for _ in range(Q):
    l, r = map(int, input().split())
    print(pp[r] - pp[l - 1])


Measured memory_bytes: 12740
n = gets.chop.to_i
v = gets.chop.split.map(&:to_f)

v.sort!

while v.length > 1 do
  new_num = (v[0] + v[1])/2

  v.delete_at(0)
  v.delete_at(0)

  v << new_num
  v.sort!

end

puts v[0]


Measured memory_bytes: 1788
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const ll MAX = 100005;
bool isPrime[MAX];
void makePrime(){
  for (ll i = 2; i < MAX; i++) isPrime[i] = true;
  for (ll i = 2; i * i < MAX + 1; i++){
    if(isPrime[i]){
      for (ll j = 2 * i; j < MAX; j += i) {
        isPrime[j] = false;
      }
    }
  }
  return;
}
bool memo[100005];
int MEMO[100005];
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  makePrime();
  FOR(i,1,100005) {
    if(i & 1) {
      memo[i] = isPrime[i] && isPrime[(i + 1) / 2];
    }
  }

  FOR(i,1,100005) {
    MEMO[i] = MEMO[i-1] + memo[i];
  }

  int Q; cin >> Q;
  FOR(i,0,Q) {
    int l, r; cin >> l >> r;
    cout << MEMO[r] - MEMO[l-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 1280
#ifdef _WIN32
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

// 継承可能な型
template <class Type>
struct IN : Type
{
	IN()
	{
		std::cin >> *this;
	}
};

// 継承不可能な型
template <class Type>
struct IN_
{
	Type val;

	IN_()
	{
		std::cin >> val;
	}

	operator Type&()
	{
		return val;
	}

	IN_<Type>& operator=(const Type& _value)
	{
		val = _value;
		return *this;
	}
};

template <class Char, class Type>
std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const IN_<Type>& value)
{
	return os << value.val;
}

template <class Char, class Type>
std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, IN_<Type>& value)
{
	return is >> value.val;
}

template <class Type>
void OUT(const Type& value)
{
	std::cout << value << std::endl;
}

template <class Type, class ... Args>
void OUT(const Type& value, const Args& ... args)
{
	std::cout << value << ' ';
	OUT(args...);
}

void Yes()
{
	OUT("Yes");
}
void No()
{
	OUT("No");
}

using ll = long long;
using inll = IN_<ll>;
using vll = std::vector<ll>;
using setll = std::set<ll>;
using msetll = std::multiset<ll>;
using instr = IN<std::string>;

#define FOR(i, m, n) for (ll (i) = (m); (i) < (n); ++(i))
#define REP(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (ll (i) = (n); (i) >= 0; --(i))
#define ITRREP(it, v) for (auto (it) = (v).begin(); (it) != (v).end(); ++(it))
#define ITRREPR(it, v) for (auto (it) = (v).rbegin(); (it) != (v).rend(); ++(it))
#define DIVUP(a, b) (((a) + (b) - 1) / (b))

void Main();

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

	Main();

#ifdef _DEBUG
	system("pause");
#endif

	return 0;
}

using namespace std;

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

void Main()
{
	instr s;
	bool a = false, b = false, c = false;
	for (const auto val : s)
	{
		if (val == 'a')
			a = true;
		if (val == 'b')
			b = true;
		if (val == 'c')
			c = true;
	}

	return a && b && c ? Yes() : No();
}


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

int main() {
  int N;
  cin >> N;
  int X = ceil(N / 1.08);

  double XshouldBe = X * 1.08;
  if (floor(XshouldBe) == N) {
    cout << X << endl;
  } else {
    cout << ":(" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{ 
	public static void main(String[] args) {
	Scanner input = new Scanner (System.in);
    String w = input.next();char ch ;
    int []counter=new int [26];
    for (int i = 0; i < w.length(); i++) {
		ch = w.charAt(i);
		counter[ch-'a']++;
	}
  String s = "Yes";
  for (int i = 0; i < counter.length; i++) {
	if (counter[i]%2!=0) {
		s="No";
	}
}	System.out.println(s);

}}

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

template<typename T>
struct Segtree {
    int n;
    T e;
    vector<T> dat;
    typedef function<T(T a, T b)> Func;
    Func f;

    Segtree(){}
    Segtree(int n_input, Func f_input, T e_input){
        initialize(n_input, f_input, e_input);
    }
    void initialize(int n_input, Func f_input, T e_input){
        f = f_input;
        e = e_input;
        n = 1;
        while(n < n_input) n <<= 1;
        dat.resize(2*n-1, e);
    }

    void update(int k, T a){
        k += n - 1;
        dat[k] = a;
        while(k > 0){
            k = (k - 1)/2;
            dat[k] = f(dat[2*k+1], dat[2*k+2]);
        }
    }

    T get(int k){
        return dat[k+n-1];
    }

    T between(int a, int b){
        return query(a, b+1, 0, 0, n);
    }

    T query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return e;
        if(a<=l && r<=b) return dat[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> RLC(M);
    for(int i=0; i<M; i++){
        int l, r, c;
        cin >> l >> r >> c;
        RLC[i] = {r-1, l-1, c};
    }
    sort(RLC.begin(), RLC.end());

    const int64_t INF = 1e18;
    Segtree<int64_t> st(N, [](int64_t a, int64_t b){ return min(a, b); }, INF);
    st.update(0, 0);
    for(auto& v : RLC){
        int r = v[0], l = v[1], c = v[2];
        int64_t res = st.between(l, r) + c;
        if(st.get(r) > res) st.update(r, res);
    }
    int64_t ans = st.get(N-1);
    if(ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}


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

 using namespace std;
 typedef long long ll;
 #define rep(i, n) for(int i = 0; i < (int)(n); i++)

 int main() {
   int N;
   ll K, tmp1, tmp2;
   cin >> N >> K;
   map<ll, ll> ab;
   rep(i, N) {
     cin >> tmp1 >> tmp2;
     ab[tmp1] += tmp2;
   }
   for (auto p: ab) {
     if (K <= p.second) {
       cout << p.first << endl;
       break;
     }
     else K -= p.second;
   }
 }


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
int main(void)
{ll x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
    return 0;
}

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

const ll MOD = 1e9 + 7;

ll powMod(ll x, ll k) {
  if (k == 0) return 1;
  if (k % 2 == 0)
    return powMod(x * x % MOD, k / 2);
  else
    return x * powMod(x, k - 1) % MOD;
}

int main() {
  int N;
  cin >> N;
  vector<ll> x(N), a(N + 1);
  for (int i = 0; i < N; i++) cin >> x[i];

  ll ans = 0, fac = 1;
  for (int i = 1; i <= N - 1; i++) {
    fac *= i;
    fac %= MOD;
  }

  for (int i = 1; i <= N; i++) {
    a[i] = a[i - 1] + fac * powMod(i, MOD - 2);
    a[i] %= MOD;
  }

  for (int i = 0; i < N - 1; i++) {
    ans = (ans + (x[i + 1] - x[i]) * a[i + 1] % MOD) % MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4836
#include<bits/stdc++.h>
#define int long long
using namespace std;
int times[100001],n,q,sum;
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%lld",&x);
		times[x]++;
		sum+=x;
	}
	scanf("%lld",&q);
	while(q--)
	{
		int x,y;
		scanf("%lld%lld",&x,&y);
		sum+=(y-x)*times[x];
		cout<<sum<<endl;
		times[y]+=times[x];
		times[x]=0;
	}
	return 0;
}

Measured memory_bytes: 4408
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define INF 1e9 + 5
using namespace std;

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

    vector<int> a(n);

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

    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j : {i + 1, i + 2})
        {
            if (j < n)
                dp[j] = min(dp[j], dp[i] + abs(a[j] - a[i]));
        }
    }
    return dp[n - 1];
}

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

    /*  int t;
    cin >> t;

    while (t--)*/
    cout << solve();

    return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;


int more_than(const vector<ll>& B, ll v) {
  int ret = B.size() - (lower_bound(ALL(B), v) - B.begin());
  return ret;
}

int main(){
  int N;
  cin >> N;
  vector<ll> a(N), b(N);
  REP(i,N) cin >> a[i];
  REP(i,N) cin >> b[i];

  ll ret = 0;
  REP(i,30){
    vector<ll> A(N), B(N);
    REP(j,N) A[j] = a[j] % (1LL << (i + 1));
    REP(j,N) B[j] = b[j] % (1LL << (i + 1));
    sort(ALL(B));

    ll tmp = 0;
    REP(j,N) {
      int mtT = more_than(B, (1LL << i) - A[j]);
      int mt2T = more_than(B, 2 * (1LL << i) - A[j]);
      int mt3T = more_than(B, 3 * (1LL << i) - A[j]);
      tmp += mtT - mt2T + mt3T;
    }
    ret += (tmp % 2) ? (1LL << i) : 0;
  }

  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 6552
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <random>
#include <ctime>
#include <sstream>
#include <numeric>
using namespace std;

int main(){
    int n ;
    cin >> n ;
    vector<pair<int,int> > a(n,pair<int,int>()) ;
    for (size_t i = 0; i < n; i++)
    {
        cin >> a.at(i).first ;
    }for (size_t i = 0; i < n; i++)
    {
        cin >> a.at(i).second ;
    }
    int ans = 0;
    for (size_t i = 0; i < n; i++)
    {
        if (a.at(i).first > a.at(i).second)
        {
            ans += a.at(i).first - a.at(i).second ;
        }
        
    }
    cout << ans << endl;
    
    
}

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

int main() {
	int n;	
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		int size=4;
		std::string a, b;
		std::vector<int> va, vb, out;
		std::cin >> a >> b;
		for (std::string::reverse_iterator aitr = a.rbegin(); aitr != a.rend(); aitr++) {
			va.push_back((int)*aitr - '0');
		}
		for (std::string::reverse_iterator bitr = b.rbegin(); bitr != b.rend(); bitr++) {
			vb.push_back((int)*bitr - '0');
		}
		out.push_back(0);
		size = va.size() > vb.size() ? va.size() : vb.size();
		for (int i = 0; i < size; i++) {
			out[i] = out[i] + (i < va.size() ? va[i] : 0) + (i < vb.size() ? vb[i] : 0);
			if (out[i] > 9) {
				out[i] = out[i] % 10;
				out.push_back(1);
			}
			else {
				out.push_back(0);
			}
		}
		if (out.back() == 0) out.pop_back();
		if (out.size() > 80) std::cout << "overflow" << std::endl;
		else {
			std::reverse(out.begin(), out.end());
			for (std::vector<int>::iterator itr = out.begin(); itr != out.end(); itr++) {
				std::cout << *itr;
			}
			std::cout << std::endl;
		}
	}
}

Measured memory_bytes: 3064
#include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<cstdlib>
    using namespace std;
    const int N=100000;
    int a[N];
    int n,m,k,u;
    long long sum;
    int main()
    {
           cin>>n>>m>>k;
           sum=0;
           for(int i=1;i<=n;i++)
            {
                u=0;
               if(i<10)
               {
                   if(i>=m&&i<=k)
                   sum+=i;
               }
               else if(i>=10&&i<100)
               {
                   u=(i/10)+(i%10);
                    if(u>=m&&u<=k)
                        sum+=i;
               }
                else if(i>=100&&i<1000)
               {
                   u=(i/100)+(i%100/10)+(i%100%10);
                    if(u>=m&&u<=k)
                        sum+=i;
               }
                else if(i>=1000&&i<10000)
               {
                   u=(i/1000)+(i%1000/100)+(i%1000%100/10)+(i%1000%100%10);
                    if(u>=m&&u<=k)
                        sum+=i;
               }
               else if(i==10000)
               {
                   u=1;
                   if(u>=m&&u<=k)
                    sum+=i;
               }
            }
            cout<<sum<<endl;
    }


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

int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s,t;
	cin>>s>>t;
	int count=0;
	for(int i=0;i<s.length();i++){
		if(s[i]==t[i])count++;
	}
	cout<<count;
	return 0;
	
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong(), a = sc.nextLong(), b = sc.nextLong();
		long sum = a * (n / (a + b));
		sum += a < n%(a+b) ? a : n%(a+b);

		System.out.println(sum);
	}
}

Measured memory_bytes: 35948
#include <bits/stdc++.h>
using namespace std;
 
//DEFINE and TYPEDEF--------------------------------------------------------------
 
#define FORG(i,a,n) for(lld i=a;i<n;i++) //for - general
#define FORZ(i,n) for(lld i=0;i<n;i++) //for - zero
#define FORGI(i,a,n,inc) for(lld i=a;i<n;i+=inc) //for - general incremental
#define FORZI(i,n,inc) for(lld i=0;i<n;i+=inc) //for - zero incremental
#define DEBUG(x) cerr<<(#x)<<" is "<<(x)<<"\n" //to debug values of variables
#define ZINDA cerr<<"\nIdhar-ich hai apun!!\n"; //to debug if code reached that point
#define SPEEDUP ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
 
#define SORTall(m) sort(m.begin(),m.end());
 
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define mod 1000000007
 
typedef long long int lld;
typedef unsigned long long int ulld;
 
lld power(lld b, lld e)
{
    if(e==0)
        return 1;
    if(e%2==1)
        return b*power(b*b,(e-1)/2);
    else
        return power(b*b,e/2);
}
 
lld power(lld b, lld e, lld m)
{
	if(e==0)
		return 1;
	if(e%2==1)
		return b*power(((b%m)*(b%m))%m,(e-1)/2,m)%m;
	else
		return power(((b%m)*(b%m))%m,e/2,m)%m;
}
 
int nDig(lld n)
{
	if(n==0)
		return 1;

    return floor(log10(n) + 1);
}

//endl : changed to '\n', to flush comment that definition
//--------------------------------------------------------------------------------

void swagWaalaFunction()
{
	double n,l,b,h;
	cin>>n;

	l=n/3;
	n-=l;
	b=n/2;
	h=n-b;

	double ans=h*l*b;
	printf("%.8lf",ans);
	return;
}

int main()
{
    SPEEDUP;
 	lld t=1;
 	//cin>>t;

 	while(t--)
 		swagWaalaFunction();

 	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = input()
B = input()
C = input()

count = 0
for i in range(N):
    if A[i] == B[i] == C[i]:
        pass
    elif A[i] == B[i] or B[i] == C[i] or C[i] == A[i]:
        count += 1
    else:
        count += 2

print(count)


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    ll n,x;cin>>n>>x;
    vl a(n);
    ll sum=0;
    rep(i,n){cin>>a[i];sum+=a[i];}
    if(sum==x){
        cout<<n<<endl;
        return 0;
    }
    if(sum<x){
        cout<<n-1<<endl;
        return 0;
    }
    sort(all(a));
    ll ans=0,cnt=0;
    rep(i,n){
        ans+=a[i];
        if(ans<=x){
            cnt++;
        }
        else{
            cout<<cnt<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	vector<ll>ch;
	for(ll i=0;i<n;i++){
		ch.push_back(i+1);
	}
	ll a,b;
	vector<ll>A,B;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		A.push_back(x);
	}
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		B.push_back(x);
	}
	ll now=0;
	do{
		if(ch==A){
			a=now;
		}
		if(ch==B){
			b=now;
		}
		now++;
	}while(next_permutation(ch.begin(),ch.end()));
	cout << abs(a-b);
	// your code goes here
	return 0;
}

Measured memory_bytes: 3592
/* ex5_3: Grid Compression
    Jun_JPN */

#include <stdio.h>

int main(void){

    int row_num, col_num, i, j;

    scanf("%d %d", &row_num, &col_num); // 行数，列数の順で値を取得

    char board[row_num][col_num];   // row_num × col_num行列を生成
    int row_flag[100] = {0}, col_flag[100] = {0};

    /* 行列boardを初期化 */
    for(i=0; i<row_num; i++){   //　まずi行を固定
        for(j=0; j<col_num; j++){   // j列を動かしていく
            scanf(" %c", &board[i][j]); // (i, j)成分を入力
        }
    }

    for(i=0; i<row_num; i++){   // まずi行を固定
        for(j=0; j<col_num; j++){   // j列を動かしていく
            if(board[i][j]=='#'){   // 少なくとも１つ'#'を含む行・列に旗を立てる（＝1を代入していく）
                row_flag[i] = 1;
                col_flag[j] = 1;
            }
        }
    }

    for(i=0; i<row_num; i++){   // まずi行を固定
        if(row_flag[i]){    // 少なくとも１つ'#'がi行に含まれているとき（＝row_flag[i]に旗が立っているとき）
            for(j=0; j<col_num; j++){   // j列を動かしていく
                if(col_flag[j]){    // col_flag[j]に旗が立っているとき
                    printf("%c", board[i][j]);
                }
                if(j==col_num-1){   // i行の最後まで調べ終えたとき
                    printf("\n");
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,k;cin >> a >> b >> k;
	bool flg=true;
	while(k>0){
		if(flg){
			b+=a/2;
			a/=2;
			flg=false;
		}
		else{
			a+=b/2;
			b/=2;
			flg=true;
		}
		k--;
	}
	cout << a << " " << b << endl;
}


Measured memory_bytes: 256
/*
ID: hafiz.i1
TASK: milk2
LANG: C++
*/
#include<bits/stdc++.h>

#define ll long long
#define mod 1000000007

using namespace std;



int main()
{
//    freopen("milk2.in", "r", stdin);
//    freopen("milk2.out", "w", stdout);
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    ll n,k,s=1e18;
    cin>>n>>k;
    ll l1[n+1];
    for(int i=1;i<=n;i++){
        cin>>l1[i];
    }
    sort(l1+1,l1+n+1,greater<int>());
    for(int i=1;i<=n-k+1;i++){
        s=min(s,l1[i]-l1[i+(k-1)]);
    }
    cout<<s<<endl;
}


Measured memory_bytes: 4336
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()
const int OPEN = 1, CLOSE = 0;
 
typedef pair<string, int> pp;
 
int main()
{
    int n, m;
    string s;
    map<string, int> l;
    cin >> n;
    REP(n){ cin >> s ; l.insert(pp(s, 1));}
    cin >> m;
    int f = CLOSE;
    REP(m)
    {
        cin >> s;
        if(l.find(s) == l.end())
            cout << "Unknown " << s << endl;
        else
        {
            if(f == CLOSE){ cout <<"Opened by " << s << endl;  f = OPEN;}
            else { cout << "Closed by " << s << endl; f = CLOSE;}
        }
    }
 
    return 0;
}

Measured memory_bytes: 1236
#include<stdio.h>

long long max(long long a,long long b){
  if(a>=b){
    return a;
  }else{
    return b;
  }
}

int main(void){
  long long a,b,c,d;
  scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
  
  printf("%lld\n",max(max(a*c,a*d),max(b*c,b*d)));
         return 0;
}


Measured memory_bytes: 1724
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)
int main(){
    int h,w,n;
    cin >> h >> w >> n;
    int ans1,ans2;
        ans1=n/h;
        ans2=n/w;
    if (ans1 > ans2){
      if (n%w > 0) ans2++;
      cout << ans2 << endl;
    }
    else {
       if (n%h > 0) ans1++;
       cout << ans1 << endl;
    }
  return 0;
}


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

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

long long int ans, n, a, b;

int main(){
	cin >> n >> a >> b;
	if(n == 1 && a != b){
	}else if(b > a){
		ans = (n - 2) * (b - a) + 1;
	}else if(b == a){
		ans = 1;
	}else{
		ans = 0;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	int n,m;
	cin >> n>>m;
	int l = 0,r = n;

	for(int i =0;i<m;i++)
	{
		int L,R;
		cin >> L >> R;
		l = max(l,L);
		r = min(r,R);
	}
	cout<<max(0,r-l+1)<<endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math

# -*- coding: utf-8 -*-
N = input()
Nint = int(N)
Nlist = list(map(int,list(N)))
l = len(N)
ans = 0
for i in range(l-1, 0, -1):
    Nint -= ((int(N[i]) + 1) % 10) * 10**(l-i-1)
    N = str(Nint)


ans = sum(list(map(int,list(N))))
print(ans)


Measured memory_bytes: 3060
package main

import (
	"bufio"
			"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		m, _ := strconv.Atoi(scanner.Text())
		if m == 0 {
			break
		}
		ab := make([][]int, 0)
		for i := 0; i < m; i++ {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			buf := make([]int, len(input))
			for j := range buf {
				buf[j], _ = strconv.Atoi(input[j])
			}
			ab = append(ab, buf)
		}
		dp := make([][]int, 8)
		for i := range dp {
			dp[i] = make([]int, 1001)
		}
		dp[0][0] = 1
		for i := 1; i < m+1; i++ {
			for j := 0; j < 1001; j++ {
				if dp[i-1][j] == 0 {
					continue
				}
				s := j
				for k := ab[i-1][1]; k > -1; k-- {
					if s < 1001 {
						dp[i][s] += dp[i-1][j]
					}
					s += ab[i-1][0]
				}
			}
		}
		scanner.Scan()
		g, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < g; i++ {
			scanner.Scan()
			n, _ := strconv.Atoi(scanner.Text())
			fmt.Println(dp[m][n])
		}
	}
}



Measured memory_bytes: 1260
n, m = map(int,input().split())
s = list(list(map(int, input().split())) for _ in range(m))
p = list(map(int,input().split()))

#print(n, m, s, p)
#print(s)
#各スイッチのon/offパターン
#0b0000000000~#0b1111111111を全部作成
sw2 = []
for i in range (1 << n):
    #各電球が点灯しているかどうか
    sw =  []
    for j in range(m):
        #各電球に関するスイッチに関するon/offパターンを全て列挙(関連しないスイッチはoff)
        cnt = 0
        for k in range(1, len(s[j])):
            if i >> (s[j][k] - 1) & 1 == 1:
                cnt += 1
            else:
                cnt += 0
            #print(bin(i), j, k, cnt)
        sw.append(cnt)
        #print(sw)
    sw2.append(sw)
#print(sw2)

ans2 = 0
for j in range(len(sw2)):
    ans = 0
    for k in range(len(sw2[j])):
        if sw2[j][k] % 2 == p[k]:
            ans += 1
    if ans == len(sw2[j]):
        ans2 += 1

print(ans2)
#     sw_cnd = []
#     for j in range(len[sw]):
#         for k in range(m):
#             if  sw[j][k] % 2 == p[j]:
#                 i_bin = bin(i)
#                 sw_cnd.append(i_bin)
#
# sw = set(sw)
# print(sw)
# print(len(sw))


Measured memory_bytes: 9232