akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int a;
  cin >> a;
  cout << 3*a*a << endl;
}

Measured memory_bytes: 256
N = int(input())
B = list(map(int,input().split()))
con = 0
for i in range(N):
  if i == 0:
    con += B[i]
  elif i == N - 1:
    con += B[N - 2]
  else:
    con += min(B[i - 1],B[i])
print(con)



Measured memory_bytes: 9112
from sys import stdin
#stdin = open("input.txt")

def insertionSort(A, N):
    for i in range(N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j += -1
        A[j+1] = v
        
        print(*A)

if __name__ == "__main__":
    N = int(stdin.readline())
    A = [int(item) for item in stdin.readline().split()]
    
    insertionSort(A, N)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=min((a), (b))

const int MOD=1000000007;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c, d;
	cin>>a>>b>>c>>d;
	abs(c-a)<=d || (abs(b-a)<=d && abs(c-b)<=d) ? cout<<"Yes"<<'\n' : cout<<"No"<<'\n';
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define x first
#define y second
#define mp make_pair
#define d long double
#define pii pair<int,int>
#define pb push_back
#define N 200003
#define inf (int)1e18
#define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int mod=1e9+7;
string s;
int n;


 
signed main()
{
    haha
    int arr[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin>>n;
    cout<<arr[n-1];
   
    
  
 
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int H; cin >> H;
    int sum = 0; int N; cin >> N;
    F0R(i, N) {
        int cur; cin >> cur; sum += cur;
    }
    cout << (sum>=H?"Yes":"No") << endl;
    
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
#define all(x) (x).begin(),(x).end()

	long long factorial(long long n) {
		if (n <= 1)
			return 1;
		else {
			return n * factorial(n - 1);
		}
	}

	long long comb(long long n, long long r) {
		long long  top = n;
		for (int i = 0; i < r - 1; i++) {
			top = top * (--n);
		}
		long long  bottom = factorial(r);
		return top / bottom;
	}

int main(){
  int n;
  cin >> n;
  map<int, ll> Map;
  vector<ll> vec(n+10);
  for(int i=0; i<n; i++){
    int num;
    cin >> num;
    vec[i+1] = num;
    Map[num] = Map[num] + 1;
  }

  ll sum = 0;
  for(int i=1; i<=n; i++){
    sum += comb(Map[i], 2);
  }
  //cout << sum << ln;

  for(int i=1; i<=n; i++){
    ll ans = sum - comb(Map[vec[i]], 2) + comb(Map[vec[i]] - 1, 2);
    cout << ans << ln;
  }

}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
#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 fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
using ll = long long; constexpr int inf = INT_MAX / 2; constexpr ll infl = 1LL << 60;
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }

void _main() {
  vector<int> a(5);
  int k;
  rep(i, 0, 5) cin >> a[i];
  cin >> k;

  bool f = true;
  rep(i, 0, 5) rep(j, i+1, 5) {
    if (a[j] - a[i] > k) f = false;
  }

  if (f) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
vector<ll>  divisor(ll n){
	vector<ll> a;
	for(ll i = 1; i*i <= n; i++) {
		if (n % i == 0){
			a.pb(i);
			if (i != n/i){
				a.pb(n/i);
			}
		}
	}
	return a;
} 


int main(){
	ll n,A,B;
	cin >> n;
	ll ans = LINF;
	vector<ll> v = divisor(n);//約数列挙。約数の数は大体ルートn個
	// for(int i = 0; i < v.size(); i++) {
	// 	cout << v[i] << endl;
	// }
	for(ll i = 0; i < v.size(); i++) {
		A = v[i];
		B = n/v[i];
		ll a = 1;
		ll b = 1;
		while(A >= 10){
			A /= 10;
			a ++;
		}

		while(B >= 10){
			B /= 10;
			b ++;
		}

		ll tmp = max(a,b);
		ans = min(tmp,ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll a, b;
  cin >> a >> b;
  bool ok = a % 3 == 0;
  ok |= b % 3 == 0;
  ok |= (a + b) % 3 == 0;

  string ans = ok ? "Possible" : "Impossible";
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# # # coding=utf-8
# # # Author: lee215

get = lambda: int(raw_input().strip())
getl = lambda: raw_input().strip()
gets = lambda: map(int, raw_input().strip().split())
getss = lambda n: [gets() for _ in xrange(n)]

# 2019-03-30 20:18
N = get()
S = getl()


if S.count('R') > S.count('B'):
    print 'Yes'
else:
    print 'No'


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

int32_t main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int n,m;
	cin >> n >> m;
	if(n<=m){
		for(int i=0;i<m;i++)
			cout << n;
	}
	else{
		for(int i=0;i<n;i++)
			cout << m;
	}
	// else cout << "No";
}


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

long long numOfInvs(int a[], int from, int to, int t[]) {
	if (from == to) {
		return 0LL;
	}
	int mid = (from + to) / 2;
	long long n = numOfInvs(a, from, mid, t) + numOfInvs(a, mid + 1, to, t);
	int i = from, j = mid + 1, k = 0;
	while (i <= mid && j <= to) {
		if (a[i] <= a[j]) {
			t[k++] = a[i++];
		}
		else {
			n += mid - i + 1;
			t[k++] = a[j++];
		}
	}
	if (i == mid + 1) {
		while (j <= to) {
			t[k++] = a[j++];
		}
	}
	else {
		while (i <= mid) {
			t[k++] = a[i++];
		}
	}
	k = 0;
	for (int i = from; i <= to; ++i) {
		a[i] = t[k++];
	}
	return n;
}

long long numOfInvs(int a[], int n) {
	int *t = new int[n];
	int from = 0;
	int to = n - 1;
	long long ret = numOfInvs(a, from, to, t);
	delete[] t;
	return ret;
}

int main() {
	int n;
	cin >> n;
	int *a = new int[n];
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	cout << numOfInvs(a, n) << endl;
	delete[] a;
}


Measured memory_bytes: 4336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;



int main()
{	
	int a,b;
	string s;
	stringstream ss;
	while(cin>>a>>b)
	{
		ss<<a+b;
		ss>>s;
		ss.clear();
		cout<<s.length()<<endl;
	}
	return 0;	
}


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

using namespace std;

int main(){
  int n,m,x;
  cin >> n >> m>> x;
  vector<int> c(n);
  vector<vector<int>> a(n,vector<int>(m,0));
  
  int64_t ans=100002000;
  for(int i=0;i<n;i++){
    cin >> c[i];
    for(int j=0; j<m; j++){
      cin >> a[i][j];
    }
  }
  
  for (int tmp = 0; tmp < (1 << n); tmp++) {
  	bitset<15> s(tmp);
    int64_t tmpmoney=0;
    vector<int> sum(m);
    
    for(int i=0; i<n;i++){
      if(s.test(i)){
        tmpmoney+=c[i];
        for(int j=0;j<m;j++){
          sum[j]+=a[i][j];
        }
      }
    }
    bool can =true;
    for(int j=0;j<m;j++){
      if(sum[j]<x)
        can =false;
    }
    if(can) ans=min(tmpmoney,ans);
  }
  if(ans!=100002000) cout << ans<< endl;
  else cout <<-1 <<endl;
      
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

int main(int argc, char* argv[])
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if(a<b && b<c) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
}



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


vector<bool> seen;

int dfs(const vector<vector<int>> &g, int s) {
    seen[s] = true;

    int cnt = 0;
    for(auto x : g[s]) {
        if(seen[x] == false) {
            cnt += dfs(g, x);
        }
    }
    return cnt + 1;
}

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

    int n,m;
    cin >> n >> m;
    vector<vector<int>> graph(n);

    rep(i,m) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    seen.assign(n, false);

    int v;
    int ans = 0;
    rep(i,n) {
        if(seen[i] == true) continue;
        v = dfs(graph, i);
        ans = max(ans, v);
    }
    cout << ans << endl;
}


Measured memory_bytes: 23540
from collections import deque


def adjacents(r, c):
    if r > 0:
        yield r - 1, c
    if r < h - 1:
        yield r + 1, c
    if c > 0:
        yield r, c - 1
    if c < w - 1:
        yield r, c + 1


def is_road(r, c):
    return s[r][c] == '.'


def bfs(r, c):
    inf = h * w

    q = deque()
    q.append((r, c))

    dist = [[inf] * w for _ in range(h)]
    dist[r][c] = 0

    while q:
        r, c = q.popleft()
        d = dist[r][c]
        for nr, nc in ((nr, nc) for nr, nc in adjacents(r, c) if is_road(nr, nc)):
            if dist[nr][nc] < inf:
                continue
            nd = d + 1
            dist[nr][nc] = nd
            q.append((nr, nc))

    return d


h, w = map(int, input().split())
s = [input() for _ in range(h)]

print(max(bfs(r, c) for r in range(h) for c in range(w) if is_road(r, c)))


Measured memory_bytes: 3316
import heapq

X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

q = []
heapq.heapify(q)
heapq.heappush(q, (-(A[0] + B[0] + C[0]), 0, 0, 0))  # heapq では昇順ソートするためマイナスにする

for _ in range(K):
    m, i, j, k = heapq.heappop(q)
    print(-m)
    if i + 1 < X:
        s = (-(A[i+1] + B[j] + C[k]), i+1, j, k) 
        if s not in q:
            heapq.heappush(q, s)
    if j + 1 < Y:
        s = (-(A[i] + B[j+1] + C[k]), i, j+1, k) 
        if s not in q:
            heapq.heappush(q, s)
    if k + 1 < Z:
        s = (-(A[i] + B[j] + C[k+1]), i, j, k+1) 
        if s not in q:
            heapq.heappush(q, s)

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

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

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin>>a>>b;
    ll ans=0;

    ans = a*b/(__gcd(a,b));

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


Measured memory_bytes: 256
s = gets.chomp
if s.match(/^keyence$/) or
   s.match(/.*keyence$/) or
   s.match(/^k.*eyence$/) or
   s.match(/^ke.*yence$/) or
   s.match(/^key.*ence$/) or
   s.match(/^keye.*nce$/) or
   s.match(/^keyen.*ce$/) or
   s.match(/^keyenc.*e$/) or
   s.match(/^keyence.*/)
    puts 'YES'
else
    puts 'NO'
end

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
 
int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int a;
  while(true) {
    C -= B;
    if (C <= 0) {
      a = 0;
      break;
    }
    A -= D;
    if (A <= 0) {
      a = 1;
      break;
    }
  }
  if (a) cout << "No" << endl;
  else cout << "Yes" << endl;
}
  

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int a; cin >> a;
    string s; cin >> s;

    if (a >= 3200) {
        cout << s << endl;
    } else {
        cout << "red" << endl;
    }
}

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

using namespace std;

#define int long long

template <typename T> T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T> T lcm(T m, T n) { return n * m / gcd(n, m); }
template <typename T> T fact(T n) { return (n == 0 ? 1 : n * fact(n - 1)); }
template <typename T> T modpow(T a, T e, T m) { return (e == (T)0 ? 1 : ((a % m) * modpow((a % m), e - 1, m)) % m); }

constexpr int MOD = 1e9 + 7;

signed main(void) {
  int num;
  int n;
  cin >> n;

  map<int, int> mem;
  for (int i = 0; i < n; ++i) {
    int a; cin >> a;
    if (a < 3200)
      mem[a / 400]++;
    else
      mem[8]++;
    // for (int j = 0; j < 9; ++j) {
    //   if (a < (j + 1) * 400) mem[i]++;
    //   break;
    // }
  }

  num = 0;
  for (int j = 0; j < 8; ++j) {
    if (mem[j] > 0) ++num;
  }

  int m = num;
  int M = num;
  if (mem[8] > 0) {
    if (m == 0) ++m;
    M += mem[8];
    num = min(M, (int)8);
  }

  cout << m << " " << M << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 3009 /// leave to tomorrow anything that can be done today
#define MOD 998244353
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
ll dp[maxn][maxn]; ///soma i tamanho j
ll mult(ll a,ll b){
    return a*b%MOD;
}
ll fastpow(ll a, ll b){
    ll calc=1;
    for(;b>=1LL;b/=2LL){
        if((b&1LL))calc=mult(calc,a);
        a=mult(a,a);
    }
    return calc;
}
ll soma(ll a,ll b){
    if(a+b>MOD)return a+b-MOD;
    else return a+b;
}
ll subt(ll a,ll b){
    if(a-b<0)return a-b+MOD;
    else return a-b;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,s;
    cin>>n>>s;
    ll vet[maxn];
    rep(i,1,n+1){
        cin>>vet[i];
    }
    dp[0][0] = fastpow(2,n);
    rep(j,1,n+1){/// caras
        rep(i,0,s+1){//soma 
            if(vet[j]<=i)dp[j][i] = soma(mult(dp[j-1][i-vet[j]],fastpow(2,MOD-2)),dp[j-1][i]);
            else dp[j][i] = dp[j-1][i];
        }
    }
    // cout<<dp[1][4]<<endl;
    cout<<dp[n][s]<<'\n';
    return 0;   
}   

Measured memory_bytes: 74112
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String steps = sc.next();
        sc.close();

        boolean judge = true;
        for (int i = 0; i < steps.length(); i++) {
            char step = steps.charAt(i);
            if (i % 2 == 0) {
                if (step == 'L') {
                    judge = false;
                    break;
                }
            } else {
                if (step == 'R') {
                    judge = false;
                    break;
                }
            }
        }

        if (judge) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23892
#include <stdio.h>

int main(void) {
   
   int N;
   scanf("%d",&N);
   
   int i;
   int p;
   int c = 0;
   for (i = 0; i < N; i++) {
      scanf("%d",&p);
      if (p != i + 1) {
         c++;
      }
   }
   
   if (c == 2 || c == 0) {
      printf("YES\n");
   }
   else {
      printf("NO\n");
   }
   
   
   return 0;
   
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < N; i++)
#define FOR(i, a, b) for (int i = a; i <= b; i++)
using namespace std;
using ll = long long;

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

  int A[N];
  REP(i, N) cin >> A[i];

  int ans = 0;
  while (true) {
    bool even = true;
    REP(i, N) {
      if (A[i] % 2 == 1) {
        even = false;
        break;
      }
      A[i] /= 2;
    }
    if (even)
      ans++;
    else
      break;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Data.List
import Control.Monad

getLineN n = replicateM n getLine
listToTuple [a,b] = (a,b)

main = do
	[n,m] <- map read.words <$> getLine :: IO [Int]
	xs' <- map (tail.map read.words) <$> getLineN m :: IO [[Int]]
	ps <- map read.words <$> getLine :: IO [Int]
	let xs = zip  xs' ps
	putStrLn.show $ foldl (answer xs) 0 [0,1..(2^n-1)]

answer :: [([Int],Int)] -> Int -> Int -> Int
answer xs cnt v = if satisfied xs then cnt+1 else cnt  where
	satisfied = all (judge (bin v))

bin 0 = replicate 10 0
bin k = mod k 2 : bin (div k 2)

judge binary (sws,p) = sum  extracted `mod` 2 == p where
		extracted = map (\i -> binary !! (i-1)) sws

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;



int main() {
    string s;
    int ans = 0;
    cin >> s;
    if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) cout << "Bad";
    else cout << "Good";
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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;}

// r:0 s:1 p:2
int kachi(char c){
	if(c=='r') return 2;
	else if(c=='s') return 0;
	else return 1;
}
int aiko(char c){
	if(c=='r') return 0;
	else if(c=='s') return 1;
	else return 2;
}
int make(char c){
	if(c=='r') return 1;
	else if(c=='s') return 2;
	else return 0;
}

int main(){
	int n,k;
	int point[3];
	string t;
	cin >> n >> k;
	REP(i,3) cin >> point[i]; 
	cin >> t;
	
	
	vector<vector<ll>> dp(n,vector<ll>(3,0));
	ll ans=0;
	
	for(int i=0; i<k; ++i){
		for(int j=i; j<n; j+=k){
			if(j<k){
				dp[j][kachi(t[j])] = point[kachi(t[j])];
			}else{
				REP(m,3){
					if(m!=kachi(t[j])) chmax(dp[j][kachi(t[j])], dp[j-k][m]+point[kachi(t[j])]);
					if(m!=aiko(t[j])) chmax(dp[j][aiko(t[j])], dp[j-k][m]);
					if(m!=make(t[j])) chmax(dp[j][make(t[j])], dp[j-k][m]);
				}
				
			}
		}
		
	}
	
	REP(i,k){
		ll a=0;
		REP(j,3){
			chmax(a, dp[n-1-i][j]);
		}
		ans += a;
	}
	cout << ans << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 8808
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();
        if(A != 1 && B != 1) {
            System.out.println(1);
        } else if (A != 2 && B != 2){
            System.out.println(2);
        } else if (A != 3 && B != 3){
            System.out.println(3);
        }
    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
ll n;
cin >> n;

string ans = "";
while(n>0){
 	n--;
    ans += ((n % 26) + 'a');
    n /= 26;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<int>v[1000],tmp,ans;
int n,m,a,b,c,pre[1000],dist[1000],MIN,cur;
int main(void){
    cin>>n>>m;
    MIN=n+1;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        a--,b--;
        v[a].push_back(b);
    }
    for(int i=0;i<n;i++){
        queue<int> que;
        for(int i=0;i<n;i++)pre[i]=-1;
        for(int i=0;i<n;i++)dist[i]=-1;
        que.push(i);
        dist[i]=1;
        while(que.size()){
            int q=que.front();
            que.pop();
            for(int x:v[q]){
                if(dist[x]==-1){
                    dist[x]=dist[q]+1;
                    pre[x]=q;
                    que.push(x);
                }
                else if(x==i){
                    while(!que.empty())que.pop();
                    tmp={i};
                    int cur=q;
                    while(cur!=i){tmp.push_back(cur),cur=pre[cur];}
                    if(MIN>tmp.size())MIN=tmp.size(),ans=tmp;
                }
            }
        }
    }
    if(MIN==n+1)cout<<-1<<endl;
    else{
        cout<<MIN<<endl;
        for(int x:ans){
            cout<<x+1<<endl;
        }
    }
}


Measured memory_bytes: 384
import Text.Printf

sd :: Double -> [Double] -> Double
sd n xs = sqrt $ (foldl (\a x -> a + (x - mean) ^ 2) 0 xs) / n
    where mean = (foldl (+) 0 xs) / n

solve :: [String] -> [Double]
solve [] = []
solve (s:ss)
    | s == "0"  = []
    | otherwise = sd (read s) (map read $ words (ss !! 0)) : solve (drop 1 ss)

main :: IO ()
main = interact (unlines . map (printf "%.8f") . solve . lines)

Measured memory_bytes: 5172
#include <iostream>
#include <climits>
using namespace std;
int main(void){
    
    int N;
    int ans = 1;
    int count_Max = INT_MIN;
    cin >> N;
    
    // 反復：「 1 ～ N」まで全探索をする
    for(int i = 1; i <= N; i++){
        
        // 定義
        int count = 0;  // カウントのリセット
        int num = i; // 2で割るためも数字（iの代わり）
        
        // 反復：2で割り切れる個数を求める
        while(!(num%2)){
            count++;
            num /= 2;
        }
        // カウントの最大数とそのときの数を答えに代入
        if(count_Max < count){
            count_Max = count;
            ans = i;
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
// Problem : C - Peaks
// Contest : AtCoder - AtCoder Beginner Contest 166
// URL : https://atcoder.jp/contests/abc166/tasks/abc166_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Muallif: Azimjon Mehmonali o'g'li

#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define sqr(x) (x) * (x)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define rALL(a) a.rbegin(), a.rend()
#define SORT(a) sort(ALL(a))
#define sc scanf
#define pr printf
#define xatop(a) cerr << #a << " = " << a << endl;
#define jsatr xatop(__LINE__)
#define INF 1000000000
#define mod 1000000007

int main() {
	int n, m;
	sc("%d%d", &n, &m);

	int h[n + 1];
	for (int i = 1; i <= n; i++)
		sc("%d", h + i);
	// jsatr;
	// int a[m + 1], b[m + 1];
	vi g(n + 1, -INF);
	int a, b;
	for (int i = 1; i <= m; i++) {
		sc("%d%d", &a, &b);
		g[a] = max(g[a], h[b]);
		g[b] = max(g[b], h[a]);
	}
	// jsatr;
	int jv = 0;
	for (int i = 1; i <= n; i++) {
		if (g[i] < h[i]) {
			jv++;
		}
	}

	cout << jv << endl;

	return 0;
}


Measured memory_bytes: 4076
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n;
    cin >> n;
    vector<int> t(n);
    rep(i, n) cin >> t[i];
    int m;
    cin >> m;
    int sum = 0;
    rep(i, n) sum += t[i];
    int p, x;
    rep(i, m) {
        cin >> p >> x;
        p--;
        cout << sum - t[p] + x << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<bitset>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<list>
#include<queue>
#include<map>
using namespace std;

int INF=1e9;
int main(){
    int a,b,c,ans=1;
    cin>>a>>b>>c;
    if(b!=a){
      ans++;
    }
    if(c!=b&&c!=a){
      ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

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

    int current = 0;
    int all = 0;
    vector<int> A(N, 0);
    for(int i = 0; i < N;i++) {
        cin >> A[i];
        all += abs(A[i] - current);
        current = A[i];
    }
    all += abs(current);

    ll sum = 0;
    for(int i = 0; i < N; i++) {
        int before = i > 0? A[i-1] : 0;
        int after = i < N-1 ? A[i+1] : 0;
        cout <<  all + abs(after - before) - abs(after - A[i]) - abs(before- A[i]) << endl;
    }





}

Measured memory_bytes: 1664
package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var llist [200000]int
var llistIdx int

func main() {
	scanInit()

	k := nextInt()

	for i := 1; i < 10; i++ {
		push(i)
	}

	// BFS
	llistIdx = 0
	for queue.Len() > 0 {
		now := pop()
		llist[llistIdx] = now
		llistIdx++

		if keta(now) < 10 {
			base := now % 10

			if base != 0 {
				push(now*10 + base - 1)
			}

			push(now*10 + base)

			if base != 9 {
				push(now*10 + base + 1)
			}
		}
	}

	anslist := llist[:llistIdx]

	fmt.Println(anslist[k-1])

}

var queue = list.New()

func push(a int) {
	queue.PushBack(a)
}
func pop() int {
	e := queue.Front()
	queue.Remove(e)
	return e.Value.(int) // 明示的キャストが必要
}

// 正数の桁数を返す
func keta(n int) int {
	keta := 0
	if n == 0 {
		return 1
	}
	for n > 0 {
		keta++
		n /= 10
	}
	return keta
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

int main(void){
	
	int x, y;
	
	cin >> x >> y;
	while( x != 0 || y != 0 ){
    	//if ( x == 0 && y == 0 ) break;
		
		if ( x < y ){
			//x, y ???????????????;
			cout << x << ' ' << y << endl;
		} else {
			//y, x ???????????????;
			cout << y << ' ' << x << endl;
		}
    	cin >> x >> y;
	}
	
	return 0;
}

Measured memory_bytes: 3032
#include <cstdio>
using namespace std;
int main() {
    int a,b,s;
    scanf("%d%d",&a,&b);
    if(a>=b) {
        s=a;
        a--;
    } else {
        s=b;
        b--;
    }
    if(a>=b)
        s+=a;
    else
        s+=b;
    printf("%d\n",s);
    return 0;
}


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

string s;
long long k;

int solve();

int main() {
  cin >> s >> k;

  cout << solve() << endl;
  return 0;
}

int solve() {
  for(int i = 0; i < k; ++i)
    if(s[i] >= '2' && s[i] <= '9') return s[i] - '0';
  return 1;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#define rep(i,n) for (int i = 0;i<n;i++)
using namespace std;

int main() {
	string words;
	getline(cin, words);

	rep(i, words.size()-4) {
		if (words[i] == 'p'&&words[i + 1] == 'e'&&words[i + 2] == 'a'&&words[i + 3] == 'c'&&words[i + 4] == 'h') {
			rep(j, 5) {
				words[i + j] = 'x';
			}
		}
	}

	rep(i, words.size() - 4) {
		if (words[i] == 'a'&&words[i + 1] == 'p'&&words[i + 2] == 'p'&&words[i + 3] == 'l'&&words[i + 4] == 'e') {
			words[i] = 'p';
			words[i + 1] = 'e';
			words[i + 2] = 'a';
			words[i + 3] = 'c';
			words[i + 4] = 'h';
		}
	}

	rep(i, words.size() - 4) {
		if (words[i] == 'x'&&words[i + 1] == 'x'&&words[i + 2] == 'x'&&words[i + 3] == 'x'&&words[i + 4] == 'x') {
			words[i] = 'a';
			words[i + 1] = 'p';
			words[i + 2] = 'p';
			words[i + 3] = 'l';
			words[i + 4] = 'e';
		}
	}

	cout << words << endl;
	return 0;
}

Measured memory_bytes: 3000
N = int(input())
X = []
Y = []
for i in range(N):
    x, y = map(int, input().split())
    X.append(x + y)
    Y.append(x - y)
# print(X, Y)

maxX = max(X)
maxY = max(Y)
minX = min(X)
minY = min(Y)

ans = max(maxX - minX, maxY - minY)
print(ans)



Measured memory_bytes: 24980
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

ll factorial(ll n, ll m=2) {
    // calculate nPm
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(NULL);
    ios::sync_with_stdio(0);
    ll x, y; cin >> x >> y;
    if ((x+y) % 3 != 0) {
        cout << 0 << endl;
    } else {
        int a = (2 * x - y) / 3;
        int b = (2 * y - x) / 3;
        if (a >= 0 && b >= 0) {
            int ans = factorial(a+b) * modinv(factorial(a), MOD) % MOD * modinv(factorial(b), MOD) % MOD;
            cout << ans << endl;
        } else {
            cout << 0 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
const int MM = 2e5+5;

int k, n, a[MM], ans = 1e9;

int main(){
    scan(k, n);
    for(int i = 1; i <= n; i++){
        scan(a[i]);
    }
    ans = a[n]-a[1];
    for(int i = 2; i <= n; i++){
        ans = min(ans, k-(a[i]-a[i-1]));
    }
    print(ans);
    
    return 0;
}

Measured memory_bytes: 1024
inp = []
i = 0
j = 0

min = 0
max = 0
sum = 0

n = int(input())
inp = list(map(int, input().split()))

for i in range(n):
    if i == 0:
        min = inp[i]
        max = inp[i]
        sum = inp[i]
    else:
        if min > inp[i]:
            min = inp[i]
        if max < inp[i]:
            max = inp[i]

        sum += inp[i]

print("%s %s %s" % (min, max, sum))



Measured memory_bytes: 6592
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<string>

using namespace std;

int partition(vector<int> &A, int p, int r){
	int x = A[r];
	int i = p - 1;
	for (int j = p; j < r; j++){
		if (A[j] <= x) swap(A[++i], A[j]);
	}
	swap(A[++i], A[r]);
	return i;
}

void solve(){
	int n;
	cin >> n;
	vector<int> A(n);
	for (int i = 0; i < n; i++) cin >> A[i];
	int x = partition(A, 0, n - 1);
	for (int i = 0; i < n; i++){
		if (i) cout << " ";
		if (i == x) cout << "[" << A[i] << "]";
		else cout << A[i];
	}
	cout << endl;
}

int main(){
	solve();
}

Measured memory_bytes: 3104
from queue import PriorityQueue


def main():
    N, M = map(int, input().split(' '))
    jobs = [[] for _ in range(M + 1)]
    for i in [input() for i in range(N)]:
        A, B = map(int, i.split(' '))
        if A > M:
            continue
        jobs[A].append(B)

    pq = PriorityQueue()
    reward = 0

    for sameJobs in jobs:
        for job in sameJobs:
            pq.put(-job)
        if not pq.empty():
            reward += -(pq.get())

    print(reward)

if __name__ == "__main__":
    main()

Measured memory_bytes: 25516
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
   
//#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, a[N], b[N], cl[N];
vector <pii> v;
set <int> can, no;
vector <pii> g[N];

void dfs (int v = 1, int pr = 0) {
   int no = -1;
   int cnt = 0;
   for (auto to : g[v]) {
      if (to.F == pr) no = cl[to.S];
   }
   for (auto to : g[v]) {
      if (to.F != pr) {
         if (cnt + 1 == no) cnt += 2;
         else cnt ++;
         cl[to.S] = cnt;
      }
   }
   for (auto to : g[v])
      if (to.F != pr)
         dfs (to.F, v);
}

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n;
   for (int i = 1; i < n; i ++) {
      cin >> a[i] >> b[i];
      g[a[i]].pb ({b[i], i});
      g[b[i]].pb ({a[i], i});
   }
   dfs ();
   cout << *max_element (cl + 1, cl + n) << endl;
   for (int i = 1; i < n; i ++)
      cout << cl[i] << endl;      
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cout << a[i] << " "; cout << "\n"; }
template<class T> void verr(const vector<T>& v){ for(auto& a : v) cout << a << " "; cout << "\n"; }
ll dbgt = 1; void err() { cout << "passed " << dbgt++ << "\n"; }
template<class H, class... T> void err(H&& h,T&&... t){ cout<< h << (sizeof...(t)?" ":"\n"); if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N,x;
    cin >> N >> x;
    vl A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));

    ll sum = accumulate(all(A), 0ll);
    if(sum<x){
        cout << N - 1 << endl;
        return 0;
    }
    else if(sum==x){
        cout << N << endl;
        return 0;
    }

    ll ans = 0, cnt = 0;
    rep(i,N){
        cnt += A[i];
        if(cnt>x){
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace DPL_1_C
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] dp = new int[x[1] + 1];
            for (int i = 0; i < x[0]; i++)
            {
                int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (int j = a[1]; j <= x[1]; j++)
                {
                    dp[j] = Math.Max(dp[j],dp[j - a[1]] + a[0]);
                }
            }
            Console.WriteLine(dp[x[1]]);
        }
    }
}


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

typedef long long ll;

using namespace std;

int main() {
	int N, p, x = 1;
	cin >> N;
	vector<pair<string, int>> r(N);

	for (int i = 0; i < N; i++) {
		cin >> r[i].first >> p;
		r[i].second = -10000 * p - x;
		x++;
	}

	sort(r.begin(), r.end());
	for (int i = 0; i < N; i++) {
		cout << (-1 * r[i].second) % 1000 << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int pp[15];

string maze[15];
int vis[15];
int h,w;
bool solve()
{
    vvc<pair<char,char>> s(h);
    memset(vis,0,sizeof(vis));
    for(int i=0;i<w;i++)
    {
        if(vis[i]) continue;
        for(int j=0;j<h;j++)
        {
            if(pp[i]==-1)
                s[j].emplace_back(maze[j][i],maze[j][i]);
            else {
                s[j].emplace_back(maze[j][i],maze[j][pp[i]]);
                vis[pp[i]]=1;
            }
        }
    }
    memset(vis,0,sizeof(vis));
    int notok=0;
    for(int i=0;i<h;i++)
    {
        if(vis[i]) continue;
        bool ok=0;
        for(int j=i+1;j<h;j++)
        {
            for(int k=0;k<s[i].size();k++)
            {
                if(s[i][k].first==s[j][k].second&&s[j][k].first==s[i][k].second);
                else break;
                if(k==s[i].size()-1) ok=1;
            }
            if(ok)
            {
                vis[j]=1;
                break;
            }
        }
        if(!ok)
        {
            for(int k=0;k<s[i].size();k++)
                if(s[i][k].first!=s[i][k].second) return false;
            notok++;
        }
    }
    return notok<=(h&1);
}
bool dfs(int u,int p)
{
    if(u==w)
    {
        if(!p) return solve();
        return false;
    }
    if(pp[u]!=-1) return dfs(u+1,p);
    bool ret=0;
    if(p) ret|=dfs(u+1,0);
    for(int i=u+1;i<w;i++)
    {
        if(pp[i]==-1)
        {
            pp[u]=i;
            pp[i]=u;
            ret|=dfs(u+1,p);
            pp[u]=-1;
            pp[i]=-1;
            if(ret) return true;
        }
    }
    return ret;
}
int main()
{
    memset(pp,-1,sizeof(pp));
    cin>>h>>w;
    for(int i=0;i<h;i++) cin>>maze[i];
    if(dfs(0,w&1))
        cout<<"YES\n";
    else cout<<"NO\n";
}

Measured memory_bytes: 256
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    long long a, b, c, d; std::cin >> a >> b >> c >> d;
    std::cout << std::max({a*c, a*d, b*c, b*d}) << std::endl;
    return 0;
}


Measured memory_bytes: 3604