akhauriyash/Code-Regression huggingface dataset:
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;
use std::cmp::min;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<usize>();
    let k = scan.read::<i64>();
    let s = scan.chars();
    let cmp = compress(&s);
    let mut ret = 0;
    for (p, _) in cmp {
        ret += p-1;
    }
    println!("{}", min(n as i64 - 1, 2*k + ret));
}

#[allow(dead_code)]
fn compress<T: Clone + PartialEq>(slice: &[T]) -> Vec<(i64, T)> {
    if slice.len() == 0 {
        return vec![];
    }
    let mut acc = vec![];
    let mut current = slice[0].clone();
    let mut cnt = 1i64;
    for i in 1..slice.len() {
        if current != slice[i] {
            acc.push((cnt, current));
            cnt = 0;
        }
        current = slice[i].clone();
        cnt += 1;
    }
    acc.push((cnt, current));
    acc
}

// region template
#[allow(dead_code)]
fn iu(i: isize) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> isize { i as isize }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

#[allow(dead_code)]
fn alt<S, T>(v: Vec<S>) -> T where T: FromIterator<S> {
    v.into_iter().collect::<T>()
}

#[allow(dead_code)]
fn dup<S, T>(v: &[S]) -> T where T: FromIterator<S>, S: Clone {
    v.iter().cloned().collect::<T>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

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

#include <atcoder/all>
typedef long long lint;
using namespace std;
using namespace atcoder;

int main() {
    int n, q;
    cin >> n >> q;
    fenwick_tree<lint> fw(n);
    for (int i = 0; i < n; i++) {
        lint a;
        cin >> a;
        fw.add(i, a);
    }
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if (t == 0) {
            int p, x;
            cin >> p >> x;
            fw.add(p, x);
        } else {
            int l, r;
            cin >> l >> r;
            cout << fw.sum(l, r) << endl;
        }
    }
}

Measured memory_bytes: 8220
n = int(input())
h = list(map(int, input().split()))

cost = [0]*n
cost[1] = abs(h[0] - h[1])

for j in range(2,n):
    cost[j] = min(cost[j-1] + abs(h[j] - h[j-1]), cost[j-2] + abs(h[j] - h[j-2]))

print(cost[n-1])

Measured memory_bytes: 13980
//*******Abhijit Burman***********//
//Jalpaiguri Government Engineering College//

// Taken From Striver_79
// Never open a ranklist untill and unless you are done with solving problems, wastes 3/4 minuts 
// Donot treat CP as a placement thing, love it and enjoy it, you will succeed for sure. 


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define MAXX (1000000000000000000+7)
#define mod 1000000007
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
ll dx1[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll dy1[] = {0, 1, 1, 1, 0, -1, -1, -1};

ll dx2[] = {1, 0, -1, 0};
ll dy2[] = {0, 1, 0, -1};

ll mul(ll a, ll b, ll p = mod) {return ((a % p) * (b % p)) % p;}
ll add(ll a, ll b, ll p = mod) {return (a % p + b % p) % p;}
ll power(ll x,ll y,ll p = mod) 
{ 
    ll res = 1;
    x = x % p;
    while (y > 0) 
    {
        if (y & 1) 
            res = (res*x) % p;
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n, ll p = mod)
{
    return power(n, p - 2, p);
}
ll ncrMod(ll n, ll r, ll p = mod)
{
    if (r == 0)
        return 1;
    ll fac[n + 1];
    fac[0] = 1;
    for (ll i = 1 ; i <= n; i++)
        fac[i] = fac[i - 1] * i % p;
    return (fac[n] * modInverse(fac[r], p) % p *
            modInverse(fac[n - r], p) % p) % p;
}
// a+b=xor(a,b)+2*(a&b)//

bool isPrime(ll n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}


void solve()
{
    ll n,k;
    cin>>n>>k;
    ll cnt=0;
    while(n--){
        ll x,y;
        cin>>x>>y;
        
        ll ans = (x*x)+(y*y);
        
        if(ans<=(k*k)){
            cnt++;
        }
    }
    cout<<cnt<<endl;
}


int main()
{
	fio;
// 	#ifndef ONLINE_JUDGE
//     // for getting input from input.txt
//     freopen("input.txt", "r", stdin);
//     // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
// 	#endif
 

	ll t=1;
// 	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	if (A == B && B == C) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3600
s = input()
l = list(s)

count = 0
clist = []
n = (len(l))
for i in range(n):
    if l[i] in 'ACGT':
        count += 1
        if i == n - 1:
            clist.append(count)
    else:
        clist.append(count)
        count = 0

print(max(clist))

Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
        int a,b,c,d,s1,s2;
        scanf("%d %d %d %d",&a,&b,&c,&d);
        if(a>b) s1=b;
        else s1=a;
        if(c>d) s2=d;
        else s2=c;
        printf("%d\n",s1+s2);
        return 0;
}

Measured memory_bytes: 128
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  [_,g,b] <- readInts
  let n = 10*g + b 
  putStrLn $ if m4 n 
               then "YES" 
               else "NO" 

m4 :: Int -> Bool
m4 n = n `rem` 4 == 0

Measured memory_bytes: 380
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define ARRAY_SIZE 2000001

int parent(int pos) {
  if( pos != 1 ) {
    return (int)pos/2;
  }else {
    return -1;
  }
}


int left(int pos, int len) {
  if( pos*2 <= len ) {
    return pos*2;
  }else {
    return -1;
  }
}


int right(int pos, int len) {
  if( pos*2+1 <= len ) {
    return pos*2+1;
  }else {
    return -1;
  }
}


void swap(int* a, int* b) {
  int tmp;

  tmp = *a;
  *a = *b;
  *b = tmp;

}


void maxHeapify(int* heap, int pos, int heapSize) {

  int l, r;
  int largest;

  l = left(pos, heapSize);
  r = right(pos, heapSize);

  //左、右、自身のうち最大のノード
  if( l != -1 && heap[l] > heap[pos] ) {
    largest = l;
  }
  else {
    largest = pos;
  }
  if( r != -1 && heap[r] > heap[largest] ) {
    largest = r;
  }


  if( largest != pos ) {
    swap(&heap[pos], &heap[largest]);
    maxHeapify(heap, largest, heapSize);
  }

}


void changeUp(int* heap, int pos) {
  /*
   * 上のノードより大きければ入れ換えていく
   */ 

  if(parent(pos) == -1) {
    //親がいない
    return;
  }
 
  if( heap[pos] > heap[parent(pos)] ) {
    swap(&heap[pos], &heap[parent(pos)]);
    changeUp(heap, parent(pos));
  }

}


void insert(int* heap, int heapSize, int insertKey) {
  
  heap[heapSize] = insertKey;

  changeUp(heap, heapSize);

}

void extractMax(int *heap, int heapSize) {
  
  printf("%d\n", heap[1]);

  heap[1] = heap[heapSize];

  maxHeapify(heap, 1, heapSize-1);

}



int main() {

  int* heap;
  int heapSize;
  int insertKey;
  char* input[10];

  int i;

  heapSize = 0;
  heap = (int*)malloc( sizeof(int) * (ARRAY_SIZE) );

  while(1) {
    scanf("%s", input);
  
    if( strcmp( input, "insert" ) == 0 ) {
      scanf("%d", &insertKey);
      heapSize += 1;
      insert(heap, heapSize, insertKey);
    }
    else if( strcmp( input, "extract" ) == 0 ) {
      extractMax(heap, heapSize);
      heapSize -= 1;
    }
    else if( strcmp( input, "end" ) == 0 ) {
      break;
    }
    
  }
  



  return 0;

}

Measured memory_bytes: 5044
// B.

#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());
	bool ans = a[0] < accumulate(a.begin() + 1, a.end(), 0);
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
// 深さ優先探索
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

#include<stack>

using namespace std;

#define MAX_N 100
// 値の定義
const int EXIST = 1;
const int NO_EXIST = 0;

const int WHITE = 0;// 未訪問
const int GRAY = 1; // 訪問中
const int BLACK = 2;// 訪問完了

const int INV = -1;

// グラフ情報を保持する配列
int ary_graph[MAX_N + 1][MAX_N + 1];

// 各頂点の訪問状態を保持する配列
int color[MAX_N + 1];

// 発見時刻と完了時刻を保持する構造体
typedef struct
{
    int start_time;
    int end_time;
}SearchTime;

SearchTime st_SearchTime[MAX_N + 1];
int search_T = 0;

int vertex_num = 0;
int nt[MAX_N + 1];

void depthFirstSearch(int now_vertex);

int main(void)
{
    int n, u, num, v_num;

    for(int i = 0; i < MAX_N + 1; i++)
    {
        color[i] = WHITE;
        nt[i] = 0;

        for(int j = 0; j < MAX_N + 1; j++)
        {
            // 配列の初期化
            ary_graph[i][j] = NO_EXIST;
        }
    }

    cin >> n;

    for(int i = 0; i < n; i++)
    {
        cin >> u >> num;

        // 0オリジンにする
        u--;

        for(int j = 0; j < num; j++)
        {
            // 隣接点を記憶する
            cin >> v_num;

            // 0オリジンにする
            v_num--;
            ary_graph[u][v_num] = EXIST;
        }
    }

    for(int i = 0; i < n; i++)
    {
        if( color[i] == WHITE )
        {
            // 未訪問の点を始点として, 深さ優先探索を実施
            vertex_num = n;
            depthFirstSearch(i);
        }
    }

    // 結果の表示
    for(int i = 0; i < n; i++)
    {
        printf("%d %d %d\n", i + 1, st_SearchTime[i].start_time, st_SearchTime[i].end_time);
    }

    return 0;
}

// u に隣接する v を番号順に取得
int next(int u)
{
    int ret = INV;

    for(int v = nt[u]; v < vertex_num; v++)
    {
        nt[u] = v + 1;

        if( ary_graph[u][v] == EXIST )
        {
            // 隣接点が存在する
            ret = v;
            break;
        }
    }

    return ret;
}

// 深さ優先探索を実施する関数
// now_vertex : 現在の頂点のNo.
void depthFirstSearch(int now_vertex)
{
    stack<int> S;

    // スタックにプッシュする
    S.push(now_vertex);
    // 訪問中を設定
    color[now_vertex] = GRAY;
    // 発見時刻の設定
    search_T++;
    st_SearchTime[now_vertex].start_time = search_T;

    while( !S.empty() )
    {
        int u = S.top();
        // uの隣接点を検索する
        int v = next(u);

        if( v != INV )
        {
            // 隣接点が訪問済みの場合は何もしない

            if( color[v] == WHITE )
            {
                // 訪問中を設定
                color[v] = GRAY;
                // 発見時刻の設定
                search_T++;
                st_SearchTime[v].start_time = search_T;
                // スタックにプッシュする
                S.push(v);
            }
        }
        else
        {
            // 隣接点が存在しない時は訪問完了なので, スタックから削除する
            S.pop();
            color[u] = BLACK;

            // 終了時刻の設定
            search_T++;
            st_SearchTime[u].end_time = search_T;
        }
    }

    return;
}



Measured memory_bytes: 3248
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(x) cout<<#x<<" = "<<x<<endl;
#define lowbit(x) x&(-x)
#define PA pair<int, int>
#define MK make_pair
using namespace std;
typedef long long LL;
inline int read()
{
	int l = 0, f = 1;
	char a = getchar();
	for (; a < '0' || a > '9'; a = getchar())
		if (a == '-') f = -1;
	for (; a >= '0' && a <= '9'; a = getchar())
		l = l*10+a-48;
	return l*f;
}
const int N = 1000005;
int n, k, num, ans, w[2005][2005];
int sum(int x1, int y1, int x2, int y2)
{
	return w[x2][y2]-w[x1-1][y2]-w[x2][y1-1]+w[x1-1][y1-1];
}
int calc(int x, int y)
{
	return sum(1, 1, x, y)+sum(x+1, y+1, x+k, y+k)+sum(x+k+1, 1, 2*k, y)+sum(1, y+k+1, x, 2*k)+sum(x+k+1, y+k+1, 2*k, 2*k);
}
int main(int argc, char const *argv[])
{
	n = read(), k = read();
	for (int i = 1; i <= n; ++i)
	{
		int x = read(), y = read();
		char a = getchar();
		while(a != 'W' && a != 'B') a = getchar();
		if (a == 'B') y += k;
		w[x%(2*k)+1][y%(2*k)+1]++;
	}
	for (int i = 1; i <= 2*k; ++i)
	{
		for (int j = 1; j <= 2*k; ++j)
			w[i][j] += w[i-1][j]+w[i][j-1]-w[i-1][j-1];
	} 
	for (int i = 0; i < k; ++i)
		for (int j = 0; j < k; ++j)
			ans = max(ans, max(calc(i, j), n-calc(i, j)));
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

// dist[v] に頂点 s から頂点 v への距離を入れる関数
void dijkstra(int s, Graph &G, vector<ll> &dist){
  fill(all(dist), INF);
  dist[s] = 0;

  priority_queue<P, vector<P>, greater<P>> pq;//距離が小さい順に取り出す
  pq.push(P(0,s)); // 頂点 s からスタート

  while (!pq.empty()) {
    P p = pq.top(); pq.pop();
    int v = p.second;
    if(dist[v] < p.first) continue;// 既に v に辿り着く短い経路有ならスルー (これはただの高速化)

    for(auto e : G[v]){// v から行ける頂点 nv 達を走査
      int nv = e.to;
      ll w = e.weight;
      if(dist[nv] > dist[v] + w){
        dist[nv] = dist[v] + w;
        pq.push(P(dist[nv], nv));
      }
    }
  }
}

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};



int main(){
  int n,m,s,t; cin>>n>>m>>s>>t;
  s--; t--;

  Graph Ga(n),Gb(n);
  rep(i,m) {
    int u,v,a,b; cin>>u>>v>>a>>b;
    u--; v--;
    Ga[u].pb(Edge(v,a));
    Ga[v].pb(Edge(u,a));
    Gb[u].pb(Edge(v,b));
    Gb[v].pb(Edge(u,b));
  }
  
  vl da(n),db(n);
  dijkstra(s,Ga,da);
  dijkstra(t,Gb,db);

  vl d(n);
  rrep(i,n) {
    if(i == n-1) d[i] = da[i] + db[i];
    else d[i] = min(d[i+1], da[i] + db[i]);
  }
  
  ll ans = 1e15;

  rep(i,n) {
    cout << ans - d[i] << endl;
  }
}

Measured memory_bytes: 16068
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

#xs,ys,xt,yt = map(int,readline().split())

s = input()

if ((s[0]==s[-1]) + len(s))&1:
    print("First")
else:
    print("Second")




Measured memory_bytes: 9044
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
using VI = vector<int>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

int main() {
  int n; cin >> n;
  VI a(n + 2, 0);
  REP(i, n) cin >> a[i + 1];
  VI d(n + 2, 0);
  FOR(i, 1, n + 2) {
    d[i] = abs(a[i] - a[i - 1]) + d[i - 1];
  }
  FOR(i, 1, n + 1) {
    cout <<  d[i - 1] + abs(a[i + 1] - a[i - 1]) + d[n + 1] - d[i + 1] << endl;
  }
  return 0;
}

Measured memory_bytes: 2048
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
    int N, K, Q;
    cin >> N >> K >> Q;
    int A[Q];
    REP(i,Q) cin >> A[i];

    int point[N];
    REP(i,N){
        point[i] = 0;
    }
    REP(i,Q){
        point[A[i]-1]++;
    }
    REP(i,N){
        if(K - (Q - point[i]) > 0){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

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

    ll ans = 0;
    ll na, nb, m;
    cin >> na >> nb >> m;

    vector<ll> a;
    for (int i = 0; i < na; i++) {
        int temp;
        cin >> temp;
        a.push_back (temp);
    }
    vector<ll> b;
    for (int i = 0; i < nb; i++) {
        int temp;
        cin >> temp;
        b.push_back (temp);
    }

    ll min = *min_element(ALL(a)) + *min_element(ALL(b));

    for (int i = 0; i < m; i++) {
        ll x, y, c;
        cin >> x >> y >> c;
        if (min > a[x-1] + b[y-1] - c) min = a[x-1] + b[y-1] - c;
    }

    cout << min << endl;
}

Measured memory_bytes: 2548
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;


int main() {
 int tmp,d,t,ans;
  ans=0;
  d=0;
  vector<int> vec(5);
  for(int i=0;i<5;i++){
   cin >> vec.at(i);
    if(vec.at(i)%10==0){
      continue;
    }
    else{
      tmp=10-vec.at(i)%10;
      if(tmp>d){
      
      t=i;
      d=tmp;
      }
      
    }
    
    
  }
  for(int i=0;i<5;i++){
    if(vec.at(i)%10==0){
      ans=ans+vec.at(i);
    }
    else{
    ans=ans+vec.at(i)+10-vec.at(i)%10;
    }
  }
  
  if(d==0){
    cout << ans << endl;
  }
  else{
  cout << ans-10+vec.at(t)%10 << endl;
}
}
  

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define rep(I,N) up(I,0,N-1)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<"\n";}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<"\n";}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<"\n";}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<"\n";}
inline void                                              out(ld p){printf("%.12Lf\n",p);}
template<class T>inline void outml(T p){for_each(all(p),out<decltype(p[0])>);}//ml=multi line
template<class T>inline void outol(T V){auto n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}//ol=one line
const long mod=1e9+7;
inline void solve(void){
  long N,K;
  in(N,K);
  out((K*(K-1)*(2*K-1)/6%mod-(N+1)*(N+2)*(2*N+3)/6%mod+((N+1)*(N+2)-K*(K-1))%mod*(N+1)/2+N-K+2)%mod);
}
int main(void){
  BEGIN;
  solve();
  END;
}


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

int main() {
  int a[5], k;
  for(int i=0;i<5;i++) {
    cin >> a[i];
  }
  cin >> k;
  bool ans = a[4] - a[0] <= k;
  cout << (ans ? "Yay!" : ":(") << endl;
}


Measured memory_bytes: 256
N,A,B,C = map(int,input().split())
l = [int(input()) for _ in range(N)]
ans = float('inf')
def dfs(d=0,a=0,b=0,c=0,mp=0):
    if d == N:
        mp = mp + abs(A-a) + abs(B-b) + abs(C-c) - 30
        global ans
        if a*b*c > 0 and mp < ans:
            ans = mp
        return
    dfs(d+1,a,b,c,mp)
    dfs(d+1,a+l[d],b,c,mp+10)
    dfs(d+1,a,b+l[d],c,mp+10)
    dfs(d+1,a,b,c+l[d],mp+10)

dfs()
print(ans)

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float('inf')
MOD = 10**9+7
dy = [0,1,0,-1]
dx = [1,0,-1,0]
ddy = [0,1,1,1,0,-1,-1,-1]
ddx = [1,1,0,-1,-1,-1,0,1]

a,b = map(int,input().split())
if a == b:
    print(a*2)
else:
    print(max(a,b)*2-1)

Measured memory_bytes: 3064
## coding: UTF-8
from collections import deque

n, m = map(int,input().split())
g = [[] for _ in range(n+1)] # 隣接リスト
for _ in range(m):
    a, b = [int(x) for x in input().split()]
    g[a].append(b)
    g[b].append(a)
#print(g)


def bfs(u):
    queue = deque([u])
    d = [None] * (n+1) # uからの距離の初期化
    r = [None] * (n+1) #return list
    d[u] = 0 # 自分との距離は0
    while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] is None:
                d[i] = d[v] + 1
                r[i] = v
                queue.append(i)
    return d, r

# 0からの各頂点の距離
d, r = bfs(1)
#print(d)
#print(r)
print('Yes')
for i in range(2, n+1):
    print(r[i])

Measured memory_bytes: 96484
n,q=(int(i) for i in input().split())
s=input()
l=[0 for i in range(q)]
r=[0 for i in range(q)]
for i in range(q):
  l[i],r[i]= input().split()
#print(n,q,s,l,r)
t=[0 for i in s]
#print(t)
for i in range(len(t)-1):
  if s[i]=='A' and s[i+1]=='C':
    t[i+1]=t[i]+1
  else:
    t[i+1]=t[i]
#print(t)
for i in range(q):
  print(t[int(r[i])-1]-t[int(l[i])-1])
  

Measured memory_bytes: 19008
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define vi vector<int>
#define pi pair<int, int>
#define pb push_back
#define ppb pop_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int N = 1e5 + 667;
int a[N];
//bool visited[100001];
//vi v[100001];
//vi ans[100001];
//int d[10001];
//queue<int> q;
//int c = 0;

//void dfs(int x){
    //if(visited[x]){
        //c++;
      //  return;
    //}
   // visited[x] = true;
   // for(auto u : v[x]){
    //    dfs(u);
  //  }
//
//}

//void bfs(int x){
   // visited[x] = true;
    //d[x] = 0;
  //  q.push(x);
//    while(!q.empty()){
    //    int s = q.front(); q.pop();
  //      for(auto u : v[s]){
//            //if(visited[u]) continue;
          //  visited[s] = true;
        //    d[u] = d[s] + 1;
      //      q.push(u);
    //    }
  //  }
//}

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

    int h, n, ans = 0;
    cin >> h >> n;
    for(int i = 0;i<n;i++){
        cin >> a[i];
        ans+=a[i];
    }
    if(ans >= h){
        cout << "Yes";
        return 0;
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 640
import sys
import time
import math
st = time.perf_counter()
def inpl():
    return list(map(int, input().split()))
# ------------------------------


N = int(input())
S = [input() for _ in range(N)]
d = dict()
mx = 0
for s in S:
	if s not in d:
		d[s] = 0
	d[s] += 1
	mx = max(d[s], mx)
ans = []
for k,v in d.items():
	if v == mx:
		ans.append(k)
ans.sort()
for a in ans:
	print(a)

# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


Measured memory_bytes: 38232
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXM = 1e5 + 5;
struct tick{int x,y,c;}t[MAXM];
int a[MAXM],b[MAXM];
inline bool cmp(tick A,tick B)
{
	if(A.x == B.x)
	{
		if(A.y == B.y) return A.c > B.c;
		else return A.y < B.y;
	}
	else return A.x < B.x;
}
int main()
{
	int A,B,M,MINA,MINB;
	scanf("%d%d%d",&A,&B,&M);
	scanf("%d",&a[1]),MINA = a[1];
	for(int i = 2;i <= A;i ++)
		scanf("%d",&a[i]),
		MINA = min(MINA,a[i]);
	scanf("%d",&b[1]),MINB = b[1];
	for(int i = 2;i <= B;i ++)
		scanf("%d",&b[i]),
		MINB = min(MINB,b[i]);
	for(int i = 0;i < M;i ++)
		scanf("%d%d%d",&t[i].x,&t[i].y,&t[i].c);
	sort(t,t + M,cmp);int tot = 0,MIN = MINA + MINB;
	for(int i = 0;i < M;i ++)
	{
		tot = max(tot,t[i].c);
		if(t[i].x != t[i + 1].x || t[i].y != t[i + 1].y) 
		{
			MIN = min(MIN,a[t[i].x] + b[t[i].y] - tot);
			tot = 0;
		}
	}
	printf("%d",MIN);
	return 0;
}


Measured memory_bytes: 2176
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, ans = 0, w, l;
vl gragh[200010];
vl visited1(200010, 0), active1(200010, 0);
ll isloop = 0;
vl TOPOSO;
void dfs1(ll x) {
	visited1[x] = 1;
	active1[x] = 1;
	for (ll i : gragh[x]) {
		if (visited1[i] == 0) {
			dfs1(i);
		}
		else {
			if (active1[i] == 1)isloop = 1;
		}
	}
	active1[x] = 0;
	TOPOSO.push_back(x);
}
void input() {
	cin >> n >> m;
	rep(i, m) {
		cin >> a >> b;
		gragh[a].push_back(b);
	}
}
void solve() {
	rep(i, n) {
		if (visited1[i] == 0)dfs1(i);
	}

	cout << isloop << endl;
}

int main() {
	input();
	solve();
}


Measured memory_bytes: 10588
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn = 200005;
int n,m;
struct Edge
{
    int from,to,dist;
    Edge(int f,int t,int d):from(f),to(t),dist(d){}
};

struct HeapNode
{
    int d,u;
    HeapNode(int d,int u):d(d),u(u){}
    bool operator< (const HeapNode &rhs)const
    {
        return d > rhs.d;
    }
};

struct Dijkstra
{
    int n,m;
    vector<Edge> edges;
    vector<int> G[maxn];
    bool done[maxn];
    int d[maxn];

    void init(int n)
    {
        this->n=n;
        for(int i=0;i<n;i++) G[i].clear();
        edges.clear();
    }

    void AddEdge(int from,int to,int dist)
    {
        edges.push_back(Edge(from,to,dist));
        m = edges.size();
        G[from].push_back(m-1);
    }

    int dijkstra(int s,int e)
    {
        priority_queue<HeapNode> Q;
        for(int i=0;i<n;i++) d[i]=INF;
        d[s]=0;
        Q.push(HeapNode(d[s],s));
        memset(done,0,sizeof(done));

        while(!Q.empty())
        {
            HeapNode x= Q.top(); Q.pop();
            int u =x.u;
            if(done[u]) continue;
            done[u]=true;

            for(int i=0;i<G[u].size();i++)
            {
                Edge &e=edges[G[u][i]];
                if(d[e.to] > d[u]+e.dist)
                {
                    d[e.to] = d[u]+e.dist;
                    Q.push(HeapNode(d[e.to],e.to));
                }
            }
        }
        if(d[e] == INF)
            return -1;
        return d[e];
    }
}DJ;

int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        DJ.init(n);
        for(int i=0;i<m;i++)
        {
            int u,v;
            scanf("%d%d",&u,&v);
            u--;
            v--;
            DJ.AddEdge(u,v,1);
            DJ.AddEdge(v,u,1);
        }

      if(DJ.dijkstra(0,n-1)==2 )
        printf("POSSIBLE\n");
      else
        printf("IMPOSSIBLE\n");
    }
    return 0;
}


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

int main() {
  
  int a, b;
  cin >> a >> b;
  
  int height = 0;
  for(int i = 0; i < b-a; i++) {
    height += i+1;
  }
  
  cout << height - b << endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>

int dp[1000005];

int main(void)
{
	int k, i;

	scanf("%d", &k);

	for (i = 1; i <= k; i++)
	{
		dp[i] = (dp[i - 1] * 10 + 7) % k;

		if (dp[i] == 0)
		{
			printf("%d", i);
			return 0;
		}
	}

	puts("-1");
	return 0;
}

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

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

 int main() {
   int N, M;
   cin >> N >> M;
   vector<int> p(M);
   vector<string> S(M);

   rep(i, M) cin >> p.at(i) >> S.at(i);

   vector<bool> solved(N + 1, false);
   vector<int> WA(N + 1, 0);

   int count_AC = 0, count_WA = 0;
   rep(i, M) {
     if (solved.at(p.at(i))) continue;
     else if (S.at(i) == "WA") WA.at(p.at(i))++;
     else {
       count_WA += WA.at(p.at(i));
       count_AC++;
       solved.at(p.at(i)) = true;
     }
   }
   cout << count_AC << " " << count_WA << endl;
 }


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

int main(void){
   int N;
   cin>>N;
   vector<long long> A(N),B(N);
   long long mini=1000000007;
   long long maxi=0;
   for(int i=0;i<N;i++){
      cin>>A[i]>>B[i];
   }
   for(int i=0;i<N;i++){
      mini=min(mini,A[i]);
      maxi=max(maxi,A[i]);
   }
   long long ans=0;
   ans+=(mini-1);
   ans+=(maxi-mini+1);
   for(int i=0;i<N;i++){
      if(A[i]==maxi) ans+=B[i];
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 4824
N= int(input())
A = [0]+[int(x) for x in input().split()]+[0]
T = 0
for i in range(N+1):
  T += abs(A[i]-A[i+1])
for j in range(1,N+1):
  print(T+abs(A[j+1]-A[j-1])-abs(A[j+1]-A[j])-abs(A[j]-A[j-1]))

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


string filtered(string s) {
    string res = "";
    rep(i, sz(s)) {
        if (s[i] >= 'A' && s[i] <= 'Z') {
            res = res + s[i];
        }
    }
    return res;
}

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

    if (s[0] != 'A' || filtered(s) != "AC") {
        puts("WA");
        return 0;
    }
    if (s[1] == 'C' || s[sz(s) - 1] == 'C') {
        puts("WA");
        return 0;
    }
    puts("AC");

    return 0;
}

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

int main (){
    ll N, K;
    cin>>N>>K;
  	ll Lar=max(N, K);
    vector<long double> B(Lar+1, 0);
  	long double T;
  	long double NN= N;
  	T = 1 / (NN);
  	//cout<<setprecision(10)<<T<<endl;
    for(ll i=1; i<=N; i++){
        B.at(i)=1;
    }
    for(int i=1; i<K; i++){
        if(i*2<=K){
            B.at(i*2) += B.at(i) * 0.5;
        }
        else{
            B.at(K) += B.at(i) * 0.5;
        }

    }
  	for(int i=K+1; i<=Lar; i++){
      	B.at(K) += B.at(i);
    }
  	B.at(K) *= T;
    cout<<setprecision(12)<<B.at(K)<<endl;
    
}



Measured memory_bytes: 1792
// codeforces.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <bits/stdc++.h>
using namespace std;
using ll =long long int;
constexpr ll mod = 1e12;
int main()
{
	ll x; cin >> x;
	ll ans = 0;
	for (ll i = 0; i <=mod; ++i) {
		if (x) {
			ans += pow(2, i);
			x /= 2;
		}
		else break;
	}
	cout << ans;
	return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


Measured memory_bytes: 512
public class Main {
	
	public void run(java.io.InputStream in, java.io.PrintStream out) {
		final java.util.Scanner sc = new java.util.Scanner(in);
		final int[] r = new int[sc.nextInt()];
		int max, min;
		
		for (int i = 0; i < r.length; ++i) {
			r[i] = sc.nextInt();
		}
		
		max = Integer.MIN_VALUE; min = r[0];
		for (int i = 1; i < r.length; ++i) {
			max = Math.max(max, r[i] - min);
			min = Math.min(min, r[i]);
		}
		out.println(max);
		
		sc.close();
	}

	public static void main(String[] args) {
		(new Main()).run(System.in, System.out);
	}

}

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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = 0;
    rep(i,n){
        if(i%2 == 1) continue;
        if(a[i] % 2 == 1){
            ans++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3624
N, K = list(map(int,input().split( )))
p = list(map(int,input().split( )))

if K==1:
    print((max(p)+1)/2)
    exit()

contents_origin=sum(p[:K])
contents=sum(p[:K])
pK = p[:K]

for idx, i in enumerate(p[:-K]):
    contents=contents-p[idx]+p[idx+K]
    contents_origin=max(contents_origin,contents)
print((contents_origin+K)/2)

Measured memory_bytes: 24804
K, S=map(int, input().split())
s=S-2*K if S-2*K>0 else 0
e=S if S<K else K
ans=0
for Z in range(s, e+1):
  if S-Z>K:
    ans+=2*K+Z-S+1
  else:
    ans+=S-Z+1
print(ans)

Measured memory_bytes: 3060
from collections import deque

N = int(input())

root = [[] for i in range(N)]
for _ in range(N-1):
    a, b = (int(x) for x in input().split())
    root[b-1].append(a-1)
    root[a-1].append(b-1)

c = list(map(int,input().split()))
c.sort(reverse=True)

stack=deque([0])
check = [-1]*N
check[0] = 0

while len(stack)>0:
    v = stack.popleft()
    for i in root[v]:
        if check[i] == -1:
            check[i]=check[v]+1
            stack.append(i)

keyCheck = [(i,check[i]) for i in range(N)]
keyCheck.sort(key=lambda t:t[1])
#print(keyCheck)
ans = [-1]*N
for i in range(N):
    ans[keyCheck[i][0]] = c[i]

print(sum(c[1:]))
print(*ans)

Measured memory_bytes: 78528
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  char a;
  cin  >>a;
  if(a>='a'&&a<='z'){
    cout <<'a'<<endl;
  }else{
    cout <<'A'<<endl;
  }
}

Measured memory_bytes: 3620
from string import printable
def func1(x, b):
    assert(x >= 0)
    assert(1< b < 37)
    r = ''
    while x > 0:
        r = printable[x % b] + r
        x //= b
    return r
def func2(s, b):
    assert(1 < b < 37)
    return int(s, b)
def convert(s, a, b):
    return func1(func2(s, a), b)
n, k= map(int, input().split())
x=convert(str(n), 10, k)
print(len(x))

Measured memory_bytes: 9804
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int to_minite(int w,int t) {
    int h=t/100;
    int m=t%100;

    return (w*1440+h*60+m);
}

int N;
int solve() {
    map<string,int> animes;
    vector<pair<int,string>> animes2;
    map<int,string> range;
    bool ok=true;
    rep(i,N) {
        string name;
        int w,t;
        cin>>name>>w>>t;
        int m=to_minite(w,t);
        //cout<<m<<endl;
        animes[name]=m;
        animes2.pb(mp(m,name));
    }
    int m; cin>>m;
    set<string> ans;
    rep(i,m) {
        string s; cin>>s;
        int m=animes[s];
        rep(i,30) {
            if(range.count(i+m)) ok=false;;
            range[i+m]=s;
        }
        ans.insert(s);
    }
    sort(all(animes2));
    for(const auto &anime : animes2) {
        string s=anime.second;
        int m=anime.first;
        bool f=true;
        rep(i,30) f&=!range.count(m+i);
        if(f) {
            ans.insert(s);
            rep(i,30) {
                range[i+m]=s;
            }
        }
    }

    if(!ok) return -1;
    return ans.size();
}
int main() {
    while(cin>>N) {
        if(!N) break;
        cout<<solve()<<endl;
    }
    return 0;
}

Measured memory_bytes: 1704
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
typedef long long ll;


int main(void){
  int n,i;
  string s;
  map<string,int> m;
  map<string,int>::iterator ite;
  
  cin >> n;
  for (i=0;i<n;i++){
    cin >> s;
    sort(s.begin(),s.end());
    m[s]++;
  }
  
  ll ans=0,t;
  for (ite=m.begin();ite!=m.end();ite++){
    t=ite->second;
    ans+=t*(t-1)/2;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
int main(){IOS;
	float d,t,s;
	cin>>d>>t>>s;
	float tt=(float)d/s;
	if(t>=tt)
		cout<<"Yes"<<endl;
		else cout<<"No"<<endl;}

Measured memory_bytes: 3736
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

using namespace std;

#ifdef LOCAL
#include<prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "{ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "}";

    return os;
}

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

ostream& operator << (ostream& os, const mint a) {
    os << a.x;

    return os;
}


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string L;
    cin >> L;

    int M = L.size();
    mint c0 = 0;
    mint c1 = 1;

    REP(i, M) {

        c0 *= 3;

        if (L[i] - '0') {
            c0 += c1;
            c1 *= 2;
        }
    }

    cout << c0 + c1 << endl;

    
}


Measured memory_bytes: 512
s = input()[::-1]
 
counts = [0] * 2019
counts[0] = 1
 
num = 0
d = 1
 
for char in s:
	num += int(char) * d
	num %= 2019
	d *= 10
	d%= 2019
	counts[num] += 1
 
ans = 0
for cnt in counts:
	ans += cnt * (cnt - 1) // 2
 
print(ans)

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

#define int long long

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

struct person {
    int A, B, C;
};

int X, Y, Z;
person p[100000];
int ans_XY[100000] = {}, ans_XZ[100000] = {};

signed main() {
    cin >> X >> Y >> Z;
    for (int i = 0; i < X + Y + Z; i++) {
        cin >> p[i].A >> p[i].B >> p[i].C;
    }
    sort(p, p + X + Y + Z, [](person l, person r) {
        return l.B - l.C > r.B - r.C;
    });
    auto c_XY = [](int l, int r) {
            return p[l].B - p[l].A > p[r].B - p[r].A;
        };
    auto c_XZ = [](int l, int r) {
            return p[l].C - p[l].A > p[r].C - p[r].A;
        };
    priority_queue<int, vector<int>, decltype(c_XY)> pq_XY(c_XY);
    priority_queue<int, vector<int>, decltype(c_XZ)> pq_XZ(c_XZ);
    for (int i = 0; i < Y; i++) {
        pq_XY.push(i);
        ans_XY[Y - 1] += p[i].B;
    }
    for (int i = X + Y + Z - 1; i >= X + Y; i--) {
        pq_XZ.push(i);
        ans_XZ[X + Y] += p[i].C;
    }
    for (int i = Y; i < X + Y; i++) {
        pq_XY.push(i);
        ans_XY[i] = ans_XY[i - 1] + p[i].B - p[pq_XY.top()].B + p[pq_XY.top()].A;
        pq_XY.pop();
    }
    for (int i = X + Y - 1; i >= Y; i--) {
        pq_XZ.push(i);
        ans_XZ[i] = ans_XZ[i + 1] + p[i].C - p[pq_XZ.top()].C + p[pq_XZ.top()].A;
        pq_XZ.pop();
    }
    int ans = 0;
    for (int i = Y - 1; i < X + Y; i++) {
        ans = max(ans, ans_XY[i] + ans_XZ[i + 1]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4224
n,x,y = map(int, input().split())
cnt = [0]*n
for i in range(1,n):
    for k in range(i+1, n+1):
        if abs(i-x) + abs(k-y) < k-i:
            cnt[abs(i-x)+ abs(k-y)+1] += 1
        else:
            cnt[k-i] += 1
for l in range(1,n):
    print(cnt[l])


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll h, w;
    cin >> h >> w;
    if(h==1 || w==1) cout << 1 << endl;
    else cout << (h*w + 1) / 2 << endl;
}


Measured memory_bytes: 256