akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    ll d=a+b+a*(n-2);
    ll u=a+b+b*(n-2);
    cout<<max(u-d+1,0ll)<<endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    div = Math.divisor(N)
    div.sort()
    if len(div) % 2 == 1:
        print(len(str(div[len(div) // 2])))
    else:
        a = div[len(div) // 2]
        b = div[len(div) // 2 - 1]
        print(max(len(str(a)), len(str(b))))


if __name__ == "__main__":
    main()


Measured memory_bytes: 60524
package main

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

func main() {
	var sc = bufio.NewScanner(os.Stdin)	
	sc.Scan()
	AB := strings.Split(sc.Text(), " ")
	A, _ := strconv.Atoi(AB[0])
	B, _ := strconv.Atoi(AB[1])
	
	towers := []int{}
	for i := 1; i <= 999; i++ {
		ans := 0
		for j := 1; j <= i; j++ {
			ans += j
		}
		towers = append(towers, ans)
	}
	
	space := B - A
	tower1 := towers[space - 2]
	//tower2 := towers[space - 1]

	fmt.Println(tower1 - A)
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>

int main() {
	char s[15], t[15];
	int count = 0;
	size_t len;
	scanf("%s", s, 15);
	scanf("%s", t, 15);
	len = strlen(s);
	for (int i = 0; i < len; i++) {
		if (s[i] == t[i]) count += 1;
	}
	if (count == len) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 1696
using System;
using System.IO;
using System.Collections.Generic;

namespace _134
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_134B();
        }

        public static void solve_134B()
        {
            string[] nd = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(nd[0]);
            int d = Convert.ToInt32(nd[1]);

            int res = n % (d * 2 + 1) == 0 ? n / (d * 2 + 1) : n / (d * 2 + 1) + 1;

            Console.WriteLine(res);
        }
        public static void solve_134A()
        {
            int r = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine(3 * r * r);
        }
    }
}


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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T>
constexpr T INF = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()

template<typename T, typename U> istream& operator>>(istream& in, pair<T, U>& a) { cin >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& in, vector<T>& a) { for (T& x : a) cin >> x; }

void LOG(const int& x) { cerr << x << "\n"; }
void LOG(const vector<int>& a) { for (int x : a) cerr << x << " "; cerr << "\n"; }

int ceil(int a, int b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

class UnionFind { private: vector<int> par; vector<int> rnk; int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); } public: UnionFind(int size) { par.resize(size); rnk.resize(size); REP(i, size) par[i] = i, rnk[i] = 0; } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } } bool same(int x, int y) { return find(x) == find(y); } };

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

signed main() {
  i64 x;
  cin >> x;
  i64 i = 0;
  while (x > 0) {
    i += 1;
    x -= i;
  }
  cout << i << endl;
}

Measured memory_bytes: 256
N = int(input())
S = list(map(int, input().split()))
S.sort(reverse=True)
Closed = [False] * (1<<N)
Closed[0] = True
for j in range(N):
    num = 1<<j
    cnt_all = 0
    cnt = 0
    cnt_ = 0
    s_old = -1
    for i, s in enumerate(S):
        if s_old!=s:
            cnt += cnt_
            cnt_ = 0
        c = Closed[i]
        if c:
            cnt_ += 1
        elif cnt > 0:
            Closed[i] = True
            cnt -= 1
            cnt_all += 1
            if cnt_all == num:
                break
        s_old = s
    else:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 34676
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

#define int long long

signed main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  priority_queue<int> que;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    // que.push(A[i]);
  }
  vector<pair<int, int>> p(M);
  for(int i = 0; i < M; i++) {
    cin >> p[i].second >> p[i].first;
  }
  sort(all(p), greater<pair<int, int>>());
  int cnt = 0;
  for(int i = 0; i < M; i++) {
    for(int j = 0; j < p[i].second; j++) {
      que.push(p[i].first);
      cnt++;
      if(cnt == N) break;
    }
    if(cnt == N) break;
  }
  for(auto a : A) que.push(a);

  ll ans = 0;
  for(int i = 0; i < N; i++) {
    ans += que.top(); que.pop();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4724
s = input()
n = len(s)

ans = 0
for i in range(2**(n-1)):
    p = []
    trig = 0
    for j in range(n-1):
        if (i >> j) & 1 == 1:
            p.append(int(s[trig:j+1]))
            trig = j+1
    p.append(int(s[trig:]))
    ans += sum(p)

print(ans)

Measured memory_bytes: 41196
#include<bits/stdc++.h>
using namespace std;
string s;
int ans[100000];
int main()
{
	cin>>s;
	int n=s.size();
	vector<int> r,l;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			r.push_back(i);
			l.push_back(i+1);
		}
	}
	for(int i=0;i<n;i++)
	{
		int a=0;
		if(s[i]=='R')
		{
			int pos=lower_bound(l.begin(),l.end(),i)-l.begin();
			int a=l[pos]-i;
			if(a%2==0)
			ans[i+a]++;
			else
			ans[i+a-1]++;
		}
		else
		{
			int pos=lower_bound(r.begin(),r.end(),i)-r.begin();
			pos--;
			int a=i-r[pos];
			if(a%2==0)
			{
				ans[i-a]++;
			}
			else
			ans[i-a+1]++;
		}
		
	}
	for(int i=0;i<n;i++)
	cout<<ans[i]<<" ";
	return 0;
}


Measured memory_bytes: 1532
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

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

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[20][20];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll dp[20500];
int main() {
	cin >> n;
	ll a, b;
	cin >> a >> b;
	ll res = (n / (a + b)) * a + (min(n % (a + b), a));
	cout << res << endl;
}



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

#define int long long
#define counter(m)     for(int i=0;i<m;i++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;
int dp[10001][101][2];
int d;
int solve(string &s,int idx,int n,int sum,bool isSmalled,int num)
{
    if(idx==n)
    {
//        if(sum%d==0)
//        cout<<num<<" "<<sum<<endl;
        return sum%d==0;
    }
    if(dp[idx][isSmalled][sum]!=-1)
        return dp[idx][isSmalled][sum];
    int ans=0;
    if(isSmalled)
    {
        for(int i=0;i<10;i++)
        {
            ans+=solve(s,idx+1,n,(sum+i)%d,true,num*10+i);
            ans=ans%mod;
        }
    }
    else{
        int Num=s[idx]-'0';
        for(int i=0;i<Num;i++)
        {
            ans+=solve(s,idx+1,n,(sum+i)%d,true,num*10+i);
            ans%=mod;
        }
        ans+=solve(s,idx+1,n,(sum+Num)%d,false,num*10+Num);
        ans%=mod;
    }
    return dp[idx][isSmalled][sum]=ans;
}
int sumdigi(int num)
{
    int sum=0;
    while(num)
    {
        sum+=num%10;
        num/=10;
    }
    return sum;
}
int32_t main() {
    nitin;
    string s;
    cin>>s;
    int n=s.length();
    cin>>d;
//    for(int i=0;i<s[0]-'0';i++)
//        dp[1][i][0]=1;
//    dp[1][s[0]-'0'][1]=1;
dp[0][0][1]=1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<d;j++)
        {
            int num=s[i]-'0';
            for(int k=0;k<10;k++)
            {
                dp[i+1][(j+k)%d][0]=(dp[i+1][(j+k)%d][0]+dp[i][j][0])%mod;
            }
            for(int k=0;k<num;k++)
            {
                dp[i+1][(j+k)%d][0]=(dp[i+1][(j+k)%d][0]+dp[i][j][1])%mod;
            }
            dp[i+1][(j+num)%d][1]=(dp[i+1][(j+num)%d][1]+dp[i][j][1])%mod;
        }
    }
//    for(int i=0;i<=n;i++)
//    {
//        for(int j=0;j<d;j++)
//        {
//            cout<<dp[i][j][0]<<" "<<dp[i][j][1]<<"   "<<i<<" "<<j<<endl;
//        }
//    }
    cout<<(dp[n][0][0]+dp[n][0][1]-1+mod)%mod<<endl;

    return 0;
}

Measured memory_bytes: 19420
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
	int n;
	int a[200000];
	int max=0, semimx=0;
	cin >> n;
	LOOP(i,n){
		cin >> a[i];
		if(max<a[i]){
			semimx = max;
			max = a[i];
		}else if(semimx<a[i]){
			semimx = a[i];
		}
	}
	int cntr = 0;
	LOOP(i,n){
		if(max==a[i])cntr++;
	}
	if(cntr>1){
		LOOP(i,n) cout << max << endl;
	}else{
		LOOP(i,n){
			if(max==a[i]) cout << semimx << endl;
			else	cout << max << endl;
		}
	}
}


Measured memory_bytes: 2432
match = ['eraser', 'erase', 'dreamer', 'dream']
len_m = [len(m) for m in match]
S = input()
n = len(S)
dp = [False] * (n + 1)
dp[0] = True
for i in range(1, n + 1):
    for lm, m in zip(len_m, match):
        if S[:i].endswith(m) and dp[i - lm]:
            dp[i] = True
            break
print('YES' if dp[n] else 'NO')

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;



int main(){ 
  
  int N, psum, qsum;
  cin >> N;

  vector<int> v(N), P(N), Q(N);
  rep(i,N) v[i] = i + 1;
  rep(i,N) cin >> P[i];
  rep(i,N) cin >> Q[i];

  psum = P[0];
  rep1(i,N-1) psum = psum * 10 + P[i];
  qsum = Q[0];
  rep1(i,N-1) qsum = qsum * 10 + Q[i];


  vector<Int> permuN(0);

  do {
    Int x = v[0];
    rep1(i,N-1) {
      x = x * 10 + v[i];
    }
    permuN.push_back(x);
  } while(next_permutation(v.begin(),v.end()));

  sort(permuN.begin(),permuN.end());


  int a, b;

  rep(i,permuN.size()) {
    if (psum == permuN[i]) a = i;
    if (qsum == permuN[i]) b = i;
  }

  cout << abs(a-b) << endl;

}


Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> L(N);
    for(int i = 0; i < N; ++i){
        cin >> L[i];
    }

    int ans = 0;
    sort(L.begin(), L.end());
    // for(int i = 0; i < N; ++i){
    //     cout << L[i] << " ";
    // }
    // cout << "\n";
    for(int i = 0; i < N; ++i){
        for(int j = i+1; j < N; ++j){
            int ab = L[i] + L[j];
            int c = lower_bound(L.begin(), L.end(), ab) - L.begin();
            ans += max(c-(j+1), 0);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST

struct Corr {
    int x;
    int y;
    ll depth;
};
queue<Corr> q;
ll bfs(vector<vector<char>> grid) {
    // 既に探索の場所を1，探索していなかったら0を格納する配列
    //cerr << grid.size() << ":" << grid[0].size() << endl;
    vector<vector<bool>> ispassed(grid.size(), vector<bool>(grid[0].size(), false));
    // このような記述をしておくと，この後のfor文が綺麗にかける
    ll minimum_cost = INF;
    int dx[8] = {1, 0, -1, 0};
    int dy[8] = {0, 1, 0, -1};
    while(!q.empty()) {
        Corr now = q.front();q.pop();
        //cerr << now.x << ":" << now.y << ":" << now.depth << endl;
        ispassed[now.y][now.x] = true;
        for(int i = 0; i < 4; i++) {
            int nextx = now.x + dx[i];
            int nexty = now.y + dy[i];
            // 探索する場所が配列外の場合
            if(nextx < 0 || nextx >= grid[0].size() || nexty < 0 || nexty >= grid.size()) continue;
            // 次に探索する場所が既に探索済みの場合
            if(ispassed[nexty][nextx]) continue;
            if(grid[nexty][nextx] == '#') continue;
            ispassed[nexty][nextx] = true;
            Corr next = {nextx, nexty, now.depth+1};
            if(nextx == grid[0].size()-1 && nexty == grid.size()-1) minimum_cost = min(ll(minimum_cost), next.depth);
            q.push(next);
        }
    }
    return minimum_cost;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long H, W;
    cin >> H >> W;
    std::vector<std::vector<char>> mat(H, vector<char>(W, ' '));
    ll count_white = 0;
    for(size_t i=0;i<H; i++)
    {
        for(size_t j=0;j<W; j++)
        {
            cin >> mat[i][j];
            if(mat[i][j] == '.') count_white++;
        }
    }
    /*
    cerr << count_white << endl;
    for(size_t i=0;i<H; i++)
    {
        for(size_t j=0;j<W; j++)
        {
            cerr << mat[i][j] << " ";
        }
        cerr << endl;
    }
    */
    Corr i = Corr{0, 0, 1};
    q.push(i);
    ll minimum_cost = bfs(mat);
    if(minimum_cost == INF) cout << -1 << endl;
    else{
        //cerr << minimum_cost << endl;
        cout << count_white - minimum_cost << endl;
    }
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.stream.IntStream;

// E - Knapsack 2 / atcoder.jp
// 문제 링크 : https://atcoder.jp/contests/dp/tasks/dp_e
// 문제 해설 : https://jinpyo.kim/EducationalDP-solution
// Submission : https://atcoder.jp/contests/dp/submissions/9204970

public class Main {
    public static void main(String[] args) {
         Scanner sc = new Scanner(System.in);
//        Reader sc = new Reader();
        int N = sc.nextInt();
        int W = sc.nextInt();
        int[] ws = new int[N+1];
        int[] vs = new int[N+1];
        PrintWriter pw = new PrintWriter(System.out);

        for(int i=1; i<=N; ++i) {
            ws[i] = sc.nextInt();
            vs[i] = sc.nextInt();
        }

        long r = Knapsack2(N, W, ws, vs);

        pw.println(r);
        pw.close();
    }

    public static long Knapsack2(int N, int W, int[] ws, int[] vs) {
        // Java 8에서 새로 추가된 Stream을 사용해서, 합을 구해봅니다.
        int V = IntStream.of(vs).sum();
        // 문제의 'Constraints'에서 주어진것 처럼 Wi의 값이 매우 크기 때문에,
        // int를 사용해서 풀면, overflow 되는 문제가 발생합니다.
        long[][] dp = new long[N+1][V+1];

        for(int n=0; n<=N; ++n) {
            for(int v=0; v<=V; ++v) {
                dp[n][v] = Integer.MAX_VALUE - V;
            }
        }

        long value = 0;
        dp[0][0] = 0;
        for(int i=1; i<=N; ++i) {
            for(int v=0; v<=V; ++v) {
                dp[i][v] = Math.min(dp[i-1][v], dp[i][v]);
                if(v-vs[i]>=0)
                    dp[i][v] = Math.min(dp[i][v], dp[i-1][v-vs[i]] + ws[i]);
                if(dp[i][v] <= W) {
                    value = Math.max(value, v);
                }
            }
        }

        return value;
    }
}


Measured memory_bytes: 129876
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Bishop | diff Bishop.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Bishop.cpp && ./a.out

/*
 
 3/15/2020
 
 22:15-22:45 give up
 
 */

LL N,M;

LL solve() {
  LL res;
  if(N>M) swap(N,M);
  if(N==1) return 1;
  if(N%2==0||M%2==0) {
    res=N*M/2;
  } else {
    res=N*M/2+1;
  }
  return res;
}

void solve_wrong() {
  LL res;
  if(N%2==0) {
    res=N/2*M;
  } else {
    LL a=(N+1)/2,b=a-1;
    LL x=(M+1)/2;
    res=a*x+b*(M-x);
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>M;
  cout<<solve()<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#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;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
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; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n;
  cin >> n;
  n /= 200;
  cout << 10 - n << endl;
  return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int h,w;
int a[1010][1010];
int fh[1010],fw[1010];

int main(void){
	cin >> h >> w;
	rep(i,h)rep(j,w) cin >> a[i][j];

	rep(i,h)rep(j,w){
		if(a[i][j]==0){
			fh[i]++;
			fw[j]++;
		}
	}
	
	rep(i,h){
		rep(j,w) cout << (j?" ":"") << (fh[i]+fw[j]+(a[i][j]==0))%2;
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 7000
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int r, d, x;
  cin >> r >> d >> x;
  for (int i = 1; i <= 10; ++i) {
    x = r * x - d;
    cout << x << endl;
  }
  return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
const long long mod = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	if (s == "KIHBR" || s == "AKIHBR" || s == "KIHABR" || s == "KIHBAR" || s == "KIHBRA" || s == "KIHABRA" || s == "AKIHABR" || s == "AKIHBAR" || s == "AKIHBRA" || s == "KIHABAR" || s == "KIHABRA" || s == "KIHBARA" || s == "KIHABARA" || s == "AKIHBARA" || s == "AKIHABRA" || s == "AKIHABAR" || s == "AKIHABARA") {
		puts("YES");
	}
	else puts("NO");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll n,k;cin>>n>>k;
  ll ans = 0;
  rep(m, min(k+1, n)){
    ll ret = 1;
    ret *= nCr(n, m);
    ret *= nCr(n-m-1 + m , n-m-1);
    ret %= MOD;
    ans += ret;
    ans %= MOD;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 1005;

int main(){
	lint n, a, b; cin >> n >> a >> b;
	if(a % 2 == b % 2) cout << abs(a - b) / 2 << endl;
	else{
		cout << (abs(a - b) + 1) / 2 + min(n - b, a - 1) << endl;
	}
}


Measured memory_bytes: 256
import math                                                                                              
INPUT_SENTENCES = 1                                                                                      
ss = [input() for i in range(INPUT_SENTENCES)][0].split(" ")                                             
N = int(ss[0])                                                                                           
D = int(ss[1])                                                                                           
INPUT_SENTENCES = N                                                                                      
ss = [input() for i in range(INPUT_SENTENCES)]                                                           
X = [[int(ii) for ii in ss[i].split(" ")] for i in range(N)]                                             
result = []                                                                                              
for i in range(N):                                                                                       
    for j in [ii for ii in range(N) if i < ii]:                                                          
        tmp = [(X[i][d] - X[j][d])*(X[i][d] - X[j][d]) for d in range(D)]                                
        if math.sqrt(sum(tmp)).is_integer():                                                             
            result.append(1)                                                                             
print(sum(result))

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

int main(){
    int x; cin >> x;
    int count = 0; 
    for( int i = 1; i < 1e+9+7; i++){
        x -= i;
        count++;
        if(x <= 0) break;
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int n,m,p,i,x[101],t,a;
  int p1;
  while(1){
    t=0;
    scanf("%d%d%d",&n,&m,&p);
    if(n==0)break;
    p1=(100-p);
    for(i=1;i<=n;i++){
      scanf("%d",&x[i]);
      t=t+x[i];
    }
    if(x[m]==0){
      printf("0\n");
    }
    else{
      a=p1*t/x[m];
      printf("%d\n",a);
    }
  }
  return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 998244353

ll tr[1000005], A[200010], g[1000005];

ll modpow(ll x, ll y) {
	ll ans = 1;
	while (y) {
		if (y & 1)ans *= x;
		x *= x;
		ans %= MOD;
		x %= MOD;
		y /= 2;
	}
	return ans;
}

int main() {
	for (int i = 1;i <= 1000000;i++) {
		tr[i] = 0;
		g[i] = 0;
	}
	for (ll i = 2;i <= 1000000;i++) {
		tr[i] -= 1 - modpow(i, MOD - 2);
		for (ll j = i * 2;j <= 1000000;j += i) {
			tr[j] -= tr[i];
			tr[j] %= MOD;
		}
	}
	int N;
	cin >> N;

	ll as = 0;
	for (int i = 0;i < N;i++) {
		cin >> A[i];
		g[A[i]] += A[i];
		g[A[i]] %= MOD;
		as += A[i];
		as %= MOD;
	}

	for (int i = 2;i <= 1000000;i++) {
		for (int j = i * 2;j <= 1000000;j += i) {
			g[i] += g[j];
			g[i] %= MOD;
		}
	}

	ll ans = as * as % MOD;
	for (int i = 2;i <= 1000000;i++) {
		ans += g[i] * g[i] % MOD * tr[i] % MOD;
		ans %= MOD;if (ans < 0)ans += MOD;
	}
	ans -= as;
	if (ans < 0)ans += MOD;
	if (ans & 1)ans = (ans + MOD) / 2;
	else ans /= 2;
	cout << ans % MOD << endl;
}

Measured memory_bytes: 17408
//S.G.N.//
#include <bits/stdc++.h>
using namespace std;
typedef vector< long long > vi;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define fr(n) for(ll i=0;i<n;i++)
#define tr(a) for(auto it=a.begin();it!=a.end();it++)
#define N 998244353445 
#define PI 3.1415926535897932384
#define F first
#define S second
#define mp make_pair
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
void solve()
{
  ll n;
  cin>>n;
  ll a[n];
  fr(n)
  cin>>a[i];
  ll dp[n];
  dp[0]=0;
  fr(n)
  {
    if(i==0)
      continue;
    if(i==1){
      dp[1]=dp[0]+abs(a[1]-a[0]);
    }
    else
    dp[i]=min(dp[i-1]+(abs(a[i]-a[i-1])),dp[i-2]+abs(a[i]-a[i-2]));
  }
  cout<<dp[n-1];

}
int main()
{
  
  #ifndef ONLINE_JUDGE
     * freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
  FAST
  ll test;
  test=1;
  //cin>>test;
  while(test--)
  {
    solve();
  }
  return 0;
}

Measured memory_bytes: 5164
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
ll MOD = 1000000007ll;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define Se second
#define Fi first
#define rep(i, n) for(int i=0;i<n;i++)
#define pb(x) push_back(x)

const int MX = 20005;

int main()
{
	string S;
	cin >> S;
	int N = S.size();
	for(int i = 0; i < N; i++){
		if(S.substr(i, 2) == "AC") return !printf("Yes\n");
	}
	printf("No\n");
}


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

vector<ll>multiple(1005);
void prime(int v){
  multiple[0]=-1;
  multiple[1]=-1;
  for(int i=2; i<=v; i++){
    if(multiple[i]!=0)continue;
    for(int j=i*2; j<=v; j+=i){
     multiple[j]=i;
    }
  }
}


int main(){
  ll n;
  cin >> n;
  prime(1000);
  vector<ll>prim(1001,1);
  
  for(int i=1; i<=n; i++){
    ll x = i;
    for(int j=1; j<=i; j++){
      if(multiple[j]!=0) continue;
      while(x%j==0){
        x/=j;
        prim[j]++;
      }
    }
  }
  
  ll ans = 1;
  for(int i=1; i<=n; i++){
    ans*=prim[i];
    ans%=mod;
  }
  
  cout << ans << endl;
  
}
       
        
      
  
    

Measured memory_bytes: 3644
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
#define mem(a,b) memset(a,b,sizeof(a))
const int maxn = 1e5+5;
const int ff = 0x3f3f3f3f;

int n,m,r;
int e[50];
int dis[202][202];

int main()
{
	cin>>n>>m>>r;
	for(int i = 1;i<= r;i++)
		cin>>e[i];
	mem(dis,ff);
	for(int i = 1;i<= m;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		dis[a][b] = c;
		dis[b][a] = c;
	}
	for(int k = 1;k<= n;k++)
		for(int i = 1;i<= n;i++)
			for(int j = 1;j<= n;j++)
				dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]);
	
	vector<int> p;
	for(int i = 1;i<= r;i++)
		p.push_back(i);
	int ans = ff;
	//cout<<ans<<endl;
	do
	{
		int tmp = 0;
		for(int i = 1;i< r;i++)
			tmp+= dis[e[p[i]]][e[p[i-1]]];
		if(tmp< ans)
			ans = tmp;
	} while(next_permutation(p.begin(),p.end()));
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main(){
  string s;
  int n; cin >> n >> s;
  int ans=0;
  
  for(int i=0; i<n; i++){
    int cur=0;
    set<char> a,b;
    for(int j=0; j<i; j++){a.insert(s[j]);}
    for(int j=i; j<n; j++){b.insert(s[j]);}
    for(auto to:a){
      if(b.find(to)!=b.end()){cur++;}
    }
    ans = max(ans,cur);
  }
  cout << ans << endl; 
  return 0;

}


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

using namespace std;

int main(){

	int n,k,a[100000],sum,ans,i;

	while(cin>>n>>k,n||k){

	sum=0;

	for(i=0;i<n;i++){
		cin>>a[i];
	}

	for(i=0;i<k;i++){
		sum=sum+a[i];
	}

    ans=sum;
    i=0;

    for(i=k;i<n;i++){
    	sum=sum-a[i-k]+a[i];
    	ans=max(ans,sum);
    }

    cout<<ans<<endl;
	}
}

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

using namespace std;

const int max_n = 1111, inf = 1000111222;

int n, m, a, b;
char s[max_n][max_n];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d%d%d%d", &n, &m, &a, &b);
    for (int i = 0; i < b; ++i) {
        for (int j = 0; j < a; ++j) {
            s[i][j] = '0';
        }
        for (int j = a; j < 2 * a; ++j) {
            s[i][j] = '1';
        }
        for (int j = 2 * a; j < m; ++j) {
            s[i][j] = '0';
        }
    }
    for (int i = b; i < n; ++i) {
        for (int j = 0; j < a; ++j) {
            s[i][j] = '1';
        }
        for (int j = a; j < 2 * a; ++j) {
            s[i][j] = '0';
        }
        for (int j = 2 * a; j < m; ++j) {
            s[i][j] = '1';
        }
    }
    for (int i = 0; i < n; ++i) {
        puts(s[i]);
    }
    return 0;
}


Measured memory_bytes: 2304
#include<iostream>
using namespace std;
int main(){
	string s;
	cin>>s;
	for (int i=0;i<s.length();i++){
		if(s[i]=='9') {
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0; 
}

Measured memory_bytes: 256
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  string s;
  cin >> s;
  for (auto &i : s) i = 'x';
  cout << s << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3596
#include<stdio.h>
#include<stdlib.h>
 
typedef struct{
    int p;
    int m;
    int k;
}Node;
 
void Preorder(int);
void Inorder(int);
void Postorder(int);
 
Node *node;
 
int main(void){
    int n,sd,rt;
    int i;
 
    scanf("%d",&n);
 
    node=(Node*)malloc(n*sizeof(Node));
 
    for(i=0;i<n;i++){
        node[i].p=-1;
        node[i].m=-1;
        node[i].k=-1;
    }
 
    for(i=0;i<n;i++){
        scanf("%d",&sd);
 
        scanf("%d",&node[sd].m);
        if(node[sd].m != -1) node[node[sd].m].p=sd;
 
        scanf("%d",&node[sd].k);
        if(node[sd].k != -1) node[node[sd].k].p=sd;
    }
 
    for(i=0;i<n;i++){
        if(node[i].p==-1) rt=i;
    }
 
    printf("Preorder\n");
    Preorder(rt);
    printf("\n");
 
    printf("Inorder\n");
    Inorder(rt);
    printf("\n");
 
    printf("Postorder\n");
    Postorder(rt);
    printf("\n");
 
    free(node);
 
    return 0;
}
 
void Preorder(int sd){
    printf(" %d",sd);
    if(node[sd].m != -1) Preorder(node[sd].m);
    if(node[sd].k != -1) Preorder(node[sd].k);
}
 
void Inorder(int sd){
    if(node[sd].m != -1) Inorder(node[sd].m);
    printf(" %d",sd);
    if(node[sd].k != -1) Inorder(node[sd].k);
}
 
void Postorder(int sd){
    if(node[sd].m != -1) Postorder(node[sd].m);
    if(node[sd].k != -1) Postorder(node[sd].k);
    printf(" %d",sd);
}



Measured memory_bytes: 2108
#include<iostream>
using namespace std;
int calc, a; char p;
int main() {
	cin >> calc;
	while (true) {
		cin >> p;
		if (p == '=') { cout << calc << endl; break; }
		cin >> a;
		if (p == '+') { calc += a; }
		if (p == '-') { calc -= a; }
		if (p == '*') { calc *= a; }
		if (p == '/') { calc /= a; }
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int a,n,m;
    long long int sum=0;
    cin>>n>>m;
    for(int i=0;i<m;i++) {
        cin>>a;
        sum+=a;
    }
    if(sum>n) cout<<-1<<endl;
    else cout<<n-sum<<endl;
    return 0;
}


Measured memory_bytes: 3624
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define                          ll                          long long int
ll gcd(int a,int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}

#define                          in(x)                       scanf("%lld",&x)
#define                          in2(x,y)                    scanf("%lld %lld",&x,&y)
#define                          in3(x,y,z)                  scanf("%lld %lld %lld",&x,&y,&z)
#define                          out(x)                      printf("%lld\n",x)
#define                          cy                          printf("YES\n")
#define                          cn                          printf("NO\n")
#define                          inf                         1e18
#define                          neg                         -1e18
#define                          mx                          2111111
#define                          fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define                          fi                          frist
#define                          si                          second
#define                          ce                          cout<<endl
#define                          pb                          push_back
#define                          vc(x)                       x.begin(),x.end()
#define                          pb                          push_back
#define                          pi                          pair<ll,ll>
#define                          debug                       printf("ok\n");
#define                          pg                          pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> >



int main(){

    string a,b,c;
    ll i,j,ans=0,s=0,n,m,p;
    cin>>a>>b;
    n=a.size();
    m=b.size();
    for(i=0;i<n-m+1;i++){
            s=0,p=0;
        for(ll j=i;j<m+i;j++){
              //  c+=a[j];
            if(a[j]==b[p++])s++;
        }
        //cout<<c<<endl;c.clear();
    ans=max(ans,s);
    }
    cout<<m-ans<<endl;
}



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

int main(){
  int n,a,b;
  cin>>n>>a>>b;
  int ans=0;
  for(int i=1;i<=n;i++){
    int sum=0;
    int t=i;
    while(t>0){
      sum+=t%10;
      t/=10;
    }
  if(a<=sum && b>=sum) ans+=i;
  }
  cout<<ans;

}


Measured memory_bytes: 3516