akhauriyash/Code-Regression huggingface dataset:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N, x = MAP()
a = LIST()

a.sort()
A = list(accumulate(a))

n = bisect(A, x)
if n == N and A[-1] < x:
	print(n-1)
else:
	print(n)


Measured memory_bytes: 10640
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long N, D, A, L[1 << 18], cur, sum;
pair<long long, long long> S[1 << 18];

int main() {
	cin >> N >> D >> A;
	for (int i = 0; i < N; i++) {
		cin >> S[i].first >> S[i].second;
		S[i].second = (S[i].second + A - 1) / A;
	}
	sort(S, S + N);

	for (int i = 0; i < N; i++) {
		cur -= L[i];
		long long pos1 = lower_bound(S, S + N, make_pair(S[i].first + 2LL * D + 1LL, -(1LL << 60))) - S;
		long long needed = max(0LL, S[i].second - cur);
		sum += needed;
		cur += needed;
		L[pos1] += needed;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 6400
N = int(input())
D = []

for i in range(N):
    s, t = input().split()
    D.append([s, int(t)])

m = input()
n = 0
for i in range(N):
    if m in D[i]:
        n = i
        break

print(sum([d[1] for d in D[n + 1:]]))




Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
const int inf = INT_MAX;
const ll INF = 1LL >> 60;
const ll mod = 1e9+7;

int main() {
    int n;
    cin >> n;
    int sum = 0;
    int ma = 0;
    rep(i, n){
        int p;
        cin >> p;
        chmax(ma, p);
        sum+=p;
    }

    sum -= ma/2;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int N=cin.nextInt();
        string ans="No";
        if(N%1111==0)ans="Yes";
        else if((N%1000)%111==0)ans="Yes";
        else if((N-(N%10))%1110==0)ans="Yes";
        Console.WriteLine(ans);
        
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,m,a,b,all,nokori;
   all=0;
  cin >> n >> m;
  nokori=m;
 vector<pair<int64_t, int64_t> > pairs(n);
  
  for (int64_t i = 0; i < n; i++) {
    cin >> a >> b;
    pairs[i] = make_pair( a , b );
  }
// firstが小さい順、secondが小さい順にソート
  sort(pairs.begin(), pairs.end());
  
  for (int i=0;i<n;i++){
    
    all+=pairs[i].first*pairs[i].second;
    nokori-=pairs[i].second;
    if(nokori<0) {
      nokori+=pairs[i].second; all-=pairs[i].first*pairs[i].second; 
      all+=nokori*pairs[i].first;
      break;
    }
  }


  cout << all << endl;

}

Measured memory_bytes: 1792
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def main():
    S = input()
    num_dicts = {}
    for i in range(len(S)):
        if S[i] not in num_dicts:
            num_dicts[S[i]] = 1
        else:
            num_dicts[S[i]] += 1
    for key_, value_ in num_dicts.items():
        if value_ == 2:
            pass
        else:
            print("No")
            sys.exit()
    else:
        if len(num_dicts) == 2:
            print("Yes")
            sys.exit()
        else:
            print("No")
            sys.exit()


if __name__ == '__main__':
    main()

Measured memory_bytes: 21920
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i,a) for(int i = 0;i < a; i++)
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = { 0,-1, 0, 1};
int field[30][30];
int h, w;
int ans;
int sx, sy, gx, gy;
bool inrange(int x, int y){
  return x >= 0 && y >= 0 && x < w && y < h;
}

void rec(int x, int y, int cnt){
  if(cnt > 10) return;
  /*  cout << x << " " << y << endl;
  rep(i, h){
    rep(j, w){
      cout << field[j][i] << " ";
    }
    cout << endl;
    }*/
  rep(i, 4){
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(inrange(nx, ny) && field[nx][ny] != 1){
      int tx = nx, ty = ny;
      while(inrange(tx, ty) && field[tx][ty] != 1){
	if(tx == gx && ty == gy){
	  ans = min(ans, cnt);
	  return;
	}
	tx += dx[i]; ty += dy[i];
      }
      if(!inrange(tx, ty)) continue;
      field[tx][ty] = 0;
      tx -= dx[i]; ty -= dy[i];
      rec(tx, ty, cnt+1);
      field[tx+dx[i]][ty+dy[i]] = 1;
    }
  }
}
int main(){
  while(cin >> w >> h, w||h){
    rep(i, h){
      rep(j, w){
	cin >> field[j][i];
	if(field[j][i] == 2){
	  sx = j; sy = i;
	  field[j][i] = 0;
	}else if(field[j][i] == 3){
	  gx = j; gy = i;
	  field[j][i] = 0;
	}
      }
    }
    ans = 12;
    rec(sx, sy, 1);
    cout << (ans==12?-1:ans) << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <iostream>
#include <complex>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef complex<double> P;
#define INF (1e100)
#define EPS (1e-10)
const double pi = atan2(0.0, -1.0);

P unit(double t) { return P(cos(t), sin(t)); }
double dot(const P& a, const P& b) { return real(conj(a)*b); }
double cross(const P& a, const P& b) { return imag(conj(a)*b); }
int ccw(const P& a, P b, P c) {
    b -= a, c -= a;
    if (cross(b, c) > 0) return 1;
    if (cross(b, c) < 0) return -1;
    if (dot(b, c) < 0) return 2;
    if (norm(b) < norm(c)) return -2;
    return 0;
}
bool intersectSS(const P& s0, const P& s1, const P& t0, const P& t1) {
    return ccw(s0, s1, t0) * ccw(s0, s1, t1) <= 0
        && ccw(t0, t1, s0) * ccw(t0, t1, s1) <= 0;
}
bool intersectSP(const P& s0, const P& s1, const P& p) {
    return abs(s0-p) + abs(s1-p) - abs(s1-s0) < EPS;
}
P projection(const P& l0, const P& l1, const P& p) {
    const double t = dot(p-l0, l0-l1) / norm(l0-l1);
    return l0 + t*(l0-l1);
}
double distanceSP(const P& s0, const P& s1, const P& p) {
    const P r = projection(s0, s1, p);
    if (intersectSP(s0, s1, r)) return abs(r-p);
    return min(abs(s0-p), abs(s1-p));
}
double distanceSS(const P& s0, const P& s1, const P& t0, const P& t1) {
    if (intersectSS(s0, s1, t0, t1)) return 0;
    return min(min(distanceSP(s0, s1, t0), distanceSP(s0, s1, t1)),
               min(distanceSP(t0, t1, s0), distanceSP(t0, t1, s1)));
}

int N, M, L;
P ps[128][8];
double xs[128], ys[128], as[128], rs[128];
double g[128][128], dp[128];
int vis[128];

double solve() {
    rep (i, N) dp[i] = INF;
    rep (i, N) vis[i] = 0;
    dp[M] = 0;
    rep (i, N) {
        int at = -1;
        rep (i, N) if (vis[i] == 0) at = i;
        rep (i, N) if (vis[i] == 0 && dp[i] < dp[at]) at = i;
        vis[at] = 1;
        rep (i, N) if (vis[i] == 0) dp[i] = min(dp[i], dp[at] + g[at][i]);
    }
    return dp[L];
}

int main() {
    for (;;) {
        scanf("%d%d%d", &N, &M, &L);
        if (N == 0) return 0;
        M--, L--;
        rep (i, N) scanf("%lf%lf%lf%lf", xs+i, ys+i, as+i, rs+i);
        rep (i, N) rep (k, 5) {
            const double t = (as[i]+90+k*144) * pi / 180.0;
            ps[i][k] = P(xs[i], ys[i]) + rs[i] * unit(t);
        }
        rep (i, N) rep (j, N) {
            g[i][j] = INF;
            rep (a, 5) rep (b, 5) {
                const double d = distanceSS(ps[i][a], ps[i][(a+1)%5],
                                            ps[j][b], ps[j][(b+1)%5]);
                g[i][j] = min(g[i][j], d);
            }
        }
        printf("%.9f\n", solve());
    }
}

Measured memory_bytes: 1396
h,w=map(int,input().split())
mod=10**9+7
l=[]
for i in range(h):
    l.append(list(input()))
dp=[[0 for i in range(w+1)] for j in range(h+1)]
dp[0][1]=1
for i in range(h):
    for j in range(w):
        if l[i][j]=='.':
            dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j])%mod
print(dp[h][w])

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

int main()
{
    int A, B;
    cin >> A >> B;
    int max = A + B;
    if(max < (A-B)) {
        max = A - B;
    }
    if(max < (A*B)) {
        max = A * B;
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 3640
# 1 How many ways?

import itertools

n_list = []
x_list = []
while True:
    _n, _x = map(int, input().split())
    if _n == 0 and _x == 0:
        break
    n_list.append(_n)
    x_list.append(_x)

l = len(n_list)

for i in range(l):
    ans = 0
    n = n_list[i]
    x = x_list[i]
    for v in itertools.combinations(range(1,n+1), 3):
        if sum(list(v)) == x:
            ans += 1
    print(ans)


Measured memory_bytes: 5644
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;

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

	for (int i = k; i < n; i++) {
		cout << (a[i] > a[i - k] ? "Yes": "No") << endl;
	}
	return 0;
}


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

#define fi first
#define se second
#define sz(v) (int)((v).size())
#define pb push_back

typedef long long ll;

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

	int n, k; cin >> n >> k;
	vector<double> p(n);
	for (int i=0; i<n; i++) cin >> p[i];
	ll exp = 0;
	for (int i=0; i<k; i++) exp += (p[i]+1);
	ll ans = exp;
	for (int i = k; i < n; i++) {
		exp -= (p[i-k]+1);
		exp += (p[i]+1);
		ans = max(ans, exp);
	}
	cout << fixed << setprecision(6) << ((double)ans)/2 << "\n";
}


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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

#define MAX_N 100000

struct edge {
  int to, dep, cost;
  edge(){}
  edge(int to, int dep, int cost):to(to), dep(dep), cost(cost){}
};

struct stat {
  int now, ela, wet;
  stat(){}
  stat(int now, int ela, int wet):now(now), ela(ela), wet(wet){}
  bool operator < (const stat s) const {
    return wet > s.wet;
  }
};

int N, M, S, G;
vector<edge> graph[MAX_N];
map<pint, int> mincost;

int dijkstra() {
  priority_queue<stat> que;
  mincost[make_pair(S, 0)] = 0;
  que.emplace(S, 0, 0);
  while(que.size()) {
    stat s = que.top(); que.pop();
    int now = s.now, ela = s.ela, wet = s.wet;
    pint p = make_pair(now, ela);
    if(now == G) return wet;
    if(mincost.count(p) && mincost[p] < wet) continue;
    for(edge& e : graph[now]) {
      pint q = make_pair(e.to, e.dep + e.cost);
      if(ela <= e.dep && (!mincost.count(q) || mincost[p] + e.dep - ela < mincost[q])) {
	mincost[q] = mincost[p] + e.dep - ela;
	que.emplace(e.to, e.dep + e.cost, mincost[q]);
      }
    }
  }
  return -1;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N >> M >> S >> G;
  --S, --G;
  rep(i, M) {
    int u, v, t, c;
    cin >> u >> v >> t >> c;
    --u, --v;
    graph[u].emplace_back(v, t, c);
  }
  cout << dijkstra() << endl;

  return 0;
}

Measured memory_bytes: 17356
#include<iostream>
using namespace std;
using ll = long long;

/*
  再帰関数でRMQを実装
*/

ll INF = (1LL<<31) - 1;

ll seg[1 << 20];

void set_value(ll pos, ll val){
  pos += 1 << 19; //20?
  seg[pos] = val;
  while((pos /= 2) > 0 ){
    seg[pos] = min(seg[pos * 2], seg[pos * 2 + 1]);//自分の左右の子供のminをとって更新
  }
}

//クエリの右橋，左端，今いる場所の区間の左右端，今いる場所
ll get_min(ll ql, ll qr, ll sl = 0, ll sr = 1 << 19, ll pos = 1){
  //全くかぶっていないとき
  if(qr <= sl || sr <= ql) return INF;  //意味のない数字を返す　maxのときは，0を返す
  //完全にかぶっているとき（セグメントがクエリに）
  if(ql <= sl && sr <= qr) return seg[pos];
  //
  ll sm = (sl + sr) / 2;
  ll lmin = get_min(ql,qr,sl,sm,pos * 2); //左右の子に託す
  ll rmin = get_min(ql,qr,sm,sr,pos * 2 + 1); //左右の子に託す
  return min(lmin, rmin);
}

int main(){
  int n, q;
  cin >> n >> q;
  for(int i = 0; i < n; i++){
    set_value(i, INF);
  }



  for(int i = 0; i < q; i++){
    ll com, x, y;
    cin >> com >> x >> y;
      if(com == 0){
        set_value(x,y);
      }
      else{
        cout << get_min(x,y+1) << endl;
      }
  }

  return 0;
}





Measured memory_bytes: 4696
# AOJ 1179: Millennium
# Python3 2018.7.14 bal4u

for cno in range(int(input())):
	y, m, d = map(int, input().split())
	ans = 195*y
	if y > 1: ans += 5*((y-1)//3)
	if y % 3: ans += 19*(m-1) + m//2
	else: ans += (m-1)*20
	print(196666-ans-d)



Measured memory_bytes: 5588
#include <iostream>
#include <cmath>

using namespace std;

int a, b;

int digits(int n)
{
    if (n <= 9) return 1;
    else return 1 + digits(n/10);
}

void solve()
{
    int c = a*pow(10, digits(b)) + b;

    int ok = 0;
    for (int i = 1; i <= 3*c/2; i++) {
        if (i*i == c) {
            ok = 1;
        }
    }

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

    solve();

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <climits>
using namespace std;
 
int main(){
  int a,b;
  cin >> a;
  bool flag = false;
 
  for(int i = 1; i < 10; i++){
    if(a%i == 0 && a/i < 10){
      cout << "Yes" << endl;
      flag = true;
      break;
    }
  }
  if(!flag)
  cout << "No" << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int cc = 0;
    if ((a + b) >= c * 2)
    {
        int mini = min(x, y);
        cc += 2 * c * mini;
        x -= mini;
        y -= mini;
        if (a > 2 * c)
        {
            cc += 2 * c * x;
            x = 0;
        }
        if (b > 2 * c)
        {
            cc += 2 * c * y;
            y = 0;
        }
    }
    cc += x * a;
    cc += y * b;
    cout << cc << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
 
while($line = fgets(STDIN)){
    $d = intval($line);
    $s = 0;
    
    // ??¬????????????
    // S = 1/6*n*(n + 1)*(2*n + 1);
    
	$n = 600/$d -1;
	$s = $d*$d*$d*$n*($n + 1)*(2*$n + 1)/6;
    
    echo $s."\n";
}

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

int main(){
    string s,t;
    cin >> s;
    cin >> t;
    int s_size = s.size();
    int t_size = t.size();
    int dex = -1;
    rep(i,s_size-t_size+1){
        int cnt = 0;
        for(int j = 0; ((i+j < s_size) && (j < t_size)); ++j){
            if(s[i+j] == '?' || s[i+j] == t[j]){
                cnt++;
            }else{
                cnt = -1;
                break;
            }
        }
        if(cnt == t_size){ // 存在
            dex = i;
        }
    }
    if(dex >= 0){
        for(int j = 0; j < dex; ++j){
            if(s[j] == '?') cout << 'a';
            else cout << s[j];
        }
        cout << t;
        for(int j = dex+t_size; j < s_size; ++j){
            if(s[j] == '?') cout << 'a';
            else cout << s[j];
        }
        return 0;
    }
    cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool is_parlindrome(string S){
  string T = S;
  reverse(T.begin(), T.end());
  return (S == T);
}
int main(){
  string S;
  cin >> S;
  int N = S.size();
  if (!is_parlindrome(S)){
    cout << "No";
  } else {
    if (is_parlindrome(S.substr(0, (N - 1) / 2))){
      cout << "Yes";
    } else{
      cout << "No";
    }
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Stack;

public class Main {

	final int[][] dir = { { -1, -1 }, { -1, 1 }, { 1, -1 }, { 1, 1 } };

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int k = readInt(sc);
		int s = readInt(sc);

		int cnt = 0;

		for (int a = 0; a <= k; a++) {
			for (int b = 0; b <= k; b++) {
				int c = s - a - b;
				if (c >= 0 && c <= k) {
					cnt++;
				}
			}
		}
		System.out.println(cnt);
	}

	static int readInt(Scanner sc) {
		return Integer.parseInt(sc.next());
	}

	static double calcDistance(Pair p1, Pair p2) {
		return Math.pow(Math.pow(p1.getX() - p2.getX(), 2) + Math.pow(p1.getY() - p2.getY(), 2), 0.5);
	}

}

class Pair {
	private int x;
	private int y;

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Pair() {

	}

	public Pair(int x, int y) {
		this.x = x;
		this.y = y;
	}

}


Measured memory_bytes: 21204
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<int,int> P;

// vector の表示用デバッグ
template<class T>
void debug(vector<T> v){
	cout << "[debug]" << endl << "{";
	for(int i = 0 ; i < v.size() ; i++ ){
		cout << v[i];
		if( i < v.size()-1 )
			cout  << ", ";
	}
	cout << "}" << endl << endl;
}

//string型からint型に変換する
int s_to_i(string s){
    int n = 0;
    for(unsigned int i=0 ; i < s.size() ; ++i ){
        n *= 10;
        n += s[i] - '0';
    }
    return n;
}

// 文字列を半角スペース区切りで数値に分割する
vector<int> split_words(string s){
    bool flag = false;
    vector<string> vs;
    string str;
    s.push_back(' ');
    for(int i=0 ; i < s.size() ; i++ ){
        char c = s[i];
        if( flag == false ){
            if( c != ' ' ){
                flag = true;
                str.clear();
                str.push_back( c );
            }
        }else{
            if( c != ' ' ){
                str.push_back( c );
            }
            if( c == ' ' ){
                flag = false;
                vs.push_back( str );
                str.clear();
            }
        }
    }
    vector<int> v;
    for(int i=0 ; i < vs.size() ; i++ ){
    	v.push_back( s_to_i( vs[i] ) );
    }
    return v;
}

// v[0] := 学籍番号, v[1..v.size()-1] := 点数の記録
// score := 点数, pos := 位置
// frame := フレーム数, k := 0のとき1投目, 1のとき2投目
// (-スコア,学籍番号)を返す
P solve(vector<int>& v, int score, int pos, int frame, int k){
	P result;
	
	if( frame > 10 || pos >= v.size() ){
		result.second = v[0];
		result.first = -score;
		return result;
	}else{
		if( k == 0 ){ // 1投目
			if( v[pos] == 10 ){ // ストライクのとき	
				score += v[pos] + v[pos+1] + v[pos+2];
				return solve( v , score , pos+1 , frame+1 , 0 );
			}else{
				score += v[pos];
				return solve( v , score , pos+1 , frame , 1 );
			}
		}else{ // 2投目
			if( v[pos-1] + v[pos] == 10 ){ // スペアのとき
				score += v[pos] + v[pos+1];
				return solve( v , score , pos+1 , frame+1 , 0 );
			}else{
				score += v[pos];
				return solve( v , score , pos+1 , frame+1 , 0 );
			}
		}
	}
	
	return result;
}

int main(){
	int n;
	while( cin >> n , n ){
		cin.ignore();
		vector<P> ans;
		for(int i=0 ; i < n ; i++ ){
			string s;
			getline(cin,s);
			vector<int> v = split_words(s);
			P p = solve( v , 0 , 1 , 1 , 0 );
			ans.push_back(p);
		}
		
		sort( ans.begin() , ans.end() );
		for(int i=0 ; i < ans.size() ; i++ ){
			cout << ans[i].second << " " << -ans[i].first << endl;;
		}
	}
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<ll> march(5, 0);
  vector<char> MARCH = {'M', 'A', 'R', 'C', 'H'};
  for (ll i = 0; i < N; ++i) {
    string S;
    cin >> S;
    for (ll j = 0; j < 5; ++j) {
      if (S[0] == MARCH.at(j)) {
        march.at(j) += 1;
      }
    }
  }
  ll ans = 0;
  for (ll i = 0; i < 3; ++i) {
    for (ll j = i + 1; j < 4; ++j) {
      for (ll k = j + 1; k < 5; ++k) {
        ans += march.at(i) * march.at(j) * march.at(k);
        // cout << ans << "\n";
      }
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
int a[105],n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int k=0;
for(int i=0;;i++)
{
 for(int j=0;j<n;j++)
 {
  if(k==0&&a[j]!=0){k=1;}
  if(k==1){if(a[j]!=0){a[j]--;} else {break;}}
 }
 if(k==0){printf("%d\n",i);break;}
 k=0;
}
}

Measured memory_bytes: 128
#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>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
const int N = 2e3+9;
int main() {
    priority_queue<ll>r,g,b;
    int x,y,ax,bx,cx;
    int tmp;
    scanf("%d %d %d %d %d",&x,&y,&ax,&bx,&cx);
    for(int i=0;i<ax;i++){
        scanf("%d",&tmp);
        r.emplace(tmp);
    }
    for(int i=0;i<bx;i++){
        scanf("%d",&tmp);
        g.emplace(tmp);
    }
    for(int i=0;i<cx;i++){
        scanf("%d",&tmp);
        b.emplace(tmp);
    }
    ll ans=0;
    dijkstra<ll>pq1;
    for(int i=0;i<x;i++){
        ans+=r.top();
        pq1.emplace(r.top());
        r.pop();
    }
    for(int i=0;i<y;i++){
        ans+=g.top();
        pq1.emplace(g.top());
        g.pop();
    }
    while (b.empty()==false && b.top()>pq1.top())
    {
        ans-=pq1.top();
        pq1.pop();
        ans+=b.top();
        b.pop();
    }
    cout<<ans<<"\n";
    
    
}


Measured memory_bytes: 4724
/*  Bismillahir Rahmanir Rahim  */

#include <bits/stdc++.h>

using namespace std;

const int N = 55;

int n, a[N], p;
long long dp[N][2];

long long recur(int at, int sum){
	if(at == n + 1){
		if(sum == p) return 1;
		else return 0;
	}
	if(dp[at][sum] != -1) return dp[at][sum];
	long long ret = 0;
	ret += recur(at + 1, (sum + a[at]) % 2);
	ret += recur(at + 1, sum);
	return dp[at][sum] = ret;
}

int main(){
	scanf("%d %d", &n, &p);
	for(int i = 1; i <= n; ++i){
		scanf("%d", &a[i]);
	}
	memset(dp, -1, sizeof(dp));
	cout << recur(1, 0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
#define pb push_back
#define mp make_pair
#define Chkmax(a,b) a=a>b?a:b
#define Chkmin(a,b) a=a<b?a:b
typedef unsigned long long uint64;
typedef unsigned int uint32;
typedef long long ll;

using namespace std;

namespace IO
{
    const uint32 Buffsize=1<<15,Output=1<<23;
    static char Ch[Buffsize],*S=Ch,*T=Ch;
    inline char getc()
    {
        return((S==T)&&(T=(S=Ch)+fread(Ch,1,Buffsize,stdin),S==T)?0:*S++);
    }
    static char Out[Output],*nowps=Out;
    
    inline void flush(){fwrite(Out,1,nowps-Out,stdout);nowps=Out;}

    template<typename T>inline void read(T&x)
    {
        x=0;static char ch;T f=1;
        for(ch=getc();!isdigit(ch);ch=getc())if(ch=='-')f=-1;
        for(;isdigit(ch);ch=getc())x=x*10+(ch^48);
        x*=f;
    }

    template<typename T>inline void write(T x,char ch='\n')
    {
        if(!x)*nowps++='0';
        if(x<0)*nowps++='-',x=-x;
        static uint32 sta[111],tp;
        for(tp=0;x;x/=10)sta[++tp]=x%10;
        for(;tp;*nowps++=sta[tp--]^48);
        *nowps++=ch;
    }
}
using namespace IO;

inline void file()
{
#ifndef ONLINE_JUDGE
    FILE*DSA=freopen("water.in","r",stdin);
    FILE*SDU=freopen("water.out","w",stdout);
#endif
}

const int MAXN=1e5+7;

static int n,m;

vector<int>nds[MAXN];

static struct edge
{
	int u,v,w;
}p[MAXN<<1];

void init()
{
	read(n);read(m);
	Rep(i,1,m)
	{
		read(p[i].u),read(p[i].v),read(p[i].w);
		nds[p[i].u].pb(p[i].w),nds[p[i].v].pb(p[i].w);
	}
}

static int e;

static int ans=INT_MAX;

typedef pair<int,int>PII;

map<PII,int>to;

vector<PII>ed[MAXN<<3];

static int rt[MAXN];

deque<int>G;

static int dis[MAXN<<3];

inline void solve()
{
	Rep(i,1,n)
	{
		sort(nds[i].begin(),nds[i].end());
		nds[i].erase(unique(nds[i].begin(),nds[i].end()),nds[i].end());
		rt[i]=to[mp(i,0)]=++e;
		for(register int v:nds[i])
		{
			to[mp(i,v)]=++e,ed[rt[i]].emplace_back(e,1)
			,ed[e].emplace_back(rt[i],1);
		}
	}
	Rep(i,1,m)
	{
		ed[to[mp(p[i].u,p[i].w)]].emplace_back(to[mp(p[i].v,p[i].w)],0);
		ed[to[mp(p[i].v,p[i].w)]].emplace_back(to[mp(p[i].u,p[i].w)],0);
	}
	G.pb(1),dis[1]=1;
	static int u;
	while(!G.empty())
	{
		u=G.front();G.pop_front();
		for(register auto v:ed[u])if(!dis[v.first])
		{
			dis[v.first]=dis[u]+v.second;
			v.second?G.pb(v.first):G.push_front(v.first);
		}
	}
	printf("%d\n",dis[rt[n]]?dis[rt[n]]/2:-1);
}

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


Measured memory_bytes: 80768
#![allow(unused)]

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
//入力マクロここまで

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;

fn main() {
    input! {
        n: usize,
        m: usize,
        sc: [(usize,u64);m],
    }

    let mut num = vec![(0, false); n];

    for e in sc {
        if !num[e.0 - 1].1 {
            num[e.0 - 1].0 = e.1;
            num[e.0 - 1].1 = true;
        } else if num[e.0 - 1].0 != e.1 {
            println!("-1");
            return;
        }
    }

    if num.len() != 1 && num[0].1 && num[0].0 == 0 {
        println!("-1");
        return;
    }

    if num.len() != 1 && num[0].0 == 0 {
        num[0].0 = 1;
    }

    for e in num {
        print!("{}", e.0);
    }

    println!();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=105,mod=1e9+7,INF=mod+233;
int Pow(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=(LL)x*x%mod)
		if (y&1)
			ans=(LL)ans*x%mod;
	return ans;
}
void Add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
void Del(int &x,int y){
	if ((x-=y)<0)
		x+=mod;
}
int Add(int x){
	return x>=mod?x-mod:x;
}
int Del(int x){
	return x<0?x+mod:x;
}
int n;
int a[N];
int g[N][N],f[N][N];
void dfs(int L,int R,int h){
	if (L==R){
		g[L][R]=Pow(2,a[L]-h);
		f[L][R]=0;
//		printf("dfs(%d,%d,%d): ",L,R,h);
//		printf("g = %d, f = %d\n",g[L][R],f[L][R]);
		return;
	}
	int mi=INF;
	For(i,L,R)
		mi=min(mi,a[i]);
	int las=L;
	For(i,L,R){
		if (a[i]==mi){
			if (las<i){
				dfs(las,i-1,mi);
				if (las==L){
					g[L][R]=g[las][i-1];
					f[L][R]=f[las][i-1];
					las=i;
				}
				else {
					int g0=g[L][R],g1=g[las][i-1];
					int f0=f[L][R],f1=f[las][i-1];
					g[L][R]=(LL)g0*g1%mod;
					f[L][R]=0;
					Add(f[L][R],(LL)g0*g1%mod);
					Add(f[L][R],(LL)f0*g1*2%mod);
					Add(f[L][R],(LL)g0*f1*2%mod);
					Add(f[L][R],(LL)f0*f1*2%mod);
				}
			}
			dfs(i,i,mi);
			if (las==L){
				g[L][R]=g[i][i];
				f[L][R]=f[i][i];
			}
			else {
				int g0=g[L][R],g1=g[i][i];
				int f0=f[L][R],f1=f[i][i];
				g[L][R]=(LL)g0*g1%mod;
				f[L][R]=0;
				Add(f[L][R],(LL)g0*g1%mod);
				Add(f[L][R],(LL)f0*g1*2%mod);
				Add(f[L][R],(LL)g0*f1*2%mod);
				Add(f[L][R],(LL)f0*f1*2%mod);
			}
			las=i+1;
		}
	}
	if (las<=R){
		dfs(las,R,mi);
		int g0=g[L][R],g1=g[las][R];
		int f0=f[L][R],f1=f[las][R];
		g[L][R]=(LL)g0*g1%mod;
		f[L][R]=0;
		Add(f[L][R],(LL)g0*g1%mod);
		Add(f[L][R],(LL)f0*g1*2%mod);
		Add(f[L][R],(LL)g0*f1*2%mod);
		Add(f[L][R],(LL)f0*f1*2%mod);
	}
	g[L][R]=(LL)g[L][R]*Pow(2,mi-h)%mod;
//	printf("dfs(%d,%d,%d): ",L,R,h);
//	printf("g = %d, f = %d\n",g[L][R],f[L][R]);
}
int main(){
	n=read();
	For(i,1,n)
		a[i]=read();
	dfs(1,n,1);
	int ans=Add(g[1][n]+f[1][n]);
	Add(ans,ans);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for (int i = 0; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
#define keta(n) cout << fixed << setprecision((n));
using ll = int64_t;
using v = vector<int>;
 
 
int main() {
  vector<int> x(5);
  for (int i = 0; i<5; i++) {
    int a;
    cin >> a;
    x.at(i) = a;
  }
  for (int i = 0; i<5; i++) {
    if (x.at(i)==0) {
      cout << i+1 << endl;
      break;
    }
  }
}

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

int main() {
	string s;
	cin >> s;
	for (int sign1 = 1; sign1 >= -1; sign1 -= 2) {
		for (int sign2 = 1; sign2 >= -1; sign2 -= 2) {
			for (int sign3 = 1; sign3 >= -1; sign3 -= 2) {
				int a[4];
				for (int i=0; i<4; i++) {
					a[i] = s[i] - '0';
				}

				if (a[0]+sign1*a[1]+sign2*a[2]+sign3*a[3] == 7) {
					cout << a[0] 
						 << (sign1*a[1] >= 0? "+": "")
						 << sign1*a[1] 
						 << (sign2*a[2] >= 0? "+": "")
						 << sign2*a[2] 
						 << (sign3*a[3] >= 0? "+": "")
						 << sign3*a[3] 
						 << "=7" << endl;
					return 0;
				}
			}
		}
	}
}

Measured memory_bytes: 256
using System;

namespace AtCoder.ABC._112
{
    class d
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim();
            var spl = line.Split(' ');
            var N = int.Parse(spl[0]);
            var M = int.Parse(spl[1]);
            var O = (double)M / N;
            for(var i = (int)Math.Floor(O); i > 1; --i)
            {
                if (M % i == 0)
                {
                    Console.WriteLine(i);
                    return;
                }
            }
            Console.WriteLine(1);
        }
    }
}


Measured memory_bytes: 13140
h, w = gets.chomp.split(" ").map(&:to_i)

ary = Array.new(h, Array.new(w))

h.times do |i|
  ary[i] = gets.chomp.split("")
end

flag = true

h.times do |i|
  w.times do |j|
    if ary[i][j] == '#'
      flag = false if ary[i][j-1] != '#' && ary[i][j+1] != '#' && ary[i-1][j] != '#' && ary[i+1][j] != '#'
    end
  end
  break if flag == false
end

if flag 
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1916
import java.util.*;

class Main{
  public static int min(int a,int b){
    return (a<b)?a:b;
  }
  
  public static int max(int a,int b){
    return (a>b)?a:b;
  }
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String str=sc.next();
    int N=str.length();
    int[] num=new int[N];
    int[][] pay=new int[N+1][2];
    int ans=0;
    
    for(int i=0;i<N;i++){
      num[i]=Character.getNumericValue(str.charAt(i));
    }
    
    pay[0][0]=0;
    pay[0][1]=1;
    
    for(int i=1;i<N+1;i++){
      pay[i][0]=min(pay[i-1][0]+num[i-1],pay[i-1][1]+10-num[i-1]);
      pay[i][1]=min(pay[i-1][0]+num[i-1]+1,pay[i-1][1]+10-num[i-1]-1);
    }
    
   System.out.print(pay[N][0]);
  }
}


Measured memory_bytes: 72264
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.List
import Data.Array.ST
import Data.Array (elems)
import Data.Maybe (fromJust)
import Debug.Trace

data Sign = Plus | Minus


calc :: Sign -> [Int] -> Int -> Int
calc _ [] _ = 0
calc Plus (x:xs) total
    | total + x > 0 = calc Minus xs (total + x)
    | otherwise = steps + (calc Minus xs 1)
    where
        steps = 1 - (total + x)
calc Minus (x:xs) total
    | total + x < 0 = calc Plus xs (total + x)
    | otherwise = steps + (calc Plus xs (-1))
    where
        steps = 1 + (total + x)


solve :: [Int] -> Int
solve arr = minimum([a, b])
    where
        a = calc Plus arr 0
        b = calc Minus arr 0


main :: IO ()
main = do
    _ <- BS.getLine
    a <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    print $ solve a



Measured memory_bytes: 13692
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<int> g[101010];
int c[1010110], ans[1010110];
int it = 0;
void dfs(int cur, int par) {
  for (int nxt : g[cur]) {
    if (nxt == par) continue;
    dfs(nxt, cur);
  }
  ans[cur] = c[it++];
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  sort(c, c + n);
  dfs(0, -1);
  cout << 1LL * accumulate(c, c + n, 0LL) - *max_element(c, c + n) << endl;
  for (int i = 0; i < n; i++) {
    if (i > 0) cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 7296
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
    
    String s1 = s.substring(2,3);
    String s2 = s.substring(3,4);
    
    String s3 = s.substring(4,5);
    String s4 = s.substring(5,6);
    
    if(s1.equals(s2)&&s3.equals(s4)){
      System.out.println("Yes");
    }else{
      System.out.println("No");
      }
    
  }
}

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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

bool isprime(int x){
	if(x<=1)
		return false;
	for(int i=2;i*i<=x;++i){
		if(x%i==0)
			return false;
	}
	return true;
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//#ifndef ONLINE_JUDGE
	////freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//#endif
	int x;
	cin>>x;
	while(!isprime(x))
		++x;
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 256
# include<bits/stdc++.h>
using namespace std;
int main(){
  long int n;
  cin >> n;
  
  long int arr[n];
  for(int i = 0; i < n; i++)
  	cin >> arr[i];
    
  int j = 0, maxi = 0;
  while(j < n){
    int temp = 1;
    for(int i = j; i < n-1; i++){
    	if(arr[i] > arr[i+1]-1) temp += 1;
        else break;
    }
    if(temp > maxi) maxi = temp;
j += temp;

}
cout << maxi-1 <<'\n';

	return 0;
}

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

#define MAX_V 300
const int INF = 2e9+1;
int V;
long d[MAX_V][MAX_V];

void init() {
  for (int i=0; i<MAX_V; i++)
    for (int j=0; j<MAX_V; j++)
      if (i != j)
        d[i][j] = INF;
}

void warshall_floyd() {
  for (int k=0; k<V; k++)
    for (int i=0; i<V; i++)
      for (int j=0; j<V; j++)
        d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
}

int main() {
  int M, L, Q, A, B, C, s, t;
  cin >> V >> M >> L;
  init();
  for (int i=0; i<M; i++) {
    cin >> A >> B >> C;
    A--; B--;
    d[A][B] = d[B][A] = C;
  }
  warshall_floyd();
  for (int i=0; i<V; i++) {
    for (int j=0; j<V; j++) {
      if (i == j)
        continue;
      if (d[i][j] <= L)
        d[i][j] = 1;
      else
        d[i][j] = INF;
    }
  }
  warshall_floyd();
  cin >> Q;
  for (int i=0; i<Q; i++) {
    cin >> s >> t;
    s--; t--;
    if (d[s][t] == INF)
      cout << -1 << endl;
    else
      cout << d[s][t]-1 << endl;
  }
  return 0;
}

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

int main() {
  int n; cin>>n;
  vector<string> v(n);
  rep(i,n){cin>>v[i];}
  string s="abcdefghijklmnopqrstuvwxyz";
  rep(i,26){
    int x=50;
    rep(j,n){
      int c=count(v[j].begin(),v[j].end(),s.at(i));
      if(x>c){x=c;}      
    }
    rep(k,x){cout<<s.at(i);}
    //cout<<x;
  }
}

Measured memory_bytes: 3604
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ld long double
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

vll A;
vll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;
class UnionFind {
public:
    vector<ll> parent; // parent[i]:iの親の番号　(例) parent[3] = 2 : 3の親が2
    UnionFind(ll N){ //最初は全てが根であるとして初期化
        for(ll node_i = 0; node_i < N; node_i++){
            ll parent_i = node_i;
            parent.push_back(parent_i);
        }
    }
    ll getRoot(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (parent[x] == x) return x;
        return parent[x] = getRoot(parent[x]);
    }
    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = getRoot(x); //xの根をrx
        ll ry = getRoot(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        parent[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }
    bool isSameRoot(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = getRoot(x);
        ll ry = getRoot(y);
        return rx == ry;
    }
};

/*
max 448,000,000
map<string,ll> count_map;
count_map['0']=0;
for(auto x : count_map) {
    string key = x.first;
    ll value = x.second;
}
*/
map<ll,ll> count_map;
int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N;
    cin >> M;
    rep(mi,M){
        cin >> ltmp;
        ltmp--;
        A.push_back(ltmp);
        cin >> ltmp;
        ltmp--;
        B.push_back(ltmp);
    }

    UnionFind uf(N);
    rep(mi,M){
        uf.unite(A[mi],B[mi]);
    }

    ll cnt = 0;
    rep(ni,N){
        ll rm = uf.getRoot(ni);
        if(count_map[rm]==0) cnt++;
        count_map[rm]++;
    }
    cout << cnt-1 << endl;


    

}

Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, x, t;
	cin >> n >> x >> t;
	x = (n + x - 1) / x;
	cout << x*t << endl;
	return 0;
}



Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

vll dx = {1, 0, -1, 0};
vll dy = {0, 1, 0, -1};

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

    ll x, y;
    cin >> x >> y;

    // 0 - 0 : B, 1 - 1 : B, 2 - 1 : B, 2 - 2 : B, 3 - 2 : B
    // 2 - 0 : A, 3 - 0 : A, 3 - 1 : A, 4 - 0 : A, 4 - 1 : A, 4 - 2 : A,  5 - 0 : A, 6 - 0 : A
    ll z = abs(x - y);
    if (z <= 1) cout << "Brown" << endl;
    else cout << "Alice" << endl;
    return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

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

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    string s;
    cin >> s;
    if (s=="Sunny") cout << "Cloudy" << endl;
    if (s=="Cloudy") cout << "Rainy" << endl;
    if (s=="Rainy") cout << "Sunny" << endl;
    return 0;
}



Measured memory_bytes: 256