akhauriyash/Code-Regression huggingface dataset:
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = (long) 1e9 + 7;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        int n = sc.nextInt();
        int[] xs = new int[n], ys = new int[n];
        for (int i = 0; i < n; i++) {
            xs[i] = sc.nextInt();
            ys[i] = sc.nextInt();
        }

        Permutation per = new Permutation(n);

        int cnt = 0;
        double len = 0;
        for (int[] cur: per) {
            for (int i = 0; i < n - 1; i++) {
                len += dist(xs[cur[i]], ys[cur[i]], xs[cur[i + 1]], ys[cur[i + 1]]);
            }
            cnt++;
        }

        out.println(len / cnt);
        out.flush();
    }

    double dist(int x1, int y1, int x2, int y2) {
        double dx = x1 - x2;
        double dy = y1 - y2;
        return Math.sqrt(dx * dx + dy * dy);
    }

    public class Permutation implements Iterator<int[]>, Iterable<int[]> {
        private final int size;

        public Permutation(int size) {
            if (size <= 0) throw new IllegalArgumentException();
            this.size = size;
            source = new int[size];
            for (int i = 0; i < size; i++) {
                source[i] = i;
            }
        }

        public Permutation(int size, int[] source) {
            this(size);
            this.source = source;
        }

        int[] source;
        boolean isFirst = true;

        public boolean hasNext() {
            if (isFirst) {
                isFirst = false;
                return true;
            }

            int n = source.length;
            for (int i = n - 1; i > 0; i--) {
                if (source[i - 1] < source[i]) {
                    int j = n;
                    while (source[i - 1] >= source[--j]);
                    swap(source, i - 1, j);
                    reverse(source, i, n);
                    return true;
                }
            }
            reverse(source, 0, n);
            return false;
        }

        public int[] next() {
            return source;
        }

        private void swap(int[] is, int i, int j) {
            int t = is[i];
            is[i] = is[j];
            is[j] = t;
        }

        private void reverse(int[] is, int s, int t) {
            while (s < --t) swap(is, s++, t);
        }

        @Override
        public Iterator<int[]> iterator() {
            return this;
        }
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    vec a(3);
    rep(i, 3) cin >> a[i];
    sort(a.rbegin(), a.rend());
    cout << a[0]*10 + a[1] + a[2] << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7752
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict

sys.setrecursionlimit(10**7)
N = int(input())
a = list(map(int, input().split()))

cnt = 1
for ai in a:
    if ai == cnt:
        cnt += 1

if cnt == 1:
    print(-1)
else:
    print(N - (cnt - 1))


Measured memory_bytes: 26780
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scanner = new Scanner(System.in);
        int k = scanner.nextInt();
        int v = 7;
        for (int i = 1; i <= k; i++) {
            v %= k;
            if (v == 0) {
                System.out.println(i);
                return;
            }
            v *= 10;
            v += 7;
        }
        System.out.println(-1);
    }
}

Measured memory_bytes: 35728
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    string s, t;
    cin >> s >> t;

    int res = inf;
    int n = s.size();
    int m = t.size();

    for(int i = 0; i < n-m+1; i++) {
        string tmp = s.substr(i, m);
        int cnt = 0;
        for(int j = 0; j < m; j++) {
            if (tmp[j] != t[j]) cnt++;
        }
        cerr << tmp << endl;
        res = min(res, cnt);
    }

    cout << res << endl;
    



    return 0;
}

Measured memory_bytes: 3632
K = int(input())
s = '0'
cnt = 0
while cnt<K:
  cnt += 1
  ns = ''
  j = -1
  for i in range(len(s)-1,0,-1):
    if int(s[i])+1<=int(s[i-1])+1 and int(s[i])+1<10:
      j = i
      break
  else:
    if s[0]<'9':
      j = 0
  if j!=-1:
    m = int(s[j])
    for i in range(len(s)):
      if i==j:
        x = str(int(s[i])+1)
      elif i<j:
        x = s[i]
      elif i==j+1:
        x = str(m)
      else:
        x = str(max(m-1,0))
        m = max(m-1,0)
      ns += x
  else:
    ns = '1'+'0'*len(s)
  s = ns
#  print(s,)
print(s)

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

int main() {
	int N;
	cin >> N;
	vector<int> B(N - 1);
	rep(i, N - 1) {
		cin >> B.at(i);
	}
	int ans = B.at(0) + B.at(N - 2);
	if (N >= 3) {
		rep(i, N - 2) {
			ans += min(B.at(i), B.at(i + 1));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
local n = io.read("*n")
local d = {}
for i = 1, n do
  local tmp = io.read("*n")
  if d[tmp] == nil then d[tmp] = 1 else d[tmp] = d[tmp] + 1 end
end
local f = true
local m = io.read("*n")
for i = 1, m do
  local t = io.read("*n")
  if d[t] == nil then f = false break
  else
    d[t] = d[t] - 1
    if d[t] == 0 then d[t] = nil end
  end
end
print(f and "YES" or "NO")


Measured memory_bytes: 12648
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
//find_by_order(k) - k is the kth element of the set
//order_of_key(k) - Number of elements striclty samller than k
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<min(a+b,min(a+c,b+c));
}

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

using namespace std;

int main(){
    long long k;
    cin >> k;
    cout << 50 << endl;

    for(int i=0; i<50; i++){
        if(i != 0) cout << " ";
        cout << 49-i+(k+49-i) / 50;
    }
    cout << endl;

    return  0;
}

Measured memory_bytes: 256
s=list(input())
s.append("D")
S=[]
i=0
while i<len(s):
  if s[i]=="A":
    S.append(1)
    i=i+1
  elif s[i]=="B":
    if s[i+1]=="C":
      S.append(2)
      i=i+2
    else:
      S.append(3)
      i=i+1
  else:
    S.append(3)
    i=i+1
ans=0
a=0
b=0
for i in range(len(S)):
  if S[i]==1:
    a=a+1
  elif S[i]==2:
    b=b+1
    ans=ans+a
  else:
    a=0
    b=0
print(ans)

Measured memory_bytes: 12160
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>

using namespace std;

struct edge{
	int f,t;
	double c;
};

bool comp(const edge &e1,const edge &e2){
	return e1.c>e2.c;
}

typedef pair<double,int> P;
int n,m;
bool used[10001];
int par[10001];
int rank[10001];
int x[10001],y[10001];
vector<edge> all;

void init(int v){
	for(int i=0;i<=v;i++)par[i]=i,rank[i]=0;
}

int find(int v){
	if(par[v]==v)return v;
	else return par[v]=find(par[v]);
}

void unite(int v,int w){
	v=find(v);
	w=find(w);
	if(v==w)return;
	if(rank[v]<rank[w])par[v]=w;
	else{
		par[w]=v;
		if(rank[v]==rank[w])rank[v]++;
	}
}

bool same(int v,int w){
	return find(v)==find(w);
}

double kruskal(){
	double res=0.0;
	init(n);
	sort(all.begin(),all.end(),comp);
	for(int i=0;i<all.size();i++){
		edge e=all[i];
		if(!same(e.f,e.t)){
			unite(e.f,e.t);
			//printf("%d %d %d %d\n",e.f,e.t,par[e.f],par[e.t]);
		}else res+=e.c;
	}
	return res;
}

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d%d",&x[i],&y[i]);
	for(int i=0;i<m;i++){
		int f,t;
		edge e;
		scanf("%d%d",&f,&t);
		double nx=(double)(abs(x[f]-x[t]));
		double ny=(double)(abs(y[f]-y[t]));
		e.c=(double)sqrt(pow(nx,2)+pow(ny,2));
		e.f=f;
		e.t=t;
		all.push_back(e);
	}
	printf("%.7f\n",kruskal());
	return 0;
}

Measured memory_bytes: 1880
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            if(n == 0){
                break;
            }
            int[] s = new int[n];
            int sum = 0;
            for(int i = 0; i < n; i++){
                s[i] = sc.nextInt();
                sum += s[i];
            }
            double m = (double)sum / n;
            double a = 0;
            for(int i = 0; i < n; i++){
                a += (s[i] - m) * (s[i] - m);
            }
            a /= n;
            a = Math.sqrt(a);
            System.out.println(a);
        }
    }
}


Measured memory_bytes: 31412
fun main(args: Array<String>) {
    val n = readInt()
    val s = readString()

    if (n % 2 != 0) {
        println("No")
        return
    }
    for (i in 0 until n / 2) {
        if (s[i] != s[i + n / 2]) {
            println("No")
            return
        }
    }
    println("Yes")
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 34408
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    rep(i, S.length())
    {
        S[i] += N;
        if (S[i] > 'Z')
        {
            S[i] = S[i] - ('Z' + 1) + 'A';
        }
    }
    cout << S << endl;
 //   system("pause");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

int main() {
    int N; cin>>N;
    vector<int> x(N);
    for (int i = 0; i < N; ++i) {
        cin>>x[i];
    }
    int mini=1e9;
    for (int i = 1; i <= 100; ++i) {
        int val=0;
        for (int j = 0; j < N; ++j) {
            val+=pow(x[j]-i,2);
        }
        chmin(mini,val);
    }
    cout<<mini<<endl;
    return 0;
}


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

const int inf = 1e9;
const int N = 100;

int grid[N][N], res[N][N], vis[N][N];
int n, m;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	cin >> n >> m;

	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		for (int j = 0; j < m; ++j) {
			grid[i][j] = s[j] == '#';
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			res[i][j] = inf;
		}
	}

	priority_queue<pair<int, pair<int, int>>> pq;
	pq.push( {0, {0, 0}} );
	res[0][0] = 0;

	while (pq.size()) {
		auto a = pq.top().second; pq.pop();
		int i = a.first, j = a.second;
		if (vis[i][j]) continue;
		vis[i][j] = 1;
		if (i < n && res[i][j] + (grid[i + 1][j] != grid[i][j]) < res[i + 1][j]) {
			res[i + 1][j] = res[i][j] + (grid[i + 1][j] != grid[i][j]);
			pq.push( { -res[i + 1][j], {i + 1, j} });
		}
		if (j < m && res[i][j] + (grid[i][j + 1] != grid[i][j]) < res[i][j + 1]) {
			res[i][j + 1] = res[i][j] + (grid[i][j + 1] != grid[i][j]);
			pq.push( { -res[i][j + 1], {i, j + 1} });
		}
	}
	int r = res[n - 1][m - 1];
	if (!r && grid[0][0]) cout << 1 << '\n';
	else if (!r) cout << 0 << '\n';
	else if ((grid[0][0] && !grid[n-1][m-1]) || (!grid[0][0] && grid[n-1][m-1])) cout << (r - 1) / 2 + 1 << '\n';
	else if (grid[0][0] && grid[n - 1][m - 1]) cout << r / 2 + 1 << '\n';
	else cout << r / 2 << '\n';
}


Measured memory_bytes: 384
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let s:String = read();

    for i in 0..s.len() {
        for j in i..s.len() {
            let t = format!("{}{}",&s[0..i],&s[j..]);
            //debug!(t);
            if t == "keyence" {
                println!("YES");
                return ();
            }
        }
    }

    println!("NO");

}


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

using namespace std;
#define ll long long
#define M 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);

int main() {
	int n;
	cin>>n;
	int a[n],b[n],c[n-1];
	for(int i=0;i<n;i++)    cin>>a[i];
	for(int i=0;i<n;i++)    cin>>b[i];
	for(int i=0;i<n-1;i++) cin>>c[i];
	long long ans=0;
	for(int i=0;i<n;i++){
	    ans+=b[a[i]-1];
	    if(a[i]-1>0 && a[i-1]+1==a[i])   ans+=c[a[i]-2];
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
"""
#decomment when needed
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
"""
n = ip()
b = str(n)
a = [int(i) for i in b]
if n <10:
    print(n)
    exit(0)
backup = copy.copy(a)
ans = sum(a)
for i in range(len(a)-1):
    if a[i] != 9:
        a[i]-=1
        for k in range(i+1,len(a)):
            a[k] = 9
ans = max(ans,sum(a))
#print(a,sum(a))
l = len(a)
if a[l-1] != 9:
    a[l-1] = 9
    a[l-2] -=1
#print(a,sum(a))
ans = max(ans,sum(a))
a = copy.copy(backup)
for i in range(1,len(a)-1):
    if a[i] != 9:
        a[i-1]-=1
        for k in range(i,len(a)):
            a[k] = 9
ans = max(ans,sum(a))
print(ans)



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

typedef long long ll;

ll N;
vector<ll> V, W;
ll Q;
const ll K = 9, L = 100000;
ll I;
vector<vector<ll>> Dp;
vector<pair<ll, ll>> C;

ll solve(ll i, ll l) {
  C.clear();
  C.push_back({l, 0});
  while (i > I) {
    ll n = C.size();
    for (ll k = 0; k < n; ++k) {
      ll l, v;
      tie(l, v) = C[k];
      if (l >= W[i]) C.push_back({l - W[i], v + V[i]});
    }
    i /= 2;
  }
  ll res = 0;
  for (auto lv : C) {
    ll l, v;
    tie(l, v) = lv;
    res = max(res, v + Dp[i][l]);
  }
  return res;
}
int main() {
  cin >> N;
  V.resize(N + 1);
  W.resize(N + 1);
  for (ll i = 1; i <= N; ++i) cin >> V[i] >> W[i];
  I = min(N, (1ll << K) - 1);
  Dp.resize(I + 1);
  for (auto &dp : Dp) dp.resize(L + 1);
  for (ll i = 1; i <= I; ++i) {
    for (ll l = 0; l <= L; ++l) {
      Dp[i][l] = Dp[i / 2][l];
      if (W[i] <= l) Dp[i][l] = max(Dp[i][l], Dp[i / 2][l - W[i]] + V[i]);
    }
  }
  cin >> Q;
  for (ll q = 0; q < Q; ++q) {
    ll i, l;
    cin >> i >> l;
    cout << solve(i, l) << endl;
  }
  return 0;
}


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

int main()
{
	int ar[3],temp;
	int i;
	for(i=0;i<3;i++)cin>>ar[i];
		int k;
	cin>>k;
	sort(ar,ar+3);
	while(k--){
		temp=ar[2]*2;
		ar[2]=temp;

	}
	int ans=ar[0]+ar[1]+temp;
	cout<<ans<<endl;

}

Measured memory_bytes: 256
N = int(input())
rest = []
for _ in range(N):
  s = input().split()
  s[1] = int(s[1])
  s.append(_+1)
  rest.append(s)    
rest.sort(key = lambda x:x[0])


tmp = []
A = []
for e in rest:
  if e == rest[0]:
    city = e[0]
  if e[0] == city:
    tmp.append(e)  
  else:
    tmp.sort(key = lambda x:x[1],reverse = True)
    A += tmp    
    tmp = [e]
    city = e[0]
  if e == rest[len(rest)-1]:
    tmp.sort(key = lambda x:x[1],reverse = True)
    A += tmp    
    
for i in A:
  print(i[2])
    
    
    

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
typedef long long ll;
ll money,a,b,remained,sum;
//(你会先买一个蛋糕，然后尽可能的多买甜甜圈) <--重要; 
int main()
{
	cin>>money>>a>>b;
	remained=money-a;//先买一个蛋糕; 
	sum=remained/b;
	if(remained%b==0)//剩下买甜甜圈;
	cout<<'0'<<endl;
	else cout<<remained-sum*b<<endl;
	return 0; 
}

Measured memory_bytes: 256
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Tue Dec 25 02:31:55 2018
//
package main

import "fmt"

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func main() {
	var A, B int
	fmt.Scan(&A, &B)

	fmt.Println(max(A+B, max(A-B, A*B)))
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	int nizyo = 1;
	for (int i = 0; i < m; i++) {
		nizyo *= 2;
	}
	cout << (1900 * m + 100 * (n - m))*nizyo << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint a, b;
double B;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> a >> B;
	b = B * 100 + 1e-9;
	a *= b;
	a /= 100;
	
	cout << a << endl;
	
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

const int MOD = 1e9 + 7;

vector <vector <int> > dp;

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

    int h, w;
    cin >> h >> w;

    char a[h][w];
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            cin >> a[i][j];
    
    dp.assign(h, vector <int> (w, 0));
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++) {
            if (!i and !j)
                dp[i][j] = 1;
            else {
                ll sum = 0;
                if (i > 0)
                if (a[i - 1][j] != '#') sum += dp[i - 1][j];
                if (j > 0)
                if (a[i][j - 1] != '#') sum += dp[i][j - 1];
                dp[i][j] = sum % MOD;
            }
        }
    
    cout << dp.back().back() << '\n';
    return 0;
}


Measured memory_bytes: 5248
M,D = map(int,input().split())
cnt = 0


for i in range(M+1):
    for j in range(D+1):
        if len(str(j)) >= 2:
            aaa=str(j)[-1]
            bbb=str(j)[-2]
            if int(aaa) >= 2 and int(bbb) >= 2 and int(aaa)*int(bbb) == i :
                cnt +=1
        else:
            pass
print(cnt)

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

#define ll long long
#define ld long double
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define sz(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/
const ll mod=1e9+7;
const ll INF=1e18;
/*****************************************************************************/

using namespace std;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	string s; cin >>s;
	for (int i=0;i<sz(s);i++) {
		if (s[i]=='7') {
			cout <<"Yes";
			return 0;
		}
	} 
	cout <<"No";
	return 0;
}
/******************************************************************************
******************************************************************************/


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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int a,b,i,j,t,ans=0;
	bool q;
	cin>>a>>b;
	vector<int> g;
	for (i=a;i<=b;i++){
		t=i;
		while (t>0){
			g.push_back(t%10);
			t/=10;
		}
		q=true;
		for (j=0;2*j<g.size()-1;j++){
			if (g[j]!=g[g.size()-1-j]){
				q=false;
				break;
			}
		}
		if (q==true){
			ans++;
		}
		g.clear();
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int ans = 0;
        for (int i = 0; i <= N; i++) {
            if (Math.floor(i * 1.08) == N) {
                ans = i;
            }
        }
        if (ans == 0) {
            System.out.println(":(");
            return;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 22740
a = list(map(int, input().split()))
n = a[0]
m = a[1]
l = a[2]
k = a[3]

if 0 < k <= n:
    print(k)

elif n < k <= n + m:
    print(n)

elif n+m <= k < n+m+l:
    print(n -1*(k -n -m))

elif n+m+l <= k:
    print(n - l)
else:
    print(0)


Measured memory_bytes: 9192
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  string s;
  cin >> s;
  ll n = s.size();
  bool can = false;
  for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
      string t="";
      for(int k=0;k<n;k++){
        if(i==k) k = j;
        t += s[k];
      }
      if(t == "keyence"){
        can = true;
      }
    }
  }
  if(can) cout <<"YES\n";
  else cout <<"NO\n";
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define long long long

int main(){
  int n,x;
  cin>>n>>x;
  vector<long> vec(n);
  rep(i,n) cin>>vec[i];

  vector<long> v(vec);
  long ans=0;
  rep(i,n-1){
    if(v[i]+v[i+1]>x){
      long rm = v[i]+v[i+1]-x;
      ans += rm;
      v[i+1]-=rm;
      if(v[i+1]<0){
        v[i]+=v[i+1];
        v[i+1]=0;
      }
    }
  }
  long a2=0;
  v = vector<long>(vec);
  rep(i,n-1){
    if(v[i]+v[i+1]>x){
      long rm = v[i]+v[i+1]-x;
      a2 += rm;
      v[i]-=rm;
      if(v[i]<0){
        v[i+1]+=v[i];
        v[i]=0;
      }
    }
  }

  cout<<min(ans, a2)<<endl;

  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define PI 3.141592653589793
#define MOD 1000000007

typedef long long ll;

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

    int a,b,k;
    cin >> a >> b >> k;

    for(int i = a; i < min(a+k, b+1); ++i) cout << i << endl;
    for(int i = max(b-k+1, a+k); i <= b; ++i) cout << i << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

#define ll long long

#define DEBUG (0)

ll getgcd(ll a, ll b);

int main()
{
  ll K = 0;

  cin >> K;

  ll sum = 0;
#if DEBUG
  cout << K << endl;
#endif

  for(ll a = 1; a <= K; a++){
    for(ll b = 1; b <= K; b++){
      for(ll c = 1; c <= K; c++){
        sum += getgcd(getgcd(a,b),c);
      }
    }
  }
  cout << sum << "\n";

}

ll getgcd(ll n, ll m){
  ll r = 0;
  if(n > m){
    ll t = m;
    m = n;
    n = t;
  }

  while((r =m%n)!= 0){
    m = n;
    n = r;
  }
#if DEBUG
  cout << n << endl;
#endif

  return n;
}


Measured memory_bytes: 3588
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

#define MAX_V 10000
#define MAX_E 100000
#define INF INT_MAX / 2 - 1

typedef long long ll;

struct edge { int u, v, cost; };

bool comp(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}

edge es[MAX_E];
int V, E;

int par[MAX_V];
int rank_[MAX_V];

void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		rank_[i] = 0;
	}
}

int find(int x) {
	if (par[x] == x) {
		return x;
	} else {
		return par[x] = find(par[x]);
	}
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;

	if (rank_[x] < rank_[y]) {
		par[x] = y;
	} else {
		par[y] = x;
		if (rank_[x] == rank_[y]) rank_[x]++;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}

ll kruskal() {
	sort(es, es + E, comp);
	init(V);
	ll res = 0;
	for (int i = 0; i < E; i++) {
		edge e = es[i];
		if (!same(e.u, e.v)) {
			unite(e.u, e.v);
			res += e.cost;
		}
	}
	return res;
}

int main() {
	cin >> V >> E;
	int s, t, w;
	for (int i = 0; i < E; i++) {
		cin >> es[i].u >> es[i].v >> es[i].cost;
	}
	cout << kruskal() << endl;
	return 0;
}

Measured memory_bytes: 2424
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long 
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;
 
const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };
 
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

vector<int> graph[100000];
int N, M, S, T;
int dist[100000][3];

int solve() {
    for(int i = 0; i < N; ++i) {
        dist[i][0] = dist[i][1] = dist[i][2] = -1;
    }
    dist[S][0] = 0;
    queue<P> que;
    que.push(P(S, 0));
    while(!que.empty()) {
        P p = que.front(); que.pop();
        for(auto i : graph[p.first]) {
            int latte = p.second + 1;
            latte %= 3;
            if(dist[i][latte] == -1) {
                dist[i][latte] = dist[p.first][p.second] + 1;
                que.push(P(i, latte));
            }
        }
    }
    return (dist[T][0] == -1) ? -1 : dist[T][0] / 3;
}

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

    cin >> N >> M;
    for(int i = 0; i < M; ++i) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        graph[u].push_back(v);
    }
    cin >> S >> T;
    --S; --T;
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 8064
//#define _USE_MATH_DEFINES
//#include <cmath>
#include <iostream>
//#include <stdio.h>
//#include <stdlib.h>
//#include <iomanip>
#include <vector>
#include <string>
//#include <algorithm>
//#include <functional>
//#include <time.h>
#include <sstream>

using namespace std;

bool isthe(string str){
	//?????????????????????????????? the this that?????¢??? ????????°ture

	int d1, d2, d3;

	d1 = (str[1] - str[0] + 26) % 26;

	if (d1 != 14){
		return false;
	}
	else{
		d2 = (str[2] - str[0] + 26) % 26;
		if (d2 != 11 && d2 != 15 && d2 != 7){
			return false;
		}
		else{
			if (d2 == 11 && str.size() == 3){
				return true;
			}
			else{
				d3 = (str[3] - str[0] + 26) % 26;
				if (d2 == 15 && d3 == 25) return true;
				if (d2 == 7 && d3 == 0) return true;
			}
		}
	}

	return false;

}


int main(){
	
	string s,sc, buf;
	stringstream ss;
	vector <string> as;
	int dif = 0;


	while (getline(cin, s)){
		dif = 0;
		buf = "";
		sc = "";
		ss.str("");
		ss.clear();

		sc += s;
		for (int i = 0; i < sc.size(); i++){
			if (sc[i] == '.')sc[i] = ' ';
		}
		ss << sc;

		while (ss >> buf){
			//the this that???????´¢
			if (buf.size() == 4){
				if (isthe(buf)){
					dif = (buf[0] - 't' + 26)%26;
					break;
				}
			}
			if (buf.size() == 3){
				if (isthe(buf)){
					dif = (buf[0] - 't' + 26) % 26;
					//break;
				}
			}
		}

		for (int i = 0; i < s.size(); i++){
			if (s[i] >= 'a' && s[i] <= 'z') {
				s[i] -= dif;
				if (s[i] < 'a') s[i] += 26;
				if (s[i] > 'z') s[i] -= 26;
			}
		}

		cout << s << endl;
	}


	return 0;
}

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

const int MOD=1000000007;

ll dp[400][400][400];

int main(){
	int n,m;cin>>n>>m;
	dp[0][1][1]=1;
	for(int i=0;i<m;i++)rep(j,n+1)rep(k,n+1){
		ll D=dp[i][j][k];
		if(!D)continue;
		if(k+1<=n)(dp[i+1][j][k+1]+=D*(n-k))%=MOD;
		(dp[i+1][k][k]+=D*j)%=MOD;
		(dp[i+1][j][k]+=D*(k-j))%=MOD;
	}
	cout<<dp[m][n][n]<<endl;
}

Measured memory_bytes: 145528
//............Created by:- Arth Raj...........................//
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vii vector<pair<int,int>>
#define tez ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lp(i,a,b) for(int i=a;i<b;i++)
#define rlp(i,a,b) for(int i=b;i>=a;i--)
#define ld long double
#define tl tuple<ll,ll,ll>
#define all(x) (x).begin(),(x).end()
#define bs(x,b) binary_search(all(x),b)
#define vip vector<pair<int,pair<int,int>>>
#define pip pair<int,pair<int,int>>
#define INF 1e18
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll abm(ll a, ll b, ll m) {ll ans = 1; a = a % m; while (b > 0) {if (b & 1)ans = (ans * a) % m; a = (a * a) % m; b = b / 2;} return ans % m;}
ll ncr(ll n, ll r, ll m) {if (r == 0)return 1; ll fac[n + 5]; fac[0] = 1; lp(i, 1, n + 1) {fac[i] = fac[i - 1] * i % m;} return (((fac[n] * abm(fac[r], m - 2, m)) % m) * (abm(fac[n - r], m - 2, m))) % m;}
int main()
{
	int n, k;
	cin >> n >> k;
	int arr[n + 1];
	lp(i, 1, n + 1)
	{
		cin >> arr[i];
	}
	int dp[n + 1];
	dp[0] = dp[1] = 0;
	lp(i, 2, n + 1)
	{
		if ((i - k) > 0)
		{
			int mini = INT_MAX;
			rlp(j, i - k, i - 1)
			{
				mini = min(mini, dp[j] + abs(arr[i] - arr[j]));
			}
			dp[i] = mini;
		}
		else
		{
			int mini = INT_MAX;
			for (int j = i - 1; j >= 1; j--)
				mini = min(mini, dp[j] + abs(arr[i] - arr[j]));
			dp[i] = mini;
		}
		// cout << dp[i] << endl;
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 4388
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
  string s;
  cin>>s;
int judge=0;
  for(int i=0;i<s.size()-1;i++){
    if(s.size()>1&&s[i]=='h'&&s[i+1]=='i'){
judge++;
    }
  }
  if(judge==(s.size()/2)&&s.size()%2==0){
cout<<"Yes"<<endl;
  }
  else{
cout<<"No"<<endl;
  }

return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;

// a と b の最大公約数を返す
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    // 再帰的に解く (x, y を入れ替えておく)
    ll d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

/**
 * ax + by = gcd(a, b)を満たすx, yを求める
 * @param a
 * @param b
 * @return P_res(gcd(a, b), P(x, y))
 */
pair<ll, pair<ll, ll>> extGCD(ll a, ll b){
    using P_xy = pair<ll, ll>;
    using P_res = pair<ll, pair<ll, ll>>;

    ll x, y;
    ll d = extGCD(a, b, x, y);
    P_res res = P_res(d, P_xy(x, y));
    return res;
}


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



// 素数判定
bool is_prime(ll N) {
    if (N == 1) return false;
    for (ll i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}


// 約数列挙
vector<ll> enum_divisors(ll N) {
    vector<ll> res;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            if (N/i != i) res.push_back(N/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}


// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll N){
    vector<pair<ll, ll>> res;
    for(ll i = 2; i * i <= N; i++){
        if(N % i != 0)  continue;
        ll ex = 0;

        while(N % i == 0){
            ex++;
            N /= i;
        }

        res.push_back({i, ex});
    }

    if(N != 1)  res.push_back({N, 1});
    return res;
};



int main(){
    int n;  cin >> n;
    if(n == 0 || n == 2){
        cout << 1 << endl;
    }
    else if(n == 1){
        cout << 2 << endl;
    }
    else{
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 3136
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
const int mod= 1e+9+7;

int main() {
    int N,K; cin>>N>>K;
    int R,S,P; cin>>R>>S>>P;
    string T; cin>>T;
    int cnt=0;
    vector<char>t(N);
    rep(i,N){
        if(i<K){
            if(T[i]=='r'){
                cnt+=P;
                t[i]='p';
            }
            else if(T[i]=='s'){
                cnt+=R;
                t[i]='r';
            }
            else{
                cnt+=S;
                t[i]='s';
            } 
        }
        else{
            //
            if(T[i]=='r'){
                if(t[i-K]=='p'){
                    if(i+K<N&&T[i+K]=='p'){
                        t[i]='r';
                    }
                    else t[i]='s';
                }
                else {
                    cnt+=P;
                    t[i]='p';
                }
            }
            //
            else if(T[i]=='s'){
                if(t[i-K]=='r'){
                    if(i+K<N&&T[i+K]=='r'){
                        t[i]='s';
                    }
                    else t[i]='p';
                }
                else {
                    cnt+=R;
                    t[i]='r';
                }
            }
            //
            else {
                 if(t[i-K]=='s'){
                    if(i+K<N&&T[i+K]=='s'){
                        t[i]='p';
                    }
                    else t[i]='r';
                }
                else {
                    cnt+=S;
                    t[i]='s';
                }
        }
    }
    
}
cout<<cnt<<endl;
}


Measured memory_bytes: 512
A=[]
while True:
    try:
        A.append(input())
    except EOFError:
        break


a=list("abcdefghijklmnopqrstuvwxyz")
counter=[0 for i in range(len(a))]
for j in A:
    for i in range(len(a)):
        counter[i]+=j.count(a[i])+j.count(a[i].upper())
for i in range(len(a)):
    print(a[i]+" : "+str(counter[i]))


Measured memory_bytes: 5568
package main

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

var G map[int][]int
var X []int
var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func dfs(v, p int) {
	for _, r := range G[v] {
		if r == p {
			continue
		}
		X[r-1] += X[v-1]
		dfs(r, v)
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	q := nextInt()
	G = make(map[int][]int)
	for i := 1; i < n; i++ {
		a, b := nextInt(), nextInt()
		G[a] = append(G[a], b)
		G[b] = append(G[b], a)
	}
	X = make([]int, n)
	for i := 0; i < q; i++ {
		X[nextInt()-1] += nextInt()
	}
	dfs(1, -1)
	for _, x := range X {
		fmt.Printf("%d ", x)
	}
	fmt.Println()
}


Measured memory_bytes: 78464
N,M=map(int,input().split())
H=list(map(int,input().split()))
A=[0]*M;B=[0]*M
C=[0]*N
for i in range(M):
  A[i],B[i]=map(int,input().split())

for i in range(M):
  if H[A[i]-1]<H[B[i]-1]:C[A[i]-1]+=1
  elif H[A[i]-1]>H[B[i]-1]:C[B[i]-1]+=1
  else:C[A[i]-1]+=1;C[B[i]-1]+=1
print(C.count(0))

Measured memory_bytes: 21764
import sys
import math

sys.setrecursionlimit(1000000)


def solve(S, T):
    if len(S) + 1== len(T) and T.startswith(S):
        return 'Yes'
    return "No"


if __name__ == "__main__":
    S = input()
    T = input()
    print(solve(S, T))

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

typedef long long ll;
using namespace std;
int main()
{
  int r,g,b,n;
  cin>>r>>g>>b>>n;

  int ans=0;
  rep(i,n+1){
    rep(j,n+1){
      // cout<<(n-r*i-j*g)<<endl;
      if((n-i*r-j*g)%b==0&&(n-i*r-j*g)>=0)ans++;
    }
  }

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


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

    using namespace std;

    #define int long long
    #define endl '\n'
    #define MOD 1000000007
    #define maxn 100010

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

        vector<int> v(n);
        for (int i = 0; i < n; ++i) {
            cin >> v[i];
        }
        vector<int> dp;
        int len = 1;
        for (int i = 0; i < n; i++) {
            if (dp.empty())
                dp.push_back(v[i]);
            else {
                if (v[i] > dp.back())
                    dp.push_back(v[i]);
                else {
                    int p = lower_bound(dp.begin(), dp.end(), v[i]) - dp.begin();
                    dp[p] = v[i];
                }
            }
        }
        cout << dp.size() << endl;
    }

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

        int t = 1;
    //    cin >> t;

        while (t--)
            solve();
        return 0;
    }


Measured memory_bytes: 4688
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
d1=defaultdict(int)
d2=defaultdict(int)

ans=0
for g in range(n):
    ans+=d1[a[g]-g]
    ans+=d2[a[g]+g]
    d1[-a[g]-g]+=1
    d2[-a[g]+1]+=1
print(ans)

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

struct Edge {
	int a, b, w;
	const bool operator<(const Edge &e) {
		return w < e.w;
	}
};

struct Dsu {
	int dsu[101];
	void init() { rep(i, 0, 101) dsu[i] = -1; }
	int find(int x) { return dsu[x] < 0 ? x : dsu[x] = find(dsu[x]); }
	int size(int x) { return -dsu[find(x)]; }
	void merge(int u, int v) {
		u = find(u), v = find(v);
		if (u == v) return;
		dsu[u] += dsu[v]; dsu[v] = u;
	}
};

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	for (;;) {
		int n, m; cin >> n >> m; if (!n && !m) break;
		vector<Edge> v;

		rep(i, 0, m) {
			Edge e; cin >> e.a >> e.b >> e.w;
			v.push_back(e);
		}
		sort(all(v));

		int ans = 9999999;
		rep(i, 0, m) if (!i || v[i].w != v[i - 1].w) {
			Dsu dsu; dsu.init();
			rep(j, i, m) {
				Edge e = v[j];
				dsu.merge(e.a, e.b);
				if (dsu.size(e.a) == n) {
					ans = min(ans, e.w - v[i].w);
					break;
				}
			}
		}

		cout << (ans == 9999999 ? -1 : ans) << endl;
	}
}



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

int main() {
  while(true) {
    int ncandid, nstone;
    cin >> ncandid >> nstone;
    if(ncandid == 0 && nstone == 0) break;
    int lastGiveStoneC = -1;
    vector<int> candides(ncandid, 0);
    int count = 0;
    while(true) {
      for(int i = 0; i < ncandid; ++i) {
        candides[(lastGiveStoneC + 1 + i) % ncandid] += nstone / ncandid;
        if(i < nstone % ncandid) {
          ++candides[(lastGiveStoneC + 1 + i) % ncandid];
        } else if(nstone / ncandid == 0) {
          break;
        }
      }
      lastGiveStoneC += nstone + 1;
      nstone = candides[lastGiveStoneC % ncandid];
      candides[lastGiveStoneC % ncandid] = 0;
      (nstone == 0) ? (++count) : (count = 0);
      if(count == ncandid - 1) break;
    }
    cout << (lastGiveStoneC + 1) % ncandid << endl;
  }
  return 0;
}

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

int main(){
    int n;
    ll in;
    cin >> n;
    ll ans = 1;
    rep(i, n){
        cin >> in;
        ans = ans/__gcd(ans, in)*in;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { s -> s.toInt() }
    val ab=Array(n){ readLine()!!.split(" ").map { s -> s.toLong() }}.sortedBy { v->v[0] }
    var count = 0
    var price:Long=0
    for (i in 0 until n){
        if(ab[i][1]<m-count){
            count+=ab[i][1].toInt()
            price+=ab[i][1]*ab[i][0]
        }else{
            price+=(m-count)*ab[i][0]
            break
        }
    }
    println(price)
}

Measured memory_bytes: 85876
int main()
{
  int n;
  scanf("%d", &n);
  char s[n];
  scanf("%s", &s);
  
  int i, cnt = 0;
  for (i = 0; i < n - 2; i++)
  {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
      cnt++;
  }
  printf("%d", cnt);
}

Measured memory_bytes: 128
H, N = map(int, input().split())
A_B = [list(map(int, input().split())) for i in range(N)]

A = [A_B[i][0] for i in range(N)]
B = [A_B[i][1] for i in range(N)]

M = H + max(A)

#dp[i][j] : i番目までの中から魔法を選んで使い体力をj減らすときの魔力の最小値

def crested(H, N, A, B):
    inf = float('inf')
    dp = [inf for j in range(M+1)]
    dp[0] = 0

    for i in range(N):
        for j in range(A[i],M):
            dp[j] = min(dp[j], dp[j-A[i]]+B[i])
    
    ans = inf
    for k in range(H, M):
        ans = min(ans, dp[k])
    print(ans)

crested(H, N, A, B)

Measured memory_bytes: 46044
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    int x,k;
    cin>>x>>k;
    ll y[x];
    for (int i=0;i<x;i++){
            cin>>y[i];
    }
    ll ans=1e18;
    for (int i=0;i<x-k+1;i++){
        ll l=y[i],r=y[i+k-1];
        if (l<0&&r<0)
            ans=min(ans,-l);
        else if (r>0&&l>0)
            ans=min(ans,r);
        else if (abs(l)>abs(r))
            ans=min(ans,2*abs(r)+abs(l));
        else
            ans=min(ans,abs(r)+2*abs(l));
    }
    cout<<ans;
    return 0;
}


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


int main(){
	int n, k;
	cin >> n >> k;
	priority_queue<int> q;
	rep(i,n){
	    int tmp;
	    cin >> tmp;
	    q.push(tmp);
	}
	int ans = 0;
	while(k--){
        ans += q.top();
        q.pop();
	}
	cout << ans << endl;
}


Measured memory_bytes: 256