akhauriyash/Code-Regression huggingface dataset:
n,q = gets.split.map {|s| s.to_i}
Dat = Struct.new(:name,:time)
que = Array.new()
for i in 0...n
  name,time = gets.split
  que.push(Dat.new(name,time.to_i))
end
t = 0
until que.empty?
  d = que.shift
  if d.time <= q
    t += d.time
    puts d.name + " " + t.to_s
  else
    t += q
    d.time -= q
    que.push(d)
  end
end

Measured memory_bytes: 13328
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int n, k, a[200005], b[200005];

void operate()
{
	rep(i, n) b[i] = 0;
	rep(i, n) {
		b[max(i - a[i], 0)] ++;
		b[min(i + a[i] + 1, n)] --;
	}
	rep(i, n) b[i + 1] += b[i];
	rep(i, n) a[i] = b[i];
}

int main()
{
	scanf("%d%d", &n, &k);
	rep(i, n) scanf("%d", &a[i]);
	k = min(k, 50);
	rep(i, k) operate();
	rep(i, n) printf("%d ", a[i]);
	return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18

int main() {
    int n ;
    cin >> n ;
    vector<int> l (n) ;
    rep(i, n){
        cin >> l[i] ;
    }
    int ans = 0 ;
    rep(i, n - 2){
        for(int j = i + 1; j < n - 1; j++){
            for(int k = j + 1; k < n ; k++ ){
                if(l[i] == l[j] || l[j] == l[k] || l[k] == l[i]){
                    continue ;
                }
                else {
                    int mx = max(l[i],max(l[j], l[k])) ;
                    int lx = min(l[i],min(l[j],l[k])) ;
                    int mid = l[i] + l[j] + l[k] - (mx + lx) ;
                    if(mx < (lx + mid)) {
                        ans++ ;
                    }
                }
            }
        }
    }
    cout << ans << endl ;
}

Measured memory_bytes: 3600
import math
n,y = map(int,input().split())
c = 0
for a in range(n+1):
	for b in range(n+1):
		if 9000*a + 4000*b == y - 1000*n and n - a - b >= 0:
			print(*[a,b,n-a-b])
			c += 1
			break
	if c == 1:
		break
if c == 0:
	print(*[-1,-1,-1])

Measured memory_bytes: 9120
H, W, K = list(map(int, input().split()))
c = []
for i in range(H):
    row = input()
    c.append(row)

a1 = []
a2 = []


def f():
    pass


at1 = [None] * H


def dfs1(pos: int):
    if pos == H:
        # print(a)
        a1.append(at1.copy())
        return

    at1[pos] = 0
    dfs1(pos + 1)

    at1[pos] = 1
    dfs1(pos + 1)


at2 = [None] * W


def dfs2(pos: int):
    if pos == W:
        # print(a)
        a2.append(at2.copy())
        return

    at2[pos] = 0
    dfs2(pos + 1)

    at2[pos] = 1
    dfs2(pos + 1)


dfs1(0)
dfs2(0)

# print(a1)
# print(a2)

ans = 0

for ai in a1:
    for aj in a2:
        g = []
        for i in range(H):
            arr = [None] * W
            g.append(arr)

        for i, aii in enumerate(ai):
            if aii == 1:
                g[i] = ['r'] * W

        for i, aji in enumerate(aj):
            if aji == 1:
                for j in range(H):
                    g[j][i] = 'r'

        # print(ai, aj, g)

        # count
        cnt = 0
        for i, row in enumerate(g):
            for j, col in enumerate(row):
                if col is None:
                    if c[i][j] == '#':
                        cnt += 1

        if cnt == K:
            ans += 1

print(ans)

Measured memory_bytes: 9108
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxm=2e3+5;
const int mod=1e9+7;
int d[maxm];
int n;
signed main(){
    cin>>n;
    d[0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=i-3;j++){
            d[i]+=d[j];
            d[i]%=mod;
        }
    }
    cout<<d[n]<<endl;
    return 0;
}
/*


*/


Measured memory_bytes: 3636
#include<stdio.h>

int main(){
  int n,ans=1,i;
  char s[100010];
  scanf("%d%s",&n,s);
  for(i=1;i<n;i++){
    if(s[i-1]!=s[i])ans++;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   ll N;
   cin >> N;
   cout << N * (N - 1) / 2 << endl;
   return 0;
}


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

int main() {
  string n;
  cin >> n;
  
  bool ok = false;
  char f = n.at(1), s = n.at(2);
  if(n.at(0) == f && n.at(2) == f) ok = true;
  if(n.at(1) == s && n.at(3) == s) ok = true;
  
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;
inline void FAST_IO(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}

int n;
vector<long long> a(100000);
long long tb[100000][2];
bool v[100000][2];

long long dp(int i, bool flip){
	if(i == n-1) return (flip ? a[i]*(-1) : a[i]);
	
	if(v[i][flip]) return tb[i][flip];
	
	long long change = dp(i+1, true) + (flip ? a[i] : a[i]*(-1));
	long long keep = dp(i+1, false) + (flip ? a[i]*(-1) : a[i]);
	
	v[i][flip] = true;
	return tb[i][flip] = max(change, keep);
}

int main() {
	FAST_IO();
	cin >> n;
	for(int i = 0; i < n; ++i)
		cin >> a[i];
	
	cout << max(a[0] + dp(1,false),a[0]*(-1)+dp(1,true)) << endl;
	
    return 0;
}

Measured memory_bytes: 7552
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    int mid = a[0] / 2;
    int dif = INF;
    int p = -1;
    for(int i = 1; i < n; ++i){
        int foo = abs(a[i] - mid);
        if(foo < dif){
            dif = foo;
            p = i;
        }
    }
    cout << a[0] << " " << a[p] << endl;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-

def main():
    # # 整数の入力
    # a = int(input())
    # # スペース区切りの整数の入力
    # b, c = map(int, input().split())
    # # 文字列の入力
    # s = input()
    # # 出力
    # print("{} {}".format(a+b+c, s))
    S = input()
    dic = {}
    for s in S:
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 1
    if len(dic)==2 and list(dic.values())==[2,2]:
        print('Yes')
    else:
        print('No')


if __name__=='__main__':
    main()


Measured memory_bytes: 2940
n = int(input())
a = list(map(int,input().split()))
ans = set()
cnt = 0
for i in range(n):
  if a[i] < 400:
    ans.add(1)
  elif a[i] < 800:
    ans.add(2)
  elif a[i] < 1200:
    ans.add(3)
  elif a[i] < 1600:
    ans.add(4)
  elif a[i] < 2000:
    ans.add(5)
  elif a[i] < 2400:
    ans.add(6)
  elif a[i] < 2800:
    ans.add(7)
  elif a[i] < 3200:
    ans.add(8)
  else:
    cnt += 1

print(max(1,len(ans)),len(ans)+cnt)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
char ch;
int bj1=0;
int main(){
    while(cin>>ch){
        if(ch=='C'&&bj1==0){
            bj1++;
        }
        if(ch=='F'&&bj1==1){
            bj1++;
        }
        if(bj1==2){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
Scanf.scanf "%d" (fun n ->
    let nei = Array.make n [] in
    for i = 1 to n - 1 do
        Scanf.scanf " %d %d" (fun a b ->
            let a = a - 1 in
            let b = b - 1 in
            nei.(a) <- b :: nei.(a);
            nei.(b) <- a :: nei.(b);
        )
    done;

    let radius =
        let calc start =
            let rec loop len next last = function
                | [] -> if next <> [] then loop (len + 1) [] last next else last, len
                | (cur, par) :: tl ->
                        let next = 
                            List.fold_left (fun next v ->
                                if v = par then next else (v, cur) :: next) next nei.(cur)
                        in
                        loop len next cur tl
            in
            loop 0 [] start [ start, -1 ]
        in
        let (farest, k1 ) = calc 0 in
        let (k2, radius) = calc farest in
        radius
    in
    print_endline @@ if radius mod 3 = 1 then "Second" else "First"
)

Measured memory_bytes: 34564
IDENTIFICATION DIVISION.
PROGRAM-ID. 154B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP  PIC X(100).
01 S    PIC X(100).
01 CNT  PIC 9(3).
01 I    PIC 9(3).
*>
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO S   COUNT CNT.
  MOVE ALL 'x' TO S(1:CNT).
  DISPLAY S(1:CNT).
*>
  STOP RUN.


Measured memory_bytes: 636
#include <bits/stdc++.h>
#define mkp make_pair
#define pb push_back
#define emb emplace_back
#define em emplace
#define ii pair<int,int>
#define iii pair<int ,ii>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define allc(x) x.begin(),x.end(),cmp
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;
const int INF = 0x3f3f3f3f;
const int MXN = 1e5 + 5;

vector<int> v[MXN];
int deg[MXN] , dp[MXN];

int main(){
    int n , m;
    scanf("%d %d" ,&n ,&m);
    for(int i = 0 ; i < m ; i++){
        int a , b;
        scanf("%d %d" ,&a ,&b);
        v[a].push_back(b);
        deg[b]++;
    }
    queue<int> q;
    for(int i = 1 ; i <= n ; i++){
        if(!deg[i]){
            q.push(i);
        }
    }
    while(q.size()){
        int a = q.front();
        q.pop();
        for(auto i : v[a]){
            dp[i] = max(dp[i] , dp[a] + 1);
            if(--deg[i] == 0){
                q.push(i);
            }
        }
    }
    int mx = -1;
    for(int i = 1 ; i <= n ; i++){
        mx = max(mx , dp[i]);
    }
    printf("%d" ,mx);
}

Measured memory_bytes: 6528
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

struct edge {
    int from, to, cost;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N, M;
    cin >> N >> M;
    vector<edge> E(M);
    rep(i, M){
        cin >> E[i].from >> E[i].to >> E[i].cost;
        E[i].from--;
        E[i].to--;
    }
    
    vector<vector<ll>> A(N, vector<ll>(N, inf));
    rep(i, N) A[i][i] = 0;
    for(edge e: E) {
        A[e.from][e.to] = e.cost;
        A[e.to][e.from] = e.cost;
    }
    
    rep(k, N) rep(i, N) rep(j, N){
        A[i][j] = min(A[i][j], A[i][k] + A[k][j]);
    }
    
    int ret = 0;
    for(edge e: E){
        if(A[e.from][e.to] != e.cost){
            ret++;
        }
    }
    output(ret);
    
    
    return 0;
}


Measured memory_bytes: 384
// ███▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓╬╬╬╬╬╬▓█
// ███▓███████▓▓╬╬╬╬╬╬╬╬╬╬╬╬▓███▓▓▓▓█▓╬╬╬▓█
// ███████▓█████▓▓╬╬╬╬╬╬╬╬▓███▓╬╬╬╬╬╬╬▓╬╬▓█
// ████▓▓▓▓╬╬▓█████╬╬╬╬╬╬███▓╬╬╬╬╬╬╬╬╬╬╬╬╬█
// ███▓▓▓▓╬╬╬╬╬╬▓██╬╬╬╬╬╬▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ████▓▓▓╬╬╬╬╬╬╬▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ███▓█▓███████▓▓███▓╬╬╬╬╬╬▓███████▓╬╬╬╬▓█
// ████████████████▓█▓╬╬╬╬╬▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬█
// ███▓▓▓▓▓▓▓╬╬▓▓▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ████▓▓▓╬╬╬╬▓▓▓▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ███▓█▓▓▓▓▓▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// █████▓▓▓▓▓▓▓▓█▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// █████▓▓▓▓▓▓▓██▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// █████▓▓▓▓▓████▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// ████▓█▓▓▓▓██▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// ████▓▓███▓▓▓▓▓▓▓██▓╬╬╬╬╬╬╬╬╬╬╬╬█▓╬▓╬╬▓██
// █████▓███▓▓▓▓▓▓▓▓████▓▓╬╬╬╬╬╬╬█▓╬╬╬╬╬▓██
// █████▓▓█▓███▓▓▓████╬▓█▓▓╬╬╬▓▓█▓╬╬╬╬╬╬███
// ██████▓██▓███████▓╬╬╬▓▓╬▓▓██▓╬╬╬╬╬╬╬▓███
// ███████▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬████
// ███████▓▓██▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓████
// ████████▓▓▓█████▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█████
// █████████▓▓▓█▓▓▓▓▓███▓╬╬╬╬╬╬╬╬╬╬╬▓██████
// ██████████▓▓▓█▓▓▓╬▓██╬╬╬╬╬╬╬╬╬╬╬▓███████
// ███████████▓▓█▓▓▓▓███▓╬╬╬╬╬╬╬╬╬▓████████
// ██████████████▓▓▓███▓▓╬╬╬╬╬╬╬╬██████████
// ███████████████▓▓▓██▓▓╬╬╬╬╬╬▓███████████
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <cassert>
#define pb push_back
#define point pair <int, int>
#define x first
#define y second
#define files(FileName) read(FileName); write(FileName)
#define read(FileName) freopen((FileName + ".in").c_str(), "r", stdin)
#define write(FileName) freopen((FileName + ".out").c_str(), "w", stdout)
using namespace std;

template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
typedef long long base;


const string FILENAME = "input";
const int MAXN = 3e5 + 1;

int n;
set <int> elem;

vector <int> arr;

int main(int argc, char const *argv[]) {
    ios::sync_with_stdio(false);
    //read(FILENAME);
    cin >> n;
    for (int i = n; i--;) {
        int a;
        cin >> a;
        if (elem.count(a)) {
            arr.pb(a);
            elem.erase(a);
        } else {
            elem.insert(a);
        }
    }
    sort(arr.rbegin(), arr.rend());
    if (arr.size() < 2) {
        cout << 0 << endl;
    } else {
        cout << (long long)arr[0] * arr[1] << endl;
    }
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep_start(a,i,n) for(ll i=a;i<=n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define rev1(i,n) for(ll i=n;i>0;i--)
#define sz(a) int((a).size())
#define all(c) c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i+=c.begin; i!=c.end(); i++)
#define present(c,x) (c.find(x)!=c.end())
#define cpresent(c,x) (find(all(c),x)!=c.end())
#define pb push_back
#define F first
#define S second
#define INF INT_MAX
#define mod 1000000007
#define print1(a) cout<<a<<"\n";
#define print2(a,b) cout<<a<<" "<<b<<"\n";
#define print3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define mt make_tuple
#define eb emplace_back

typedef long long int ll;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef tuple<int,int,int> State;

void solve(){
    ll n,q,b,c,tmp;cin>>n;
    map<ll,ll> m;
    ll sum=0;
    rep(i,n) {cin>>tmp;m[tmp]++;sum+=tmp;}
    cin>>q;
    rep(i,q){
        cin>>b>>c;
        sum=sum-m[b]*b+m[b]*c;
        m[c]+=m[b];
        m[b]=0;
        print1(sum);
    }
}

signed main() {
    // your code goes here
    IOS
    ll t=1;
    //cin>>t;
    rep1(i,t){
        solve(); 
    }
    return 0;
}

Measured memory_bytes: 9564
#include<stdio.h>
int main()
{
    int x,y,w,h,i;
    while(1){
        scanf("%d %d",&h,&w);
        if(h == 0 && w == 0) break;
        char a[h][w];
        for(i = 0; i < h; i++){
            scanf("%s",a[i]);
        }
        x = y = 0;
        for(;;){
            if(a[y][x] == '>'){
                a[y][x] = 1;
                x++;
            }
            if(a[y][x] == '<'){
                a[y][x] = 1;
                x--;
            }
            if(a[y][x] == '^'){
                a[y][x] = 1;
                y--;
            }
            if(a[y][x] == 'v'){
                a[y][x] = 1;
                y++;
            }
            if(a[y][x] == '.'){
                printf("%d %d\n",x,y);
                break;
            }
            if(a[y][x] == 1){
                printf("LOOP\n");
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 624
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, m, u, v, w;
    ll c[100005] = {}, d[100005] = {}, l = mod * 1000005ll, r = -mod * 1000005ll, l2 = mod * 1000005ll, r2 = -mod * 1000005ll, u0 = 0, v0 = 0, w0 = 0;
    bool y = 0;
    vector<pair<int, ll>> g[100005] = {};
    cin >> n >> m;
    fr1(n) c[i] = -1; c[1] = 0;
    fr(m) cin >> u >> v >> w, g[u].push_back({v, w}), g[v].push_back({u, w});
    queue<int> q;
    q.push(1);
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        for (pair<int, ll> i : g[x]) {
            if (c[i.first] == -1) c[i.first] = !c[x], d[i.first] = i.second - d[x], q.push(i.first);
            else if (c[i.first] == c[x]) {
                y = 1;
                if (!u0) {
                    u0 = x;
                    v0 = i.first;
                    w0 = i.second;
                }
            }
        }
    }
    if (!y) {
        fr1(n) {
            for (pair<int, ll> j : g[i]) if (d[i] + d[j.first] != j.second) {
                cout << 0;
                return 0;
            }
        }
        fr1(n) {
            if (c[i]) l2 = min(l2, d[i]), r2 = max(r2, d[i]);
            else l = min(l, d[i]), r = max(r, d[i]);
        }
        //cout << l << ' ' << r << ' ' << l2 << ' ' << r2 << '\n';
        r -= l - 1; l2 += l - 1; r2 += l - 1; l -= l - 1;
        if (l2 < 1) cout << 0;
        else cout << l2;
    } else {
        if ((w0 - d[u0] - d[v0]) % 2) {
            cout << 0;
            return 1;
        }
        w0 -= d[u0] + d[v0]; w0 /= 2;
        if (c[u0]) {
            fr1(n) {
                if (c[i]) d[i] += w0;
                else d[i] -= w0;
            }
        } else {
            fr1(n) {
                if (c[i]) d[i] -= w0;
                else d[i] += w0;
            }
        }
        //cout << u0 << ' ' << v0 << ' ' << w0 << '\n';
        //fr1(n) cout << d[i] << ' ';
        fr1(n) {
            for (pair<int, ll> j : g[i]) {
                if (d[i] + d[j.first] != j.second) {
                    cout << 0;
                    return 0;
                }
            }
        }
        fr1(n) {
            if (d[i] <= 0) {
                cout << 0;
                return 0;
            }
        }
        cout << 1;
    }
}


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

int main() {
	ll t;
	//cin>>t;
	t=1;
	while(t--){
	    long double n,k;
	    cin>>n>>k;
	    ll temp=n*k;
	    cout<<temp<<endl;
	}   
}

Measured memory_bytes: 3732
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <deque>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <complex>
#include <cstring>
#include <cassert>
#include <bitset>

using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define repd(i, a, b) for(int i = (a); i > (b); i--)
#define forIt(it, a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define forRev(it, a) for(__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++)
#define ft(a) __typeof((a).begin())
#define ll long long
#define ld long double
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define bitcount(n) __builtin_popcountll(n)
#define randchar() ((rand() % 26) + 'a')


typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int N = 200000 + 7;
const int M = 1000000;
const ll MM = 1ll * M * M;
const int inf = 1e9 + 7;
const long long linf = 1ll * inf * inf;
const double pi = acos(-1);
const double eps = 1e-7;
const bool multipleTest = 0;

ll lo = 0, hi = 10000000000000000ll + 1000;
int m;
ll a[N];

void solve() {
	ll k;
	cin >> k;
	for (int n = 2; n <= 50; ++n) {
		ll x = (k + n - 1) / n + n - 1;
		ll r = ((k + n - 1) / n) * n - k;
		for (int i = 0; i < n; ++i) a[i] = x;
		while (r > 0) {
			sort(a, a + n);
			a[n - 1] -= n;
			for (int i = 0; i + 1 < n; ++i) a[i]++;
			--r;
		}
		bool ok = true;
		for (int i = 0; i < n; ++i) if (a[i] < lo || a[i] > hi) ok = false;
		if (ok) {
			cout << n << '\n';
			for (int i = 0; i < n; ++i) cout << a[i] << ' ';
			return;
		}
	}
	
}

int main() {
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin);
	//	freopen("out.txt", "w", stdout);
#endif
	int Test = 1;
	if (multipleTest)
		cin >> Test;
	for(int i = 0; i < Test; ++i) {
		solve();
	}
	
#ifdef _LOCAL_
	cout<<"\n" << 1.0 * clock() / CLOCKS_PER_SEC<<endl;
#endif
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n, l;
  cin >> n >> l;
  vector<string> v(n);
  rep(i,n) cin >> v[i];
  sort(ALL(v));
  rep(i,n) cout << v[i];
  cout << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define double long double
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, a[100010];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	for (int i = n - 2; i >= 0; i--) {
		if (a[i] > a[i + 1] + 1) {
			puts("No");
			return 0;
		}
		else if (a[i] == a[i + 1] + 1)a[i] = a[i + 1];
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
int i,j,k[3]={-1};
for(i=0;i<10;i++){
cin>>j;
if(j>k[0]){k[2]=k[1];k[1]=k[0];k[0]=j;}
else if(j>k[1]){k[2]=k[1];k[1]=j;}
else if(j>k[2])k[2]=j;
}
for(i=0;i<3;i++)cout<<k[i]<<endl;
return 0;
}

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

# define C continue;
# define D double
# define ll long long
# define ld long double
# define ull unsigned long long

# define pb push_back
# define vi vector < int >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()

# define pii pair < int , int >
# define vpii vector < pii >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b));
# define mod 1000000007

# define pp(n) printf("%.10f",n);
# define line cout<<"\n";

const D pie = acos(-1);
const D hpie = asin(1);
const D qpie = atan2(-1,1);
const D tpie = 2*pie;

int gcd ( int a , int b )
{
    while ( a%b )
    {
        int temp = b;
        b = a%b;
        a = temp;
    }

    return b;
}

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

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

    vi pref_gcd ( n );
    vi suff_gcd ( n );

    pref_gcd[0] = v[0];
    suff_gcd[n-1] = v[n-1];

    for ( int i=1 ; i<n ; i++ )
        pref_gcd[i] = gcd(pref_gcd[i-1] , v[i] );

    for ( int i=n-2 ; i>=0 ; i-- )
        suff_gcd[i] = gcd ( suff_gcd[i+1] , v[i] );

    int ans = max(suff_gcd[1] , pref_gcd[n-2]);

    for ( int i=1 ; i<n-1 ; i++ )
        ans = max ( ans , gcd(pref_gcd[i-1] , suff_gcd[i+1] ) );

    cout<<ans<<"\n";
}

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

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



Measured memory_bytes: 1408
n,m,x = map(int,input().split())
san = list(tuple(map(int, input().split())) for _ in range(n))
dp = [float('inf')]*(1<<n)
ans = float('inf')
for i in range(1<<n):
    dai = 0
    ri = [0]*m
    for j in range(n):
        if i&(1<<j):
            dai += san[j][0]
            for k in range(1,m+1):
                ri[k-1] += san[j][k]
    for r in range(m):
        flag = True
        if ri[r]<x:
            flag = False
            break
    if flag:
        ans = min(ans, dai)
if ans == float('inf'):
    print(-1)
else:
    print(ans)


Measured memory_bytes: 68616
// ???????????????
#include<vector>
#include<climits>
// ?????°
const int INF = INT_MAX;
// ?????????
class RangeMinimumQuery {
public:
  explicit RangeMinimumQuery(int s);
  void update(int i, int v);
  int index(int left, int right) const;
  int value(int left, int right) const;
private:
  int parent(int node) const;
  int left_child(int node) const;
  int right_child(int node) const;
  int power_of_two(int n) const;
  int query(int left, int right, int node, int node_left, int node_right) const;
  int size_, nil_, inf_;
  std::vector<int> index_, value_;
};
// ????????????
RangeMinimumQuery::RangeMinimumQuery(int s) : size_(power_of_two(s)), nil_(size_), inf_(INF), index_(2 * size_ - 1, nil_), value_(size_ + 1, inf_) {}
void RangeMinimumQuery::update(int i, int v) {
  int node = i + size_ - 1;
  index_.at(node) = i;
  value_.at(i) = v;
  while((node = parent(node)) != nil_) {
    int l = value_.at(index_.at(left_child(node)));
    int r = value_.at(index_.at(right_child(node)));
    index_.at(node) = index_.at(l <= r ? left_child(node) : right_child(node));
  }
}
int RangeMinimumQuery::index(int left, int right) const {
  return query(left, right, 0, 0, size_ - 1);
}
int RangeMinimumQuery::value(int left, int right) const {
  return value_.at(query(left, right, 0, 0, size_ - 1));
}
int RangeMinimumQuery::parent(int node) const {return node ? (node - 1) / 2 : nil_;}
int RangeMinimumQuery::left_child(int node) const {return 2 * node + 1;}
int RangeMinimumQuery::right_child(int node) const {return 2 * node + 2;}
int RangeMinimumQuery::power_of_two(int n) const {
  while(n & (n - 1)) n += n & -n;
  return n;
}
int RangeMinimumQuery::query(int left, int right, int node, int node_left, int node_right) const {
  if(node_right < left || right < node_left) return nil_;
  if(left <= node_left && node_right <= right) return index_.at(node);
  int middle = (node_left + node_right) / 2;
  int l = query(left, right, left_child(node), node_left, middle);
  int r = query(left, right, right_child(node), middle + 1, node_right);
  return value_.at(l) <= value_.at(r) ? l : r;
}

#include<bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n >> q;
  RangeMinimumQuery rmq(n);
  for(int i = 0; i < q; ++i) {
    int com, x, y;
    cin >> com >> x >> y;
    if(com) cout << rmq.value(x, y) << endl;
    else    rmq.update(x, y);
  }
}

Measured memory_bytes: 2584
import math

H, W = map(int, input().split())

if H == 1 or W == 1:
    print(1)
else:
    h1 = math.ceil(H / 2)
    w1 = math.ceil(W / 2)
    h2 = math.floor(H / 2)
    w2 = math.floor(W / 2)

    print(h1*w1 + h2*w2)

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

using namespace std;

int main(){
  int h,w,s,t; cin >> h >> w >> s >> t;
  if(h%2==0||w%2==0 || (s==1&&t==1)||(s==h&&t==1)||(s==1&&t==w)||(s==h&&t==w) || (h%2==1&&w%2==1&&(s%2==t%2))) cout << "Yes";
  else cout << "No";
  cout <<endl;

  return 0;
}



Measured memory_bytes: 3096
N = int(input())
P = list(map(float, input().split()))
import numpy as np
def prob_ret():
  prob = [0.0]*(N+1)
  prob[0] = 1
  prob=np.array(prob)
  for n in range(N):
    p = prob[:N]*P[n]
    prob = prob * (1-P[n])
    prob[1:] = prob[1:] + p
  return sum(prob[N//2+1:])
print(prob_ret())

Measured memory_bytes: 12572
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long 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 gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * b / g;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
using Graph = vector<VE>;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, k; cin >> n >> k;
	string s; cin >> s;
	int ans = 0;
	rep(i, n) {
		if (s[i] == s[i + 1])ans++;
	}
	ans = min(2 * k + ans, n - 1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
# coding: utf-8
from math import ceil
N = int(input())
ans = 0
A, B = [], []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
A, B = A[::-1], B[::-1]
for i in range(N):
    a, b = A[i], B[i]
    cnt = b * ceil((a + ans) / b) - (a + ans)
    ans += cnt
print(ans)


Measured memory_bytes: 12648
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

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

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    unsigned int N;
    cin >> N;
    vector<pair<int,int>>ab(N),cd(N);
    vector<bool>ab_used(N,false);

    rep(i,N){
        cin >> ab[i].first >> ab[i].second;
    }
    rep(i,N){
        cin >> cd[i].first >> cd[i].second;
    }

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

    int ans=0;

    for(int i=0; i<N; i++){
        int point=N+1;
        int Max = -1;
        for(int j=0; j<N; j++){
            if(ab[j].first< cd[i].first && ab[j].second< cd[i].second && !ab_used[j]){
                if(ab[j].second > Max) {
                    point = j;
                    Max = ab[j].second;
                }
            }
        }
        if(point != N+1){
            ans++;
            ab_used[point]=true;
        }

    }

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



Measured memory_bytes: 256
n,m = map(int,input().split())
A = [list(input()) for i in range(n)]
B = [list(input()) for i in range(m)]

if n == m:
    print ("Yes") if A == B else print ("No")
    exit ()

for A_i in range(len(A)):
    for a_i in range(len(A[A_i])):
        if A[A_i][a_i] == B[0][0]:
            if m <= n-A_i and m <= n-a_i:
                tmp = []
                for i in range(A_i,A_i+m):
                    tmp_l = []
                    for j in range(a_i,a_i+m):
                        tmp_l.append(A[i][j])
                    tmp.append(tmp_l)
                if B == tmp:
                    print ("Yes")
                    exit ()
print ("No")


Measured memory_bytes: 9216
from collections import defaultdict
from collections import deque

N, M = map(int, input().split())
route = defaultdict(set)
for i in range(M):
    A_i, B_i = map(int, input().split())
    route[A_i].add(B_i)
    route[B_i].add(A_i)

q = deque()
q.append(1)
seen = [-1] * (N + 1)
seen[0], seen[1] = 0, 0

while len(q) > 0:
    now = q.popleft()
    for i in route[now]:
        if seen[i] == -1:
            q.append(i)
            seen[i] = now

if -1 in seen:
    print("No")
else:
    seen[1] = "Yes"
    print(*seen[1:], sep="\n")


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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;

vector<int> divisor(int n){
  vector<int> res;
  for (int i(1);i*i<=n;i++){
    if (n%i==0){
      res.push_back(i);
      if (i != n/i) res.push_back(n/i);
    }
  }
  return res;
}

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  int B[1000001] = {0};
  for(int i(0);i<N;i++){
    cin>>A[i];
    B[A[i]]++;
  }
  int cnt(0);
  for(int i(0);i<N;i++){
    vector<int> m = divisor(A[i]);
    bool flag(true);
    for(int j(0);j<int(m.size());j++){
      if(m[j] == A[i]){
        if(B[A[i]] >= 2) flag = false;
      }else{
      //  cout << m[j] << " "<<  B[m[j]] << endl;
        if(B[m[j]] != 0){
          flag = false;
        }
      }
    }
    //cout << endl;
    if(flag){
      cnt++;
      //cout << A[i] << endl;
    }
  }
  cout << cnt << endl;
  return 0;
}



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

#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    int N,K;
    cin>>N>>K;
    map<int,int> cnt;
    REP(i,N){
        int A;
        cin>>A;
        cnt[A]++;
    }
    vector<int> v;
    for(auto &it:cnt)v.pb(it.se);
    sort(ALL(v));
    K=max(0,(int)v.size()-K);
    int ret=0;
    REP(i,K){
        ret+=v[i];
    }
    cout<<ret<<endl;
    return 0;
}


Measured memory_bytes: 10744
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int s = sc.nextInt();

		int counter = 0;
		for(int x=0; x<=k; x++){
			for(int y=0; y<=k; y++){
				int z = s-x-y;
				if(0 <= z && z <= k){
					counter++;
				}
			}
		}
		System.out.println(counter);
	}
}

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

using namespace std;

int main(int argc, char* argv[]){
	long long int i,a[4],min,N;//2L買うときの値段の配列

	cin >> a[0];
	a[0] = a[0]*8;
	min = a[0];
	for(i=1; i<3; i++){
		cin  >> a[i];
		a[i] = a[i]*2*(3-i);
		if(a[i] < min){
			min = a[i];
		}
	}
	cin >> a[3];

	cin >> N;

	if(N%2 == 0){
		if(a[3]<min){
			cout << a[3]*(N/2);
		}else{
			cout << min*(N/2);
		}
	}else{
		if(a[3]<min){
			cout << a[3]*(N/2) + min/2;
		}else{
			cout << (min/2)*N;
		}
	}

  return 0;
}


Measured memory_bytes: 256
teams = []
teams << $_.split(?,).map(&:to_i) while gets !='0,0
'
teams.sort!{|a,b|b[1]<=>a[1]}

tmp = teams[0][1]
i = 1

teams.each do |team|
  if team[1] != tmp then
    tmp = team[1]
    i+=1
  end
  team << i
end

while gets do
  t = $_.to_i
  index = teams.index{|x| x[0] == t}
  p teams[index][-1]
end

Measured memory_bytes: 6108
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int top, S[200];//?????¶??????top?????¨??\?????¨??°???????????´??´?????°???S
void push(int x)
{
	 top++;
	S[top] = x; //??\?????¶?????????????????°???
}
int pop()
{ 
	int x= S[top];
	top--;//????????¶??????????????°?????????????????????
	return x;
}
int main()
{
	int a, b;
	top = 0;//?????????
	int i = 0;
	char s[100];
	//cout << "---";
	while (scanf("%s",s)!=EOF)
	{

		if (s[0] == '+')
		{
			a = pop();

			b = pop();
	
			push(a + b);
		
		}
		else if (s[0] == '-')
		{
			b = pop();
		
			a = pop();
		
			push(a - b);
		
		}
		else if (s[0] == '*')
		{
			a = pop();
		
			b = pop();
		
			push(a*b);
		
		}
		else
		{
			push(atoi(s));

		}
		i++;
	}
	printf("%d\n", pop());
	return 0;

}

Measured memory_bytes: 548
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include <set>
#define ll long long
using namespace std;
int a[200005];
int b[200005];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];
    }
    sort(a+1,a+n+1);
    sort(b+1,b+1+n);
    if(n%2==1)
    {
        cout<<b[(n+1)/2]-a[(n+1)/2]+1<<endl;
    }
    else
    {
        cout<<b[n/2]+b[n/2+1]-a[n/2]-a[n/2+1]+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 5180
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <utility>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <set>
#include <chrono>
#include <climits>
#include <unordered_map>
#include <iomanip> 

#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define repf(i,st,end,inc) for(int i = st; i < end; i += inc)
#define repb(i,st,end,dec) for(int i = st; i >= end; i -= dec) 

#define MOD 1000000007

#define trace1(a) cout << a << endl;
#define trace2(a,b) cout << a << " | " << b << endl;
#define trace3(a,b,c) cout << a << " | " << b << " | " << c << endl;
#define trace4(a,b,c,d) cout << a << " | " << b << " | " << c << " | "<< d << endl;

using namespace std;
using namespace std::chrono;

int fact(int n){
	int ans = 1;
	for(int i = 1; i <= n; i++){
		ans = ans*i;
	}
	return ans;
}

int main(){
	fast;
	#ifdef LOCAL_PROJECT
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	auto start = high_resolution_clock::now(); 

	int n;
	cin >> n;
	vector<double> x(n),y(n);
	for(int i = 0 ; i < n; i++)
		cin >> x[i] >> y[i];

	vector<int> perm(n,0);
	for(int i = 0; i < n; i++){
		perm[i] = i;
	}

	double ans = 0.0;
	int fact_val = fact(n); 
	do{
		double dist = 0.0;
		for(int i = 0; i < n-1; i++){
			dist += sqrt(pow(x[perm[i]] - x[perm[i+1]], 2) + pow(y[perm[i]] - y[perm[i+1]], 2));
		}
		// trace1(dist)
		ans += dist/double(fact_val); 
	}while(next_permutation(perm.begin(), perm.end()));

	cout << fixed << setprecision(12) << ans << endl;

	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start);	
	// cout << endl;
	// cout << fixed << setprecision(9) << double(duration.count()) / 1000000 << endl; 

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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

int main()
{
  ll N,M;
  cin >> N >> M;
  VEC(ll,A,N);
  vector<ll> imos(N+1,0);
  REP(i,N){
    imos[i+1]=A[i];
    imos[i+1]+=imos[i];
  }

  map<ll,ll> amari;
  REP(i,N+1){
    amari[imos[i]%M]++;
  }

  ll ans = 0;
  for(auto x:amari){
    ans+=x.se*(x.se-1)/2;
  }

  cout << ans << endl;
}


Measured memory_bytes: 8540
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  1000000007
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n; cin>>n;
    vi a(n+1),pref(n+1);
    for (int i=1;i<=n;i++){
        cin >> a[i];
    }
    pref[n] = a[n];
    for (int i=n-1;i>0;i--){
      pref[i] = pref[i+1]+a[i];
      pref[i] = pref[i]%mod;
    } 
    int ans=0;
    for (int i=1;i<=n-1;i++){
        ans += (a[i]*pref[i+1])%mod;
        ans = ans % mod;
    }
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 6420
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int ans[60001];
    Fr(x,100) Fr(y,100) Fr(z,100){
        ++ans[x*x+y*y+z*z+x*y+y*z+z*x];
    }
    int n;
    cin>>n;
    Fr(i,n) cout<<ans[i]<<'\n';
}

Measured memory_bytes: 3860
#include<bits/stdc++.h>
using namespace std;
#define INF (1LL<<60)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
/*
signed main(){
  int n;
  cin>>n;
  cout<<(n-2)*180<<endl;
  return 0;
}
signed main(){
  string s;
  cin>>s;
  while(1){
    if(s.size()==15) break;
    s=s+"o";
  }
  int cnt=0;
  lp(i,s.size()){
    if(s[i]=='o')cnt++;
  }
  if(cnt>=8) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}
*/
int check[20010];
int ans[20010];
signed main(){
  int n;
  cin>>n;
  vector<int> g[20010];
  lp(i,n-1){
    int a,b;
    cin>>a>>b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  queue<int> q;
  q.push(1);
  check[1]=1;
  vector<int> c;
  lp(i,n){
    int x;
    cin>>x;
    c.push_back(x);
  }
  sort(c.begin(),c.end());
  reverse(c.begin(),c.end());
  int sum=0;
  lp(i,c.size()){
    if(i==0) continue;
    sum+=c[i];
  }
  int hoge=0;
  while(!q.empty()){
    int now=q.front();
    q.pop();
    ans[now]=c[hoge];
    hoge++;
    lp(i,g[now].size()){
      if(check[g[now][i]]==0){
        check[g[now][i]]=1;
        q.push(g[now][i]);
      }
    }
  }
  cout<<sum<<endl;
  if(n==1) return 0;
  lp(i,n){
    if(i!=0) cout<<" ";
    cout<<ans[i+1];
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <sstream>
using namespace std;
int main(void){
	string sa,sb;
	int a,b;
	cin >> sa >> sb;
	if(sa.size()==sb.size()){
		for(int i=0; i<sa.size(); i++){
			if(sa[i]>sb[i]){
				a=1;b=0;
				break;
			}else if(sa[i]<sb[i]){
				a=0;b=1;
				break;
			}
		}
	}else if(sa.size()<sb.size()){
		a=0;b=1;
	}else{
		a=1;b=0;
	}
	if(a>b){
		cout << "GREATER" << endl;
	}else if(a<b){
		cout << "LESS" << endl;
	}else{
		cout << "EQUAL" << endl;
	}
	return 0;
}

Measured memory_bytes: 256