akhauriyash/Code-Regression huggingface dataset:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    S = readline().strip()

    ans = 0
    acgt = ["A", "C", "G", "T"]
    for i in range(len(S)):
        if S[i] in acgt:
            m = i
            tmp = 0
            while m < len(S) and S[m] in acgt:
                tmp += 1
                m += 1
            ans = max(ans, tmp)

    print(ans)


if __name__ == "__main__":
    main()


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

const int N = 5e3 + 7;
const int SS = 4 * N;
const int INF = 1e9 + 7;
const int M = 2e2 + 7;

ll mx[SS], lazy[SS];
ll a[N][M], x[N];
int n, m;
stack<int> st[M];

void update(int v, ll val)
{
	mx[v] += val;
	lazy[v] += val;
}

void shift(int v)
{
	update(2 * v, lazy[v]);
	update(2 * v + 1, lazy[v]);
	lazy[v] = 0;
}

void merge(int v)
{
	mx[v] = max(mx[2 * v], mx[2 * v + 1]);
}

void add(int l, int r, ll val, int s = 0, int e = n, int v = 1)
{
	if (l >= e || r <= s)
		return;
	if (l <= s && e <= r)
	{
		update(v, val);
		return;
	}
	shift(v);
	int mid = (s + e) / 2;
	add(l, r, val, s, mid, 2 * v);
	add(l, r, val, mid, e, 2 * v + 1);
	merge(v);
}

int main()
{
	ios::sync_with_stdio(false);

	cin >> n >> m;
	for (int i=1; i<n; i++)
		cin >> x[i];
	for (int i=0; i<n; i++)
		for (int j=0; j<m; j++)
			cin >> a[i][j];
	for (int i=0; i<m; i++)
		st[i].push(n);
	ll ans = 0;
	for (int i=n-1; i>=0; i--)
	{
		for (int j=0; j<m; j++)
		{
			ll cnt = 0;
			while (st[j].top() != n && a[st[j].top()][j] < a[i][j])
			{
				add(i, st[j].top(), a[st[j].top()][j] - cnt);
				cnt = a[st[j].top()][j];
				st[j].pop();
			}
			add(i, st[j].top(), a[i][j] - cnt);
			st[j].push(i);
		}
		add(i+1, n, -x[i+1]);
		ans = max(ans, 1LL * mx[1]);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ar array
#define db long double
#define pow pw
const db pi = 3.14159265358979323846;
int pw(int a,int b){
    int ans=1;
    while(b){
    if (b%2) ans*=a;
    a*=a;
    b/=2;
    }
    return(ans);
}
const int mxn=1e5+7;
int n,m;
vector<int> g[mxn];
int dp[mxn],vis[mxn],in_degree[mxn];
void dfs(int u)
{
    vis[u]=1;
    for(int v : g[u]) 
    {
        dp[v]=max(dp[v],dp[u]+1);
        in_degree[v]--;
        if (in_degree[v]==0) dfs(v);
    }
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for (int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        in_degree[v]++;
    }
    for (int i=1;i<=n;i++)
    if (!vis[i]&&in_degree[i]==0) dfs(i);
    int ans=0;
    for (int i=1;i<=n;i++) ans=max(ans,dp[i]);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 16000
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
using namespace std;
#define sd(n) scanf("%d", &n)
#define sdd(n, m) scanf("%d%d", &n, &m)
#define sddd(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define pd(n) printf("%d\n", n)
#define pc(n) printf("%c", n)
#define pdd(n, m) printf("%d %d\n", n, m)
#define pddd(n, m, z) printf("%d %d %d\n", n, m, z)
#define pld(n) printf("%lld\n", n)
#define pldd(n, m) printf("%lld %lld\n", n, m)
#define plddd(n, m, z) printf("%lld %lld %lld\n", n, m, z)
#define sld(n) scanf("%lld", &n)
#define sldd(n, m) scanf("%lld%lld", &n, &m)
#define slddd(n, m, k) scanf("%lld%lld%lld", &n, &m, &k)
#define sf(n) scanf("%lf", &n)
#define sc(n) scanf("%c", &n)
#define sff(n, m) scanf("%lf%lf", &n, &m)
#define sfff(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)
#define ss(str) scanf("%s", str)
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = a; i >= n; i--)
#define mem(a, n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ce i == n ? '\n' : ' '
#define mod(x) ((x) % MOD)
#define gcd(a, b) __gcd(a, b)
#define lowbit(x) (x & -x)
typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
inline int read()
{
	int ret = 0, sgn = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
	{
		if (ch == '-')
			sgn = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		ret = ret * 10 + ch - '0';
		ch = getchar();
	}
	return ret * sgn;
}
inline void Out(int a) //ê?3?ía1ò
{
	if (a > 9)
		Out(a / 10);
	putchar(a % 10 + '0');
}

ll gcd(ll a, ll b)
{
	return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
///快速幂m^k%mod
ll qpow(ll x, ll n, ll mod)
{
	ll res = 1;
	while (n)
	{
		if (n & 1)
			res = (res * x) % mod;
		x = x * x % mod, n >>= 1;
	}
	return res;
}

const int N = 2e5 + 10;

int main()
{
	int n, m;
	int sum = 0;
	sdd(n, m);
	rep(i, 1, m)
	{
		int x;
		sd(x);
		sum += x;
	}
	if (sum > n)
		puts("-1");
	else
		pd(n - sum);
	return 0;
}


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

const int N=1e6+50;
char s[N],t[N]; int n,pos[N];
queue <int> q;
int main() {
	scanf("%d%s%s",&n,s+1,t+1);
	for(int i=n,p=n;i>=1;i--) {
		p=min(p,i); 
		while(p>1 && s[p]!=t[i]) --p;
		if(s[p]!=t[i]) {puts("-1"); return 0;}
		if(!pos[p]) pos[p]=i;
	}
	int ans=0;
	for(int i=1;i<=n;i++) if(pos[i] && (pos[i]^i)) {
		while(!q.empty() && q.front()+q.size()<=i) q.pop();
		q.push(pos[i]); ans=max(ans,(int)q.size());
	} cout<<ans<<'\n';
}

Measured memory_bytes: 10240
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

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

    ll a,b,c,d,ans=0,i,j,k;
	
	cin >> a >> b >> c >> d;

	ll cc=c,dd=d;

	if(cc<dd){
    ll tmp = cc;
    cc = dd;
	dd = tmp;
  }
	ll r = cc % dd;
  while(r!=0){
    cc = dd;
    dd = r;
    r = cc % dd;
  }

	ll cd = c*d/dd;

	//cout << cd << endl;

	if(a%c==0){
		i = (b/c)-a/c+1;
	}
	else{
		i = (b/c)-(a/c+1)+1;
	}
	if(a%d==0){
		j = b/d+-a/d+1;
	}
	else{
		j = (b/d)-(a/d+1)+1;
	}
	if(a%cd==0){
		k = b/cd-a/cd+1;
	}
	else{
		k = (b/cd)-(a/cd+1)+1;
	}

	ans = b-a+1 - (i + j - k);

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forab(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using ui = unsigned int;
const ll infll = (ll)(1e18) + 10;
const int inf = int(1e9) + 10;
const int maxn = int(1e5) + 10;
const int mod = int(1e9) + 7;

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    vector<double> probs(n + 1);
    forn(i, n) cin >> probs[i + 1];
    vector<vector<double>> dp(n + 1, vector<double>(n + 1));
    dp[0][0] = 1;
    forab(i, 1, n + 1) {
        forab(j, 0, i + 1) {
            dp[i][j] = dp[i - 1][j] * (1 - probs[i]);
            if (j > 0) {
                dp[i][j] += dp[i - 1][j - 1] * probs[i];
            }
        }
    }
    ld ans = 0;
    forab(i, (n + 1) / 2, n + 1) {
        ans += dp[n][i];
    }
    cout.precision(10);
    cout << ans << "\n";
    return 0;
}

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


struct Edge{
  int to, cost, id;
  Edge(int to, int cost, int id)
    : to(to), cost(cost), id(id) {}
};

const int MAX_NS = 12;
const int MAX_NL = 22;

int NS, NL;
vector<Edge> E[MAX_NS];
bool vis[MAX_NL];

vector<int> path;
int maxCost;
vector<int> maxPath;

void dfs(int p, int cost) {
  path.push_back(p+1);

  bool flag = false;
  for(int i = 0; i < E[p].size(); ++i) {
    Edge &e = E[p][i];
    if(vis[e.id]) continue;
    vis[e.id] = true;
    dfs(e.to, cost + e.cost);
    vis[e.id] = false;
    flag = true;
  }

  if(!flag) {
    if(cost > maxCost) {
      maxCost = cost;
      maxPath = path;
    }
  }
  path.pop_back();
}

void solve() {
  maxCost = -1;
  for(int i = 0; i < NS; ++i) {
    fill(vis, vis+NL, false);
    dfs(i,0);
  }

  cout << maxCost << endl;
  for(int i = 0; i < maxPath.size(); ++i) {
    if(i) cout << " ";
    cout << maxPath[i];
  }
  cout << endl;
}

int main() {
  while(cin >> NS >> NL && (NS|NL)) {
    for(int i = 0; i < MAX_NS; ++i) E[i].clear();
    for(int i = 0; i < NL; ++i) {
      int s1, s2, d;
      cin >> s1 >> s2 >> d;
      --s1; --s2;
      E[s1].push_back(Edge(s2,d,i));
      E[s2].push_back(Edge(s1,d,i));
    }
    solve();
  }
  return 0;
}

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

class plogram
{
    static void Main()
    {
        int[] line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int A = line[0];
        int B = line[1];

        int sum = Math.Max(A, B);
        if(A>B)
        {
            A -= 1;
        }
        else
        {
            B -= 1;
        }
        sum += Math.Max(A, B);

        Console.WriteLine(sum);

    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int w,a[2];
  cin>>w>>a[0]>>a[1];
  sort(a,a+2);
  if(a[0]+w >= a[1]) cout<<0<<endl;
  else cout<<a[1]-a[0]-w<<endl;

  return 0;
}


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

int main()
{
    long long n;
    cin >> n;
    vector<long long> box;
    long long i = -1;
    while (cin >> i)
    {
        box.push_back(i);
    }

    auto m = map<long long, long long>();
    for (auto i = 0; i < box.size(); i++)
    {
        m[box.at(i)] = m[box.at(i)] + 1;
    }

    unsigned long long ans = 0;
    auto it = m.begin();
    while (it != m.end())
    {
        if (it->second > 1)
        {
            ans += (it->second) * (it->second - 1) / 2;
        }
        it++;
    }

    for (auto k = 0; k < box.size(); k++)
    {
        auto v = box.at(k);
        auto old_count = m[v];
        auto added = old_count > 0 ? ((old_count) * (old_count - 1) / 2) : 0;
        auto new_count = m[v] - 1;
        auto newcount = new_count > 0 ? (new_count) * (new_count - 1) / 2 : 0;

        cout << ans - added + newcount << endl;
    }
}


Measured memory_bytes: 11120
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.printf("%d %d %f\n", a / b, a % b, Double.valueOf(a) / Double.valueOf(b));
        sc.close();
    }

}



Measured memory_bytes: 26424
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	long a, b, x;
	std::cin >> a >> b >> x;
	
	long aa;
	if (a == 0)
		aa = 0;
	else
		aa = (a-1) / x + 1;
	long bb = b / x + 1;
	std::cout << (bb-aa) << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
typedef long long int ll;
int main(){
    int N;
    string S;
    cin>>N>>S;
    int count=0;
    rep(i,N-2){
        if(S.substr(i,3)=="ABC"){
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int physical = sc.nextInt();       //体力
		int type = sc.nextInt();            //技の種類
		int technique[] = new int[type];  //技の配列
		//技の値を入力し、都度体力から引く
		for(int i=0 ; i<type ; i++) {
			technique[i] = sc.nextInt();
			physical -= technique[i];
		}
		//体力が0以下か判断
		System.out.print(physical<=0 ? "Yes" : "No");
	}
}

Measured memory_bytes: 48668
#include<cstdio>
#include<algorithm>
#include<map>
#include<cstring>
using namespace std;
#define LL long long
LL h,w,n;
map<LL,LL>m;
int dx[9]={-2,-2,-2,-1,-1,-1,0,0,0};
int dy[9]={-2,-1,0,-2,-1,0,-2,-1,0};
LL ans[10];
void Alter(LL x,LL y)
{
	LL a,b,tmp;
	for(int i=0;i<9;i++)
	{
		a=x+dx[i];b=y+dy[i];
		if(a<1||b<1||a>h-2||b>w-2)continue;
		tmp=(h-2)*(b-1)+a;
		m[tmp]++;
	}
}
int main()
{
	scanf("%lld%lld%lld",&h,&w,&n);
	LL x,y;
	for(LL int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&x,&y);
		Alter(x,y);
	}
	memset(ans,0,sizeof(ans));
	ans[0]=(h-2)*(w-2);
	LL tmp;
	map<LL,LL>::iterator it=m.begin();
	while(it!=m.end())
	{
		tmp=it->second;
		ans[tmp]++;
		ans[0]--;
		it++;
	}
	for(int i=0;i<=9;i++)
		printf("%lld\n",ans[i]);
	//return 0;
}

Measured memory_bytes: 56448
#include <iostream>
#include <cmath>
#include <vector>
#include <array>
#include <set>
#include <queue>

using namespace std;

const int N = 4;
const int N2 = N * N;

int MDT[N2][N2];

struct Puzzle {
    array<char, N2> board;
    int empty;
    int cost;
    int rank;

    bool operator < (const Puzzle& other) const {
        return cost + rank > other.cost + other.rank;
    }
};

int distance(const Puzzle& p) {
    int d = 0;
    for (int i = 0; i < N2; ++i) {
        if (p.board[i] == N2) continue;
        d += MDT[i][p.board[i] - 1];
    }
    return d;
}

const vector<array<int, 2>> dir = {
    {-1, 0}, // left
    {0, -1}, // up
    {1, 0},  // right
    {0, 1},  // down
};

int astar(Puzzle start) {
    auto puzzle_less = [](const Puzzle& a, const Puzzle& b) {
        for (int i = 0; i < N2; ++i) {
            if (a.board[i] != b.board[i])
                return a.board[i] < b.board[i];
        }
        return false;
    };

    Puzzle ans;
    set<Puzzle, decltype(puzzle_less)> visited(puzzle_less);
    priority_queue<Puzzle> Q;
    Q.push(start);
    while (!Q.empty()) {
        auto u = Q.top();
        Q.pop();
        if (u.rank == 0) {
            return u.cost;
        }
        visited.insert(u);

        auto sx = u.empty % N;
        auto sy = u.empty / N;
        for (auto& d : dir) {
            auto tx = sx + d[0];
            auto ty = sy + d[1];
            if (tx < 0 || ty < 0 || tx >= N || ty >= N) {
                continue;
            }
            auto v = u;

            auto k = tx + ty * N;
            swap(v.board[v.empty], v.board[k]);
            v.empty = k;
            v.rank = distance(v);
            if (visited.find(v) == visited.end()) {
                ++v.cost;
                Q.push(v);
            }
        }
    }
    return -1;
}

int main() {
    for (int i = 0; i < N2; ++i) {
        for (int j = 0; j < N2; ++j) {
            // iからjへのマンハッタン距離
            MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
        }
    }

    Puzzle start;
    for (int i = 0; i < N2; ++i) {
        int x;
        cin >> x;
        start.board[i] = x;
        if (x == 0) {
            start.board[i] = N2;
            start.empty = i;
        }
    }
    start.cost = 0;
    start.rank = distance(start);
    cout << astar(start) << endl;

    return 0;
}


Measured memory_bytes: 100580
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readlines

from collections import defaultdict

def main():

    ac_num = 0
    pt_num = 0

    C = defaultdict(lambda: {"status":False, "penaulty":0} )

    lines = input()
    N, M = list(map(int, lines[0].split()))
    for i in range(1, M+1):
        pi, si = lines[i].split()
        pi = int(pi)
        if C[pi]["status"]:
            continue
        else:
            if si == "AC":
                C[pi]["status"] = True
                ac_num += 1
            else:
                C[pi]["penaulty"] += 1

    for i in range(1, N+1):
        if C[i]["status"]:
            pt_num += C[i]["penaulty"]

    print(ac_num, pt_num)

main()

Measured memory_bytes: 47972
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1000000000000;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
int n,m,r;
int mati[10];
int miti[250][250];
int mm[250][250];


signed main(){
  cin >> n >> m >> r;
  REP(i,r){
    int k1;
    cin >> k1;
    mati[i] = k1-1;
  }
  REP(i,n){
    REP(j,n){
      miti[i][j] = INF;
    }
  }
  REP(i,m){
    int a1,b1,c1;
    cin >> a1 >> b1 >> c1;
    miti[a1-1][b1-1] = c1;
    miti[b1-1][a1-1] = c1;
  }
  REP(i,n){
    REP(j,n){
      mm[i][j] = miti[i][j];
      if(i==j) mm[i][j] = 0;
    }
  }
  REP(k,n){
    REP(i,n){
      REP(j,n){
        mm[i][j] = min(mm[i][j],mm[i][k]+mm[k][j]);
        //cout << mati[i] << "から" << mati[j] << "は" << ans[k+1][mati[i]][mati[j]] << endl;
      }
    }
  }
  int ans2 = INF;
  sort(mati,mati+r);
  do{
    int k = 0;
    REP(i,r-1){
      k += mm[mati[i]][mati[i+1]];
    }
    ans2 = min(k,ans2);
  }while(next_permutation(mati,mati+r));

  cout << ans2 <<endl;

  return 0;
}


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

using namespace std;
typedef long long ll;
inline ll read()
{
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
long long A,B,C,cnt;
int main()
{
	A=read(); B=read(); C=read();
	while(!((A&1)||(B&1)||(C&1)))
	{
		if(cnt==10000000) break;
		int tA,tB,tC;
		tA=(B+C)/2; tB=(A+C)/2; tC=(A+B)/2;
		A=tA; B=tB; C=tC;
		cnt++;
		//cout << A << " " << B << " " << C << endl;
	}
	if(cnt==10000000) cout << "-1" << endl;
	else cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define FIR first
#define SEC second
#define ll long long
#define db double
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
#include <assert.h>
const db eps=1e-10,Pi=acos(-1.0);
int sgn(db x) { return x<-eps?-1:(x>eps); }
db R[20],a[20];
int n;
db calc(db x) {
    a[0]=x; db tot=x;
    for(int i=1;i<n;++i) {
        if(R[i-1]*cos(a[i-1])-eps>R[i+1]) return 0;
        a[i]=acos(R[i-1]*cos(a[i-1])/R[i+1]);
        tot+=a[i];
    }
    return tot;
}
db ans=0,r[20];
void work(int *p) {
    for(int i=0;i<=n;++i) R[i]=r[p[i%n]];
    db lb=0,rb=Pi;
    for(int tt=0;tt<50;++tt) {
        db mid=(lb+rb)/2;
        int tmp=sgn(calc(mid)-2*Pi);
        if(tmp==0) {
            db sum=0;
            for(int i=0;i<n;++i)
                sum+=R[i]*R[i+1]*sin(a[i]);
            ans=max(ans,sum/2);
            return;
        }
        if(tmp>0) rb=mid;
        else lb=mid;
    }
    return;
}
int p[20],m;
int vis[20];
void dfs(int u) {
    if(u>=3) n=u,work(p);
    for(int i=0;i<m;++i) if(!vis[i]) {
        vis[i]=1,p[u]=i,dfs(u+1);
        vis[i]=0;
    }
}
int main() {
    rd(m);
    for(int i=0;i<m;++i) scanf("%lf",&r[i]);
    dfs(0);
    printf("%.9lf",ans);
    return 0;
}


Measured memory_bytes: 3624
#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; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fi first
#define se second
#define endl '\n'
// #define int int64_t
#define double long double
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using reverse_queue = priority_queue<T, vector<T>, greater<T>>;
mt19937_64 rnd(time(0));
const int64_t FIXED_RANDOM = rnd();
template<typename T> struct custom_hash{T operator()(T x)const{return (T) x^FIXED_RANDOM;}}; // check hash in whether int64 or int32
template<typename T1, typename T2> using hash_map = gp_hash_table<T1, T2, custom_hash<T1>>;
// Tao luyện kỹ thuật trong 8 năm mày luyện kỹ thuật trong buồng tắm nam
const int MAXN = (int) 2e5 + 2;
const int INF = numeric_limits<int>::max() >> 1;
const int MOD = (int) 1000000009;
signed main(){
  ios_base::sync_with_stdio(0); 
  cin.tie(0);
  // freopen("FDT.txt", "r", stdin);
  int n;
  cin >> n;
  int ans = 0;
  for(int a = 1; a < n; a ++){
    int nb = n/a;
    if(a*nb == n) ans += nb - 1;
    else ans += nb;
  }
  cout << ans;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main(){
	int x,y;
	cin >> x>>y;
	if(x==2||y==2)cout<<"No"<<endl;
	else if(x==4||x==6||x==9||x==11){
		if(y==4||y==6||y==9||y==11){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
	else{
		cout<<"Yes"<<endl;
	}

		

}



Measured memory_bytes: 256
#include <stdio.h>

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

int main(void)
{
  int K;
  int a, b, c;
  scanf("%d", &K);
  long ans = 0;

  ans += K * (K + 1) / 2;
  //a < b < c
  for(a = 1; a <= K-1; a++){
    for(b = a + 1; b <= K; b++){

      long buf = gcd(a, b);

      ans += buf * 6;//aab/aba/baa/bba/bab/abb

      for(c = b + 1; c <= K; c++){
        ans += gcd(buf, c) * 6;//abc/acb/bac/bca/cab/cba
      }
    }
  }
  printf("%ld\n", ans);
	return 0;
}


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

long long n, a, b, ans = 0;

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

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int sum = 0;
  for (char &c : s) sum += c - '0';
  int a = stoi(s);
  if (a % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main(){
    string s;
    cin >> s;
    int ans = 700;
    if(s[0] == 'o') ans += 100;
    if(s[1] == 'o') ans += 100;
    if(s[2] == 'o') ans += 100;
    cout << ans << endl;
}


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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  ll H,W;
  cin >> H >> W;
  if(H%3 == 0 || W%3==0){
    cout << 0 << endl;
    return 0;
  }

  // H方向
  ll min_val = H*W;
  ll S_max, S_min;
  ll S1,S2,S3;
  for(ll i = 1; i < W; i++){
    S1 = H * i;
    S2 = (H/2) * (W - i); 
    S3 = H * W - S1 - S2;

    S_max = max(S1, max(S2, S3));
    S_min = min(S1, min(S2, S3));

    min_val = min(min_val, S_max - S_min);

    S1 = H * i;
    S2 = H * ( (W - i) / 2 );
    S3 = H * W - S1 - S2;

    S_max = max(S1, max(S2, S3));
    S_min = min(S1, min(S2, S3));

    min_val = min(min_val, S_max - S_min);

  }

  for(ll i = 1; i < H; i++){
    S1 = W * i;
    S2 = (W/2) * (H - i); 
    S3 = H * W - S1 - S2;

    S_max = max(S1, max(S2, S3));
    S_min = min(S1, min(S2, S3));

    min_val = min(min_val, S_max - S_min);

    S1 = W * i;
    S2 = W * ( (H - i) / 2 ); 
    S3 = H * W - S1 - S2;

    S_max = max(S1, max(S2, S3));
    S_min = min(S1, min(S2, S3));

    min_val = min(min_val, S_max - S_min);
  }

  cout << min_val << endl;
}


Measured memory_bytes: 3604
N = int(input())
A = list(map(int,input().split()))
ans = 0
A.sort()
A.reverse()
ans += A[0]
cnt = 0
p = 1
for i in range(N-2):
    if cnt == 2:
        p += 1
        cnt = 0
    ans += A[p]
    cnt += 1
print(ans)


Measured memory_bytes: 94216
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;
typedef unsigned long long BITMASK; typedef long long ll; typedef long double ld;
#define has_bit(bit_mask, x) ((bit_mask) & (1Uint << (x)))
#define turn_on_bit(bit_mask, x) (bit_mask |= (1Uint << (x)))
#define turn_off_bit(bit_mask, x) (bit_mask &= (~(1Uint << (x))))
#define smallest_on_bit(bit_mask) (__builtin_ctzint((bit_mask) & (-(bit_mask))))
#define CLOCK_START clock_t chrono_clk_beg = clock()
#define CLOCK_END clock_t chrono_clk_end = clock(); cerr << (double(chrono_clk_end - chrono_clk_beg) / CLOCKS_PER_SEC) << " sec"
#define bug(args ...) cerr << __LINE__ << ">> ", err(new istringstream(string(#args)), args), cerr << '\n'
#define all(x) x.begin(), x.end()
#define mapfind(mp, x) (mp.find(x) != mp.end())
#define removeDuplicates(vec) sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define int ll
#define double ld
void err(istringstream *iss) {} template<typename T, typename ... Args> void err(istringstream *iss, const T &_val, const Args & ... args) { string _name; *iss >> _name; if (_name.back()==',') _name.pop_back(); cerr << _name << " = " << _val << "; ", err(iss, args ...); }
#define MOD 1000000007

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 2; i < n; ++i)
    {
        if (s[i-2] == 'A' && s[i-1] == 'B' && s[i] == 'C') ans++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  string s1, s2, res = "";
  cin >> s1 >> s2;
  int x = 0, y = 0;
  for(int i = 1; i <= s1.size() + s2.size(); i++){
    res += i % 2 ? s1[x++] : s2[y++]; 
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<algorithm>
using namespace std;
priority_queue<int, deque<int>, greater<int> > a;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long long int N, M;
	while (cin >> N >> M)
	{
		int tp;
		for (int i = 1; i <= N; i++)
		{
			cin >> tp;
			a.push(tp);
		}
		pair<int, int> oper[100001];
		for (int i = 1; i <= M; i++)
		{
			cin >> oper[i].second>>oper[i].first;
		}
		sort(oper + 1, oper + M + 1);
		reverse(oper + 1, oper + M + 1);
		for (int i = 1; i <= M; i++)
		{
			while (oper[i].second--)
			{
				if (a.top() < oper[i].first)
				{
					a.pop();
					a.push(oper[i].first);
				}
				else
				{
					break;
				}
			}
				
			
		}
		long long int cnt = 0;
		while (!a.empty())
		{
			cnt += a.top();
			a.pop();
		}
		cout << cnt << '\n';
	}
}



Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    long int a,b,c,d,x,y,max;
    cin >> a >> b >> c >> d;
    //
    max = b * d;
  	if(max <= a * c){
      max = a * c;
    }
  	if(max <= a * d){
      max = a * d;
    }
  	if(max <= b * c){
      max = b * c;  
    }
    // 出力
    cout << max << endl;
    return 0;
}

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


int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(30);
    int N,M,p;
    cin >> N >> M;
    priority_queue<int> q;
    for(int i=0; i<N;i++){
        cin >> p;
        q.push(p);
    }
    for(int i=0;i<M;i++){
        int a=q.top()/2;
        q.pop();
        q.push(a);
    }

    long long ans=0;
    while(!q.empty()){
        ans+=q.top();
        q.pop();
    }
    cout << ans;
    return 0;

}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N = 3005;
const int mod = 1e9 + 7;
int n, q, x[N], y[N], a[N];
ll inv[N], fac[N];
ll Pow(ll a, int x) {
	ll res = 1;
	while (x) {
		if (x & 1) (res *= a) %= mod;
		(a *= a) %= mod;
		x >>= 1;
	}
	return res;
}
ll s[N][N], ss[N][4], ans;
pair<int, int> Swap(int X, int Y, int i) {
	if (X == x[i]) X = y[i];
	else if (X == y[i]) X = x[i];
	if (Y == x[i]) Y = y[i];
	else if (Y == y[i]) Y = x[i];
	return mk(X, Y); 
}
int main() {
	cin >> n >> q;
	for (int i = 1; i <= n; ++i) scanf("%d", a + i);
	for (int i = 1; i <= q; ++i) scanf("%d %d", x + i, y + i);
	fac[0] = 1;
	for (int i = 1; i < N; ++i) fac[i] = fac[i - 1] * 2 % mod;
	for (int i = 0; i < N; ++i) inv[i] = Pow(fac[i], mod - 2);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			s[i][j] = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if (a[i] < a[j]) s[i][j] = 1;
	for (int i = 1; i <= q; ++i) {
		for (int j = 1; j <= n; ++j) {
			ss[j][0] = s[x[i]][j];
			ss[j][1] = s[y[i]][j];
			ss[j][2] = s[j][x[i]];
			ss[j][3] = s[j][y[i]];
		}		
		for (int j = 1; j <= n; ++j) {
			pair<int, int> p;
			p = Swap(x[i], j, i);
			(s[p.first][p.second] += (ss[j][0] - s[p.first][p.second] + mod) * inv[1] % mod) %= mod;
			//
			p = Swap(y[i], j, i);
			(s[p.first][p.second] += (ss[j][1] - s[p.first][p.second] + mod) * inv[1] % mod) %= mod;
			//
			p = Swap(j, x[i], i);
			if (j != x[i] && j != y[i])
				(s[p.first][p.second] += (ss[j][2] - s[p.first][p.second] + mod) * inv[1] % mod) %= mod;
			//
			p = Swap(j, y[i], i);
			if (j != x[i] && j != y[i])
				(s[p.first][p.second] += (ss[j][3] - s[p.first][p.second] + mod) * inv[1] % mod) %= mod;
			//
		}
	}
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j < i; ++j)
			(ans += fac[q] * s[i][j] % mod) %= mod;
	//
	/*for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			s[i][j] = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if (a[i] > a[j]) s[i][j] = 1;
	for (int i = 1; i <= q; ++i) {
		for (int j = 1; j <= n; ++j) {
			ss[j][0] = s[x[i]][j];
			ss[j][1] = s[y[i]][j];
			ss[j][2] = s[j][x[i]];
			ss[j][3] = s[j][y[i]];
		}		
		for (int j = 1; j <= n; ++j) {
			pair<int, int> p;
			p = Swap(x[i], j, i);
			(s[p.first][p.second] += (ss[j][0] - s[p.first][p.second] + mod) * inv[1] % mod) %= mod;
			//
			p = Swap(y[i], j, i);
			(s[p.first][p.second] += (ss[j][1] - s[p.first][p.second] + mod) * inv[1] % mod) %= mod;
			//
			p = Swap(j, x[i], i);
			if (j != x[i] && j != y[i])
				(s[p.first][p.second] += (ss[j][2] - s[p.first][p.second] + mod) * inv[1] % mod) %= mod;
			//
			p = Swap(j, y[i], i);
			if (j != x[i] && j != y[i])
				(s[p.first][p.second] += (ss[j][3] - s[p.first][p.second] + mod) * inv[1] % mod) %= mod;
			//
		}
	}
	for (int i = 1; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j)
			(ans += fac[q] * s[i][j] % mod) %= mod;*/
	//
	cout << ans;
}

Measured memory_bytes: 70912
using static System.Console;

namespace For_Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(ReadLine());
            int ans = 0;
            if (N >= 105)
            {
                ans++;
            }
            if (N >= 135)
            {
                ans++;
            }
            if (N >= 165)
            {
                ans++;
            }
            if (N >= 189)
            {
                ans++;
            }
            if (N >= 195)
            {
                ans++;
            }

            WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a,b) (abs((a)-(b)) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
//typedef
typedef complex<double> Point;
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;



double cross(Point a, Point b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}

int a[100], b[100];
signed main(){
  while(1){
    int n, m, s1 = 0, s2 = 0;
    scanf("%lld", &n);
    if(n == 0)break;
    rep(i,n-1){scanf("%lld", &a[i]);s1 += a[i];}
    scanf("%lld", &m);
    rep(i,m-1){scanf("%lld", &b[i]);s2 += b[i];}
    a[n-1] = 360-s1;b[m-1] = 360-s2;
    
    double S1 = 0, S2 = 0;
    rep(i,n){
      double r = a[i]/180.0*M_PI;
      Point p1 = Point(1, 0);
      Point p2 = Point(cos(r), sin(r));
      S1 += cross(p1, p2);
    }
    rep(i,m){
      double r = b[i]/180.0*M_PI;
      Point p1 = Point(1, 0);
      Point p2 = Point(cos(r), sin(r));
      S2 += cross(p1, p2);
    }
    if(EQ(S1, S2))printf("0\n");
    else if(S1-S2 > -EPS)printf("1\n");
    else printf("2\n");
  }
	return 0;
}











Measured memory_bytes: 3572
alpha = ["","',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ"]
while 1:
    try:
        ans = ""
        sers = ""
        c = 0
        for key in raw_input():
            if key == "0":
                if len(sers) > 0:
                    n,l = int(sers[0]),len(sers)
                    l = (l-1)%len(alpha[n])
                    ans += alpha[n][l]
                    sers = ""
                else:
                    ans += " "
            elif len(sers) == 0 or sers[-1] == key:
                sers += key
            else:
                n,l = int(sers[0]),len(sers)
                l = (l-1)%len(alpha[n])
                ans += alpha[n][l]
                sers = key
        if len(sers) > 0:
            if sers[0] == 0:
                ans += " "*len(sers)
            else:
                n,l = int(sers[0]),len(sers)
                l = (l-1)%len(alpha[n])
                ans += alpha[n][l]
        print ans
    except:
        break

Measured memory_bytes: 4276
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
void inline swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void inline swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }


class B {
	int n, k;

public:
	B()
	{
		cin >> n >> k;
	}
	void solve()
	{
		int ans{ 0 };
		REP(i, n)
		{
			int x;
			cin >> x;

			ans += 2 * min(x, abs(x - k));
		}

		cout << ans << endl;
	}
};


int main()
{
	B solution;
	solution.solve();

	return 0;
}

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

int main(int argc, char const *argv[])
{
	int a, b; cin >> a >> b;
	if ((a + b) % 2) printf("IMPOSSIBLE\n");
	else printf("%d\n", (a + b) / 2);
	return 0;
}


Measured memory_bytes: 256
#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 N, M, Q;
vector<int> a(50),b(50),c(50),d(50);

int dfs(vector<int> A) {
    if (A.size() == N) {
        int ans = 0;
        rep(i,Q) {
            if (A[b[i]] - A[a[i]] == c[i]) ans += d[i];
        }
        return ans;
    }
    else {
        int res = 0;
        for (int i = A[A.size()-1]; i <= M; i++) {
            A.push_back(i);
            res = max(res, dfs(A));
            A.pop_back();
        }
        return res;

    }
}

int main(){ 

    cin >> N >> M >> Q;


    rep(i,Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }


    int ans;

    vector<int> A(1,1);

    ans = dfs(A);

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3632
def card_suit_check(s):
    if(s=='S'):
        return 0
    elif(s=='H'):
        return 1
    elif(s=='C'):
        return 2
    elif(s=='D'):
        return 3
    else:
        return False

def convert_to_card_suit(num):
    if(num==0):
        return 'S' 
    elif(num==1):
        return 'H'
    elif(num==2):
        return 'C'
    elif(num==3):
        return 'D'
    else:
        return False


card_list =list([[0 for i in range(13)] for j in range(4)])

n = int(input())
for i in range(n):
    suit,card_num = input().split()
    row = card_suit_check(suit)
    col = int(card_num) - 1
    card_list[row][col] = 1

for i in range(len(card_list)):
    for j in range(len(card_list[0])):
        if card_list[i][j] == 0:
            suit = convert_to_card_suit(i)
            miss_card_num = j + 1
            print(suit+' '+str(miss_card_num))




Measured memory_bytes: 5616
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int a, b, ans = 0;
    cin >> a >> b;
    cout << (b % a == 0? a + b : b - a) << endl;
    return 0;
}


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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define RREP(i,a) for(int i = a;i >= 0;i--)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = 0x3f3f3f3f;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string A, B;
    cin >> A >> B;
    string ans = "EQUAL";
    if (A.size() > B.size()) {
        ans = "GREATER";
    } else if (A.size() < B.size()) {
        ans = "LESS";
    } else {
        rep (i, A.size()) {
            if (A[0] > B[0]) {
                ans = "GREATER";
                break;
            } else if (A[0] < B[0]) {
                ans = "LESS";
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a[100050]={0},b[100050]={0};
ll dp1[100050]={0},dp2[100050]={0},ma1[100050]={0},ma2[100050]={0};
int main(){
	int n,i;
	ll c,sum=0,ans=0,t;
	cin>>n>>c;
	for(i=1;i<=n;i++){
		scanf("%lld %lld",&b[i],&a[i]);
	}
	dp1[0]=0;
	dp2[0]=-c;
	for(i=1;i<=n;i++){
		dp1[i]=dp1[i-1]+a[i]-b[i]+b[i-1];
		ma1[i]=max(ma1[i-1],dp1[i]);
		ans=max(ans,dp1[i]);
		dp2[i]=dp2[i-1]+a[n-i+1]+b[n-i+1]-b[n-i+2];
		ans=max(ans,dp2[i]);
		ma2[i]=max(ma2[i-1],dp2[i]);
	}
	for(i=1;i<n;i++){
		t=dp1[i]-b[i];
		if(t>0) {
			sum=t+ma2[n-i];
			ans=max(sum,ans);
		}
	}
	for(i=1;i<n;i++){
		t=dp2[i]-c+b[n-i+1];
		if(t>0) {
			sum=t+ma1[n-i];
			ans=max(sum,ans);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4992
a, b, c, n = list(map(int, input().split()))

cnt = 0
for i in range(n//a+1):
  an = n - a * i
  for j in range(an//b+1):
    num = an - b * j
    if num >= 0 and num % c == 0:
      cnt+=1
        
print(cnt)

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

#define INF (INT32_MAX)
#define MOD (1000000000+7)
#define MAX 9

int N, M;
int A[MAX];

int num[9] = { 2, 5, 5, 4, 5, 6, 3, 7, 6 };
int dp[10000 + 1];

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

	for( int i = 0; i <= N; i++ ) {
		dp[i] = -INF;
	}
	dp[0] = 0;
	for( int i = 1; i <= N; i++ ) {
		for( int j = 0; j < M; j++ ) {
			int a = A[j] - 1;
			int n = num[a];
			if( i - n >= 0 ) {
				dp[i] = max( dp[i], dp[i - n] + 1 );
			}
		}
	}
	int d = dp[N];
	sort( A, A + M, greater<int>() );
	string ans;
	for( int i = 0; i < d; i++ ) {
		for( int j = 0; j < M; j++ ) {
			int a = A[j] - 1;
			int n = num[a];
			if( N - n >= 0 && dp[N - n] == dp[N] - 1 ) {
				ans += (char)(A[j] + '0');
				N -= n;
				break;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
from collections import deque
import sys


mX = [0, 1, 0, -1]
mY = [1, 0, -1, 0]
zX = [2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, -1, -1, -1, -1, -2, -2, -2, -2, -2]
zY = [2, 1, 0, -1, -2, 2, 1, -1, -2, 2, -2, 2, -2, 1, -1, 2, 1, 0, -1, -2]


def bfs(u, S, M, H, W):  # u 開始点

    q = deque()
    q.append(u)
    visited = deque()
    while q:
        while q:
            u = q.popleft()
            visited.append([u[0], u[1]])

            # 徒歩移動
            for i in range(4):
                nx, ny = u[0] + mX[i], u[1] + mY[i]

                if nx < 0 or H <= nx or ny < 0 or W <= ny or S[nx][ny] == "#":
                    continue

                if M[nx][ny] == -1 or M[nx][ny] > M[u[0]][u[1]]:  # state を確認
                    M[nx][ny] = M[u[0]][u[1]]  # 徒歩移動
                    q.append([nx, ny])
                    visited.append([nx, ny])



        # 魔法移動
        while visited:
            u = visited.popleft()
            for j in range(20):
                wx = u[0] + zX[j]
                wy = u[1] + zY[j]
                if wx < 0 or H <= wx or wy < 0 or W <= wy or S[wx][wy] == "#":
                    continue
                if M[wx][wy] == -1 or M[wx][wy] > M[u[0]][u[1]] + 1:  # state を確認
                    M[wx][wy] = M[u[0]][u[1]] + 1
                    q.append([wx, wy])


def main():

    H, W = map(int, sys.stdin.readline().rstrip().split())
    Ch, Cw = map(int, sys.stdin.readline().rstrip().split())
    Dh, Dw = map(int, sys.stdin.readline().rstrip().split())

    S = []
    for i in range(H):
        S.append(sys.stdin.readline().rstrip())

    M = [[-1 for _ in range(W)] for _ in range(H)]

    if S[Ch - 1][Cw - 1] == "#":
        print(-1)
        return

    M[Ch - 1][Cw - 1] = 0
    bfs([Ch - 1, Cw - 1], S, M, H, W)

    print(M[Dh - 1][Dw - 1])


main()


Measured memory_bytes: 127644
n,m = map(int,input().split())
ab = [[] for _ in range(10**5)]
for i in range(n):
	a,b = map(int,input().split())
	a -= 1
	ab[a].append(b)

import heapq

q = []
heapq.heapify(q)

ans = 0
for i in range(m):
	if len(ab[i]) != 0:
		for j in range(len(ab[i])):
			heapq.heappush(q,-1*ab[i][j])
	if len(q) != 0:
		ans += -1 * heapq.heappop(q)

print(ans)


Measured memory_bytes: 18352