akhauriyash/Code-Regression huggingface dataset:
import Data.List
import qualified Data.Map as Map

scan :: [Int] -> Int
scan l = iter 0 (load l) where
    iter c m
        | Map.null m = c
        | otherwise  =
            if Map.member y m1
                then iter (c+1) (remove y m1)
                else iter c m1
                where
                    (x,_) = Map.findMax m
                    m1 = remove x m
                    y = iter 2 where
                            iter p
                                | x < p = p - x
                                | otherwise = iter (p*2)
    load = iter Map.empty where
        iter m [] = m :: Map.Map Int Int
        iter m (x:xs) = case Map.lookup x m of
            Just n  -> iter (Map.update (\n -> Just (n+1)) x m) xs 
            Nothing -> iter (Map.insert x 1 m) xs
    remove x m = case Map.lookup x m of
        Just 1  -> Map.delete x m
        Just n  -> Map.update (\n -> Just (n-1)) x m
        Nothing -> m
    
readData :: IO [Int]
readData = do
    line1 <- getLine
    let xs = map (\x -> read x :: Int) (words line1)
    return xs

main :: IO() 
main = do
    n  <- readLn :: IO Int
    la <- readData
    let ans = scan la
    print ans

Measured memory_bytes: 108924
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};


map<ll, ll>mp;
int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    ll N, M; cin >> N >> M; ll ret = 0;
    vector<ll> A(N+1, 0), prefix(N+1, 0);
    
    for(int i = 1; i <= N; i++)
        cin >> A[i];
    
    for(int i = 1; i <= N; i++)
        prefix[i] = prefix[i-1] + A[i];
    
    mp[0] = 1;
    for(int i = 1; i <= N; i++)
    {
        ll r = prefix[i] % M;
        ret += mp[r];
        mp[r] += 1;
    }
    
    cout << ret << endl;
    
    return 0;
}


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

int main(){
  int a,b,c;
  int answer;
  cin >> a >> b >> c;
  if(a==b && b==c)
    answer = 1;
  else if(a!=b && b!=c &&c!=a)
    answer = 3;
  else
    answer = 2;
  cout << answer << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            sS = Console.ReadLine().Trim().Split(' ');
            int iMut4 = 0;
            int iNot4 = 0;
            int iNot2 = 0;
            for (int i = 0; i < sS.Length; i++)
            {
                int iTmp = int.Parse(sS[i]);
                if (iTmp % 4 == 0) { iMut4 += 1; }                  // 4の倍数の数
                else { iNot4 += 1; }                                // 4の倍数以外の数
                if (iTmp % 2 != 0) { iNot2 += 1; }                  // 奇数の数
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "No";
            if (iMut4 + 1 >= iNot4) { sOut = "Yes"; }                               // 4の倍数がそれ以外より-1以上多いか？
            if (iMut4 >= iNot2)     { sOut = "Yes"; }                               // 4の倍数が奇数以上か？
            if (iMut4 + 1 == iNot2 && iMut4 + iNot2 == sS.Length) { sOut = "Yes"; } // 奇数が4の倍数より1多くてそれ以外存在しない場合か？
            if (iNot2 == 0)              { sOut = "Yes"; }                          // 全部が偶数

            //出力
            Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 20192
package main

import "fmt"

func main() {
	var k, s, z int
	fmt.Scan(&k, &s)

	ans := 0
	for x := 0; x <= k; x++ {
		for y := 0; y <= k; y++ {
			z = s - x - y
			if 0 <= z && z <= k {
				ans++
			}
		}
	}

	fmt.Println(ans)
}


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

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

# 本来の各柱の高さリスト
columns = [(i ** 2 + i) // 2 for i in range(1, 1000)]

for i in range(998):
    ab = columns[i+1] - columns[i]
    # 本来の柱と今見えている柱で差が一致する所を探す
    if ab == b - a:
        print(columns[i] - a)
        exit()

Measured memory_bytes: 3060
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>
#include <random>

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

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

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

random_device seed_gen;
mt19937 engine(seed_gen());
// 0, 1, 2 のどれかが得られる一様分布
// uniform_int_distribution<> dist(0, 2);
// cout << dist(engine) << endl;
// みたいに、先に確率分布を宣言して、そこにengineを与えて使う。

// =========ここまでテンプレ============

int main()
{
  vector<bool> aho(60000000000,true);
    ll n, x, t;
    cin >> n >> x >> t;
    ll m = n / x;
    if (n % x != 0)
    {
        ++m;
    }
    cout << t * m << endl;
    return 0;
}


Measured memory_bytes: 3196
num = input()
num = int(num)

s = input().split()

list = []
for i in range(num):
    x = int(s[i])
    list.append(x)

for i in range(num-1,-1,-1):
    print(list[i],sep="",end="")
    if i!=0:
        print(" ",sep="",end="")

print()



Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
class disjoint_set {
  public:
    vector<int> rank, p, cnt;
    vector<long long> wt;
    disjoint_set (int size) {
      rank.resize(size, 0);
      p.resize(size, 0);
      for (int i = 0; i < size; i++) {
        p[i] = i;
        rank[i] = 0;
      }
      wt.resize(size, 0);
      cnt.resize(size, 0);
    }
    void initWt (int x, int w) {
      wt[x] = w;
    }
    long long getWt (int x) {
      return wt[find(x)];
    }
    void addCnt (int x) {
      cnt[find(x)]++;
    }
    void clrCnt (int x) {
      cnt[find(x)] = 0;
    }
    int getCnt (int x) {
      return cnt[find(x)];
    }
    bool is_equiv (int x, int y) {
      return find(x) == find(y);
    }
    void unite (int x, int y) {
      x = find(x);
      y = find(y);
      if (x == y) {
        return;
      }
      if (rank[x] > rank[y]) {
        p[y] = x;
        wt[x] += wt[y];
        cnt[x] += cnt[y];
      } else {
        p[x] = y;
        wt[y] += wt[x];
        cnt[y] += cnt[x];
        if (rank[x] == rank[y]) {
          rank[y]++;
        }
      }
    }
    int find (int x) {
      if (x != p[x]) {
        p[x] = find(p[x]);
      }
      return p[x];
    }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  disjoint_set djs(n);
  for (int i = 0; i < n; i++) {
    int w;
    cin >> w;
    djs.initWt(i, w);
  }
  vector<pair<int, pair<int, int>>> edg(m);
  for (int i = 0; i < m; i++) {
    int a, b, w;
    cin >> a >> b >> w;
    a--;
    b--;
    edg[i] = {w, {a, b}};
  }
  sort(edg.begin(), edg.end());
  int usd = 0;
  for (int i = 0; i < m; i++) {
    auto e = edg[i];
    int w = e.first;
    int a = e.second.first;
    int b = e.second.second;
    djs.unite(a, b);
    djs.addCnt(a);
    if (w <= djs.getWt(a)) {
      usd += djs.getCnt(a);
      djs.clrCnt(a);
    }
  }
  int ans = m - usd;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3456
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn dijk(tree: &Vec<Vec<(usize, i64, i64)>>, s: usize, x: i32) -> Vec<i64> {
    let mut res = vec![-1; tree.len()];
    let mut q = std::collections::BinaryHeap::new();
    use std::cmp::Reverse;
    res[s] = 0;
    q.push((Reverse(0), s));
    while let Some((Reverse(c), u)) = q.pop() {
        if res[u] != c {
            continue;
        }
        for &(v, a, b) in &tree[u] {
            let x = c + if x == 0 { a } else { b };
            if res[v] != -1 && res[v] <= x {
                continue;
            }
            res[v] = x;
            q.push((Reverse(x), v));
        }
    }
    res
}

fn main() {
    input! {
        n: usize,
        m: usize,
        s: Usize1,
        t: Usize1,
        uvab: [(Usize1, Usize1, i64, i64); m],
    }

    let mut tree = vec![vec![]; n];
    for (u, v, a, b) in uvab {
        tree[u].push((v, a, b));
        tree[v].push((u, a, b));
    }

    let from_s = dijk(&tree, s, 0);
    let from_t = dijk(&tree, t, 1);

    let mut res = vec![0; n];

    let mut mx = 0;
    for i in (0..n).rev() {
        let x = 1_000_000_000_000_000;
        mx = std::cmp::max(mx, x - from_s[i] - from_t[i]);
        res[i] = mx;
    }

    for res in res {
        println!("{}", res);
    }
}


Measured memory_bytes: 17352
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using static System.Math;
using Debug = System.Diagnostics.Debug;

class P
{
    static void Main()
    {
        var nm = Console.ReadLine().Split().Select(int.Parse).ToList();
        var abs = Enumerable.Repeat(0, nm[1]).Select(_ => Console.ReadLine().Split().Select(int.Parse).ToList()).ToList();
        List<long> res = new List<long>();
        UnionFind uf = new UnionFind(nm[0]);
        long now = (long)nm[0] * (nm[0] - 1) / 2;
        foreach (var ab in abs.Reverse<List<int>>())
        {
            res.Add(now);
            long acount = uf.GetSize(ab[0] - 1);
            long bcount = uf.GetSize(ab[1] - 1);
            if (uf.Unite(ab[0] - 1, ab[1] - 1))
            {
                now -= acount * bcount;
            }
        }
        res.Reverse();
        Console.WriteLine(string.Join("\n", res));
    }
}


class UnionFind
{
    public int Size { get; private set; }
    List<int> parent;
    List<int> sizes;
    public UnionFind(int count)
    {
        Size = 0;
        parent = new List<int>(count);
        sizes = new List<int>(count);
        ExtendSize(count);
    }
    public bool Unite(int x, int y)
    {
        int xp = Find(x);
        int yp = Find(y);
        if (yp == xp) return false;
        if (sizes[xp] < sizes[yp])
        {
            var tmp = xp;
            xp = yp;
            yp = tmp;
        }
        parent[yp] = xp;
        sizes[xp] += sizes[yp];
        return true;
    }
    public IEnumerable<int> AllParents => parent.Where(x => x == parent[x]);
    public int GetSize(int x) => sizes[Find(x)];
    public int Find(int x) => parent[x] == parent[parent[x]] ? parent[x] : parent[x] = Find(parent[x]);
    public void ExtendSize(int treeSize)
    {
        if (treeSize <= Size) return;
        parent.Capacity = treeSize;
        sizes.Capacity = treeSize;
        while (Size < treeSize)
        {
            parent.Add(Size);
            sizes.Add(1);
            Size++;
        }
    }
}

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

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define sz(v) ll(v.size())

int main(){
    int n;
    cin>>n;
    if (n<=999){
        cout<<"ABC";
    }else{
        cout<<"ABD";
    }
}

Measured memory_bytes: 256
n=int(input())
ans=0
count=0
for i in range(n+1):
    if i%2==0:
        continue
    else:
        for j in range(i+1):
            if j==0:
                continue
            else:
                if i%j==0:
                    count+=1
            #print(j,count)
            if j==i:
                if count==8:
                    ans+=1
                    count=0
                else:
                    count=0
print(ans)

Measured memory_bytes: 3060
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for x in range(N)]

x_max = [0]
x_min = [W]
y_max = [0]
y_min = [H]

for i in range(N):
    if xya[i][2] == 1:
        x_max.append(xya[i][0])
    if xya[i][2] == 2:
        x_min.append(xya[i][0])
    if xya[i][2] == 3:
        y_max.append(xya[i][1])
    if xya[i][2] == 4:
        y_min.append(xya[i][1])

x_1 = max(x_max)
x_2 = min(x_min)
y_3 = max(y_max)
y_4 = min(y_min)

if x_2 - x_1 > 0 and y_4 - y_3 > 0:
    print((x_2 - x_1) * (y_4 - y_3))
else :
    print(0)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
#if !DEBUG
    using System.IO;
#endif

public class Program {

    static int[] arr;
    static List<string> answers = new List<string>();
    static void Calculate(int p, bool isPlus, string history, int remainN) {
        if (p > 3) {
            if (remainN == 0) {
                answers.Add(history);
            }
            return;
        }

        if (p != 0) {
            history += isPlus ? "+" : "-";
        }

        history += arr[p].ToString();

        var nextRemainN = isPlus ? remainN - arr[p] : remainN + arr[p];

        Calculate(p + 1, true, history, nextRemainN);
        Calculate(p + 1, false, history, nextRemainN);
    }

    public static void Main() {
        #region SetAutoFlushIsFalse
#if !DEBUG
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
#endif
        #endregion
        arr = Console.ReadLine().Select(i => int.Parse(i.ToString())).ToArray();
        Calculate(0, true, "", 7);
        var answer = answers.First();
        Console.WriteLine(answer + "=7");
        #region Flush
#if !DEBUG
        Console.Out.Flush();
        sw.Close();
#endif
        #endregion
    }
}


static class ReadLib {
    public static long ReadAsLong() {
        return long.Parse(Console.ReadLine());
    }

    public static int ReadAsInt() {
        return int.Parse(Console.ReadLine());
    }

    public static int[] ReadAsIntArray() {
        return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
    }

    public static string[] ReadAsStringArray() {
        return Console.ReadLine().Split(' ');
    }

    public static int[] ReadNTimesAsInt(int n) {
        return Enumerable.Range(1, n).Select(s => int.Parse(Console.ReadLine())).ToArray();
    }
}

Measured memory_bytes: 13396
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
using namespace std;
int main(){
	
	string str;
	int a;
	int k=0;
	map<string,int> data;
	vector<string> s;
	vector< vector<int> > p(1000); 
	
	while(cin>>str>>a){
		if(data.find(str)==data.end()){
			data[str]=k++;
			s.push_back(str);
		}
		p[data[str]].push_back(a);
		
	}
	sort(s.begin(),s.end());
	
	for(int i=0;i<s.size();i++){
		cout<<s[i]<<endl;
		sort(p[data[s[i]]].begin(),p[data[s[i]]].end());
		cout<<p[data[s[i]]][0];
		for(int j=1;j<p[data[s[i]]].size();j++)
			cout<<" "<<p[data[s[i]]][j];
		cout<<endl;
	}
}

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

int main(){
  int N;
  cin >> N;
  vector<int> vec(100);
  vec[0]=1;
  int a;
  int cnt=0;
  for(int i=1;;i++){
    a=pow(6,i);
    if(a>N){
      break;
    }
    cnt++;
    vec[cnt]=a;
  }
  for(int i=1;;i++){
    a=pow(9,i);
    if(a>N){
      break;
    }
    cnt++;
    vec[cnt]=a;
  }
  sort(vec.begin(),vec.end(),greater<int>());
  vector<int> dp(100010,200000);
  dp[0]=0;
  for(int i=0;i<=N;i++){
    for(int j=cnt;j>=0;j--){
      if(i<vec[j]){
        break;
      }
      dp[i]=min(dp[i-vec[j]]+1,dp[i]);
    }
  }
  cout << dp[N] <<endl;
}

Measured memory_bytes: 4256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

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

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
var array = lines[0];
var n1 = array.indexOf(1);
if (n1 !== -1) {
var n2 = array .indexOf(9);
 if (n2 !== -1){
 var n3 = array .indexOf(7);
  if (n3 !== -1){
 var n4 = array .indexOf(4);
 if (n4 !== -1){
console.log("YES");
} else {
console.log("NO");
}
} else {
console.log("NO");
}

} else {
console.log("NO");
}

} else {
console.log("NO");
}

});

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

#define REP(i,n) for(ll i=0; i < (n); ++i)
#define REPR(i,n) for(ll i=(n); i >= 0; --i)
#define FOR(i, m, n) for(ll i = (m); i < (n); ++i)

#define INF 1e9

int N;
vector<int> x, y;
vector<int> homon;
double ans = 0;
int cnt = 0;
void dfs(double dist, int pos){
  homon[pos] = 1;
  bool flag = true;
  REP(i, N){
    if(homon[i] == 0){
      double d = sqrt((x[pos] - x[i]) * (x[pos] - x[i])+(y[pos] - y[i])*(y[pos] - y[i]));
      dfs(dist+d, i);
      flag = false;
    }
  }
  if(flag){
    ans += dist;
    cnt++;
  }
  homon[pos] = 0;
}
int main(){
  cin >> N;
  x.resize(N), y.resize(N), homon.resize(N, 0);
  REP(i, N){
    cin >> x[i] >> y[i];
  }
  REP(i, N){
    dfs(0, i);
  }
  printf("%.10f\n", ans/cnt);
  return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseFloat(x) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    x1,y1,x2,y2=parseMap(split(readline()))
    println("$(x2-(y2-y1)) $(y2+x2-x1) $(x1-(y2-y1)) $(x2-x1+y1)")
end
main()

Measured memory_bytes: 112392
s = gets.chomp.to_i
MOD = 1000000007
dp = Array.new(s+1, 0)
dp[0] = 1
(1..s).each do |i|
    ((i-3)+1).times do |j|
        dp[i] += dp[j]
        dp[i] %= MOD
    end if (i-3)+1 > 0
end

puts dp[s]

Measured memory_bytes: 14336
#include<stdio.h>

void prans(int tsm,int t){
  if(tsm<t){
    printf("%d\n",t-tsm);
  }
  else{
    printf("OK\n");
  }
}

int sumup(int n){
  if(n!=0){
    int st,et;
    scanf("%d %d",&st,&et);
    return (et-st)+sumup(n-1);
  }
  else{
    return 0;
  }
}

void doit(){
  int t;
  scanf("%d",&t);
  if(t!=0){
    int n;
    int stm;
    scanf("%d",&n);
    stm=sumup(n);
    prans(stm,t);
    doit();
  }
}

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

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

int main(){
  string S;
  cin >> S;
  
  bool flg=1;
  for(int i=0; i<S.size(); i+=2){
    if(S.at(i)=='L'){
      flg = 0;
      break;
    }
  }
  for(int j=1; j<S.size(); j+=2){
    if(S.at(j)=='R'){
      flg = 0;
      break;
    }
  }
  cout << (flg ? "Yes" : "No") << endl;
  
  return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
def cmb(n, r, mod):#コンビネーションの高速計算　
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 4*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

if n>k:
    print(sum(cmb(n,k-i,mod)*cmb(n-1,k-i,mod) for i in range(0,k+1))%mod)

else:
    print(cmb(2*n-1,n,mod))


Measured memory_bytes: 118764
#include<stdio.h>
 int main(void)
 {
     int A,B,C,D;

     scanf("%d%d%d%d",&A,&B,&C,&D);

     if(B>C){
       if(A>D) { printf("0\n"); return 0; }
       if((A>=C)&&(B>=D)){
         printf("%d\n",D-A); return 0;
       }
       if((A>=C)&&(B<=D)){
         printf("%d\n",B-A); return 0;
       }
       if((A<=C)&&(B<=D)){
         printf("%d\n",B-C); return 0;
       }
       if((A<=C)&&(B>=D)){
         printf("%d\n",D-C); return 0;
       }
     }

     else { printf("0\n"); return 0; }

 }


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	int A1, A2, A3;
	//long long N, M;
	//double d, e;
	//string s, t;
	//vector<int> v;
	//vector<pair<int, int>> pl;

	//while() {}
	//for(int i=0; i<N; i++) {}
	
	cin >> A1 >> A2 >> A3;
	cout << ((A1+A2+A3)>21 ? "bust" : "win");
	// cout << "[deb: val ]" << val <<endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

map<string, int> mp;
int jg(int a, int b, int c, int d) {
    int ans = 0;
    ans = abs(c - a) + abs(d - b);
    return ans;
}
int a[50]; int b[50];
int c[50]; int d[50];
int main() {
    int n, m;
    cin >> n >> m;
    int a[50]; int b[50];
    int c[50]; int d[50];
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> c[i] >> d[i];
    }
    for (int i = 0; i<n; i++) {
        int ans;
        int cnt = 2100000000;
        for (int j = m - 1; j >= 0; j--) {
            if (cnt >= abs(a[i] - c[j]) + abs(b[i] - d[j])) {
                ans = j + 1;
                cnt = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            }
        }
        cout << ans << endl;
    }
}

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

const int MOD = (int)1e9+7;

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

int main(){
  int N,X;
  cin >> N >> X;
  vector<int> x(N);
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    x.at(i)=abs(X-a);
  }

  int ans=x.at(0);
  for(int i=1;i<N;i++){
    ans=gcd(ans,x.at(i));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>

const int size = 300000;

bool a[size]={false};
std::vector<int> MS;

void eratos(){

	for(int i=6; i<size; i++)
		a[i] = true;
		
	for(int i=6; i<size; i++){
	
		if(a[i] && (i%7 == 1 || i%7 == 6)){
		
			MS.push_back(i);
			for(int j=i+i; j<size; j+=i)
				a[j] = false;
				
		}else
			a[i] = false;
	}
	
}

void solve(int x){
	std::vector<int>::iterator it = MS.begin();
	
	std::cout << x << ':';

	for(; it != MS.end(); ++it)
		if(x % (*it) == 0)
			std::cout << ' ' << *it;

	std::cout << std::endl;

}

int main(){
	int x;

	eratos();
	
	while(true){
	
		std::cin >> x;
		
		if(x == 1)
			break;
		
		solve(x);
		
	}
	
	return 0;
}

Measured memory_bytes: 1464
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+5;
int a[maxn],r[maxn],b[maxn];// r记录传送城市信息，b记录城市出现顺序 默认城市1为0 
int n,p=1,cnt,be,len;
ll k;
int main()
{
   cin>>n>>k;
   for(int i=1;i<=n;i++) cin>>a[i];
   while(1)
   {
   	  if(b[a[p]]!=0)
   	  {
   	  	be=b[a[p]];
   	  	len=cnt-be+1;
   	  	break;
		 }
	  r[++cnt]=a[p];
	  b[a[p]]=cnt;
	  p=a[p];
	   
   }
   if(k<=be) cout<<r[k];
   else
      {
      	  int s=(k-be)%len;
			cout<<r[s+be]; 
	  } 

return 0;
}


Measured memory_bytes: 5908
#include<stdio.h>
#define N 100
#define INF 1000000
#define WHITE 0
#define BLACK 2

int A[N][N],k,T[N],d[N],color[N],x,min,v,c;

void shortest(){

  int i,j,u;
  
  for(i=0;i<x;i++){
    d[i]=INF;
    color[i]=WHITE;
  }
  d[0]=0;
  while(1){
    min = INF;
    u=-1;
    for(i=0;i<x;i++){
      if(min >d[i] && color[i]!=BLACK){
	u=i;
	min=d[i];
      }
    }
    if(u==-1) break;
    color[u]=BLACK;
    for(i=0;i<x;i++){
      if(color[i] != BLACK && A[u][i] != INF && d[i] > d[u] + A[u][i]){

	  d[i] = d[u] + A[u][i];

	
      }
    }
  }
  for(i=0;i<x;i++){
    printf("%d %d\n",i,d[i]);
  }
  
}

int main(){

  int i,j,u;

  scanf("%d",&x);

  for(i=0;i<x;i++){
      for(j=0;j<x;j++){
	A[i][j]=INF;
      }
  }

  for(i=0;i<x;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      A[u][v]=c;
    }
  }

  shortest();

  
  return 0;
  
}



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

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

  vector<int> v(n + 1, 0);
  for (int i = 1; i <= m; i++) {
    int from, to;
    cin >> from >> to;
    v[from]++;
    v[to]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << v[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
private fun readStrings() = readLine()!!.split(" ")
private fun readInts() = readStrings().map { it.toInt() }

fun getCost(a: Int, b: Int) = Math.abs(a - b)
fun Pair<Int, Int>.getCost() = getCost(first, second)

fun computeMiddleOmitDiff(a: Int, b: Int, c: Int) = getCost(a, c) - (getCost(a, b) + getCost(b, c))

inline fun <T> T.also(block: (T) -> Unit): T { block(this); return this }

fun <T> List<T>.pairAdjacent() = iterator().pairAdjacent()
fun <T> Iterator<T>.pairAdjacent() = when {
    hasNext() -> {
        var prev = next()
        asSequence().map { elem -> (prev to elem).also { prev = elem } }
    }
    else -> sequenceOf()
}

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = readInts()

    val paths = listOf(0) + A + listOf(0)
    val totalCost = paths.pairAdjacent().map { it.getCost() }.sum()

    (1 until N+1).forEach { index ->
        val (a, b, c) = listOf(index - 1, index, index + 1).map { paths[it] }
        println(totalCost + computeMiddleOmitDiff(a, b, c))
    }
}

Measured memory_bytes: 62564
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int c, d, w, x;
int gain[16][40];
int fuel[16][40];
int eSum[16][16][40];
int fSum[16][16][40];

int memo[40][6][60];
int calc(int day, int rest, int w) {
  if (w < 0 || rest < 0) { return -10000000; }
  if (day == d) { return 0; }
  if (memo[day][rest][w] != -1) { return memo[day][rest][w]; }
  int ret = calc(day + 1, rest, w);
  REP(i, c) {
    ret = max(ret, calc(day + 1, rest, w - fuel[i][day]) + gain[i][day]);
  }
  REP(e, c) {
    REP(s, e + 1) {
      ret = max(ret, calc(day + 1, rest - 1, w - fSum[s][e][day]) + eSum[s][e][day]);
    }
  }
  return memo[day][rest][w] = ret;
}

int main() {
  while (scanf("%d %d %d %d", &c, &d, &w, &x), c|d|w|x) {
    MEMSET(memo, -1);
    MEMSET(eSum, 0);
    MEMSET(fSum, 0);
    REP(y, c) {
      REP(x, d) {
        scanf("%d", &gain[y][x]);
      }
    }
    REP(y, c) {
      REP(x, d) {
        scanf("%d", &fuel[y][x]);
      }
    }
    REP(e, c) {
      REP(s, e + 1) {
        REP(day, d) {
          FOREQ(i, s, e) {
            if (gain[i][day] == 0) {
              eSum[s][e][day] -= 100000;
              fSum[s][e][day] += 100;
            } else {
              eSum[s][e][day] += gain[i][day];
              fSum[s][e][day] += fuel[i][day];
            }
          }
        }
      }
    }
    printf("%d\n", calc(0, x, w));
  }
}

Measured memory_bytes: 0
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <tuple>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long int ll;
using namespace std;

int main() {
	
	string s;
	cin >> s;
	string yn[2] = {"NO","YES"};
	
	bool ans = 0;
	while(1)
	{
		if(s.size() == 0){	ans = true;	break;}
		else if(s.size() > 4 && s.substr(s.size()-5,5) == "dream"){	s = s.substr(0,s.size()-5);	}
		else if(s.size() > 6 && s.substr(s.size()-7,7) == "dreamer"){	s = s.substr(0,s.size()-7);	}
		else if(s.size() > 4 && s.substr(s.size()-5,5) == "erase"){	s = s.substr(0,s.size()-5);	}
		else if(s.size() > 5 && s.substr(s.size()-6,6) == "eraser"){	s = s.substr(0,s.size()-6);	}
		else{	ans = false;	break;}
	}
	
	cout << yn[ans] << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <map>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; ++i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

int main() {
	char a, b;
	scanf("%c %c", &a, &b);
	if (a == 'H') {
		if (b == 'H') printf("H\n");
		else printf("D\n");
	}
	else {
		if (b == 'H') printf("D\n");
		else printf("H\n");
	}
	return 0;
}

Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
c=0
for i in range(n):
  for j in range(i+1, n ):
    for k in range(j+1, n ):
    
        if abs(l[j]-l[k])<l[i] and l[i]<l[j]+l[k] and l[i]!=l[j]and l[j]!=l[k] and l[i]!=l[k]:
            c+=1
            

print(c)

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  string s;
  cin>>s;
  REP(i,s.size())
    cout<<"x";
  cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize(2)

using namespace std;

#define LL long long
#define Re register
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define pb push_back
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dir[4][2]={1,0,0,1,-1,0,0,-1};
int n;
LL a[maxn],b[maxn];
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
   	cout.tie(0);
    cin>>n;
    for(int i=1;i<=n+1;i++)
    {
        cin>>a[i];
    }
    LL ans=0;
    for(int i=1;i<=n;i++)
    {
        cin>>b[i];
        if(b[i]>=a[i])
        {
            ans+=a[i];
            b[i]-=a[i];
            if(b[i]>=a[i+1])
            {
                ans+=a[i+1];
                a[i+1]=0;
            }
            else
            {
                ans+=b[i];
                a[i+1]-=b[i];
            }
        }
        else
        {
            ans+=b[i];
        }
    }
    cout<<ans;
	return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
    int N,D;
    cin >> N >> D;
    int X[20][20];

    for(int i = 0; i < N; i++){
        for(int j = 0; j < D; j++){
            cin >> X[i][j];
        }
    }

    int ans = 0;
    double dist_abs;
    for(int k =0; k < N-1; k++){
        for(int l = k+1; l < N; l++){
            dist_abs = 0;
            for(int z = 0; z < D; z++){
                dist_abs += abs( X[k][z] - X[l][z] ) * abs( X[k][z] - X[l][z] );
            }
            dist_abs = sqrt(dist_abs);
            if(dist_abs == int(dist_abs))
                ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 2e9;

int main() {
  string s;
  int k;
  cin >> s >> k;
  vector<string> res;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= k; j++) res.emplace_back(s.substr(i, j));
  }
  sort(res.begin(), res.end());
  res.erase(unique(res.begin(), res.end()), res.end());
  cout << res[k - 1] << endl;
  return 0;
}

Measured memory_bytes: 4348
#include <iostream>

using namespace std;

int main(){
  while(true){
  int m,nmin,nmax;
  cin >> m >> nmin >> nmax;
  if(m==0)break;
  int list[m];
  for(int i=0;i<m;i++){
    cin >> list[i];
  }
  int gap=0,c;
  for(int i=nmin-1;i<nmax;i++){
    if(list[i]-list[i+1]>=gap){
      gap=list[i]-list[i+1];
      c=i+1;
    }
  }
  cout << c << endl;
  }
  return 0;
}

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

#define ll long long



void solve(){
    int a[3]; cin>>a[0]>>a[1]>>a[2];
    int cnt1=0; int cnt2=0;
    for(int i=0; i<3; i++){
        if(a[i]==5)cnt1++;
        if(a[i]==7)cnt2++;
    }
    if(cnt1==2 && cnt2==1){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
import numpy as np

def main():
    N,K = map(int,input().split())
    A = [0]
    A += list(map(int,input().split()))
    A = np.array(A)
    
    i = 1
    pas = np.zeros(N)
    pas[0] = i
    k = 1
    pass_set = set(pas)
    while k <= K:
        if A[i] in pass_set:
            rps = np.where(pas==(A[i]))[0]
            ans = A[i]
            break
        pas[k] = A[i]
        pass_set.add(A[i])
        ans = A[i]
        i = A[i]
        k += 1

    if k >= K:
        print(ans)
    else:
        rpnum = (K-rps[0])%(k-rps)
        print(int(pas[rps[0]+rpnum]))

main()

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

int main() {

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int n;
    cin>>n;
    vector<int> arr(n);
    for(int i = 0; i < n; i++)
    	cin>>arr[i];

    make_heap(arr.begin(), arr.end());
    int aSum = 0, bSum = 0;
    while(!arr.empty()) {
    	//cout<<aSum<<" "<<bSum<<endl;
    	aSum += arr.front();
    	pop_heap(arr.begin(), arr.end());
    	arr.pop_back();
    	if(!arr.empty()) {
    		bSum += arr.front();
    		pop_heap(arr.begin(), arr.end());
    		arr.pop_back();
    	}
    }
    int ans = (aSum - bSum);
    cout<<ans;
	return 0;		
}


Measured memory_bytes: 256
N = int(input())
A = []
for i in range(5):
    A.append(int(input()))

neck_idx = -1
neck = -1
for i in range(5):
    if min(A) == A[i]:
        neck_idx = i
        neck = A[i]
        break

x = N // neck
if N % neck > 0:
    x += 1

print(x + 4)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iostream>
#include <numeric>
using namespace std;
int main(){
    ios::sync_with_stdio(false), cin.tie(0);
    long long n;
    cin>>n;
    long long x=1;
    for(long long i=1;i<=n;i++){
        x*=i;
    }
    cout<<x<<endl;
	return 0;
}



Measured memory_bytes: 3136
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
bool ok(string s){
	rep(i,sz(s)){
		if(s[i]!=s[sz(s)-1-i])
		re false;
	}
	re true;
}
int main(){
	ios::sync_with_stdio(0);
	string s;
	cin>>s;
	if(ok(s)&&ok(s.substr(0,sz(s)/2))&&ok(s.substr((sz(s)+1)/2)))
	cout<<"Yes";
	else
	cout<<"No";
	re 0;
}

Measured memory_bytes: 256
N = gets.to_i
S = Array.new(N + 1, 0)
gets.split.map(&:to_i).each_with_index do |w, i|
  S[i + 1] = S[i] + w
end
puts (1 .. N).map{|i| (S[N] - 2 * S[i]).abs }.min


Measured memory_bytes: 1788
using System;
using System.IO;

namespace ABC118A
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().calc();
        }

        void calc()
        {
            var temp = Console.ReadLine().Split(' ');
            int a = int.Parse(temp[0]);
            int b = int.Parse(temp[1]);

            if (b % a == 0)
            {
                Console.WriteLine(a + b);
            }
            else
            {
                Console.WriteLine(b - a);
            }
        }
    }
}


Measured memory_bytes: 13140
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using P = pair<int, int>;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> City[N + 1];
  int P[M], Y[M];
  for (int i = 0; i < M; i++) {
    int p, y;
    cin >> p >> y;
    City[p].push_back(y);
    P[i] = p, Y[i] = y;
  }

  for (int i = 0; i < N + 1; i++) sort(all(City[i]));

  for (int i = 0; i < M; i++) {
    auto iter = upper_bound(all(City[P[i]]), Y[i]);
    cout << setfill('0') << right << setw(6) << P[i] << setfill('0') << right
         << setw(6) << iter - City[P[i]].begin() << endl;
  }

  return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

struct Edge{
	int to,cost;
};

const int MAX_N=100000;
int n,m,k,q,f[MAX_N],d[MAX_N],par[MAX_N];
vector<Edge> g[MAX_N];
unordered_set<int> s[MAX_N];


void Dijkstra(){
	fill_n((int*)d,MAX_N,INF);
	priority_queue<pii,vector<pii>,greater<pii>> que;
	rep(i,0,k){
		d[f[i]]=0;
		que.push(mp(0,f[i]));
	}

	while(!que.empty()){
		pii p=que.top(); que.pop();
		if(d[p.second]<p.first) continue;

		for(auto &e:g[p.second]){
			if(d[e.to]>d[p.second]+e.cost){
				d[e.to]=d[p.second]+e.cost;
				que.push(mp(d[e.to],e.to));
			}
		}
	}
}

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

void Solve(){
	cin >> n >> m >> k >> q;

	vector<pii> e(m);
	rep(i,0,m){
		int a,b,l;
		cin >> a >> b >> l;
		--a; --b;
		g[a].push_back(Edge{b,l});
		g[b].push_back(Edge{a,l});
		e[i]=mp(a,b);
	}

	rep(i,0,k){
		cin >> f[i];
		--f[i];
	}
	Dijkstra();

	rep(i,0,q){
		int a,b;
		cin >> a >> b;
		--a; --b;
		s[a].insert(i);
		s[b].insert(i);
	}

	vector<pair<int,pii>> es(m);
	rep(i,0,m){
		es[i].first=min(d[e[i].first],d[e[i].second]);
		es[i].second=mp(e[i].first,e[i].second);
	}
	sort(es.rbegin(),es.rend());

	rep(i,0,n) par[i]=i;
	vector<int> ans(q);
	rep(i,0,m){
		int a=Find(es[i].second.first),b=Find(es[i].second.second);
		if(a==b) continue;
		if(s[a].size()<s[b].size()) swap(a,b);

		for(auto it=s[b].begin(); it!=s[b].end(); ++it){
			if(!s[a].insert(*it).second){
				ans[*it]=es[i].first;
				s[a].erase(*it);
			}
		}
		par[b]=a;
	}

	rep(i,0,q) cout << ans[i] << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

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

int main () {
  string S;
  cin >> S;
  int l = 0;
  l = S.length();
  for (int i = 0; i < l; i++) {
    if ((i + 1) % 2 == 0) {
      if (S[i] == 'R') {
        cout << "No";
        return 0;
      }
    }
    else {
      if (S[i] == 'L') {
        cout << "No";
        return 0;
      }
    }
  }
  cout << "Yes";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> k(m);
	vector<vector<int>> s(m);
	rep(i, m) {
		cin >> k[i];
		s[i] = vector<int>(k[i]);
		rep(j, k[i]) cin >> s[i][j];
	}
	vector<int> p(m);
	rep(i, m) cin >> p[i];
	int ans = 0;
	rep(bit, (1 << n)) {
		int res = 0;
		rep(i, m) {
			int cnt = 0;
			rep(j, k[i]) {
				if (bit & (1 << (s[i][j] - 1))) cnt++;
			}
			if (cnt % 2 == p[i] % 2) res++;
		}
		if (res == m) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
#define mp make_pair
#define pb push_back
#define pi pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

struct an{
	int sy,sx,gy,gx;
};

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

	int t=1;
//	cin>>t;
	while(t--){
	int h,w;
	cin>>h>>w;
	int a[h+5][w+5];
	
	for(int i=0;i<h;i++)
	{
	   for(int j=0;j<w;j++)	
	   cin>>a[i][j];
	}
	w--;
	vector<an>ans;
	
	for(int i=0;i<h;i++)
	{
		 for(int j=0;j<w;j++)
		 {
		 	if(a[i][j]%2==0) continue;
		 	a[i][j+1]++;
		 	ans.pb({i+1,j+1,i+1,j+2});
		 }
		 if(i>=h-1 || a[i][w]%2==0) continue;
		 a[i+1][w]++;
		 ans.pb({i+1,w+1,i+2,w+1});
	}
	cout<<ans.size()<<endl;
	for(auto i:ans)
	{
		cout<<i.sy<<" "<<i.sx<<" "<<i.gy<<" "<<i.gx<<endl;
	}
	}		
}

Measured memory_bytes: 6336
import collections
n=int(input())
s=[input() for i in range(n)]
m=int(input())
t=[input() for i in range(m)]
smax=collections.Counter(s)
tmax=collections.Counter(t)
ans=[0]
for i,j in smax.items():
    if i in tmax.keys():
        ans+=[smax[i]-tmax[i]]
    else:
        ans+=[j]
print(max(ans))

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

int main(){
  int a[]={0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int x,y;
  cin >> x >> y;
  if(a[x]==a[y]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=1e5;
int N;
bool flg[MAX_N];
int a[MAX_N+1];
int inx[2];
const ll MOD=1e9+7;
ll fac[MAX_N+2];
ll ifac[MAX_N+2];
ll mpw(ll n,ll m){
	ll ret=1;
	while(m){
		if (m&1){
			ret*=n;
			ret%=MOD;
		}
		n*=n;
		n%=MOD;
		m>>=1;
	}
	return ret;
}
ll minv(ll n){
	return mpw(n,MOD-2);
}
ll comb(ll n,ll m){
	return fac[n]*ifac[m]%MOD*ifac[n-m]%MOD;
}
int main(){
	cin>>N;
	memset(flg,true,sizeof(flg));
	REP(i,N+1){
		cin>>a[i];
		a[i]--;
		flg[a[i]]=!flg[a[i]];
	}
	{
		int tem;
		REP(i,N){
			if (flg[i]){
				tem=i;
				break;
			}
		}
		inx[0]=-1;
		REP(i,N+1){
			if (a[i]==tem){
				if (inx[0]==-1){
					inx[0]=i+1;
				}else{
					inx[1]=i+1;
				}
			}
		}
	}
	fac[0]=1;
	REP(i,N+1){
		fac[i+1]=(fac[i]*(i+1)%MOD);
	}
	ifac[N+1]=minv(fac[N+1]);
	for(int i=N;i>=0;i--){
		ifac[i]=ifac[i+1]*(i+1)%MOD;
	}
	FOR(k,1,N+2){
		ll c;
		ll tem=inx[0]+N-inx[1];
		if (tem>=k-1){
			c=comb(tem,k-1);
		}else{
			c=0;
		}
		cout<<(comb(N+1,k)-c+MOD)%MOD<<endl;
	}
	return 0;
}

Measured memory_bytes: 3200
package main

import "fmt"

var (
	a, b int
	c, d int
)

func main() {
	fmt.Scan(&a, &b, &c, &d)

	fmt.Println(
		plus(
			min(b, d) - max(a, c),
		),
	)

}

func min(x, y int) int {
	if x < y {
		return x
	}

	return y
}

func max(x, y int) int {
	if x < y {
		return y
	}

	return x
}

func plus(x int) int {
	if x < 0 {
		return 0
	}

	return x
}


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

map<ll,ll>l2;

int main()
{
    ll n;
    ll a,b;
    cin>>a>>b;
    double x,y;
    //if(b/2==a||b/4==a){cout<<"Yes";return 0;}
    for(int i=0;i<=a;i++){
        if((i*2)+(a-i)*4==b){
            cout<<"Yes";return 0;
        }
        else if((i*4)+(a-i)*2==b){
            cout<<"Yes";return 0;
        }
    }
    cout<<"No";

    return 0;
}


Measured memory_bytes: 3636
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


vector<ll> inv,fac;

void inverse(ll n){
    //要素数:n+1 (0~n)
    inv[0]=1;
    inv[1]=1;
    for(ll i=2;i<=n;i++){
        inv[i]=(MOD-inv[MOD%i]*(MOD/i))%MOD;
    }
}

void inverse_u(ll n){
    //要素数:n+1 (0~n)
    for(ll i=2;i<=n;i++){
        inv[i]=(inv[i]*inv[i-1])%MOD;
    }
}

void factorial(ll n){
    //要素数:n+1 (0~n)
    fac[0]=1;
    fac[1]=1;
    for(ll i=2;i<=n;i++){
        fac[i]=(fac[i-1]*i)%MOD;
    }
}

ll nCr(ll n,ll r){
    return fac[n]*inv[r]%MOD*inv[n-r]%MOD;
}

ll proinverse(ll x,ll m){
    ll res=1,M=m-2;
    while(M>0){
        if(M&1) res=res*x%m;
        x=x*x%m;
        M>>=1;
    }
    return res;
}

void init_nCr(ll n){
    inv.assign(n+1,0);
    fac.assign(n+1,0);
    inverse(n); inverse_u(n);
    factorial(n);
}

int main(){
    ll n,k; cin>>n>>k;
    init_nCr(n);
    for(ll i=1;i<=k;i++){
        if(i>n-k+1){
            printf("0\n");
            continue;
        }
        ll ans=1;
        ans=(ans*nCr(n-k+1,i))%MOD;
        ans=(ans*nCr(k-1,i-1))%MOD;
        printf("%lld\n",(ans+MOD)%MOD);
    }
}

Measured memory_bytes: 3736
#include <iostream>
using namespace std;
int main() {
    int a = 0;
    int b = 0;
     cin >> a >> b;
     int c = a + b;
     int d = a + a-1;
     int f = b + b -1;

     int max = c;
     if(max < d){
         max = d;
     }
     if(max < f){
         max = f;
     }

     cout << max;
     return 0;
}

Measured memory_bytes: 256