akhauriyash/Code-Regression huggingface dataset:
import sys
from bisect import bisect_left

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

def get_sum(a, d, n):
    """ 等差数列の和：(初項a, 公差d, 項数n) """
    return (2*a + (n-1)*d) * n // 2

D = INT()
M = 26
C = LIST()
S = [[]] * (D+1)
S[0] = [0] * M
for i in range(1, D+1):
    S[i]  = LIST()
adjli = [[0] for i in range(M)]
T = [0] + [t-1 for t in LIST(D)]
for d, t in enumerate(T[1:], 1):
    adjli[t].append(d)
for i in range(M):
    adjli[i].append(D+1)

def check(T):
    score = 0
    for a in range(M):
        for i in range(1, len(adjli[a])):
            curd = adjli[a][i-1]
            nxtd = adjli[a][i]
            cnt = nxtd - curd
            score += S[curd][a]
            score -= C[a] * get_sum(0, 1, cnt)
    return score

# day日目のコンテストをaからbに変更する
def change(day, a, b):
    res = 0
    # コンテストaのコストを再計算
    res -= S[day][a]
    di = adjli[a].index(day)
    for i in range(di, di+2):
        curd = adjli[a][i-1]
        nxtd = adjli[a][i]
        cnt = nxtd - curd
        res += C[a] * get_sum(0, 1, cnt)
    adjli[a].pop(di)
    curd = adjli[a][di-1]
    nxtd = adjli[a][di]
    cnt = nxtd - curd
    res -= C[a] * get_sum(0, 1, cnt)

    # コンテストbのコストを再計算
    res += S[day][b]
    di = bisect_left(adjli[b], day)
    curd = adjli[b][di-1]
    nxtd = adjli[b][di]
    cnt = nxtd - curd
    res += C[b] * get_sum(0, 1, cnt)
    adjli[b].insert(di, day)
    for i in range(di, di+2):
        curd = adjli[b][i-1]
        nxtd = adjli[b][i]
        cnt = nxtd - curd
        res -= C[b] * get_sum(0, 1, cnt)

    return res

score = check(T)
Q = INT()
for i in range(Q):
    d, q = MAP()
    q -= 1

    score += change(d, T[d], q)
    print(score)
    T[d] = q


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

int main()
{
	int A, B;
	cin >> A >> B;
	if (A>=13) {
		cout << B << endl;
	}
	if (6 <= A&&A <= 12) {
		cout << B / 2 << endl;
	}
	if(A<=5) {
		cout << "0" << endl;
	}
}


Measured memory_bytes: 256
# ABC093-C
tmp = list(map(int, input().split()))
tmp = sorted(tmp)
A = tmp[0]
B = tmp[1]
C = tmp[2]
ans = 0
ca = (C - A) // 2
cb = (C - B) // 2
ans += ca + cb
A = A + ca * 2
B = B + cb * 2
if C == A and C == B:
    print(ans)
elif C == A and C == B + 1:
    print(ans + 2)
elif C == A + 1 and C == B:
    print(ans + 2)
elif C == A + 1 and C == B + 1:
    print(ans + 1)


Measured memory_bytes: 3064
#18:31
#Bugged
n=int(input())
s=[]
t=[0]*n
for i in range(n):
    a=int(input())
    s.append(a)
    if a%10!=0:
        t[i]=a

pt=sum(s)
s=sorted(s)
t=sorted(t)

for i in range(n):
    if pt%10==0:
        pt-=t[0]
        t.pop(0)   
if pt%10!=0:
    print(pt)
else:
    print(0)

Measured memory_bytes: 38256
// Implementation practice (Have seen the editorial)
#include <bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << (a) << "\n"

const int N = 50 + 10;
string s, t;
int id = -1;

bool check(int at) {
	int ss = s.length(), tt = t.length();
	if (at + tt > ss) return false;
	for (int i = at; i < ss && i < at+tt; i++)
		if (s[i] != '?' && s[i] != t[i-at]) return false;
	return true;
}

int main() {
	/*freopen("in", "r", stdin);
	freopen("out", "w", stdout);*/
	ios::sync_with_stdio(false);cin.tie(NULL);

	cin >> s >> t;
	for (int i = s.length()-1; i >= 0; i--)
		if (check(i)) {
			id = i;
			break;
		}
	if (id == -1) cout << "UNRESTORABLE" << endl;
	else {
		for (int i = 0; i < id; i++)
			cout << (s[i]=='?'?'a':s[i]);
		cout << t;
		for (int i = id+t.length(); i < s.length(); i++)
			cout << (s[i]=='?'?'a':s[i]);
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000123LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


class point_t {
public:
  int x;
  int y;

public:
  bool operator<(const point_t& p) const {
    if (x != p.x)
      return x < p.x;

    return y < p.y;
  };
};


bool ycomp(const point_t& a, const point_t& b) {
  if (a.y != b.y)
    return a.y < b.y;
  
  return a.x < b.x;
}


int N, K;


long long test(std::vector<point_t> pts)
{
  long long Am = INF;
  
  std::sort(ALL(pts));

  for (int i = 0; i < N; i ++)
    for (int j = i; j < N; j ++) {
      int size = j + 1 - i;
      
      if (size < K)
        continue;
      
      long long w = pts[j].x - pts[i].x;

      std::vector<point_t> pts2(std::begin(pts) + i, std::begin(pts) + j + 1);

      assert(pts2.size() == size);

      std::sort(ALL(pts2), ycomp);
        
      for (int k = 0; k < size; k ++)
        for (int l = k; l < size; l ++) {
          if (l + 1 - k < K)
            continue;

          long long h = pts2[l].y - pts2[k].y;

          Am = std::min(w * h, Am);
        }
    }

  return Am;
}
  

int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  std::cin >> N >> K;

  std::vector<point_t> pts(N);

  for (int i = 0; i < N; i ++)
    std::cin >> pts[i].x >> pts[i].y;

  long long Am = INF;

  Am = std::min(test(pts), Am);

  for (int i = 0; i < N; i ++)
    std::swap(pts[i].x, pts[i].y);

  Am = std::min(test(pts), Am);
  
  std::cout << Am << std::endl;

  return 0;
}


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

using P = pair<int, int>;
using ll = long long;

class union_find {
public:
    union_find(int n)
        : par_(n, -1)
    {}
    void init(int n) {
        par_.assign(n, -1);
    }

    int root(int x) {
        return par_[x] < 0 ? x : par_[x] = root(par_[x]);
    }

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if(x == y) {
            return false;
        } else {
            if(par_[x] < par_[y]) {
                par_[x] += par_[y];
                par_[y] = x;
            } else {
                par_[y] += par_[x];
                par_[x] = y;
            }
            return true;
        }
    }

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

    int size(int x) {
        return -par_[root(x)];
    }

private:
    std::vector<int> par_;
};

int main() {
    int N;
    cin >> N;
    vector<int> c(N);
    for(int i=0; i<N; ++i) {
        cin >> c[i];
    }
    int M;
    cin >> M;
    union_find uf(N);
    vector<vector<int>> g(N);
    vector<vector<P>> next(N);
    for(int i=0; i<M; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if(c[a] > c[b]) {
            g[b].push_back(a);
        } else if(c[a] < c[b]) {
            g[a].push_back(b);
        } else {
            uf.unite(a, b);
        }
        next[a].emplace_back(c[b], b);
        next[b].emplace_back(c[a], a);
    }

    for(int i=0; i<N; ++i) {
        if(next[i].size() == 0) {
            continue;
        }
        sort(next[i].begin(), next[i].end());
        for(int j=0; j<next[i].size()-1; ++j) {
            P u = next[i][j], v = next[i][j+1];
            if(u.first == v.first) {
                uf.unite(u.second, v.second);
            } else {
                g[u.second].push_back(v.second);
            }
        }
    }

    vector<int> order;
    vector<ll> dp(N);
    for(int i=0; i<N; ++i) {
        if(uf.root(i) == i) {
            order.push_back(i);
            dp[i] = 1;
        } else {
            for(auto& v : g[i]) {
                g[uf.root(i)].push_back(v);
                g[i].clear();
            }
        }
    }
    sort(order.begin(), order.end(), [&](int const v1, int const v2) {
        return c[v1] < c[v2];
    });
    ll res = 0;
    for(auto i : order) {
        for(auto to : g[i]) {
            dp[uf.root(to)] = max(dp[uf.root(to)], dp[i] + 1);
        }
        res += dp[i] * uf.size(i);
    }
    cout << res << endl;
}


Measured memory_bytes: 19860
#include<stdio.h>
#include<stdlib.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

typedef struct{
    int id;
    int sum;
}data;

//昇順
int asc(const void* a, const void* b){
    data p=*(data*)a;
    data q=*(data*)b;
    return p.sum-q.sum;
}

int main(void){
    int N;
    scanf("%d",&N);

    //A[0]~A[N-1]に格納する
    data* A;
    NEW(A,N);
    for(int i=0;i<N;i++){
        A[i].id=i+1;
        scanf("%d",&A[i].sum);
    }

    qsort(A,N,sizeof(data),asc);

    for(int i=0;i<N;i++){
        printf("%d ",A[i].id);
    }
    printf("\n");

    return 0;
}

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

typedef int Weight;
struct Edge{
	int src,dst;
	Weight weight;
};

bool asc(const Edge &e,const Edge &f){
	return e.weight < f.weight;
}

vector<Edge> Edges;
vector<int> L(100005,-1);

int check(Edge &e,int n){
	int j;
	if (L[e.src]!=L[e.dst]){
		int t = L[e.dst];
		for (j=0;j<n;j++){
			if (L[j]==t){
				L[j]=L[e.src];
			}
		}
		return 1;
	}else{
		return 0;
	}
}

int main(){
	int n,m,i,j,w;
	cin >> n ;
	
	for (i=0;i<n;i++){
		for(j=0;j<n;j++){
			cin >> w;
			if ((w!=-1)&&(i>j)){
				Edge edge={i,j,w};
				Edges.push_back(edge);
			}
		}
	}
	
	sort(Edges.begin(),Edges.end(),asc);
	
	m = Edges.size();
	
	for (j=0;j<n;j++){
		L[j]=j;
	}
	
	int TotalWeight=0;
	int count=0;
	int k;
	for (i=0;i<m;i++){
		if (count==n-1){break;}
		if (check(Edges[i],n)){
			TotalWeight+=Edges[i].weight;
			count++;
		}
	}
	cout << TotalWeight<<endl;
	return 0;
}

Measured memory_bytes: 1536
import math

n = int(raw_input())
p = raw_input().split()
pb = list(range(n))
q = raw_input().split()
qb = list(range(n))

ps = 0
qs = 0

for i in range(n - 1):
    p0 = pb.index(int(p[i]) - 1)
    pb.remove(int(p[i]) - 1)
    ps = (n - i - 1) * (ps + int(p0))

    q0 = qb.index(int(q[i]) - 1)
    qb.remove(int(q[i]) - 1)
    qs = (n - i - 1) * (qs + int(q0))

if qs - ps > 0:
    print qs - ps
else:
    print ps - qs

Measured memory_bytes: 2692
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i,n)cin >> a[i];

    ll ans = 1;
    ll MOD = 1e9+7;

    int b[3];
    rep(j,3)b[j] = -1;

    rep(i,n){
        ll cnt = 0;
        rep(j,3){
            if(a[i] == b[j] + 1)cnt++;
        }
        ans *= cnt;
        ans %= MOD;
        rep(j,3){
            if(a[i] == b[j] + 1){
                b[j]++;
                break;
            }
        }
    }

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


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

int main() {
    int N, K; cin >> N >> K;
    int R, S, P; cin >> R >> S >> P;
    string T; cin >> T;
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        if (i < K || T[i] != T[i-K]) {
            if (T[i] == 'r') ans += P;
            if (T[i] == 's') ans += R;
            if (T[i] == 'p') ans += S;
        } else if (T[i] == T[i-K]) {
            T[i] = '.';
        }
    }
    cout << ans << endl;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int m = (1 << n);
    vector<ll> s(m);
    for (int i = 0; i < m; i++) cin >> s[i];
    sort(s.begin(), s.end(), greater<>());

    vector<int> used(m, false);
    used[0] = true;
    vector<ll> v;
    v.push_back(s[0]);

    for (int i = 0; i < n; i++) {
        sort(v.begin(), v.end(), greater<>());
        int cur = 0;
        vector<ll> newv;
        for (ll x : v) {
            newv.push_back(x);
            bool f = false;
            while (cur < m) {
                if (used[cur] || s[cur] >= x) {
                    cur++;
                    continue;
                }
                used[cur] = true;
                newv.push_back(s[cur]);
                cur++;
                f = true;
                break;
            }
            if (!f) {
                cout << "No\n";
                return 0;
            }
        }
        v = move(newv);
    }

    cout << "Yes\n";

    return 0;
}

Measured memory_bytes: 6504
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll n,m;
    cin >> n >> m;
    vector<ll> a(m);
    for(int i = 0; i < m; i++) cin >> a[i];
    a.push_back(n+1);
    COMinit();
    ll ans = 1;
    ll now = 0;
    for(int i = 0; i < a.size(); i++){
        ll dif = a[i] - now - 1;
        ll way = 0;
        for(int j = 0; 2 * j <= dif; j++){
            way += COM(dif - j, j);
            way = (way + MOD) % MOD;
        }
        ans *= way;
        ans =  (ans + MOD) % MOD;
        now = a[i] + 1;
    }
    cout << ans << endl;
}

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

#define DEBUG(C) cerr << #C << " = " << C << endl

using namespace std;

template<typename T>
class BIT {
private:
  vector<T> bit;
public:
  BIT(const int n) : bit(n + 10) {}
  void add(int idx, T val) {
    ++idx;
    while (idx <= bit.size()) {
      bit[idx] += val;
      idx += idx & -idx;
    }
  }
  T get(int l, int r) {
    return this->get(r) - this->get(l - 1);
  }
  T get(int r) {
    ++r;
    T res = 0;
    while (r > 0) {
      res += bit[r];
      r -= r & -r;
    }
    return res;
  }
};

int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  BIT<int> bit(n);
  while (q--) {
    int c, x, y;
    scanf("%d%d%d", &c, &x, &y);
    if (c) {
      printf("%d\n", bit.get(x - 1, y - 1));
    } else {
      bit.add(x - 1, y);
    }
  }
  return 0;
}

Measured memory_bytes: 3344
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if w-v==0:
    if a-b==0:
        print("YES")
    else:
        print("NO")
elif w-v>0:
    print("NO")
else:
    if -(-abs(a-b)//abs(w-v))<=t:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9192
#!/usr/bin/env python
"""M-SOLUTIONS プロコンオープン 2020: C - Marks
https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_c
"""


def main():
    N, K = list(map(int, input().split()))
    As = list(map(int, input().split()))

    # N, K = [5, 3]
    # As = [96, 98, 95, 100, 20]

    # N, K = [3, 2]
    # As = [1001, 869120, 1001]

    # N, K = [15, 7]
    # As = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9]
    for i in range(0, N-K):
        # print('i:{}({})'.format(i, i+K))
        prev_score = As[i]
        score = As[K + i]
        # print('{} => {}'.format(prev_score, score))
        if prev_score < score:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()


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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;

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




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

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;






void printv(vint &V){
  for(auto e:V)cout<<e<<" ";
  cout<<endl;
}

vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}

vector< int > prime_numbers;






int main() {


  cout<<fixed<<setprecision(10);

  ll h,w; cin>>h>>w;

  ll ans=0;

  if(h==1 || w==1){
    cout<<1<<endl;
    return 0;
  }

  if(h%2==0){
    ans  = (h/2)*w;
  }else{
    ans = (h/2)*w + (w+1)/2;
  }
  cout<<ans<<endl;


}

//


Measured memory_bytes: 256
primes = set([])
n = 10**5
is_prime = [True]*(n+1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, n+1):
    if is_prime[i]:
        primes.add(i)
        for j in range(2, n//i+1):
            is_prime[j*i] = False
# DP[i] = i以下の2017 likeな数
DP = [0]*(n+1)
for i in range(1, n+1):
    if i in primes and (i+1)//2 in primes:
        DP[i] = DP[i-1] + 1
    else:
        DP[i] = DP[i-1]
q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(DP[r] - DP[l-1])

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


int main(){
	int sx,sy,gx,gy,dx,dy;
	cin >> sx >> sy >> gx >> gy;
	
	dx=gx-sx;
	dy=gy-sy;
	
	cout << string(dy,'U') << string(dx,'R');
	cout << string(dy,'D') << string(dx,'L');
	cout << 'L' << string(dy+1,'U') << string(dx+1,'R') << 'D';
	cout << 'R' << string(dy+1,'D') << string(dx+1,'L') << 'U';
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
nyuryoku = ""

try:
    while True:
        s = input()
        if s == '':
            break
        nyuryoku += s

except EOFError:
    pass

s = nyuryoku

a = "abcdefghijklmnopqrstuvwxyz"
alphabet = [0] * 26

for i in range(len(s)):
    for j in range(len(a)):
        if(s[i] == a[j] or s[i] == a[j].upper()):
            alphabet[j] += 1
            
for i in range(len(a)):
    print("{} : {}".format(a[i],alphabet[i]))


Measured memory_bytes: 5564
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

// s = "112223" -> [[1,2],[2,3],[3,1]]
vector<pair<int,int>> rle (vector<int> x) {
  vector<pair<int,int>> res;
  int n = (int)x.size();
  for (int i = 0; i < n;) {
    int j = i;
    int cnt = 0;
    while (j < n && x[j] == x[i]) {
      ++j;
      ++cnt;
    }
    res.emplace_back(x[i], cnt);
    i = j;
  }
  return res;
}

int main () {
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  
  sort(a.begin(), a.end());
  auto x = rle(a);

  //rep(i,x.size()) printf("%d %d\n", x[i].fi, x[i].se);
  int ans = 0;
  for (auto p : x) {
    if (p.fi <= p.se) ans += p.se - p.fi;
    else ans += p.se;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2168
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        h: u64,
        w: u64,
    }

    if h == 1 || w == 1 {
        println!("1");
        return;
    }

    let n = h * w;
    let ans = (n + 1) / 2;
    println!("{}", ans as u64);
}


Measured memory_bytes: 2144
package main

import "fmt"

func main() {
    var company string
    var countA, countB int
    
    fmt.Scan(&company)
    
    for _, c := range company {
        if c == 'A' {
            countA++
        } else if c == 'B' {
            countB++
        } else {
            fmt.Println("algorithm Error")
        }
    }
    
    if countA < 3 && countB < 3 {
        fmt.Println("Yes")
    } else {
        fmt.Println("No")
    }
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
	int n,i;
	int a,max=0,semimax=0,count1=0,count2=0;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		if(a>max){
			semimax=max;
			max=a;
			count2=i;
			count1=1;
		}
		else{
			if(a==max)
				count1=2;
			else if(a>semimax)
				semimax=a;
			}
		}
	for(i=0;i<n;i++){
		if(count2==i && count1==1)
			printf("%d\n",semimax);
		else
			printf("%d\n",max);
	}
	return 0;
}
		


Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        long[] h = new long[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            h[i] = sc.nextLong();
        }

        for (int cx = 0; cx <= 100; cx++) {
            for (int cy = 0; cy <= 100; cy++) {
                for (int i = 0; i < n; i++) {
                    long hh = h[i] + Math.abs(x[i] - cx) + Math.abs(y[i] - cy);
                    boolean allMatched = true;
                    for (int j = 0; j < n; j++) {
                        if (Math.max(hh - Math.abs(x[j] - cx) - Math.abs(y[j] - cy), 0) != h[j]) {
                            allMatched = false;
                            break;
                        }
                    }
                    if (!allMatched) {
                        continue;
                    }
                    System.out.println(cx + " " + cy + " " + hh);
                    return;
                }
            }
        }
    }

}


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

namespace ABC158C
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int res = -1;
            for (int i = 1; i <= 10000; i++)
            {
                if ((int)Math.Floor(i * 1.08)==i+ab[0] && (int)Math.Floor(i * 1.10) == i + ab[1])
                {
                    res = i;
                    break;
                }
            }
            Console.WriteLine(res);
        }
    }
}


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

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

    vector<long long int> A(N+1);
    for(long long int i = 0; i <= N; ++i) cin >> A[i];

    vector<long long int> B(N);
    for(long long int i = 0; i < N; ++i) cin >> B[i];
    
    long long int ans = 0;
    long long int b = 0;
    for(long long int i = 0; i < N; ++i){
        if(A[i] >= B[b]){
            ans += B[b];
        }else{
            ans += A[i];
            B[b] -= A[i];

            if(A[i+1] >= B[b]){
                ans += B[b];
                A[i+1] -= B[b];
            }else{
                ans += A[i+1];
                A[i+1] = 0;
            }
        }

        ++b;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	s := nextString()
	ans := ""
	if s == "ABC" {
		ans = "ARC"
	} else {
		ans = "ABC"
	}

	fmt.Println(ans)
}


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

const int INF = 1<<28;
const int MAX = 31;
int w, h;
int costs[4];
int brd[MAX][MAX];

enum { EAST = 0, SOUTH, WEST, NORTH };
enum { STRAIGHT = 0, RIGHT, BACK, LEFT };

// east, south, west, north
int dy[4] = { 0, 1, 0, -1 };
int dx[4] = { 1, 0, -1, 0 };

class State {
public:
  int x, y, d, c;

  State(int x, int y, int d, int c):x(x), y(y), d(d), c(c) {}

  bool operator>(const State &a) const {
    return c > a.c;
  }
};

int dijkstra()
{
  int dist[MAX][MAX][4];
  priority_queue<State, vector<State>, greater<State> > que;
  que.push(State(0, 0, EAST, 0));
  fill(dist[0][0], dist[MAX][0], INF);
  dist[0][0][EAST] = 0;
  while (!que.empty()) {
    State s = que.top(); que.pop();
    if (dist[s.y][s.x][s.d] < s.c) continue;
    if (s.x == w-1 && s.y == h-1) return s.c;
    for (int i = 0; i < 4; i++) {
      int nx, ny, nd, nc;
      nd = (s.d+i)%4;
      nx = s.x + dx[nd];
      ny = s.y + dy[nd];
      nc = s.c + (i == brd[s.y][s.x]?0:costs[i]);
      if (!(0 <= nx && nx < w)) continue;
      if (!(0 <= ny && ny < h)) continue;
      if (dist[ny][nx][nd] > nc) {
        que.push(State(nx, ny, nd, nc));
        dist[ny][nx][nd] = nc;
      }
    }
  }

  assert(false);
  return -1;
}

int main()
{
  while (cin >> w >> h, w|h) {
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++)
        cin >> brd[i][j];

    for (int i = 0; i < 4; i++)
      cin >> costs[i];

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

Measured memory_bytes: 1328
while True:

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

    if H==0 and W==0:
        break

    hh=H

    while True:
        ww = W

        if hh == 0: break
        while True:
            if ww == 0: break
            print("#",end="")
            ww -=1
            if ww == 0: break
            print(".",end="")
            ww -=1
        print()
        hh -=1

        ww = W
        if hh == 0: break
        while True:
            if ww == 0: break
            print(".", end="")
            ww -= 1
            if ww == 0: break
            print("#", end="")
            ww -= 1
        print()
        hh -=1

    print()


Measured memory_bytes: 7004
N,M = map(int,input().split())
MOD = 10**9+7
S = list(map(int,input().split()))
T = list(map(int,input().split()))
DP = [[1]*(M+1) for i in range(N+1)]
for i in range(N):
    hoge = 0
    for j in range(M):
        if S[i] == T[j]:
            hoge += DP[i][j]
            hoge %= MOD
        DP[i+1][j+1] = (DP[i][j+1] + hoge)%MOD
print(DP[-1][-1])


Measured memory_bytes: 72540
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k,a,b,t=0;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {   double s;
        cin>>a>>b;
        a=a*a;
        b=b*b;
        s=a+b;
        s=sqrt(s);


    if(k>=s)
    {
      t++;
    }
    }
    cout<<t<<endl;
    return 0;


}


Measured memory_bytes: 3636
#! /usr/bin/env python3


def gcd(a, b):
    if a < b : return gcd(b, a)
    while b != 0:
        t = a % b
        a = b
        b = t
    return a

N = int(input())
T = sorted(set([int(input()) for x in range(N)]))
a = T[-1]
for i in T[:-1]:
    a = (a * i) // gcd(a, i)

print(a)

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

using namespace std;

typedef long long LL;

LL Solve(LL x, LL y) {
	if (x % y == 0) return (x / y * 2 - 1) * y;
	return Solve(y, x % y) + (x / y * 2) * y;
}

int main() {
	LL n, x;
	
	cin >> n >> x;
	
	cout << Solve(std::max(x, n - x), std::min(x, n - x)) + n << endl;
	
	return 0;
}

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


int main() {
    int n ;
    cin >> n  ;
  
    if(n%3<2)
    {
      cout << floor(n/3) ;
    }else
    {
      cout << n/3 ;
    }

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

int ans;
int n,m;
int a[111],p[111];

int fact(int k,int x){//レベKをしたからx層
	if(k==0)return 1;
	if(x==1)return 0;
	if(1<x && x<=a[k-1]+1)return fact(k-1,x-1);
	if(x==a[k-1]+2)return p[k-1]+1;
	if(a[k-1]+2<x && x<=a[k-1]*2+2)return p[k-1]+1+fact(k-1,x-(a[k-1]+2));
	if(x==a[k-1]*2+3)return p[k-1]*2+1;
}

signed main(){
	
	cin>>n>>m;
	a[0]=1;p[0]=1;
	rep(i,n){
		a[i+1]=a[i]*2+3;
		p[i+1]=p[i]*2+1;
	}
	cout<<fact(n,m)<<endl;
	

}

Measured memory_bytes: 256
mod = int(1e9+7)
def add(a, b):
    c = a + b
    if c >= mod:
        c -= mod
    return c

def main():
    #N, K = map(int,raw_input().split())
    n = int(raw_input())
    
    d = n % 10
    
    if d == 3:
        print('bon')
    elif d == 0 or d == 1 or d == 6 or d == 8:
        print('pon')
    else:
        print('hon')
        
    
main()

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

int main(){
  string S;
  cin>>S;
  int j=0;
  for(int i=0;i<(S.size()+1)/2;i++){
    if(S[i]!=S[S.size()-1-i])
      j++;
  }
  cout<<j<<endl;
}

Measured memory_bytes: 256
#include <iostream>
    #include <vector>
    #include <algorithm>
    #include <set>
    #include <cstring>
    #include <string>
    #include <stack>
    #include <tuple>
    #include <queue>
    #include <functional>
     
    using namespace std;
    typedef long long ll;
    ll MOD = 1e9 + 7;
     
    int main()
    {
        int numMountain;
        cin >> numMountain;
        vector<int> aHeight(numMountain), tHeight(numMountain);
        for (int i = 0; i < numMountain; i++) cin >> tHeight[i];
        for (int i = 0; i < numMountain; i++) cin >> aHeight[i];
        vector<pair<int, int>> heightWidth(numMountain, pair<int, int>(1, 1e9));
        int maxHeight = 0;
        for (int numOfMountain = 0; numOfMountain < numMountain; numOfMountain++)
        {
            if (tHeight[numOfMountain] > maxHeight)
            {
                maxHeight = tHeight[numOfMountain];
                heightWidth[numOfMountain] = make_pair(maxHeight, maxHeight);
            }
            else
            {
                heightWidth[numOfMountain] = make_pair(heightWidth[numOfMountain].first, maxHeight);
            }
        }
        maxHeight = 0;
        for (int numOfMountain = numMountain - 1; numOfMountain >= 0; numOfMountain--)
        {
            if (aHeight[numOfMountain] > maxHeight)
            {
                maxHeight = aHeight[numOfMountain];
                if (heightWidth[numOfMountain].first == heightWidth[numOfMountain].second && heightWidth[numOfMountain].first != maxHeight)
                {
                    cout << 0 << endl;
                    return 0;
                }
                heightWidth[numOfMountain] = make_pair(maxHeight, maxHeight);
            }
            else
            {
                heightWidth[numOfMountain] = make_pair(heightWidth[numOfMountain].first, min(heightWidth[numOfMountain].second,maxHeight));
            }
        }
        ll sum = 1;
        for (int numOfMountain = 0; numOfMountain < numMountain; numOfMountain++)
        {
            if (heightWidth[numOfMountain].first != heightWidth[numOfMountain].second && heightWidth[numOfMountain].first != 1) sum = 0;
            sum *= heightWidth[numOfMountain].second - heightWidth[numOfMountain].first + 1;
            sum %= MOD;
        }
        cout << sum << endl;
        return 0;
    }

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	vl v(5);
	cin >> n;
	REP(i, 5)cin >> v[i];
	ll m = *min_element(ALL(v));
	cout << (n + m - 1) / m  + 4 << endl;
}

Measured memory_bytes: 256
#include <utility>
#include <stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define YES(b) std::cout<< (b ? "Yes" : "No")
using namespace std;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, a[100000], b = 0, d = 0;
	cin >> n;
	REP(i, n) {
		cin >> a[i];
		if (a[i] % 4 == 0) {
			d++;
		}
		else if (a[i] % 2 == 1) {
			b++;
		}
	}
	if (n % 2 == 0) {
		YES(d >= b);
	}
	else {
		YES(d + 1 >= b);
	}
}


Measured memory_bytes: 640
import java.io.*;
import java.util.*;

public class Main { // "Main" should be used for most online judges
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int nestValue = sc.nextInt();
		int result = 0;

		for (int i = 0; i <= nestValue; i++) {
			if (maxValue(i) >= nestValue) {
				result = i;
				i = nestValue;
			}
		}

		System.out.println(result);
		sc.close();
	}

	public static int maxValue(int n) {
		int max = 0;
		for (int i = 1; i <= n; i++) {
			max += i;
		}
		return max;
	}
}

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


int main(){
  int n;
  long k;
  cin >> n >> k;
  int a[n];
  rep(i,n){
    cin >> a[i];
    a[i]--;
  }
  int flag[n];
  rep(i,n)flag[i]=0;
  int count[n+1];
  int now=0;
  int flag1=0;
  int end;
  rep(i,n){
    if(flag[now]==1){
      flag1=1;
      end=i;
      break;
    }
    flag[now]=1;
    count[now]=i;
    now=a[now];
  }
  if(flag1){
    int loop=end-count[now];
    if(k-1<=end){
      int ans=0;
      rep(i,k)ans=a[ans];
      cout << ans+1 << endl;
    }else{
      int ans=count[now]+(k-count[now])%loop;
      int answer=0;
      rep(i,ans)answer=a[answer];
      cout << answer+1 <<endl;
    }
  }else{
    int ans=0;
    rep(i,k%n)ans=a[ans];
    cout << ans+1 <<endl;
  }
  return 0;
}

Measured memory_bytes: 5980
#include <bits/stdc++.h>
using namespace std;
struct node{
	int c,lim;
	bool operator < (const node& y){
		return lim<y.lim;
	}
};
node a[200200];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i].c,&a[i].lim); 
	}
	sort(a+1,a+n+1);
	int cnt=0;
	int fg=1;
	for(int i=1;i<=n;i++){
		cnt+=a[i].c;
		if(cnt>a[i].lim){
			fg=0;
			break;
		}
	}
	if(fg){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 1792
n = int(input())

a = list(map(int, input().split()))

q = int(input())

#初期化

a_dic ={}
ans = 0

for i in a:
    if i not in a_dic:
        a_dic[i] = 1
    else:
        a_dic[i] += 1
    
    ans += i

#print(ans)
#a_sorted = sorted(a)
for i in range(q):
    #ans = 0
    b,c = map(int, input().split())
    #print(a_dic)
    
    if b in a_dic:
        if c not in a_dic:
            a_dic[c] = a_dic[b]

        else:
            tmp_c = a_dic[c]
            tmp_c += a_dic[b]
            a_dic[c] = tmp_c
        tmp_a = (c-b) * a_dic[b]
        a_dic.pop(b)
        ans += tmp_a
    print(ans)

Measured memory_bytes: 93440
#include<iostream>
#include<string>
using namespace std;
int main(){
  string word;
  getline(cin,word);
  for(int i=0; i<word.size(); i++){
    if(word[i]>='a' && word[i]<='z'){word[i]-='a'-'A';}
  }
  cout <<word<<endl;
  return 0;
}

Measured memory_bytes: 1172
#include "bits/stdc++.h"
using namespace std;
#define INF (1 << 29)

struct edge { int to, cost; };
typedef pair<int, int> P;   // firstは最短距離、secondは頂点の番号

const int MAX_V = 222222, MAX_E = 222222;

int V, E;
vector<edge> G[MAX_V];
int d[MAX_V];

bool dijkstra(int s) {
	// greater<P>を指定することでfirstが小さい順に取り出せるようにする
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + V, INF);
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0; i<G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
	if(d[V-1]==2) return true;
	else return false;
}

int main() {
	cin >> V >> E;
	for (int i = 0; i < E; i++) {
		int s, t;
		cin >> s >> t;
		s--; t--;
		G[s].push_back(edge{ t,1 });
		G[t].push_back(edge{ s,1 });
	}
	cout << (dijkstra(0)?"POSSIBLE":"IMPOSSIBLE") << endl;
}

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

using namespace std;

using pii = pair<int, int>;
using Edge = tuple<int, int, int>;
constexpr int MAX = 252521;
constexpr int INF = INT_MAX;

struct State {
    int v, cost, trans, en;
    
    State () {}
    State (int v, int cost, int trans, int en) :
        v{v}, cost{cost}, trans{trans}, en{en} {}

    bool operator < (const State& s) const {
        if (cost != s.cost) {
            return cost > s.cost;
        }
        return trans > s.trans;
    }
};

int N, T;
vector<Edge> G[MAX];

pii dijkstra()
{
    vector<pii> d(MAX, pii(INF, INF));
    
    priority_queue<State> pq;
    pq.push(State(0, 0, 0, -1));
    while (!pq.empty()) {
        auto st = pq.top(); pq.pop();
        int v = st.v, cost = st.cost, trans = st.trans, en = st.en;

        if (pii(cost, trans) > d[en]) continue;
        
        if (v == 1) {
            return d[en];
        }
        
        for (const auto& g : G[v]) {
            int to, ncost, nen;
            int ntrans = trans;
            
            tie(to, ncost, nen) = g;
            ncost += cost;
            
            if (en != -1 && abs(en - nen) > 1) {
                ncost += T;
                ntrans++;
            }
            
            if (pii(ncost, ntrans) < d[nen]) {
                d[nen] = pii(ncost, ntrans);
                pq.push(State(to, ncost, ntrans, nen));
            }
        }        
    }
    return pii(-1, -1);
}

int main()
{
    string A, B;
    map<string, int> s2i;
    int n = 0;
    
    cin >> N >> T >> A >> B;
    
    s2i[A] = 0;
    s2i[B] = 1;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        vector<int> v;
        for (int j = 0; j < a; j++) {
            string s;
            cin >> s;
            if (s2i.count(s) == 0) {
                s2i[s] = s2i.size();
            }
            v.emplace_back(s2i[s]);
        }
        for (int j = 0; j < a - 1; j++) {
            int cost;
            cin >> cost;
            G[v[j]].emplace_back(v[j + 1], cost, n + j);
            G[v[j + 1]].emplace_back(v[j], cost, n + j);           
        }
        n += a;
    }
    pii res = dijkstra();
    if (res.first == -1) {
        cout << -1 << endl;
    } else {
        cout << res.first << " " << res.second << endl;
    }
    return 0;
}

Measured memory_bytes: 21984
uses math;
var
  n,i,j,s,t:longint;
  a:array[1..1000]of longint;
begin
  readln(n);
  for i:=1 to n*2 do read(a[i]);
  for i:=1 to n*2-1 do
    for j:=i+1 to n*2 do
    if a[i]<a[j] then
    begin
      t:=a[i];
      a[i]:=a[j];
      a[j]:=t;
    end;
  for i:=1 to n do s:=s+min(a[i*2-1],a[i*2]);
  writeln(s);
end.

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
    unsigned long long int n,a[100001],mul,i,j,c;
    scanf("%llu",&n);
    for(i=0;i<n;i++)
    {
        scanf("%llu",&a[i]);
    }
    mul=1;
    c=0;
    for(i=0;i<n;i++)
    {
        if(a[i]==0)
            c++;
    }
    if(c>0)
    {
        printf("0");
        return 0;
    }
    for(i=0;i<n;i++)
    {
        if(a[i]<=1000000000000000000/mul)
           mul=mul*a[i];
        else
        {
            printf("-1");
            return 0;
        }
    }
    printf("%llu\n",mul);
    return 0;
}


Measured memory_bytes: 2480
A,B,M = list(map(int, input().split()))

PA = list(map(int, input().split()))
PB = list(map(int, input().split()))

x = [0] * M
y = [0] * M
c = [0] * M

for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())

total = [0] * M

#　割引のMAXを求める
# dct = sorted(c, reverse=True)
# p rint(dct)

for k in range(M):
        # 割引パターン
        total[k] = (PA[x[k]-1] + PB[y[k]-1]) - c[k]

# なしパターン
ntotal = min(PA) + min(PB)
# ありパターン
ytotal = min(total)

if ntotal > ytotal:
        print(ytotal)
else:
        print(ntotal)




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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int N, M, K; cin >> N >> M >> K;
    vector<int> A(M), B(M), C(K), D(K);
    for(int i = 0; i < M; i++) cin >> A[i] >> B[i];
    for(int i = 0; i < K; i++) cin >> C[i] >> D[i];
    //vector<vector<int>> VF(N+1, vector<int>(N+1));
    vector<vector<int>> VF(N+1);
    UnionFind tree(N+1);
    for(int i = 0; i < M; i++){
        VF[A[i]].push_back(B[i]);
        VF[B[i]].push_back(A[i]);
        tree.unite(A[i], B[i]);
    }
    for(int i = 0; i < K; i++){
        if(tree.same(C[i], D[i])){
            VF[C[i]].push_back(D[i]);
            VF[D[i]].push_back(C[i]);
        }
        
    }
    vector<int> GN(N+1);
    for(int i = 1; i < N+1; i++){
        int r = tree.root(i);
        GN[r]++;
    }
    for(int i = 1; i <= N; i++){
        int r = tree.root(i);
        GN[i] = GN[r];
    }

    for(int i = 1; i < N+1; i++){
        int n = VF[i].size();
        int cnt = 0;
        //for(int j = 0; j < n; j++){
        //    int x = VF[i][j];
        //    if(tree.same(i, x)) cnt++;
        //}
        cout << GN[i] - n - 1 << " ";
    }
    cout << endl;
}

Measured memory_bytes: 9976
#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i,n) for(int (i)=0, i##_len = (n);(i)<i##_len;(i)++)
#define reps(i,x) for(int (i)=1;(i)<=(int)(x);(i)++)
#define rrep(i,x) for(int (i)=((int)(x)-1);(i)>=0;(i)--)
#define rreps(i,x) for(int (i)=((int)(x));(i)>0;(i)--)
#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1)<<(n))
#define all(x) (x).begin(),(x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl 

using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
typedef pair<int,int> p;
typedef pair<double,double> dop;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;


signed main()
{
int n;
int sum = 0;
int max = 0;
std::cin >> n;
for(int i = 0; i < n; i++){
    int temp;
    std::cin >> temp;
    if(temp > max){
        max = temp;
    }
    sum += temp;
}
std::cout << sum - max/2 << std::endl;
return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9

def main():
    n = int(input())
    k = int(input())

    num = 1
    for i in range(n):
        if num < k:
            num *= 2
        else:
            num += k
    print(num)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62136
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

int getMinCost(const std::vector<int> heights, const int max_jump) {
  std::vector<int> dp(heights.size() + 10, 0);
  dp[0] = 0;

  for (int i = 1; i < static_cast<int>(heights.size()); ++i) {
    const int h1 = std::abs(heights[i] - heights[i - 1]);
    dp[i] = h1 + dp[i - 1];
    for (int j = 2; j <= max_jump; ++j) {
      const int index = i - j;
      if (index >= 0) {
        const int h2 = std::abs(heights[i] - heights[index]);
        dp[i] = std::min(dp[i], h2 + dp[index]);
      }
    }
  }
  return dp[heights.size() - 1];
}

int main() {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> heights(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> heights[i];
  }
  std::cout << getMinCost(heights, k) << std::endl;
  return 0;
}

Measured memory_bytes: 1408