akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        mut l: [i64; n],
    }
    l.sort();

    let ans = l[0..n - 1].iter().sum::<i64>() > l[n - 1];

    println!("{}", if ans { "Yes" } else { "No" });
}


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

int main() {
  string s;
  cin >> s;
  rep(i,4){
    int cnt = 0;
    rep(j,4){
      if(s[i] == s[j]) cnt ++;
    }
    if(cnt !=2){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3568
/*+lmake
 * STD = c++14
 * DEFINE += MDEBUG
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
#ifdef DEBUG
     #define debug(args...)            {dbg,args; cerr<<endl;}
#else
    #define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;
bool x[110][110];
void solve(long long A, long long B){
	const int h=100,w=100;
	for(int i=1; i<=h/2; ++i) {
		for(int j=1; j<=w; ++j) {
			x[i][j]=true;
		}
	}	
	for(int i=51; i<=h; ++i) {
		for(int j=1; j<=w; ++j) {
			x[i][j]=false;
		}
	}	
	A--; B--;
	printf("100 100\n");
	for(int i=1; i<=A; ++i) {
		x[(i/50)*2+2][(i%50)*2+1]=false;
	}
	for(int i=1; i<=B; ++i) {
		x[(i/50)*2+52][(i%50)*2+1]=true;
	}
	for(int i=1; i<=h; ++i) {
		for(int j=1; j<=w; ++j) {
			putchar(x[i][j]?'#':'.');
		}
		puts("");
	}
}

int main(){	
	long long B;
	long long A;
	scanf("%lld",&A);
	scanf("%lld",&B);
	solve(A, B);
	return 0;
}



Measured memory_bytes: 384
#include<stdio.h>
int main(){
 int i,x,five=0,seven=0;
 for(i=0;i<3;i++){
  scanf("%d",&x);
  if(x==5){
   five++;
  }else if(x==7){
   seven++;
  }else{
   printf("NO");
   return 0;
  }
 }
  if(seven==1&&five==2){
    printf("YES");
    return 0;
  }
  printf("NO");
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main()
{
    vector<int> sides(3);
    for (int i = 0; i < 3; ++i) cin >> sides[i];
    sort(sides.begin(), sides.end());
    cout << sides[0] * sides[1] / 2 << endl;
}


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

int main(){
	int n;
	cin>>n;
	int t[n+10],x[n+10],y[n+10];
	for(int i=1;i<=n;i++){
		cin>>t[i]>>x[i]>>y[i];
	}
	for(int i=1;i<=n;i++){
		if(x[i]+y[i]>t[i]||(t[i]-x[i]-y[i])%2!=0){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
} 


Measured memory_bytes: 1408
char buf[2<<20],out[6];
sz;
cnt[1<<20];
main()
{
	read(0,buf,2<<20);
	int N=0;
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		N=N*10+k-'0';
	}
	for(int i=0;i<N;i++)
	{
		int A=0;
		for(;;)
		{
			char k=buf[sz++];
			if(k<'0')break;
			A=A*10+k-'0';
		}
		cnt[A]++;
	}
	int ans=0;
	for(int i=1;i<=1000000;i++)
	{
		if(cnt[i])
		{
			ans+=cnt[i]<2;
			for(int j=i+i;j<=1000000;j+=i)cnt[j]=0;
		}
	}
	int osz=6;
	do{
		out[--osz]=ans%10+'0';
	}while(ans/=10);
	write(1,out+osz,6-osz);
}


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

int n;
char s[11];

void func(int st, int cnt){
    if(st == n){
        puts(s);
        return;
    }
    for(int i = 0; i < cnt; i++){
        s[st] = 'a'+i;
        func(st+1, cnt);
    }
    s[st] = 'a'+cnt;
    func(st+1, cnt+1);
}

int main(){
    cin >> n;
    func(0, 0);
    return 0;
}

Measured memory_bytes: 1536
'use strict'

main()

function main (input) {
  readInput()
  .then(parseInput)
  .then(calc)
}

function calc (input) {
  let a = input[0]
  let b = input[1]
  let c = input[2]
  let ok = c >= a && c <= b
  let answer = ok ? 'Yes' : 'No'
  console.log(answer)
}

function parseInput (inputRaw) {
  let input = inputRaw.split(' ').map(Number)
  return input
}

function readInput () {
  return new Promise((resolve) => {
    let inputArr = []
    process.stdin.resume()
    process.stdin.setEncoding('utf8')
    process.stdin.on('data', (chunk) => {
      inputArr.push(chunk)
    })
    process.stdin.on('end', () => {
      let input = inputArr.join('').trim()
      resolve(input)
    })
  })
}


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

using namespace std;

class Solution {
public:
	void solve() {
		int n, m;
		cin >> n >> m;
		vector<int> s(m, 0), c(m, 0);
		for(int i=0; i < m; i++)cin >> s[i] >> c[i];
		for(int i = 0; i < 1000; i++){
			if(to_string(i).length() != n)continue;
			bool flag = true;
			for(int j=0; j < m; j++){
				int x = i;
				for(int k = 0; k < n-s[j]; k++){
					x/=10;
				}
				if(x % 10 != c[j])flag = false;
			}
			if(flag){
				cout << i << endl;
				return;
			}
		}
		cout << -1 << endl;
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
using namespace std;
//cout << << endl;
typedef long long int ll;
typedef long double ld;



int main(){
    char a,b;
    cin >> a >> b;
    if (a==b){
        cout << "H" << endl;
    }else{
        cout << "D" << endl;

    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include<string>
#include <array>
#include <vector>
using namespace std;

int main() {
	long long N, K, ans;
	cin >> N >> K;
	ans = K;
	for (int i = 1; i < N; i++) {
		ans *= (K - 1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

const int N = 30;
const int d[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int n, m;
char a[N][N];

int BFS(int s) {
  queue<int> Q;
  Q.push(s);
  vector<int> visit(n * m, -1);
  visit[s] = 0;
  int ret = 0;
  while (!Q.empty()) {
    int u = Q.front();
    ret = max(ret, visit[u]);
    Q.pop();
    int x = u / m, y = u % m;
    for (int k = 0; k < 4; ++k) {
      int nx = x + d[k][0];
      int ny = y + d[k][1];
      if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
      if (visit[nx * m + ny] >= 0 || a[nx][ny] == '#') continue;
      Q.push(nx * m + ny);
      visit[nx * m + ny] = visit[u] + 1;
    }
  }
  return ret;
}

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", a[i]);
  }
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == '#') continue;
      int cur = BFS(i * m + j);
      ret = max(ret, cur);
    }
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <deque>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
int h, w;
char s[100][110];
int g[100][100];

int main() {
  deque<pair<int, int> > d;
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++) {
    scanf("%s", s[i]);
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      g[i][j] = 1000;
    }
  }
  if (s[0][0] == '#') {
    g[0][0] = 1;
  } else {
    g[0][0] = 0;
  }
  d.push_back({0, 0});
  while (!d.empty()) {
    pair<int, int> p = d.front();
    d.pop_front();
    int x = p.first, y = p.second;
    if (x + 1 < h) {
      if ((s[x][y] == s[x + 1][y] || s[x + 1][y] == '.') &&
          g[x + 1][y] > g[x][y]) {
        g[x + 1][y] = g[x][y];
        d.push_front({x + 1, y});
      } else if (s[x][y] != s[x + 1][y] && g[x + 1][y] > g[x][y] + 1) {
        g[x + 1][y] = g[x][y] + 1;
        d.push_back({x + 1, y});
      }
    }
    if (y + 1 < w) {
      if ((s[x][y] == s[x][y + 1] || s[x][y + 1] == '.') &&
          g[x][y + 1] > g[x][y]) {
        g[x][y + 1] = g[x][y];
        d.push_front({x, y + 1});
      } else if (s[x][y + 1] != s[x][y] && g[x][y + 1] > g[x][y] + 1) {
        g[x][y + 1] = g[x][y] + 1;
        d.push_back({x, y + 1});
      }
    }
  }
  printf("%d\n", g[h - 1][w - 1]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define xmod (int)1e9+7
using namespace std;

ll n,k,dp[105][100005],sum,a[100005],yo,pt;
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> k;
	for (int i=1;i<=n;i++){
		cin >> a[i];
	}
	dp[0][0]=1;
	for (int i=1;i<=n;i++){
		sum=0; yo+=a[i]; pt=0;
		for (int j=0;j<=min(yo,k);j++){
			sum+=dp[i-1][j];
			dp[i][j]=sum;
			dp[i][j]%=xmod;
			while (pt+a[i] <= j){
				sum-=dp[i-1][pt];
				pt++;
			}
			if (sum < 0)
			sum+=xmod;
		}
	}
	cout << dp[n][k] << "\n";
    return 0;
}

Measured memory_bytes: 78592
using System;

namespace abc079A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string N = Console.ReadLine();
            string[] str = new string[4];
            for(int i = 0; i < 4; i++)
            {
                str[i] = N.Substring(i, 1);
            }
            if ((str[0] == str[1] && str[1] == str[2]) || (str[1] == str[2] && str[2] == str[3]))
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


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

int main(){
  int n,k;
  cin >> n >> k;
  vector<bool> sun(n,false);//各人がお菓子を持っているかどうか
  rep(i,k){
    int d;
    cin >> d;
    rep(j,d){
      int a;
      cin >> a;
      sun[a-1] = true;//お菓子を持っている者をtrueに
    }
  }

  int ans = 0;
  for(bool i : sun){
    if(!i) ans++;//お菓子持っていなければインクリメント
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3536
#include <iostream>
using namespace std;
int cnt1,cnt2;
int temp1[100],temp2[100];
string s;
int main(){
	while(1){
		getline(cin,s);
		if(s[0]=='.')break;
		cnt1=cnt2=0;
		for(int i=0;i<s.size();i++){
			if(s[i]=='('){
				cnt1++;
				temp1[cnt1]=cnt2;
			}else if(s[i]==')'){
				if(temp1[cnt1]!=cnt2)break;
				cnt1--;
			}else if(s[i]=='['){
				cnt2++;
				temp2[cnt2]=cnt1;
			}else if(s[i]==']'){
				if(temp2[cnt2]!=cnt1)break;
				cnt2--;
			}
			if(cnt1<0||cnt2<0)break;
		}
		if(cnt1==0&&cnt2==0){
			cout <<"yes" <<endl;
		}else{
			cout <<"no" <<endl;
		}
	}
}

Measured memory_bytes: 3116
def rch(dis, mov, goal)
  dp = [{}]
  if dis == 0 then
    dp[-1][0] = 1
  else
    #最初に進む時は後ろへは行けない
    dp[-1][mov[0]] = 1
    mov = mov[1..-1]
  end
  mov.each.with_index{|step,i|
    next if i%2==0
    h = {}
    dp[-1].each_key{|k|
      h[k-step] = 1
      h[k+step] = 1
    }
    dp << h
  }
  
  dp[-1][goal]
end

def rchX(mov, x)
  rch(1, mov, x)
end

def rchY(mov, y)
  rch(0, mov, y)
end


s = gets.chomp
x, y = gets.split.map &:to_i

mov = []
count = 0

s.chars{|c|
  if c=='F' then
    count+=1
  elsif c=='T'then
    mov << count
    count = 0
  end
}
mov << count

puts (rchX(mov, x)&&rchY(mov, y)) ? 'Yes' : 'No'

Measured memory_bytes: 266492
n, k, q  = map(int, input().split())
arr = [ (k - q) for i in range(n)]
for i in range(q):
    arr[int(input()) - 1]  += 1
for i in range(n):
    if arr[i] >0:
        print("Yes")
    else:
        print("No")
     



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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a <= b && b <= c) {
		cout << a << " " << b << " " << c << endl;
	}
	else if (a<= b && b>c) {
		if (a <= c) {
			cout << a << " " << c << " " << b << endl;
		}
		else {
			cout << c << " " << a << " " << b << endl;
		}
	}
	else if (a > b&&b >= c) {
		cout << c << " " << b << " " << a << endl;
	}
	else if(a>b && b<c) {
		if (a <= c) {
			cout << b << " " << a << " " << c << endl;
		}
		else {
			cout << b << " " << c << " " << a << endl;
		}
	}
		return 0;
}

Measured memory_bytes: 3060
import sys
N, M = [int(i) for i in input().split()]

A = [[i for i in input()] for j in range(N)]
B = [[i for i in input()] for k in range(M)]

for i in range(N-M+1):
    for j in range(N-M+1):
        diff = 0

        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    diff = 1
                    break

            if diff == 1:
                break

        if diff == 0:
            print('Yes')
            sys.exit()

print('No')


Measured memory_bytes: 3064
import Control.Applicative

main :: IO ()
main = solve <$> f >>= putStrLn
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> String
solve [a, b, c, d]
  | a + b > c + d = "Left"
  | a + b < c + d = "Right"
  | otherwise = "Balanced"


Measured memory_bytes: 508
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;

namespace AtCoder_Beginner_Contest_128
{
    class Program
    {
        public struct Pair
        {
            public long T;
            public long E;
            public long X;
            public Pair(long t, long e, long x) { T = t; E = e; X = x; }
        }
        static public int[] SIn() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public string[] SInS() { return ReadLine().Split().ToArray(); }
        static void Main(string[] args)
        {
            var NQ = SIn();
            var N = NQ[0];
            var Q = NQ[1];
            var start = new long[N];
            var end = new long[N];
            var stx = new List<Pair>(2 * N);
            for (var i = 0; i < N; ++i)
            {
                var STX = SIn();
                stx.Add(new Pair(STX[0] - STX[2], 1, STX[2]));
                stx.Add(new Pair(STX[1] - STX[2], -1, STX[2]));
            }
            var orderd = stx.OrderBy(st => st.T).ToArray();
            var Di = new long[Q];
            var dst = new long[Q];
            for(var i=0;i<Q;++i)
            {
                Di[i] = SIn()[0];
                dst[i] = -1;
            }
            var Kouji = new SortedDictionary<long, long>();//x,なんでもいい
            int dcnt = 0;
            for (var i = 0; i < orderd.Length; ++i)
            {
                while (dcnt < Q && Di[dcnt] < orderd[i].T)
                {
                    if (0 != Kouji.Count)
                    { dst[dcnt] = Kouji.Keys.First(); }
                    ++dcnt;
                }
                if (orderd[i].E == 1)
                { Kouji[orderd[i].X] = 1; }
                else
                { Kouji.Remove(orderd[i].X); }
            }
            StringBuilder ans=new StringBuilder();
            foreach (var d in dst)
            {
                ans.Append($"{d}\n");
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 64508
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int n  = sc.nextInt();

        int[] w = new int[n];
        int sum = 0;
        for(int i=0; i<n; i++) {
            w[i] = sc.nextInt();
            sum+=w[i];
        }

        int l = 0;
        int r = sum;

        int res = 1000000000;

        for(int i=0; i<n-1; i++) {
            l+=w[i];
            r-=w[i];
            res = Math.min(res, Math.abs(l-r));
        }

        System.out.println(res);

    }


}


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

#define NUM 200001
#define HASH 200001

typedef struct List {
	struct List *next;
	int id;
} list;

int hash_string(char* s)
{
	long long x = 0;
	int i;
	for (i = 0; s[i] != 0; i++) {
		x += s[i] - 'a';
		x = x << 5;
	}
	return x % HASH;
}

int lex_smaller(char* s1, char* s2)
{
	int i;
	for (i = 0; s1[i] != 0 && s2[i] != 0; i++) {
		if (s1[i] < s2[i]) return 1;
		else if (s1[i] > s2[i]) return -1;
	}
	if (s1[i] == s2[i]) return 0;
	else if (s1[i] == 0) return 1;
	else return -1;
}

void push(char* s, char** heap, int* n)
{
	int i = *n;
	char *tmp;
	heap[(*n)++] = s;
	while (1) {
		if (i == 0) break;
		else if (lex_smaller(heap[i], heap[(i - 1) / 2]) == 1) {
			tmp = heap[(i - 1) / 2];
			heap[(i - 1) / 2] = heap[i];
			heap[i] = tmp;
			i = (i - 1) / 2;
		} else break;
	}
}

char* pop(char** heap, int* n)
{
	int i = 0, j;
	char *tmp, *output = heap[0];
	heap[0] = heap[--(*n)];
	while (1) {
		if (i * 2 + 1 >= *n) break;
		else if (i * 2 + 2 >= *n) j = i * 2 + 1;
		else if (lex_smaller(heap[i * 2 + 1], heap[i * 2 + 2]) == 1) j = i * 2 + 1;
		else j = i * 2 + 2;
		if (lex_smaller(heap[j], heap[i]) == 1) {
			tmp = heap[j];
			heap[j] = heap[i];
			heap[i] = tmp;
			i = j;
		} else break;
	}
	return output;
}

int main()
{
	int i, N;
	char S[NUM][11];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%s", S[i]);
	
	list data[NUM], *hash[HASH] = {}, *hp;
	int h, j, k, count[NUM] = {}, type[NUM] = {};
	for (i = 1, k = 0; i <= N; i++) {
		h = hash_string(S[i]);
		for (hp = hash[h]; hp != NULL; hp = hp->next) {
			if (lex_smaller(S[i], S[type[hp->id]]) == 0) {
				count[hp->id]++;
				break;
			}
		}
		if (hp == NULL) {
			type[k] = i;
			data[i].id = k++;
			data[i].next = hash[h];
			hash[h] = &(data[i]);
		}
	}

	int p = 0, max = -1, argmax[NUM] = {};
	for (j = 0; j < k; j++) {
		if (count[j] > max) {
			max = count[j];
			argmax[0] = j;
			for (; p > 0; argmax[p--] = 0);
		} else if (count[j] == max) argmax[++p] = j;
	}
	
	int n = 0;
	char **heap = (char**)malloc(sizeof(char*) * (++p));
	for (i = 0; i < p; i++) push(S[type[argmax[i]]], heap, &n);
	while (n > 0) printf("%s\n", pop(heap, &n));

	fflush(stdout);
	return 0;
}

Measured memory_bytes: 12672
N = gets.to_i
V = gets.split(' ').map(&:to_i)
C = gets.split(' ').map(&:to_i)
diff = []
sum = 0

N.times do |i|
  diff.push(V[i] - C[i])
end

diff = diff.sort.reverse

N.times do |i|
  break if diff[i] < 0
  sum += diff[i]
end

puts sum

Measured memory_bytes: 3836
#include <iostream>
#include <stdio.h>
#include <string>

#define MAX_H 100

using namespace std;

char A[MAX_H][MAX_H]{};

int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < W; ++j) {
      A[i][j] = s[j];
    }
  }
  int i = 0;
  while (i < H) {
    int j = 0;
    while (j < W && A[i][j] == '.') {
      ++j;
    }
    if (j == W) {
      for (int k = i; k < H - 1; ++k) {
        for (j = 0; j < W; ++j) {
          A[k][j] = A[k + 1][j];
        }
      }
      --H;
    } else {
      ++i;
    }
  }
  int j = 0;
  while (j < W) {
    int i = 0;
    while (i < H && A[i][j] == '.') {
      ++i;
    }
    if (i == H) {
      for (int k = j; k < W - 1; ++k) {
        for (i = 0; i < H; ++i) {
          A[i][k] = A[i][k + 1];
        }
      }
      --W;
    } else {
      ++j;
    }
  }
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      printf("%c", A[i][j]);
    }
    printf("\n");
  }
}

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

#define pb push_back

vector<vector<int> > a;

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

	a = vector<vector<int> > (n+1);

	for(int i=0;i<m;i++) {
		int u,v; cin >> u >> v;
		a[u].pb(v); a[v].pb(u);
	}

	vector<int> dist(n+1,-1);

	queue<int> q; q.push(1); dist[1] = 0;

	while(!q.empty()) {
		int x = q.front(); q.pop();

		for(int y:a[x]) {
			if(dist[y] == -1) {
				q.push(y);
				dist[y] = x;
			}
		}
	}

	for(int i=1;i<=n;i++) {
		if(dist[i] == -1) {
			cout << "No"; return 0;
		}
	}

	cout << "Yes" << endl;
	for(int i=2;i<=n;i++) cout << dist[i] << endl;
}

Measured memory_bytes: 10276
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if((b - a) == (c - b)){
        cout << "YES";
    }else{
        cout << "NO";
    }
    return 0;
}

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

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

  string S; cin >> S;
  int N = S.size();

  string ans = "Yes";
  ll s, e;
  s = 0, e = N;
  for (ll i = 0; i < e - s; i++) {
    if (S[s + i] != S[e - 1 - i]) ans = "No";
  }

  s = 0, e = (N - 1) / 2;
  for (ll i = 0; i < e - s; i++) {
    if (S[s + i] != S[e - 1 - i]) ans = "No";
  }

  s = (N + 3) / 2 - 1, e = N;
  for (ll i = 0; i < e - s; i++) {
    if (S[s + i] != S[e - 1 - i]) ans = "No";
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

ll N, W;
ll w1;
const ll INF = 1e15;
vector<vi> v(4);

ll solve(int p, ll w)
{
	if (w > W) return -INF;
	if (p == 4) return 0;
	ll tmp = 0;
	ll res = solve(p + 1, w);
	REP(i, v[p].size())
	{
		tmp += v[p][i];
		chmax(res, solve(p + 1, w + (w1 + p) * (i + 1)) + tmp);
	}
	return res;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	cin >> N >> W;
	REP(i, N)
	{
		ll a, b; cin >> a >> b;
		if (i == 0) w1 = a;
		v[a - w1].push_back(b);
	}
	for (auto &i : v) sort(i.rbegin(), i.rend());
	cout << solve(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool up_min(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool up_max(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }

    ll operator"" _64(unsigned long long x){ return ll(x); }
    ull operator"" _64u(unsigned long long x){ return ull(x); }

    template<class T>
    vector<T> make_mdvector(int n, T t){
        return vector<T>(n, t);
    }
    template<class ...Ts>
    auto make_mdvector(int n, Ts ... ts){
        return vector<decltype(make_mdvector(ts...))>(n, make_mdvector(ts...));
    }

    inline ll bit(int x){
        return 1ll << x;
    }

    template<class T>
    istream& operator>>(istream& is, vector<T>& v){
        for (auto &&x : v) { is >> x; } return is;
    }

    template<class T>
    ostream& operator<<(ostream& os, const vector<T>& v){
        for (auto &&x : v) { os << x << ' '; } cout << endl; return os ;
    }
}
using namespace utils;

class solver{
    istream& is;
    ostream& os;

public:
    solver(istream& I, ostream& O) :is(I), os(O) {}
    ll N;
    void run();
};

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef XELMH
    string test_cases = "test_D.txt";
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int loop = 0;
    while(fs) {
        loop++;
        cout << '#' << loop << "#------\n";
        solver(fs, cout).run();
    }
    if(loop <= 1) {
        cout << "===" << endl;
        while(cin) solver(cin, cout).run();
    }
#else
    solver(cin, cout).run();
#endif
    return 0;
}


void solver::run(){
    is >> N;
    if(!is) return;
    ll ans = 0;
    ll fdig = 0;
    ll us = 0;
    for (int i = 0; i < N; ++i) {
        ll d, c;
        is >> d >> c;
        fdig += c;
        us += d*c;
    } // end i

    ans = fdig - 1 + us/9;
    ll up = us % 9;
    if(up == 0){
        ans--;
    }
    os << ans << endl;

}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace task2
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = input[0];
            var M = input[1];
            var A = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(s => s);
            var border = A.Sum() / 4.0 / M;

            Console.WriteLine(A.Take(M).All(s => s >= border) ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13396
N, MOD = int(input()), 10 ** 9 + 7
memo = [{} for i in range(N+1)]

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True

def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in 'ACGT':
        if ok(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
    memo[cur][last3] = ret
    return ret

print(dfs(0, 'TTT'))

Measured memory_bytes: 3872
'use strict'

function Main(input){
	let temp = input.trim().split("\n");
	let temp2 = temp[0].split(" ");
	let H = parseInt(temp2[0]);
	let W = parseInt(temp2[1]);
	
	temp2 = temp[1].split(" ");
	let h = parseInt(temp2[0]);
	let w = parseInt(temp2[1]);

	let sum = H*W;

	sum = sum - ( h*W + H*w ) + h*w;
	
	console.log(sum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21192
H,W,K = gets.split.map(&:to_i)
cc = H.times.map { gets.chomp!.chars }

ans = 0
(1 << H).times do |is|
  (1 << W).times do |js|
    cnt = 0
    H.times do |i|
      W.times do |j|
        next if is >> i & 1 == 1
        next if js >> j & 1 == 1
        cnt += 1 if cc[i][j] == '#'
      end
    end

    ans += 1 if cnt == K
  end
end

puts ans


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

#define int long long

#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)

using namespace std;

using vi = vector<int>;

signed main() {
    int N,L;
    cin>>N>>L;
    vector<string> V(N);
    rep(i,N){
        cin>>V[i];
    }

    sort(V.begin(),V.end());
    rep(i,N) cout<<V[i];
    cout<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>


int main (void) {
	int  num, hun, ten, one;
	
	scanf("%d", &num);
	
	hun = num/100;
	num -= hun*100;
	ten = num/10;
	num -= ten*10;
	one = num/1;

	if(one == 7 || ten == 7 || hun == 7)
		printf("Yes\n");
	else
		printf("No\n");
	
	return 0;
}


Measured memory_bytes: 1628
<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE);
 
define('MOD', pow(10, 9) + 7);
 
fscanf(STDIN, "%s", $s);
$n = strlen($s);
 
$dp[0][0] = 1;
for ($i = 0; $i < $n; $i++) {
    if ($s[$i] == '?') {
        $c = -1;
    } else {
        $c = $s[$i] - '0';
    }
    
    for ($j = 0; $j < 10; $j++) {
        if ($c != -1 && $c != $j) continue;
        for ($ki = 0; $ki < 13; $ki++) {
            $dp[$i + 1][($ki * 10 + $j) % 13] += $dp[$i][$ki];
        }
    }
    for ($j = 0; $j < 13; $j++) $dp[$i + 1][$j] %= MOD;
}
$res = $dp[$n][5];
 
printf("%d", $res);

Measured memory_bytes: 87296
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=1e5;
#define yi first
#define er second
typedef pair<int,int> node;
node a[yuzu|10];
 
bool cmp(node a,node b){
return a.er<b.er;
}
 
int main(){
int i,j,n=read(),m=read();
for (i=1;i<=m;++i) a[i].yi=read(),a[i].second=read();
sort(a+1,a+m+1,cmp);
int now=-1,llx=0;
for (i=1;i<=m;++i){
  if (now<a[i].yi){
    now=a[i].er-1,++llx;
    }
  }write(llx);
}

Measured memory_bytes: 1024
//下に解法を書きました．
#include<bits/stdc++.h>
#include<iostream>

using namespace std;

const int MAX = 680000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    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;
    }
}

#define comuse Comuse()

int combi(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;
}


void Solve();

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(20)<<fixed;
  Solve();
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

/*
前提条件として，入力で与えられる座標に必ず移動できるとする．
移動する回数は(X+Y)/3で得ることができるので，移動する回数をnとすると直線y=-x+3n上の格子点のみをみればよいことがわかる．
いま駒はすべて(i,j)から(i+2,j+1)に遷移したと仮定して考える．
すると，端の座標は(2n,n)と(n,2n)であることがわかる．

ここでパスカルの三角形を考えると，入力で与えられる座標はパスカルの三角形の左からいくつ目なのかは2n-xまたはy-nで得ることができる．
あとはそれに対する二項係数(n)C(2n-x)を計算すればよい．

コーナーケースは(X+Y)が3の倍数ではない場合と，パスカルの三角形の端から端を定義域としたときに(X,Y)がy=-x+3n上にない場合である．
*/

void Solve(){
  int x,y;
    scanf("%d%d",&x,&y);

  int n=(x+y)/3;
  
  if(2*n<x||2*n<y||(x+y)%3!=0){
    printf("%d\n",0);
    return;
  }
  
  comuse;
  
  printf("%d\n",combi(n,2*n-x));
}

Measured memory_bytes: 16256
judge :: (Int, Int) -> [Int] -> (Int, Int)
judge (a, b) [a1, b1]
  | a1 > b1 = (a + a1 + b1, b)
  | a1 < b1 = (a, b + a1 + b1)
  | otherwise = (a + a1, b + b1)
judge _ _ = error "3"

showScore :: (Int, Int) -> String
showScore (a, b) = show a ++ ' ' : show b

solve :: [[Int]] -> String
solve [[0]] = ""
solve ([n]:r) = showScore (foldl judge (0, 0) (take n r)) ++ '\n':solve (drop n r)
solve _ = ""
main :: IO ()
main = do
  args <- fmap (map (map (\n -> read n :: Int) . words) . lines) getContents
  putStr $ solve args

Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  rep(i,s.size()-1) {
    if(s[i] != s[i+1]) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N, K;
  int x;
  int y=0;
  cin >> N;
  vector<int> vec(N);
  vector<int> vec2(N);
  
  for (int i=0; i< N; i++) {
    cin >> vec.at(i);
    vec2.at(vec.at(i)-1)=i+1;
  }

  for (int i=0; i< N; i++) {
    cout << vec2.at(i) << " ";
  }
  cout << endl;
}

Measured memory_bytes: 1664
#include<string>
#include <iostream>
#include <algorithm>

using namespace std;

string days[] = { "MON","TUE","WED","THU","FRI","SAT" };

int main() {
	string s;
	cin >> s;
	if (s == "SUN") {
		cout << 7;
		return 0;
	}
	cout << 6 - (find(days, days + 6, s) - days);
	return 0;
}

Measured memory_bytes: 256
using System;

namespace PrintTestCases
{
	class MainClass
	{
		public static void Main (string[] args)
		{   
			int i=0;

			while(true)
			{
				//??\??????
				string input = Console.ReadLine();
				int x = int.Parse (input);

				i++;
				//x???0?????¨????????????
				if(x==0)
				break;
				//???????????±??????????????¨x?????????
				Console.WriteLine ("Case"+" " + i + ":"+" "+ x);
			}
		}
	}
}

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

vector< vector<int> > graph(100001);
vector<int> visited(100001);
vector<int> longest_path(100001);


int l_path(int from)
{
	if(graph[from].empty())
		longest_path[from] = 0;

	if(longest_path[from] != -1)
		return longest_path[from];

	int max_p = -1, vert_p;
	for(int i = 0; i < graph[from].size(); i++)
	{
		vert_p = 1 + l_path(graph[from][i]);
		max_p = (vert_p > max_p)?vert_p:max_p;
	}

	longest_path[from] = max_p;
	return longest_path[from];
}

int main(int argc, char const *argv[])
{
	int n, m, i, x, y; cin >> n >> m;
	fill_n(longest_path.begin(), 100001, -1);

	for(i = 0; i < m; i++)
	{
		cin >> x >> y;
		graph[x-1].push_back(y-1);
	}
	
	int max_path = -1;
	bool all_visited = false;

	while(!all_visited)
	{
		all_visited = true;
		for(i = 0; i < n; i++)
		{
			if(!visited[i])
			{
				all_visited = false;
				int path = l_path(i);
				max_path = (path > max_path)?path:max_path;
				visited[i] = 1;
			}
		}
	}

	cout << max_path << endl;
	return 0;
}


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

int main() {
    int N;
    cin>>N;
    map<int, int>cardnum;
    vector<int>arr;
    int tmp;
    for(int i=0;i<N;++i){
        cin>>tmp;
        if(cardnum[tmp]==0){
            arr.push_back(tmp);
        }
        cardnum[tmp]++;
        if(cardnum[tmp]==3){
            cardnum[tmp]=1;
        }
    }
    int twonum = 0;
    for(int i=0;i<arr.size();++i){
        if(cardnum[arr[i]]==2){
            twonum++;
        }
    }
    if(twonum%2==0)cout<<arr.size()<<endl;
    else cout<<arr.size()-1<<endl;
}


Measured memory_bytes: 5368
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
    int n;
    cin>>n;
    int R[MAX];
    
    for(int i=0; i<n; i++){
        cin>>R[i];
    }
    int maxv = -2000000000;
    int minv = R[0];
    
    for(int j=1; j<n; j++){
        maxv = max(maxv, R[j]-minv);
        minv = min(minv, R[j]);
    }
    cout<< maxv <<endl;
    return 0;
}


Measured memory_bytes: 3880
#include <iostream>
using namespace std;
int main() 
{
    int a[3],c=0,i;
    for(i=0;i<3;i++)
    {
        cin>>a[i];
    }
    for(i=1;i<3;i++)
    {
        if(a[0]==a[i])
        {
            c++;
        }
    }
    if(c==2)
    {
        cout<<"No";
    }
    if(c==1)
    {
        cout<<"Yes";
    }
    if(c==0)
    {
        if(a[1]==a[2])
        {
            cout<<"Yes";
        }
        else
        {
            cout<<"No";
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define repitr(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	ll t, a, tot;
	rep(i, n){
		int it, ia;
		cin >> it >> ia;
		if(i == 0){
			t = it;
			a = ia;
			tot = t + a;
			continue;
		}
		ll n = max((t+it-1)/it, (a+ia-1)/ia);
		t = n*it;
		a = n*ia;
		tot = t + a;
	}
	cout << tot << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun Oct  7 22:06:12 2018
ABC073D
@author: maezawa
"""
import itertools as itr
import sys
input = sys.stdin.readline

def wf(graph):
    """ Warshall-Floyd Algorithm """
    for k in range(len(adjmatrix)):
        for i in range(len(adjmatrix)):
            for j in range(len(adjmatrix[i])):
                if adjmatrix[i][j] > adjmatrix[i][k] + adjmatrix[k][j]:
                    adjmatrix[i][j] = adjmatrix[i][k] + adjmatrix[k][j]
                    adjmatrix[j][i] = adjmatrix[i][k] + adjmatrix[k][j]				
    return graph

n, m, r = list(map(int, input().split()))
rarray = list(map(int, input().split()))
adjmatrix = [[float("inf")]*n for _ in range(n)]
#for i in range(n):
#    adjmatrix[i][i] = 0

for i in range(m):
    a, b, c = list(map(int, input().split()))
    adjmatrix[a-1][b-1] = c
    adjmatrix[b-1][a-1] = c

#print(abc)

costmatrix = wf(adjmatrix)
        
#print(*adjmatrix, sep='\n')
    
# search for ri to rj
mincnt = float("inf")
for route in itr.permutations(rarray):
    cnt = 0
    for i in range(len(route)-1):
        cnt += costmatrix[route[i]-1][route[i+1]-1]
    if cnt < mincnt:
        mincnt = cnt

print(mincnt)
        
        

Measured memory_bytes: 4724
import java.util.BitSet;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int M = sc.nextInt();
		BitSet bs = new BitSet(N + 1);
		for (int i = 0; i < M; ++i) {
			int C = sc.nextInt();
			int D = sc.nextInt();
			bs.set(C, D);
		}
		System.out.println(N + 1 + bs.cardinality() * 2);
	}

}

Measured memory_bytes: 30200
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
string st;
int main()
{
	cin>>st;
	if (st[0]!=st[st.length()-1]) st.push_back(st[0]);
	if (st.length()&1)
	{
		cout<<"Second";
	}
	else
	{
		cout<<"First";
	}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

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

    if (a == 1) a += 13;
    if (b == 1) b += 13;

    if (a == b)
        cout << "Draw" << endl;
    else if (a > b)
        cout << "Alice" << endl;
    else
        cout << "Bob" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

struct DSU
{
	int father[100005];
	int size[100005];
	
	inline int getroot(int x)
	{
		return father[x]==x?x:father[x]=getroot(father[x]);
	}
	
	inline long long merge(int x, int y)
	{
		int rx=getroot(x),ry=getroot(y);
		if (size[rx]>size[ry]) swap(rx,ry);
		father[rx]=ry;;
		int tmp=size[ry];
		size[ry]+=size[rx];
		return 1LL*size[rx]*tmp;
	}
	
	inline DSU(int n)
	{
		for (int i=1; i<=n; i++)
		{
			father[i]=i;
			size[i]=1;
		}
	}
};

int N,M;
pair<int,int> rec[100005];
long long ans[100005];

int main()
{
	cin >> N >> M;
	for (int i=1; i<=M; i++) cin >> rec[i].first >> rec[i].second;
	ans[M]=1LL*N*(N-1)/2;
	DSU dsu(N);
	for (int i=M-1; i>=1; i--) ans[i]=ans[i+1]-(dsu.getroot(rec[i+1].first)!=dsu.getroot(rec[i+1].second)?dsu.merge(rec[i+1].first,rec[i+1].second):0);
	for (int i=1; i<=M; i++) cout << ans[i] << endl;
	return 0;
}

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



int main(void){
    int a,p;
    cin >> a >> p;
    int sum=3*a+p;
    int ans = sum/2;
    cout << ans <<endl;
    return 0;
}





























Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
	int hoge[10];

	for( int i = 0;i < 10;i++ ){
		cin >> hoge[i];
	}

	sort( hoge, hoge + 10, greater<int>() );

	for( int i = 0;i < 3;i++ ){
		cout << hoge[i] << endl;
	}

	
	return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int h, w, k, a[300][300];
    char c[300][300];
    cin >> h >> w >> k;
    bool r[300] = {};
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> c[i][j];
            if (c[i][j] == '#') {
                r[i] = true;
            }
        }
    }
    int d = 0;
    bool f;
    int first_cake_row;
    for (int i = 0; i < h; ++i) {
        if (r[i]) {
            if (d == 0) first_cake_row = i;
            ++d;
            f = true;
            for (int j = 0; j < w; ++j) {
                if (c[i][j] == '#') {
                    if (!f) ++d;
                    f = false;
                }
                a[i][j] = d;
            }
        }
    }
    for (int i = first_cake_row - 1; i >= 0; --i) {
        for (int j = 0; j < w; ++j) a[i][j] = a[i + 1][j];
    }
    for (int i = first_cake_row + 1; i < h; ++i) {
        if (!r[i]) {
            for (int j = 0; j < w; ++j) a[i][j] = a[i - 1][j];
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) cout << a[i][j] << ' ';
        cout << '\n';
    }
    return 0;
}


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

int main() {
  string s,t;
  cin>>s>>t;
  vector<ll> table1(30, 0);
  vector<ll> table2(30, 0);
  rep(i,s.size()) {
    ll si = s[i]-'a';
    ll ti = t[i]-'a';
    table1[ti]++;
    table2[si]++;
    if(table1[ti] != table2[si]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

using namespace std;    

const int maxn = 3e5 + 222;

int n, m;
char a[200][200];
int s[200][200];

int get(int xa, int ya, int xb, int yb) {
int sum = s[xb][yb];
sum -= s[xa - 1][yb];
sum -= s[xb][ya- 1];
sum += s[xa - 1][ya - 1];
return sum;
}
int dp[200][200];

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

    cin >> n >> m;
	for(int i = 1; i <= n; i++){
	int cur = 0;
	for(int j = 1; j <= m; j++) {
		cin >> a[i][j], dp[i][j] = 1e8;
		cur += (a[i][j] == '#');

		s[i][j] = s[i - 1][j] + cur;
	}
	}


	dp[1][1] = (a[1][1] == '#');

	for(int i = 1; i <= n; i++)
		for(int j = 0; j <= i - 1; j++)
		if(get(j + 1, 1, i, 1) == (i - j))
		dp[i][1] = min(dp[i][1], dp[j][1] + 1);
		else {
			if(a[i][1] == '.')
				dp[i][1] = min(dp[i][1], dp[i - 1][1]);
		}
	for(int j = 1; j <= m; j++)
		for(int i = 0; i <= j - 1; i++)
		if(get(1, i + 1, 1, j) == j - i)
			dp[1][j] = min(dp[1][j],dp[1][i] + 1);
		else if(a[1][j]=='.')
			dp[1][j] =min(dp[1][j],dp[1][j-1]);
	for(int i = 0; i <= max(n, m); i++)
		dp[0][i]=dp[i][0]=1e6;
	for(int i = 2; i <= n; i++)
	for(int j = 2; j <= m; j++) {
		for(int k = 1; k <= i; k++)
		for(int l = 1; l <= j; l++) {
		int mn = min(dp[k - 1][l], dp[k][l - 1]);
		if(mn > 1e6) continue;
		if(get(k , l , i, j) != (i - k + 1) * (j - l + 1) && a[i][j] == '#') continue;
		if(a[i][j] =='#'){

			int val = 0;
			if(a[k - 1][l]!='#') val = 1;dp[i][j]=min(dp[i][j], dp[k - 1][l] + val);
			val = 0;
			if(a[k][l - 1]!='#') val = 1;dp[i][j]=min(dp[i][j], dp[k][l-1] + val);
		}
		else if(a[i][j]=='.'){
			if(abs(i - k) + abs(j - l) == 1) 
				dp[i][j] = min(dp[i][j], dp[k][l]);
		}
		}
	}
	for(int i = n; i <= n; i++, cout << endl)
	for(int j = m; j <= m; j++)
	cout<<dp[i][j];
	return 0;
}
                                               

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007
// order_of_key and *find_by_order
int32_t main()
{
	fast;
	int ans = 1e18;
	int n, m, x;
	cin >> n >> m >> x;
	int c[n];
	int a[n][m];
	for (int i = 0; i < n; i++) {
		cin >> c[i];
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < (1 << n); i++) {
		int to = 0;
		int p = i;
		int row = 0;
		int co[m] = {};
		while (p) {
			if (p & 1) {
				to += c[row];
				for (int j = 0; j < m; j++) {
					co[j] += a[row][j];
				}
			}
			p /= 2;
			row++;
		}
		int fl = 0;
		for (int i = 0; i < m; i++) {
			if (co[i] < x)
			{
				fl = 1;
				break;
			}
		}
		if (fl == 0) {
			ans = min(ans, to);
		}
	}
	if (ans == 1e18) {
		cout << -1;
	}
	else {
		cout << ans;
	}











}

Measured memory_bytes: 3660