akhauriyash/Code-Regression huggingface dataset:
import std.stdio;
import std.string, std.conv;
import std.algorithm, std.array;
import std.typecons;

void main() {
  for(int N; N = readln.chomp.to!int, N; ) {
    int[string] buy;
    foreach(i; 0 .. N) {
      string[] s = readln.split.array;
      buy[s[0]] = s[1].to!int;
    }

    int M = readln.chomp.to!int;

    alias string[] from;
    from[string] make;
    foreach(i; 0 .. M) {
      string[] s = readln.split;
      string name = s[0];
      make[name] = s[2 .. $];
    }

    for(;;) {
      bool f = false;
      foreach(key; make.keys) {
        int sum = 0;
        foreach(value; make[key]) {
          auto p = value in buy;
          if(p == null) {
            sum += cast(int)1e9;
          }
          else {
            sum += *p;
          }
        }

        if((key in buy) == null || sum < buy[key]) {
          buy[key] = sum;
          f = true;
        }
      }
      if(f == false) break;
    }

    writeln(buy[readln.chomp]);
  }
}

Measured memory_bytes: 1276
from collections import deque

n, m = [int(item) for item in input().split()]
edge = [[] for _ in range(n)]
inverse = [[] for _ in range(n)]
ab = []
for i in range(m):
    a, b = [int(item) - 1 for item in input().split()]
    ab.append((a, b))
    edge[a].append(b)

seen = [0] * n
checked = [0] * n
hist = deque()
ret = -1
def dfs(v):
    global ret
    seen[v] = 1
    hist.append(v)
    for nv in edge[v]:
        if checked[nv]: 
            continue
        if seen[nv] and not checked[nv]:
            ret = nv
            return
        dfs(nv)
        if ret != -1: 
            return
    hist.pop()
    checked[v] = 1

for i in range(n):
    dfs(i)
    if ret != -1:
        break

if ret == -1:
    print(-1)
    exit()

cycle = []
while hist:
    t = hist.pop()
    cycle.append(t)
    if t == ret:
        break
cycle.reverse()

while True:
    in_cycle = set(cycle)
    deg = [0] * n 
    for item in cycle:
        for v in edge[item]:
            if v in in_cycle:
                deg[v] += 1
    
    ok = True
    for i, item in enumerate(cycle):
        if deg[item] > 1:
            ok = False
            cur_id = start = i
    if ok:
        print(len(cycle))
        print("\n".join([str(item + 1) for item in cycle]))
        exit()

    ncycle = []
    cur = cycle[cur_id]
    while True:
        ncycle.append(cur)
        if cycle[start] in edge[cur]:
            break
        cur_id = (cur_id + 1) % len(cycle)
        cur = cycle[cur_id]
    cycle = ncycle[:]

Measured memory_bytes: 44396
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed _main(){
  int N,ans=0; cin >> N;
  string S; cin >> S;
  for(int i=0;i<=999;i++){
    int num[3];
    num[0]=i/100;
    num[1]=(i%100)/10;
    num[2]=i%10;
    int index=0;
    rep(j,N){
      if(S[j]=='0'+num[index]){
        index++;
      }
      if(index==3){
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s          second
#define sz(x)       (int)x.size()
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep0(a,n)  for(int i=0;i<n;i++)cin>>a[i]
#define si(x)       cin>>x
#define sii(x,y)    cin>>x>>y
#define siii(x,y,z) cin>>x>>y>>z
#define ahell   998244353
#define hell 1000000007
#define N 1000001
#define fl 1.0000000000
//#define mod 998244353
#define cntbit(a) __builtin_popcountl(a)
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
main()
{
  ios
int n,m,i;
int j;
int u,v,q;
int test=1;
//si(test);

while(test--)
{
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  int dp[n][n];
  for(i=0;i<n;i++)
  {
    dp[i][i]=a[i];
  }
  for(int l=2;l<=n;l++)
  {
    for(i=0;i+l<=n;i++)
    {
        int t=max(a[i]-dp[i+1][i+l-1],a[i+l-1]-dp[i][i+l-2]);
        dp[i][i+l-1]=t;
    }
  }

  cout<<dp[0][n-1];

}

}


Measured memory_bytes: 49736
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL 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; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
 
struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int x;

int main(){
    cin >> x;
    int cnt = x / 100;
    int minl = 0;
    x %= 100;
    while(x != 0){
        minl++;
        x -= (x >= 5 ? 5 : x);
    }
    cout << (cnt >= minl ? 1 : 0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
     
    using namespace std;
     
    #define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
    #define rep(i, n) for (int i = 0; i < (int)(n); ++i)
    #define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
    #define ALL(r) r.begin(), r.end()
    #define YES puts("YES")
    #define Yes puts("Yes")
    #define NO puts("NO")
    #define No puts("No")
    #define IMP puts("IMPOSSIBLE")
    #define Imp puts("Impossible")
    #define imp puts("impossible")
    #define pb push_back
     
    template <typename T>
    T dup(T x, T y)
    {
        return (x + y - 1) / y;
    };
    template <typename A, size_t N, typename T>
    inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
    template <class T>
    inline bool chmax(T &a, T b)
    {
        if (a < b)
        {
            a = b;
            return true;
        }
        return false;
    }
    template <class T>
    inline bool chmin(T &a, T b)
    {
        if (a > b)
        {
            a = b;
            return true;
        }
        return false;
    }
     
    using ll = int64_t;
    using vint = vector<int32_t>;
    using vvint = vector<vint>;
    using vll = vector<ll>;
    using vvll = vector<vll>;
    using vstr = vector<string>;
    using pint = pair<int32_t, int32_t>;
    using pll = pair<ll, ll>;
    using vpint = vector<pint>;
    using vpll = vector<pll>;
    using sint = set<int32_t>;
    using sstr = set<string>;
    using qint = queue<int32_t>;
     
    constexpr std::int32_t INF = 1001001001;
    constexpr std::int64_t LINF = 1001001001001001001;
     
    void Main()
    {
        int n;
        cin >> n;
        int cn = n;
        int sum = 0;
        while (n != 0)
        {
            sum += n % 10;
            n /= 10;
        }
        if (cn % sum == 0)
            Yes;
        else
            No;
    }
     
    int main()
    {
        std::cin.tie(nullptr);
        std::ios_base::sync_with_stdio(false);
        std::cout << std::fixed << std::setprecision(15);
        Main();
        return 0;
    }

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n =  scanner.nextInt();
		for (int i = 0; i < n; i++) {
			double[] c = new double[6];
			for (int j = 0; j < 6; j++) {
				c[j] = scanner.nextDouble();
			}
			double a0 = 2 * (c[2] - c[0]);
			double a1 = 2 * (c[4] - c[0]);
			double b0 = 2 * (c[3] - c[1]);
			double b1 = 2 * (c[5] - c[1]);
			double c0 = (c[0] * c[0] - c[2] * c[2]) + (c[1] * c[1] - c[3] * c[3]);
			double c1 = (c[0] * c[0] - c[4] * c[4]) + (c[1] * c[1] - c[5] * c[5]);
			double x = (b0 * c1 - b1 * c0) / (a0 * b1 - a1 * b0);
			double y = (c0 * a1 - c1 * a0) / (a0 * b1 - a1 * b0);
			double r = Math.sqrt(Math.pow(c[0] - x, 2) + Math.pow(c[1] - y, 2));
			System.out.printf("%.3f %.3f %.3f\n", x, y, r);
		}
	}
}

Measured memory_bytes: 28544
N = int(input())

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

sum = 0
for a_i in a:
    sum+=a_i

min = abs(a[0]-(sum-a[0]))
x=a[0]
for a_i in a[1:-1]:
    x +=a_i
    if (min>abs(x-(sum-x))):
        min=abs(x-(sum-x))

print(min)

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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

struct Q
{
	int pos;
	int left;
	int ind;

	Q(int pos, int left, int ind)
	{
		this->pos = pos;
		this->left = left;
		this->ind = ind;
	}

	bool operator <(const Q& q) const
	{
		if (pos == q.pos) return ind < q.ind;
		return pos < q.pos;
	}
};

const int MAX = 555;

int A[MAX];
int RES[MAX * MAX];
int P[MAX * MAX];

set<Q> S, T;
int n;

void NO()
{
	cout<<"No"<<endl;
	/*FOR (i, 0, n*n)
	{
		cout<<RES[i] + 1<<' ';
	}
	cout<<endl;*/
	exit(0);
}


int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_Stdio(false); cin.tie(0);

	FILL(P, -1);
	FILL(RES, -1);

	scanf("%d", &n);
	FOR (i, 0, n)
	{
		int x;
		scanf("%d", &x);
		x--;

		if (i) S.insert(Q(x-1, i, i));
		A[i] = x;

		if (P[x] != -1) NO();
		P[x] = i;
	}

	FOR (i, 0, n*n)
	{
		if (P[i] != -1)
		{
			RES[i] = P[i];
			if (n - P[i] - 1) T.insert(Q(i+1, n - P[i] - 1, P[i]));
			continue;
		}

		if (SZ(S))
		{
			Q a = *S.begin();
			S.erase(S.begin());
			if (a.pos < i) NO();

			RES[i] = a.ind;
			a.left--;
			if (a.left) S.insert(a);
		}
		else
		{
			if (T.empty()) NO();

			Q a = *T.begin();
			T.erase(T.begin());

			RES[i] = a.ind;
			a.left--;
			if (a.left) T.insert(a);
		}
	}

	if (SZ(S) || SZ(T)) NO();

	printf("Yes\n");
	FOR (i, 0, n*n)
	{
		printf("%d ", RES[i] + 1);
	}
	printf("\n");


}


Measured memory_bytes: 3584
N = int(input())
A = list(map(int,input().split()))

A = sorted(A)

ans = 1

cum = [0]*N
for i, a in enumerate(A) :
    if i == 0 :
        cum[i] = a
    
    else :
        cum[i] = cum[i-1] + a

for i in range(N-2,-1,-1) :
    if cum[i]*2 >= A[i+1] :
        ans += 1
    else :
        break
print(ans)


Measured memory_bytes: 14224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




int main() {
    // 所詮4本 -> 2つずつまとめて半分全列挙
    
    int n, m;
    while (cin >> n >> m && n) {
        
        vector<int> p(n);
        rep(i, n) cin >> p[i];
        
        vector<int> v;
        rep(i, n) v.eb(p[i]);
        rep(i, n) rep(j, n) v.eb(p[i] + p[j]);
        
        vector<int> v2;
        rep(i, n) v2.eb(p[i]);
        rep(i, n) rep(j, n) v2.eb(p[i] + p[j]);
        sort(all(v2));
        
        int ans = 0;
        rep(i, sz(v)) {
            int it = (int)(upper_bound(all(v2), m - v[i]) - v2.begin());
            if (it == 0) continue;
            chmax(ans, v[i] + v2[it - 1]);
            // cout << v[i] << " " << v2[it - 1] << endl;
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 14720
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>

using namespace std;

const int N = 2e5 + 7;
const int INF = 1e9 + 7;

int n;
int upper[N], lower[N];
vector<int> adj[N];
pair<int, int> farest[N][2], up[N];

void fresh(pair<int, int> far[2], pair<int, int> tmp) {
	if (tmp > far[0]) {
		far[1] = far[0];
		far[0] = tmp;
	} else if (tmp > far[1]) {
		far[1] = tmp;
	}
}

void dfs_down(int u, int from) {
	for (int i = 0; i < 2; i++) {
		farest[u][i] = {0, 0};
	}
	for (auto v : adj[u]) {
		if (v == from) continue;
		dfs_down(v, u);
		auto tmp = make_pair(farest[v][0].first + 1, v);
		fresh(farest[u], tmp);
	}
}

void dfs_up(int u, int from) {
	for (auto v : adj[u]) {
		if (v == from) continue;
		up[v].first = max(up[u].first + 1, v == farest[u][0].second ?
			farest[u][1].first + 1 : farest[u][0].first + 1);
		up[v].second = u;
		dfs_up(v, u);
	}
	fresh(farest[u], up[u]);
	upper[u] = min(farest[u][1].first + 1, farest[u][0].first - 1);
}

vector<int> queue[N];
int finish[N];

void go(int i, int u) {
	for (auto v : adj[u]) {
		int duv = farest[u][0].second == v ? farest[u][1].first : farest[u][0].first;
		int dvu = farest[v][0].second == u ? farest[v][1].first : farest[v][0].first;
		//printf("v = %d\n", v);
		int t = min(max(duv + 1, lower[u] - 1), max(dvu + 1, lower[u]) + 1);
		queue[t].push_back(v);
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs_down(1, 0);
	up[1] = make_pair(0, 0);
	dfs_up(1, 0);
	{
		static char buffer[N];
		scanf("%s", buffer + 1);
		for (int i = 1; buffer[i]; i++) {
			if (buffer[i] == '1') {
				lower[i] = 0;
				queue[0].push_back(i);
			}
		}
	}
	for (int i = 0; i <= n; ) {
		if (i > 0 && queue[i - 1].size()) {
			i--;
		} else if (queue[i].size() == 0) {
			i++;
		} else {
			int top = queue[i].back();
			queue[i].pop_back();
			if (!finish[top] || i < lower[top]) {
				lower[top] = i;
				finish[top] = true;
				go(i, top);
			}
		}
	}
	long long ans = 0;
	assert(queue[0].size() == 0);
	for (int i = 1; i <= n; i++) {
		if (upper[i] >= lower[i]) ans += upper[i] - lower[i] + 1;
		//printf("i = %d lower = %d upper = %d\n", i, lower[i], upper[i]);
		assert(queue[i].size() == 0);
		assert(finish[i]);
	}
	cout << ans + 1 << endl;
	return 0;
}


Measured memory_bytes: 36472
# パナソニック2020D
import sys
def write(x):
    sys.stdout.write(x)
    sys.stdout.write("\n")
    
from queue import deque
n = int(input())
q = deque([("a", "a")])
while True:
    s, m = q.pop()
    if len(s)==n:
        write(s)
    elif len(s)>=n+1:
        break
    for o in range(ord("a"), ord(m)+2):
        if ord(m)<o:
            m = chr(o)
        q.appendleft((s + chr(o), m))

Measured memory_bytes: 158168
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 1000000007;

//bool operator< (pint a, pint b) {
	//return a.second < b.second;

//}



ll gcd(ll a, ll b) {

	if (b == 0)
		return a;

	return gcd(b, a % b);


}

ll max(ll a, ll b) {
	if (a < b) {
		return b;
	}
	else
		return a;

}

ll min(ll a, ll b) {
	if (a < b)
		return a;

	return b;
}




pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

vector<pint> list;










void floyd(int N, ll** d) {

	rep(k, N+1){
		rep(i, N+1) {
			if (d[i+1][k+1] == inf) continue;
			rep(j, N+1) {
				if (d[j+1][k+1] == inf) continue;

				d[i+1][j+1] = min(d[i+1][j+1], d[i+1][k+1] + d[j+1][k+1]);

			}

		}
	}




}


ll vis[100005];
ll d[100005];
vector<ll> M[100005];
vector<ll> anslist;


stack<int> to_1;

ll col[100005];

void dfs(ll K, ll dist) {

	
	d[K] = dist;
	vis[K] = 1;

		
	for (int i = 0; i < M[K].size(); i++) {
		if (vis[M[K][i]] == 0) {
			
			dfs(M[K][i], dist + 1);
			
		}
	}

}



vector<unsigned long long> v;




int ketasuu(ll a) {

	ll retval = 1;
	ll val = a;
	while ((val / 10) != 0) {

		retval += 1;
		val /= 10;
	}

	return retval;

}




int main() {
	ll N, M;
	ll a, b;
	cin >> N;

	ll kotae = 10000;

	for (ll i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			kotae = min(kotae, max(ketasuu(i), ketasuu(N / i)));

		}

	}


	cerr << ketasuu(9876543210) << endl;

	cout << kotae << endl;
	return 0;
}

Measured memory_bytes: 3584
# LIS on Tree

from collections import deque
import bisect
import sys
sys.setrecursionlimit(10**7)

N = int(input())
V = list(map(int, input().split()))
V.insert(0, 0)
visited = [False for i in range(N+1)]
inf = 10**18
dp = [inf for i in range(N+1)]
ans = [-1 for i in range(N+1)]
stack = deque()

G = [[] for i in range(N+1)]
for _ in range(N-1):
    u, v = map(int, input().split())
    G[u].append(v)
    G[v].append(u)


def dfs(s_node):
    visited[s_node] = True
    # dp値の更新
    value = V[s_node]
    index = bisect.bisect_left(dp, value)
    old_value = dp[index]
    dp[index] = value
    ans[s_node] = bisect.bisect_right(dp, inf-1)
    stack.append((index, old_value, value))
    for child in G[s_node]:
        if visited[child] == False:
            dfs(child)
    # 帰りがけにバックトラックを行う
    index, old_value, value = stack.pop()
    dp[index] = old_value


dfs(1)

for i in range(1, N+1):
    print(ans[i])

Measured memory_bytes: 238908
import copy
import sys
S = input()
T = input()
if len(T) > len(S):
    print("UNRESTORABLE")
    sys.exit()
I = []
S1 = []
for k in range(len(S)):
    if S[k] == '?':
        S1.append("a")
    else:
        S1.append(S[k])
for i in range(len(S)-len(T) + 1):
    S_ = copy.deepcopy(S1)
    flag = 1
    for j in range(i, i + len(T)):
        if S[j] != T[j-i] and S[j] != "?":
            flag = 0
            break
        else:
            S_[j] = T[j-i]     
    if flag:
        temp = ''.join(S_)
        I.append(temp)
S_ = S_.sort()
if len(I) > 0:
    print(I[-1])
else:
    print("UNRESTORABLE")

Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());

		if (Math.abs(a- b) <= d && Math.abs(b- c) <= d || Math.abs(a- c) <= d){
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 20820
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

  int N, K;
  cin >> N >> K;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];

  ll ans = LLINF;
  rep(bit, 1 << N){
  	vector<ll> b;
	rep(i, a.size()) b.push_back(a[i]);
    int popcnt = __builtin_popcount(bit);
    ll ma = 0;
    ll res = 0;
    rep(i, N){
      int tmp = N - i - 1;
      if(bit >> tmp & 1){
        if(b[i] <= ma){
          res += ma+1 - b[i];
          b[i] = ma+1;
        }
      }
      chmax(ma, b[i]);
    }

    int cnt = 0;
    ll ma2 = 0;
    rep(i, N){
      if(ma2 < b[i]){
        ma2=b[i];
        cnt++;
      }
    }
    if(cnt < K) continue;
    chmin(ans, res);
  }

  cout <<  ans << endl;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pair<ll, ll>> vpll;

//mt19937 random(566);
//uniform_int_distribution<ll> distr;
//ll rnd(ll a, ll b) {return a + distr(random) % (b - a + 1);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vi a(n, -1);
    int m;
    cin >> m;
    forn(it, m) {
        int pos, d;
        cin >> pos >> d;
        pos--;
        if (a[pos] == -1) a[pos] = d;
        else if (a[pos] != d) {
            cout << "-1\n";
            return 0;
        }
    }
    if (a[0] == 0 && n != 1) {
        cout << "-1\n";
        return 0;
    }
    if (a[0] == -1 && n != 1) a[0] = 1;
    for (int x : a) {
        cout << max(0, x);
    }
    cout << "\n";
    return 0;
}

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

#define PI 4*atan(1)
#define INF 1e8

typedef long long ll;

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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  if(A == B)cout << C << endl;
  else if(B == C)cout << A << endl;
  else cout << B << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using v  = vector<int>;
using vv = vector<v>;
const int MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    
    int k = n/2;
    
    vector<ll> a(n+1);
    ll sum = 0;
    
    for(int i=1; i<=n; i++){
        cin >> a[i];
        sum += a[i];
    }
    
    sum /= 2;
    vector<ll> d(n+1,0);
    
    for(int i=1; i<=k; i++){
        d[1] += a[2*i];
    }
    
    for(int i=3; i<=n; i+=2){
        d[i] = d[i-2] + a[i-2] - a[i-1];
    }
    
    d[2] = d[n] + a[n] - a[1];
    
    for(int i=4; i<n; i+=2){
        d[i] = d[i-2] + a[i-2] - a[i-1];
        
    }
    
    for(int i=1; i<=n; i++){
        //cout << d[i];
        cout << 2*(sum - d[i]);
        if(i!=n)cout << " ";
        else cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main() {
	int n, k;
	int a[55];
	cin >> n >> k;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	reverse(a, a + n);
	int ans = 0;
	rep(i, k) {
		ans += a[i];
	}
	cout << ans << endl;
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define clr(i, j)     memset(i, j, sizeof(i))
#define pb            push_back
 
typedef long long     ll;
 
//-*-*-*-*-*-*-*-*-



ll n,m,k,x,y,ans;ll a[9999];
 vector<pair<ll,ll>>v;
 // vector<ll>v;
vector<pair<ll,ll>>vv;

int main()
{ 
 //clr(dp,0);
 /*
 ll f[99999];
cin>>a>>n>>m;
for(int i=0;i<n;i++){
   cin>>x>>y;v.push_back({x,y});
}sort(v.begin(),v.end());
   for(int i=0;i<m;i++){
   cin>>x>>y;
   f[x]=min(y,f[x]);
}
for(int i=0;i<a;i++){
   nxt=v[t].first;ll o=
   if(f[i]&&i<=nxt){dp[t]=min(dp[i]+s*)}
}*/
cin>>n;
for(int i=0;i<n;i++){
   cin>>a[i];
}for(int i=0;i<n;i++){
   cin>>y;
  
  x=a[i];
  if(x-y>0){ans+=x-y;}
}
cout<<ans;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define MAX 200002
#define INF 1000000
#define EXP 1e-6
#define endl '\n'
#define all(v) v.begin(), v.end()
#define FOR(i, a, b, c) for( int i = a; i < b; i+=c )
#define rep(i, a) for( int i = 0; i < a; i++ )
#define fastio ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);

typedef long long int ll;
const int maxn = 1e6 + 5;
const ll MOD = 100000007;

using namespace std;

typedef pair <int, int> ii;
typedef pair <int, ii> trie;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vii> vvii;
typedef vector <vi> vvi;
typedef vector <bool> vb;
typedef vector <trie> vtrie;
typedef bitset <maxn> bs;

int n;
ll product[101][2];
ll dp[101][maxn];

ll knap_sack( int item, int cap )
{
	if( item > n )
		return 0LL;
	ll &ans = dp[item][cap];
	if( ans != -1 ) return ans;

	ll niya = 0LL, na_niya = 0LL;
	na_niya = knap_sack( item + 1, cap );
	if( product[item][0] <= cap )
		niya = product[item][1] + knap_sack( item + 1, cap - product[item][0] );

	return ans = max( niya, na_niya );
}

int main()
{
	fastio

    int cap;
    cin >> n >> cap;

    for( int i = 1; i <= n; i++ )
    	cin >> product[i][0] >> product[i][1];

    memset(dp, -1, sizeof(dp) );
    ll ans = knap_sack( 1, cap );

    cout << ans << endl;


	return 0;

}


Measured memory_bytes: 789376
def revPolish(input_list):
    stack_list = list()

    for data in input_list:
        if data.isdecimal():
            stack_list.append(int(data))
        else:
            a, b = [stack_list.pop(), stack_list.pop()]
            if data == '+':
                stack_list.append(b + a)
            elif data == '-':
                stack_list.append(b - a)
            elif data == '*':
                stack_list.append(b * a)

    return stack_list[0]


if __name__ == "__main__":
    print(revPolish(input().split()))


Measured memory_bytes: 5600
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  ll a,b,c,k;
  cin >> a >> b >> c >> k;

  ll ans=0;
  ans+=min(a,k);
  k-=min(a,k);
  k-=min(b,k);
  ans+=-min(c,k);

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 21 19:18:37 2018
ABC103B
@author: maezawa
"""

s = input()
t = input()
#print(s)
n = len(s)

ans = 'No'

for i in range(n):
    s = s[-1] + s[:n-1]
    #print(s)
    if t == s:
        ans = 'Yes'
        break

print(ans)

Measured memory_bytes: 3060
import statistics
n=int(input())

la, lb = [], []
for _ in range(n):
  a, b = map(int, input().split())
  la.append(a)
  lb.append(b)
c=statistics.median(la)
d=statistics.median(lb)
if n%2==1:
  print(d-c+1)
else:
  print(int(2*d-2*c+1))

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<double,double> pdd;

const ll big = 1000000007;
const ll mod = 998244353;

ll n,m,k,q;


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // freopen("input.txt","r",stdin);
   // freopen("autput.txt","w",stdout);
    ll a,b,c,d;

    cin >> n >> k;

    ll n0 = (n+k)/k;
    ll n2 = n0 - (n%k < k/2);
    n0--;
    if(k%2 == 0){
        cout << n0*n0*n0 + n2*n2*n2 << "\n";
    }
    else{
        cout << n0*n0*n0 << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n;cin>>n;
  vector<vector<int> > A(n+1);
  for(int i = 0; (1<<n) > i; i++){
    int t;cin>>t;
    A[0].push_back(t);
  }
  for(int i = 1; n >= i; i++){
    for(int j = 0; A[i-1].size() > j; j+=2){
      if(A[i-1][j] == A[i-1][j+1]){
        A[i].push_back(A[i-1][j]);
      }else{
        A[i].push_back(abs(A[i-1][j]-A[i-1][j+1]));
      }
    }
  }
  cout << A[n][0] << endl;

}

Measured memory_bytes: 2292
def prepare(n, MOD):
 
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return factorials, invs

def func(r, c):
    return f[r+c] * i[r] % MOD * i[c] % MOD

MOD = 10**9+7
f, i = prepare(2*10**6 + 2, MOD)


r1, c1, r2, c2 = map(int,input().split())

combi = func(r2+1, c2+1) - func(r2+1, c1) - func(r1, c2+1) + func(r1, c1)
print(combi % MOD) 

Measured memory_bytes: 204928
from collections import deque
h, w, k = map(int, input().split())
y1, x1, y2, x2 = map(int, input().split())
c = []
for _ in range(h):
    c.append(input())
q = deque([(x1-1, y1-1)])
dxdy = [(-1,0), (0,-1), (0,1), (1,0)]
dist = [[1000000]*w for _ in range(h)]
dist[y1-1][x1-1] = 0
while q:
    x, y = q.popleft()
    for ddx, ddy in dxdy:
        for i in range(1, k+1):
            dx = ddx*i
            dy = ddy*i
            if not (0<=x+dx<w and 0<=y+dy<h):
                break
            if c[y+dy][x+dx]=='@' or dist[y+dy][x+dx]<=dist[y][x]:
                break
            if x+dx==x2-1 and y+dy==y2-1:
                print(dist[y][x]+1)
                exit(0)
            if dist[y+dy][x+dx]>dist[y][x]+1:
                dist[y+dy][x+dx] = dist[y][x]+1
                q.append((x+dx, y+dy))
print(-1)

Measured memory_bytes: 97104
#include<bits/stdc++.h>
#define REP(i,n) for(int i=1;i<n;i++)
using namespace std;
int main(){
    long long N,L1=1,L2=3;
    cin>>N;
    if(N==1)cout<<L1<<endl;
    else if(N==2)cout<<L2<<endl;
    else {
        long long ans=0;
        REP(i,N-1){
            ans=L1+L2;
            L1=L2;
            L2=ans;
        }
        cout<<ans<<endl;
    }
}

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

int main() {
  int H, W;
  cin >> H >> W;
  string temp;
  string m_map[50][50]={};
  int kosuu=0;
  int up,dn,lt,rt;
  for (int i=0;i<H;i++) {
    cin >> temp;
    for (int j=0;j<W;j++) {
      m_map[i][j] = temp.at(j);
    }
  }
  for (int i=0;i<H;i++) {
    for (int j=0;j<W;j++) {
      kosuu = 0;
      if (m_map[i][j] == ".") {
        up=0;dn=0;lt=0;rt=0;
      	if (i!=0) {
          up=1;
          if (m_map[i-1][j] == "#") {
            kosuu++;
          }
      	}
      	if (j!=0) {
          lt=1;
          if (m_map[i][j-1] == "#") {
            kosuu++;
          }
      	}
      	if (i!=H-1) {
          dn=1;
          if (m_map[i+1][j] == "#") {
            kosuu++;
          }
      	}
      	if (j!=W-1) {
          rt=1;
          if (m_map[i][j+1] == "#") {
            kosuu++;
          }
      	}
        
        
      	if (up==1 && lt==1) {
          if (m_map[i-1][j-1] == "#") {
            kosuu++;
          }
      	}
      	if (up==1 && rt==1) {
          if (m_map[i-1][j+1] == "#") {
            kosuu++;
          }
      	}
      	if (dn==1 && lt==1) {
          if (m_map[i+1][j-1] == "#") {
            kosuu++;
          }
      	}
      	if (dn==1 && rt==1) {
          if (m_map[i+1][j+1] == "#") {
            kosuu++;
          }
      	}
        m_map[i][j] = to_string(kosuu);
      }
      cout << m_map[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
code = r"""
# distutils: language=c++
# distutils: include_dirs=[/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl]
from libcpp cimport bool
from libcpp.vector cimport vector
cdef extern from "<atcoder/dsu>" namespace "atcoder" nogil:
    cdef cppclass dsu:
        dsu(int n)
        int merge(int a, int b)
        bool same(int a, int b)
        int leader(int a)
        int size(int a)
        vector[vector[int]] groups()
from cython.parallel cimport prange
from libc.stdio cimport getchar, printf
cdef inline int read() nogil:
    cdef int b, c = 0
    while 1:
        b = getchar() - 48
        if b < 0: break
        c = c * 10 + b
    return c
cdef int i
cdef dsu *d = new dsu(read())
for i in prange(read(), nogil=1):
    if read(): printf("%d\n", d.same(read(), read()))
    else: d.merge(read(), read())
"""
import os, sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    open('solve.pyx', 'w').write(code)
    os.system('cythonize -i -3 -b solve.pyx')
import solve

Measured memory_bytes: 10764
import java.util.*;

public class Main{
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int [][] data = new int[n][n];
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					data[i][j] = sc.nextInt();
				}
			}
			long sum = 0;
			for(int i = 0; i < n; i++){
				for(int j = i + 1; j < n; j++){
					sum += Math.min(data[i][j], data[j][i]);
				}
			}
			System.out.println(sum);
		}
	}
	
	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 31288
s = gets.chomp.split('')
t = gets.chomp.split('')

s_l = s.length
t_l = t.length
max = s_l - t_l
min_cnt = t.length

(0..max).each do |i|
  cnt = 0
  s[i..(i + t_l - 1)].each_with_index do |ele,  i|
    cnt += 1 unless ele == t[i]
  end
  min_cnt = cnt if cnt < min_cnt
end

puts min_cnt


Measured memory_bytes: 14256
N = int(input())
A = int(input())

max_B = 10000//500

boolian = False

for b in range(max_B+1):
    if boolian == True:
        break
    for a in range(A+1):
        someone = 500*b + a 
        if someone == N:
            boolian = True
            break
        if someone != N:
            boolian = False
            continue
            
if boolian == True:
    print('Yes')
if boolian == False:
    print('No')

Measured memory_bytes: 9152
N = int(input())
A = [0]
ans = 0
i = 1
q = [False for i in range(N + 1)]
for i in range(N):
    A.append(int(input()))
i = 1
while q[A[i]] == False:
    q[A[i]] = True
    ans += 1
    i = A[i]
    if i == 2:
        break
if i == 2:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 13576
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main() {
  int n ;
  cin >>n ;
  string s ;
  cin >>s ;
  ll d=0 ;
  ll e=0 ;
  ll f=0 ;
  for(int i=0 ;i<n ;i++){
    if( s.at(i)== 'R')
    d ++ ;
  }
  for(int i=0; i<n ;i++){
    if(s.at(i)=='G')
     e++ ;
  }
  for(int i=0 ; i<n ;i++){
    if( s.at(i)=='B')
    f++ ;
  }
  ll sum= d*e*f ;
  for(int i=0 ; i<n ; i++){
   for(int j=1;j< min(i+1,n-i) ;j++ ){
     if(s.at(i)!=s.at(i+j) &&s.at(i)!=s.at(i-j)&&s.at(i+j)!= s.at(i-j))
     sum-- ;
   }
  }
  cout << sum <<endl ;
  
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>

int main() {
  uint32_t N = 0;
  std::cin >> N;
  const uint32_t ans[] = {105, 135, 165, 189, 195};
  uint32_t i = 0;
  for (; i < 5 && N >= ans[i]; i++) continue;
  std::cout << i << std::endl;

  return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
h = gets.chomp.split.map(&:to_i)
ans = []
ans[0] = 0
ans[1] = (h[1] - h[0]).abs
for i in (2...n) do
  ans[i] = [ans[i-1] + (h[i] - h[i-1]).abs, ans[i-2] + (h[i] - h[i-2]).abs].min
end
puts ans[n-1]


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

bool has3(int x) {
  while(x) {
    if (x%10 == 3) return true;
    x /= 10;
  }
  return false;
}

void call(int n) {
  for (int i = 1; i <= n; i++) {
    if (i%3 == 0 || has3(i)) {
      cout << " " << i;
    }
  }
  cout << endl;
}

int main() {
  int n;
  cin >> n;
  call(n);

  return 0;
}


Measured memory_bytes: 3100
from collections import deque

INF = 10**6
walk_area=[(1,0), (0,1), (-1,0), (0,-1)]
warp_area=[]
for i in range(-2, 3):
    for j in range(-2, 3):
        warp_area.append((i, j))
    
def walk(a, b, num, S, COST):
    m = S[a][b] 
    if m == '.':
        COST[a][b] = num
        # d.appendleft([a, b])
        return
    else:
        # d.append
        return

def warp(x,y,num, S, COST, d):
    m = S[x][y]
    if m == '.':
        COST[x][y] = num
        d.append([x, y])
        return
    if m == '#':
        return
    S[x][y] = min(num, m)
    return

def main():
    h, w = map(int, input().split())
    ch, cw = map(lambda x: int(x) + 1, input().split())
    dh, dw = map(lambda x: int(x) + 1, input().split())
    S = ['#'*(w+4)]
    S.append('#'*(w+4))
    for i in range(h):
        S.append('##'+input()+'##')
    S.append('#'*(w+4))
    S.append('#'*(w+4))
    
    # 各場所までワープ何回で辿り着くか
    COST = [[INF for i in range(w+4)] for j in range(h+4)]
    COST[ch][cw] = 0

    d = deque([[ch,cw,0]])
    d2 = deque()
    while len(d) > 0:
        t = d.popleft()
        d2.append(t)
        x = t[0]
        y = t[1]
        num = t[2] # COST[x][y]
        for dx, dy in walk_area:
            X = x + dx
            Y = y + dy
            if S[X][Y] == '#' or COST[X][Y] <= num:
                continue
        
            COST[X][Y] = num
            d.append([X, Y, num])
        if not d:
            while len(d2) > 0:
                x, y, num = d2.popleft()
                for dx, dy in warp_area:
                    X = x + dx
                    Y = y + dy
                    if S[X][Y] == '#' or COST[X][Y] <= num+1:
                        continue
                    
                    COST[X][Y] = num + 1
                    d.append([X, Y, num + 1])
    # for i in COST:
    #     print(i)
    if COST[dh][dw] == 10**6:
        print(-1)
    else:
        print(COST[dh][dw])
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 97164
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
map<string,int>v;
vector<pair<int,string>>v1;

    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
   cin>>n;
   l(i,1,n+1)
   {
       cin>>s1;
   v[s1]++;

   }
for(auto x:v){

   v1.pb({x.second,x.first});


}
lw(v1);
for(auto x:v1){
    if(x.first==v1[v1.size()-1].first)
    {
        cout<<x.second<<endl;
    }


}

}



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

int main() {
	int n,m,a,b;
	int ans;

	cin >> n >> m ;

	dsu d(n);
	rep(i, m){
		cin >> a >> b ;
		a--;
		b--;
		d.merge(a,b);
	}
	ans=d.groups().size()-1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8972
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,max_c=0;
vector<P> G[100010];
int c[100010];

void dfs(int s,int par,int color){
    int k=0;
    for(P p:G[s]){
        int t=p.first,e=p.second;
        if(t==par)continue;
        if(k==color)k+=1;
        max_c=max(max_c,k);
        c[e]=k;
        dfs(t,s,k);
        k+=1;
    }
}

void solve(){
    cin >> n;
    rep(i,n-1){
        int a,b;cin >> a >> b;a--;b--;
        G[a].push_back(P(b,i));
        G[b].push_back(P(a,i));
    }
    dfs(0,-1,-1);
    cout << max_c+1 << endl;
    rep(i,n-1){
        cout << c[i]+1 << endl;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

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

typedef struct{int color; int point;}QUEUE;
 
int N, C;
vector<vector<int>> D(31, vector<int>(31));
vector<vector<int>> grid(501, vector<int>(501));
vector<priority_queue< QUEUE, vector<QUEUE>, std::greater<QUEUE> >> que(3);
int pat[6][3] = {{0, 1, 2},{0, 2, 1},{1, 0, 2},{1, 2, 0},{2, 0, 1},{2, 1, 0}};

bool operator> (const QUEUE &que1, const QUEUE &que2){ return que1.point > que2.point; }
 
int main(void){
    
    cin >> N >> C;
    for(int i = 1; i <= C; ++i){ for(int j = 1; j <= C; ++j){ cin >> D[i][j]; }}
    for(int i = 1; i <= N; ++i){ for(int j = 1; j <= N; ++j){ cin >> grid[i][j]; }}
    
    
    QUEUE buf;
    for(int c = 1; c <= C; ++c){
        int x[3] = {0};
        for(int i = 1; i <= N; ++i){
            for(int j = 1; j <= N; ++j){
                int g;
                if((g = grid[i][j]) != c) x[(i + j) % 3] += D[g][c];
            }
        }
        for(int i = 0; i < 3; ++i) buf.color = c, buf.point = x[i], que[i].push(buf);
    }
    
    int result = INT_MAX;
    auto v = que;
    for(int i = 0; i < 6; ++i){
        int a, b, p, sum = 0;
        
        p = pat[i][0];
        sum += que[p].top().point;
        a = que[p].top().color;
        
        p = pat[i][1];
        while(que[p].top().color == a) que[p].pop();
        sum += que[p].top().point;
        b = que[p].top().color;
        
        p = pat[i][2];
        while(que[p].top().color == a || que[p].top().color == b) que[p].pop();
        sum += que[p].top().point;
        
        result = min(result, sum);
        que = v;
    }
    
    cout << result << endl;
    
    return 0;
    
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 1000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MAX_INT = (1 << 31) - 1;
const double eps = 1e-6;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("battleship.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //int TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n;
    cin >> n;
    map<int, int> m;
    rep(i, 1, n + 1)
    {
        int x = i;
        for (int j = 2; j * j <= x; j++)
            while (x % j == 0)
            {
                m[j]++;
                x /= j;
            }
        if (x > 1)
            m[x]++;
    }
    ll ans = 1;
    for (auto it : m)
        ans = (ans * (it.se + 1)) % MOD;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, K = LI()
A = LI()

"""
明るさが一定値を超えると計算しなくて良い
一定？d > math.floort(N/2)
"""
if K > 50:
    b = [str(N)] * N
    print(" ".join(b))
    sys.exit()

lamps = [[0 for i in range(N)] for j in range(K + 1)]
lamps[0] = A

"""
累積和〜
"""
for i in range(K):
    if lamps[i] == [N for i in range(N)]:
        ans = [str(N) for i in range(N)]
        print(" ".join(ans))
    tmps = [0 for i in range(N)]
    for j in range(N):
        w = lamps[i][j]
        tmps[max(0, j - w)] += 1
        r = min(N-1, j + w)
        if r + 1 < N:
            tmps[r + 1] -= 1
    hoge = 0
    for j in range(N):
        hoge += tmps[j]
        lamps[i + 1][j] = hoge
ans = lamps[-1]
ans = map(str, ans)
print(" ".join(ans))


Measured memory_bytes: 240100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int e = (a + (d - 1)) / d;
  int f = (c + (b - 1)) / b;
  e < f ? cout << "No" : cout << "Yes";
}


Measured memory_bytes: 3560