akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    for(int i = 0; i < n-1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> d(n);
    for(int i = 0; i < n; i++)
    {
        d[i] = -1;
    }
    function<void(int)> dfs = [&](int v)
    {
        for(int nx : g[v])
        {
            if(d[nx] != -1) continue;
            d[nx] = d[v] + 1;
            dfs(nx);
        }
    };
    d[0] = 0;
    dfs(0);
    int pos = 0;
    int ma = 0;
    for(int i = 0; i < n; i++)
    {
        if(ma < d[i])
        {
            ma = d[i];
            pos = i;
        }
    }
    for(int i = 0; i < n; i++)
    {
        d[i] = -1;
    }
    d[pos] = 0;
    dfs(pos);
    ma = 0;
    pos = 0;
    for(int i = 0; i < n; i++)
    {
        if(ma < d[i])
        {
            ma = d[i];
            pos = i;
        }
    }
    ma++;
    if(ma % 3 == 2)
    {
        cout << "Second" << endl;
    }
    else
    {
        cout << "First" << endl;
    }
}


Measured memory_bytes: 24448
import sys
input = sys.stdin.readline

#l = list(map(int, input().split()))
#import numpy as np
#arr = np.array([int(i) for i in input().split()])
'''
a,b=[],[]
for i in range(n):
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''


n=int(input())

a,x=[],[]
for i in range(n):
    A = int(input())
    a.append(A)
    B=[]
    for j in range(A):
        B.append(list(map(int, input().split())))
    x.append(B)

ma=0
for i in range(2**n):
    now=0
    flg=True
    e=[0]*n
    for j in range(n):
        if (i>>j)&1:
            now+=1
            e[j]=1

    for j in range(n):
        #print(e)
        if (i>>j)&1:
            
            if e[j]==0:
                flg=False
                break
            elif not flg:
                break

            for k in range(a[j]):
                """if e[x[j][k][0]-1]==-1: 
                    if x[j][k][1] and
                    e[x[j][k][0]-1]=x[j][k][1]"""
                
                if (e[x[j][k][0]-1]==0 and x[j][k][1]==1) or (e[x[j][k][0]-1]==1 and x[j][k][1]==0):
                    flg=False
                    break

    if flg and ma<now:
        ma=now
        #print(ma)

print(ma)



Measured memory_bytes: 9296
import math
import collections
import sys

#input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]

s=input()
val=int(s[5:7]+s[8:10])
#print(val)
if val<=430:
    print("Heisei")
else:
    print("TBD")

Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll S;
    cin >> S;

    const ll m = 1e9;
    
    if(S == 1e18) {
        cout << 0 << " " << 0 << " " << m << " " << 0 << " " << 0 << " " << m;
    }
    else {
        cout << 0 << " " << 0 << " " << m << " " << 1 << " " << m - S%m << " " << S/m + 1;
    }

    cout << endl;
    re0;
}

Measured memory_bytes: 256
import sys
import numpy as np
import collections as cl
import itertools as it
# import more_itertools as mit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(100000)

n, m = map(int, readline().split())
A = []
B = []
for _ in range(m):
    a, b = map(int, readline().split())
    A.append(a)
    B.append(b)
for i in range(n):
    print(A.count(i+1)+B.count(i+1))

Measured memory_bytes: 27108
#include <cstdio>
#include <vector>
using namespace std;

typedef struct P {
	int p, d;
} P;
int n;

int main(){
	int p, d1, d2;
	P m, t;
	while (true) {
		scanf("%d", &n);
		if (n == 0) break;
		m = { 0,-1 };
		for (int i = 0; i < n; i++) {
			scanf("%d %d %d", &p, &d1, &d2);
			t = { p,d1 + d2 };
			if (m.d < t.d) {
				m = t;
			}
		}
		printf("%d %d\n", m.p, m.d);
	}

	return 0;
}

Measured memory_bytes: 2660
defmodule Main do
  def main do
    [h, _] =
      IO.gets("")
      |> String.trim()
      |> String.split()
      |> Enum.map(&String.to_integer/1)
      
    IO.stream(:stdio, :line)
    |> Enum.take(h)
    |> Enum.map(&String.trim/1)
    |> Enum.each(fn elem ->
      IO.puts(elem)
      IO.puts(elem)
    end)
  end
end


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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

struct pot {
    int a, b, pt;
};

void solve() {
    int d, g;
    cin >> d >> g;

    vector<pot> v(d);
    vector<int> perm(d);
    iota(perm.begin(), perm.end(), 0);
    for (int i = 0; i < d; i++) {
        cin >> v[i].a >> v[i].b;
        v[i].pt = (i + 1) * 100;
    }

    int ct = LLONG_MAX;
    do {
        int pct = 0, ans = 0;
        for (int i = 0; i < d; i++) {
            int idx = perm[i];
            int need = g - ans;
            int del = need / v[idx].pt + (need % v[idx].pt > 0);

            if (del <= v[idx].a) {
                pct += del;
                ans += del * v[idx].pt;
            } else if (del > v[idx].a) {
                ans += v[idx].a * v[idx].pt;
                pct += v[idx].a;
            }
            if (del >= v[idx].a)ans += v[idx].b;
            if (ans >= g)break;
        }
        ct = min(ct, pct);
    } while (next_permutation(perm.begin(), perm.end()));
    cout << ct << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

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

const int MAXN = 100005;

vector <int> G[MAXN];
int N, M, A[MAXN], B[MAXN];
bool vis[MAXN], s[MAXN], x[MAXN];

int fix(int u){
	vis[u] = true;
	
	int r = x[u];
	for(int i : G[u]){
		int v = A[i] ^ B[i] ^ u;
		if(vis[v])continue;
		
		if(fix(v) == 1){
			s[i] ^= 1;
			r ^= 1;
		}
	}
	return r;
}

int main(){		
	scanf("%d %d", &N, &M);
	for(int i = 0; i < M; i++){
		scanf("%d %d", &A[i], &B[i]);
		A[i]--, B[i]--;
		
		G[A[i]].push_back(i);
		G[B[i]].push_back(i);
		
		x[A[i]] ^= 1;
	}
	
	if(M % 2 != 0)printf("-1\n");
	else{
		fix(0);
		for(int i = 0; i < M; i++){
			if(!s[i])printf("%d %d\n", A[i] + 1, B[i] + 1);
			else printf("%d %d\n", B[i] + 1, A[i] + 1);
		}
	}
	
	return 0;
}


Measured memory_bytes: 12672
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s,t;
  cin>>s>>t;
  int ans=INF;
  rep(i,(int)s.size()){
    int count=0;
    REP(j,i,(int)t.size()+i){
      if(j>=(int)s.size()){
        count=INF;
        break;
      }
      if(t[j-i]!=s[j]){
        count++;
      }
    }
    chmin(ans,count);
  }
  cout<<ans<<'\n';
  return(0);
}


Measured memory_bytes: 3656
N,M = (int(i) for i in input().split())
s = [0] * M
for i in range(M):
    s[i] = list(map(int,input().split()))
p = list(map(int,input().split()))
cnt = 0
sw = [1] * N
tmp = 0
ans = 0
for i in range(1,N):
    sw[i] = sw[i-1] * 2
while cnt < 2**N:
    flag = 1
    for i in range(M):
        tmp = 0
        for j in range(s[i][0]):
            x = cnt % (2**(s[i][j+1]))
            if x >= 2**(s[i][j+1]-1):
                tmp += 1
        tmp %= 2
        if tmp != p[i]:
            flag = 0
            break
    cnt += 1
    if flag == 1:
        ans += 1
print(ans)


Measured memory_bytes: 40560
#topologivcal sort

from collections import deque

n, k = map(int, input().split())

a = [[] for i in range(n)]
in_num = [0]*n
for _ in range(k):
    p, q = map(int, input().split())
    a[p] += [q]
    in_num[q] += 1
# print(a)
# print(in_num)
# a = [[1],[2],[],[1,4],[5],[2]]
# n = len(a)
# in_num = [0, 2, 2, 0, 1, 1]
color = [0]*n
result = deque()
aa = deque()

def topologicalSort_w(s):
    aa.append(s)
    color[s] = 1
    while aa:
#         print(aa)
#         print(in_num)
        u = aa.popleft()
        result.append(u)
        for v in a[u]:
            in_num[v] -= 1
            if in_num[v] == 0 and color[v] == 0:
                color[v] = 1
                aa.append(v)
        

for i in range(n):
    if in_num[i] == 0 and color[i] == 0:
        topologicalSort_w(i)
        

                
for i in range(len(result)):
    print(result.popleft())
    


Measured memory_bytes: 8996
open System
open System.Collections
open System.Collections.Generic
open System.IO
open System.Linq
open System.Net
open System.Security.Cryptography.X509Certificates

type IO<'T> = private | Action of (unit -> 'T)
[<AutoOpen>]
module IO =
    let private raw  (Action f) = f
    let private run  io         = raw io ()
    let private eff  g   io     = raw io () |> g
    let private bind io  rest   = Action (fun () -> io |> eff rest |> run)
    let private comb io1 io2    = Action (fun () -> run io1; run io2)
    
    type IOBuilder() =
        member b.Return(x)              = Action (fun () -> x)
        member b.ReturnFrom(io) : IO<_> = io
        member b.Delay(g) : IO<_>       = g ()
        member b.Bind(io, rest)         = bind io rest
        member b.Combine(io1, io2)      = comb io1 io2

    let io = new IOBuilder()
    let (|Action|) io = run io

    let write     (x:obj) = Action (fun () -> stdout.Write(x))
    let writeLine (x:obj) = Action (fun () -> stdout.WriteLine(x))
    let read              = Action (fun () -> stdin.ReadLine())

[<EntryPoint>]
let main _ = 
    let (Action())= io{
        let! l1 = read
        let x = l1 |> int64
        let ans = 
            let a = (x / 11L) * 2L
            let b = 
                let t = x % 11L
                if   t =  0L then 0L
                elif t <= 6L then 1L
                else              2L
            a + b
        return! writeLine ans
    }
              
    0
    



Measured memory_bytes: 11348
s=input()
a=int(s[:2])
b=int(s[2:])
if 1<=a<=12 and 1<=b<=12:print("AMBIGUOUS")
elif 1<=a<=12 and (b==0 or 12<b):print("MMYY")
elif (a==0 or 12<a) and 1<=b<=12:print("YYMM")
else:print("NA")

Measured memory_bytes: 3060
A = input()
a = A[0]
found = False
if a == A[1] and a!=A[2] and A[2]==A[3]:
    found =True
if a == A[2] and a!=A[1] and A[1]==A[3]:
    found =True
if a == A[3] and a!=A[1] and A[1]==A[2]:
    found =True
if found:
    print("Yes")
else:
    print("No")

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

int main(){
 
  int r;
  cin >> r;
  string ans;
  if(r < 1200){
  	ans = "ABC"; 
  }else if(r < 2800){
    ans = "ARC";
  }else{
   	ans = "AGC"; 
  }
  cout << ans << endl;
  
  
  
}

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

long n, a;
long xs[64];
long dp[2][4096];
long zero;

int main() {
  scanf("%ld", &n);
  scanf("%ld", &a);
  for(int i = 0; i < n; ++i) {
    scanf("%ld", &xs[i]);
  }

  dp[0][0] = dp[1][0] = 1;
  for(int i = 0; i < n; ++i) {
    int y = xs[i] - a;
    if( y == 0 ) {
      zero += 1;
    }
    else if( y < 0 ) {
      for(int j = 4000; j >= 0; --j) {
        dp[0][j+(-y)] += dp[0][j];
      }
    }
    else if( y > 0 ) {
      for(int j = 4000; j >= 0; --j) {
        dp[1][j+(+y)] += dp[1][j];
      }
    }
  }

  long res = 0;
  for(int i = 1; i < 4096; ++i) {
    res += dp[0][i] * dp[1][i] * (1LL << zero);
  }
  res += (1LL << zero) - 1;
  printf("%ld\n", res);    
  
  return 0;
}



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;

#define chmax(x,y) x=max(x,y)
int dp[10010]; // dp[i] : i本のマッチを丁度使う場合の最大桁数

int main()
{
    int N[10];
    N[1] = 2;
    N[2] = 5;
    N[3] = 5;
    N[4] = 4;
    N[5] = 5;
    N[6] = 6;
    N[7] = 3;
    N[8] = 7;
    N[9] = 6;

    int n, m;
    cin >> n >> m;
    vector<int> A(m);
    rep(i,m) cin >> A[i];
    sort(A.rbegin(), A.rend());

    rep(i,n) dp[i] = -1;
    dp[0] = 0;

    for (int i=1; i<=n; i++) {
        for (auto a : A) {
            int x = i - N[a];
            if (x < 0) continue;
            if (dp[x] == -1) continue;
            chmax(dp[i], dp[x] + 1);
        }
    }

    vector<int> Ans;
    int match = n;
    for (int i=dp[n]; i>=1; i--) {
        for (auto a : A) {
            if (match -N[a] < 0) continue;
            if (dp[match-N[a]] == i-1) {
                Ans.push_back(a);
                match -= N[a];
                break;
            }
        }
    }

    for (auto ans : Ans) {
        cout << ans;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef pair<int,int> P;
typedef long long ll;

int main(void){
    int n,d;
    cin>>n>>d;
    int x=2*d+1;
    int y=n/x;
    if(n%x==0)cout<<y<<endl;
    else cout<<y+1<<endl;
    return 0;
}

Measured memory_bytes: 256
N, A, B, C = map(int, input().split())
li = list(int(input()) for i in range(N))
INF = 10 ** 9

def dfs(cur, a, b, c):
    if cur == N:
        return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else INF
    ret0 = dfs(cur+1, a, b, c)
    ret1 = dfs(cur+1, a+li[cur], b, c) + 10
    ret2 = dfs(cur+1, a, b+li[cur], c) + 10
    ret3 = dfs(cur+1, a, b, c+li[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
def get_fibonacci_number(n):
    if n < 2:
        return 1
    if not fibonacci_numbers[str(n)]:
        fibonacci_numbers[str(n)] = get_fibonacci_number(n-1) + get_fibonacci_number(n-2)
    return fibonacci_numbers[str(n)]

if __name__ == "__main__":
    n = int(input())
    fibonacci_numbers = {str(i):None for i in range(45)}
    print(get_fibonacci_number(n))


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    string s; cin >> s;

    int n = s.size() -1;
    if(n&1) n--;

    while(1){
        bool jud = true;
            rep(j,n/2){
                if(s[j] != s[j+n/2]) jud = false;
            }

        if(jud) break;
        n-=2;
        if(n == 0) break;
    }

    cout << n << endl;
}

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

using namespace std;

void insertion_sort(vector<int> A, int S) {
  for (int i = 1; i < S; ++i) {
    int tmp= A[i];
    int j = i - 1;
    while (j >= 0 && A[j] > tmp) {
      A[j + 1] = A[j];
      --j;
    }
    A[j + 1] = tmp;
    for (vector<int>::iterator it = A.begin(); it != A.end() - 1; ++it) {
      cout << *it << ' ';
    }
    cout << *(A.end() - 1) << endl;
  }
}

int main() {
  int N; cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (vector<int>::iterator it = A.begin(); it != A.end() - 1; ++it) {
    cout << *it << ' ';
  }
  cout << *(A.end() - 1) << endl;

  insertion_sort(A, A.size());
}

Measured memory_bytes: 1216
def vac(l,n):
    dp=[[0 for i in range(3)]for j in range(n+1)]
    for i in range(1,n+1):
        x=l[i-1]
        for j in range(3):
            for k in range(3):
                if(k==j):
                    continue
                else:
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+x[k])
    m=max(dp[n][0],max(dp[n][1],dp[n][2]))
    # print(dp)
    return m

n=int(input())
l=[]
for i in range(n):
    x=list(map(int,input().split()))
    l.append(x)

# print(l)
print(vac(l,n))


Measured memory_bytes: 75352
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int p[30],left[30],right[30],s[30],dep[30],h[30],deg[30]; 
void setdep (int cur,int d) {
	dep[cur]=d;
	if (left[cur]!=-1) setdep (left[cur],d+1);
	if (right[cur]!=-1) setdep (right[cur],d+1);
}
int seth (int cur) {
	if (left[cur]!=-1) h[cur]=max(h[cur],seth(left[cur])+1);
	if (right[cur]!=-1) h[cur]=max(h[cur],seth(right[cur])+1);
	return h[cur];
}
int main () {
	int n;
	scanf ("%d",&n);
	memset (p,-1,sizeof(p));
	memset (left,-1,sizeof(left));
	memset (right,-1,sizeof(right));
	memset (s,-1,sizeof(s));
	for (int i=0;i<n;i++) {
		int id,l,r;
		scanf ("%d%d%d",&id,&l,&r);
		left[id]=l;
		right[id]=r;
		if (l!=-1) {
			deg[id]++;
			p[l]=id;
		}
		if (r!=-1) {
			deg[id]++;
			p[r]=id;
		}
		if (l!=-1&&r!=-1) {
			s[l]=r;
			s[r]=l;
		}
	}
	for (int i=0;i<n;i++) {
		if (p[i]==-1) {
			setdep (i,0);
			seth (i);
			break;
		}
	}
	for (int i=0;i<n;i++) {
		printf ("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,p[i],s[i],deg[i],dep[i],h[i]);
		if (p[i]==-1) printf ("root\n");
		else if (deg[i]==0) printf ("leaf\n");
		else printf ("internal node\n");
	}
    return 0;
}


Measured memory_bytes: 2752
#include<iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include<unordered_map>
using namespace std;
const long long int mod1=1000000007;
const long long int mod2 = 998244353;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back                                       
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define ordered1 tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define inf mod1
#define all(x) x.begin(),x.end()
ll gcd(ll a, ll b){
    ll c;
     while(b){
        c = b;
        b = a % b;
        a = c;
     }
     return a;
}
ll power1(ll a, ll b){
     if(b == 0) return 1;
     else if(b % 2) return a * power1(a, b - 1);
     else {
        ll temp = power1(a, b / 2);
        return temp * temp;
     }
}
ll power2(ll a, ll b, ll m){
     a %= m;
     if(b == 0) return 1;
     else if(b % 2) return (a * power2(a, b - 1, m)) % m;
     else{
        ll temp = power2(a, b / 2, m);
        return (temp * temp) % m;
     }
}
ll mod(ll x, ll p){
return (x % p + p) % p;
}
ll lcm(ll x, ll y){
return (x * y)/gcd(x, y);
}
int main(){
    fast;
    ll tt = 1;
    //cin >> tt;
    while(tt--){
        ll n, k;
        cin >> n >> k;
        ll h[n];
        for(int i = 0; i < n; i++){
            cin >> h[i];
        }
        ll dp[n];
        dp[0] = 0;
        for(int i = 1; i < n; i++){
            dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
            for(int j = i - 2; j >= max((ll)0, (ll)i - k); j--){
                dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
            }
        }
        cout << dp[n - 1] << endl;
    }
}


Measured memory_bytes: 1792
mod = 10**9+7
N, X = map(int, input().split())

S = sorted(list(map(int, input().split())))
S_max = 10**5
dp = [[0]*(S_max+1) for _ in range(N+1)]

for x in range(S_max+1):
    dp[0][x] = x
for i in range(1, N+1):
    for x in range(S_max+1):
        dp[i][x] = (dp[i-1][x]*(i-1)+dp[i-1][x%S[i-1]])%mod
print(dp[N][X]%mod)


Measured memory_bytes: 193544
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  int A[N];
  for(int i=0;i<N;++i) cin>>A[i];
  int prime[1000005];
  for(int i=0;i<1000005;++i) prime[i] = -1;
  prime[0] = 1;
  prime[1] = 1;
  for(int i=2;i<1000005;++i) {
    if(prime[i]==-1) {
      prime[i] = i;
      for(int j=2;i*j<1000005;++j) {
        if(prime[i*j]==-1) prime[i*j] = i;
      }
    }
  }
  int tmp=A[0];
  map<int, int> amap;
  vector<int> arr, arr1;
  int waru;
  while(tmp>1) {
    waru = prime[tmp];
    if(amap[waru]==0) arr.push_back(waru);
    amap[waru]++;
    while(tmp%waru==0) tmp /= waru;
  }
  bool pairwise = true;
  for(int i=1;i<N;++i) {
    tmp = A[i];
    while(tmp>1) {
      waru = prime[tmp];
      if(amap[waru]>0) pairwise = false;
      amap[waru]++;
      while(tmp%waru==0) tmp /= waru;
    }
    arr1.clear();
    for(int j=0;j<arr.size();++j) {
      if(A[i]%arr[j]==0) arr1.push_back(arr[j]);
    }
    arr = arr1;
  }
  if(pairwise) cout<<"pairwise coprime"<<endl;
  else if(arr.size()==0) cout<<"setwise coprime"<<endl;
  else cout<<"not coprime"<<endl;
}



Measured memory_bytes: 14884
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;

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; }

template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;

int main() {
	string s, t;
	cin >> s >> t;
	int min_cnt = t.size();
	for (int i = 0; i <= s.size()-t.size(); ++i) {
		int cnt = 0;
		for (int j = 0; j < t.size(); ++j) {
			if (s[i+j] != t[j]) ++cnt;
		}
		min_cnt = min(cnt, min_cnt);
	}
	cout << min_cnt << endl;
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long int
#define ff first
#define ss second
#define S size()
#define mod (ll)(1e9+7)
#define mset(a,k) memset(a,k,sizeof(a));
#define fr(i, x, y) for ( ll i = x; i < y;i++)
#define dr(i, x, y) for ( ll i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define pqueue priority_queue<ll>
#define piqueue priority_queue<ll,vll ,greater<ll>>
#define mapcl map<char,ll>
#define mapll map<ll,ll>
#define mapsl map<string,ll>
#define vi vector<ll>
#define vs vector<string>
#define vb vector<bool>
#define psi pair<string,ll>
#define pii pair<ll,ll>
#define piii pair<ll,pii>
#define vii vector<pii>
#define vvi vector<vi>
#define vvii vector<vii>
using namespace std;
void fast() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}
//----------------------------------------FUNCTIONS-------------------------------------
ll gcd(ll x, ll y )						{if (y == 0) return x; return gcd(y, x % y);}
ll lcm(ll a, ll b)						{return (a * b) / gcd(a, b);}
ll logx(ll base, ll num)				{int cnt = 0; while (num != 1) {num /= base; ++cnt;} return cnt;}
vi vin(ll n)							{vi a(n); fr(i, 0, n) cin >> a[i]; return a;}
void out(vi a)							{for (int i = 0; i < (ll)a.S; i++) { cout << a[i] << " "; } cout << endl;}
void in(ll *a, ll n)        			{for (ll i = 0; i < n; i++)cin >> a[i];}
void out(ll *a, ll n)					{fr(i, 1, n + 1) {cout << a[i] << " ";} cout << '\n';}
void out1(vi v)							{fr(i, 0, (ll)v.S) {cout << v[i] << " ";} cout << endl;}
//----------------------------------------START-------------------------------------------
const ll maxN = (ll)(1 * 1e6 + 5 );

void solve()
{
	ll n;
	cin >> n;
	ll a[n];
	in(a, n);
	sort(a, a + n);
	set < pair < ll, pii>> s;
	fr(i, 0, n)
	{
		fr(j, i + 1, n)
		{
			fr(k, j + 1, n)
			{
				if (a[i] != a[j] && a[j] != a[k] && a[i] != a[k])if (a[i] + a[j] > a[k])s.insert({i, {j, k}});
			}
		}
	}
	cout << s.S << '\n';
}
int main()
{
	fast();
#ifndef ONLINE_JUDGE
	freopen ("inp1.txt", "r", stdin);

	freopen ("out1.txt", "w", stdout);
#endif
	ll t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}



Measured memory_bytes: 13744
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x3 = 0;
  int y3 = 0;
  int x4 = 0;
  int y4 = 0;
  int a = 0;
  int b = 0;
  if(x2 >= x1 && y2 >= y1){
    a = x2 - x1;
    if (a < 0)
      a = a * (-1);
    b = y2 - y1;
    if (b < 0)
      b = b * (-1);
    x3 = x2 - b;
    y3 = y2 + a;
    x4 = x1 - b;
    y4 = y1 + a;
  }
  else if(x2 <= x1 && y2 >= y1){
    a = x1 - x2;
    if (a < 0)
      a = a * (-1);
    b = y2 - y1;
    if (b < 0)
      b = b * (-1);
    x3 = x2 - b;
    y3 = y2 - a;
    x4 = x1 - b;
    y4 = y1 - a;
  }
  else if(x2 <= x1 && y2 <= y1){
    a = x1 - x2;
    if (a < 0)
      a = a * (-1);
    b = y1 - y2;
    if (b < 0)
      b = b * (-1);
    x3 = x2 + b;
    y3 = y2 - a;
    x4 = x1 + b;
    y4 = y1 - a;
  } 
  else{
    a = x2 - x1;
    if (a < 0)
      a = a * (-1);
    b = y1 - y2;
    if (b < 0)
      b = b * (-1);
    x3 = x2 + b;
    y3 = y2 + a;
    x4 = x1 + b;
    y4 = y1 + a;
  }
  char s = ' ';
    cout << x3 << s << y3 << s <<  x4 << s <<  y4 << endl;
}

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

using namespace std;

int main() {
  int D;
  
  cin >> D;
  
  cout << "Christmas";
  
  for (int i = 0; i < 25 - D; i++) {
    cout << " Eve";
  }
  
  cout << endl;
  
  return 0;
}

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

if N % 2 == 0:
    s = A[0]
    for i in range(1,N):
        s = s^A[i]
    
    for i in range(N):
        print(s^A[i],end=" ")
    print()
else:
    print()

Measured memory_bytes: 31580
#include <iostream>
#include <iomanip>
#include <math.h>
#include <map>
#include <list>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <sstream>
#include <string.h>
// #include <limits.h>

#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define INTMAX  99999999

#define DEBUG 1

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

#define MAX_N (1000*100+5)
#define MAX_A (1000*100+5)

int A[MAX_N];
int B[MAX_A];

int N;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);

	cin >> N;
	FOR(a,MAX_A) {
		B[a] = 0;
	}
	FOR(n,N) {
		cin >> A[n];
		B[A[n]] += 1;
	}

	int count = 0;
	FOR(a,MAX_A) {
		if (B[a]>=1) {
			count++;
		}
	}

	if(count%2) { cout << count << endl; }
	else { cout << count -1 << endl; }

	return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
    string S;
    int snum = 0;
    int count = 0;

    cin >> S;

    snum = S.length();

    if((snum%2) == 0){
        for(int i=0;i<(snum/2);i++){
            if(S[i] != S[snum-1-i]) count++;
        }
    }
    else{
        for(int j=0;j<(snum/2);j++){
            if(S[j] != S[snum-1-j]) count++;
        }
    }

    cout << count << endl;

    return 0;
}

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

using namespace std;

#define endl '\n'


int main(){

  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);

  map <string,int> mp;

  int n;
  cin >> n;

  while(n--){
    string s;
    cin >> s;
    mp[s]++;
  }

  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;
 
  return 0;
}

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

bool is_prime[300000];
int main()
{

	is_prime[1] = true;
	for (int i = 2; i < 300000; i++){
		const int mod7 = i % 7;

		if (!(mod7 == 1 || mod7 == 6)){
			is_prime[i] = true;
			continue;
		}

		int sq = sqrt(i);
		for (int j = 2; j <= sqrt(i); j++){
			if (i % j == 0 && (!is_prime[j] || !is_prime[i/j])){
				is_prime[i] = true;
				break;
			}
		}
	}

	int n;
	while (cin >> n, n != 1){
		cout << n << ":";
		for (int i = 1; i <= n; i++){
			if (!is_prime[i] && n % i == 0)
				cout << " " << i;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1452
buf = list(map(int,input().split(" ")))
A,V = buf[0],buf[1]

buf = list(map(int,input().split(" ")))
B,W = buf[0],buf[1]

T = int(input())

if V <= W:
    print("NO")
    exit(0)
if (abs(A - B) / (V - W)) <= T:
    print("YES")
else:
    print("NO")

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

int main() {

  int n;
  cin >> n;
  vector<int> h(n);
  int ans = 1;

  for(int i = 0; i < n; i++) { cin >> h.at(i); }

  int t = h.at(0);

  for(int i = 1; i < n; i++) {
    if(t <= h.at(i)) {
      ans++;
    }
    t = max(t, h.at(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void)
{
    int n, s = 0;
    cin >> n;
    int D[100][2];
    for (int i = 0; i < n; i++)
    {
        cin >> D[i][0] >> D[i][1];
    }
    for (int i = 0; i < n; i++)
    {
        if (D[i][0] == D[i][1])
        {
            s++;
        }
        else if (s < 3)
        {
            s = 0;
        }
        
    }
    if (s >= 3)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}


Measured memory_bytes: 3632
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝




*/
#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;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>n>>s1;
    l(i,0,s1.size())
    {d=0;
       d=int(s1[i]);d=d+(n);
       if(d>90)
       {//cout<<d<<endl;
        cout<<char(65+(d-90)-1);
       }
       else
       { //cout<<d;
           cout<<char(d);
       }
    }

}



Measured memory_bytes: 3680
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0;i<n;i++);
int main(){
  double n;cin>>n;
  double t,a;cin >> t >> a;
  vector<double> h(n);
  for(int i=0;i<n;i++)cin>>h[i];
  vector<double> ave(n);
  for(int i=0;i<n;i++)ave[i]=t-h[i]*0.006;
  double mini=1000000007;
  int s;
  for(int i=0;i<n;i++){
    if(mini>abs(a-ave[i]))s=i+1;
    mini=min(mini,abs(a-ave[i]));
    
  }
  cout << s << endl;}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int h = hw[0];
        int w = hw[1];
        List<int>[] graph = Enumerable.Repeat(0, h * w).Select(_ => new List<int>()).ToArray();
        for (int i = 0; i < h - 1; i++)
            for (int j = 0; j < w; j++)
            { var id = i * w + j; graph[id].Add(id + w); }
        for (int i = 0; i < h; i++)
            for (int j = 0; j < w - 1; j++)
            { var id = i * w + j; graph[id].Add(id + 1); }

        var arrived = new bool[h * w];
        var a = Enumerable.Repeat(0, h).SelectMany(_ => Console.ReadLine().Split().Select(int.Parse)).ToArray().Zip(
            Enumerable.Repeat(0, h).SelectMany(_ => Console.ReadLine().Split().Select(int.Parse)).ToArray(),
            (x, y) => Abs(x - y)
        ).ToArray();
        var offset = 80 * 80;
        var mask = (BigInteger.One << (offset * 2 + 1)) - 1;
        BigInteger[] diffs = Enumerable.Repeat(0, h * w).Select(_ => new BigInteger(0)).ToArray();
        Queue<int> queue = new Queue<int>();
        queue.Enqueue(0);
        diffs[0] |= BigInteger.One << offset;
        while (queue.Count != 0)
        {
            var last = queue.Dequeue();
            var copied = diffs[last];
            diffs[last] <<= a[last];
            copied >>= a[last];
            diffs[last] |= copied;
            diffs[last] &= mask;
            foreach (var next in graph[last])
            {
                diffs[next] |= diffs[last];
                if (arrived[next]) continue;
                arrived[next] = true;
                queue.Enqueue(next);
            }
        }
        var min = int.MaxValue;
        var lastDiff = diffs.Last();
        for (int i = 0; i <= offset * 2; i++)
        {
            if (((lastDiff >> i) & 1) == 0) continue;
            min = Min(min, Abs(offset - i));
        }
        Console.WriteLine(min);
    }
}


Measured memory_bytes: 34528
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<vi> vvi;
int d;
int main() {
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>d;
	cout<<"Christmas ";
	for(int i=d;i<25;i++)cout<<"Eve ";
	cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}

int A,B,C;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> A >> B >> C;
  vector<int> diff;
  diff.emplace_back(abs(A-B));
  diff.emplace_back(abs(B-C));
  diff.emplace_back(abs(C-A));
  sort(all(diff));
  cout << diff[1] + diff[0] << endl;

  return 0;
}


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

signed main(){
  int n;
  int w[100];
  cin >> n;
  LOOP(i,n){
    cin >> w[i];
  }
  int ans = INF;
  LOOP1(t,n-1){
    int s1=0,s2=0;
    LOOP(i,n){
      if(i<t)s1+=w[i];
      else  s2+=w[i];
    }
    ans = min(ans, s1>s2?s1-s2:s2-s1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <limits>
#define N 110

int main(){
  int n;
  std::cin >> n;
 
  int A[N][N];
  int d[N] = {};
  int p[N];
  for(int i=0; i<n; i++){
    d[i] = std::numeric_limits<int>::max();
    p[i] = -1;
    for(int j=0; j<n; j++){
      std::cin >> A[i][j];
      if( A[i][j] == -1){ //no line
        A[i][j] = std::numeric_limits<int>::max();
      }
    }
  }
  d[0] = 0;

  int used[N] = {};
  while(1){
    int u = -1;
    int min = std::numeric_limits<int>::max();
    for(int i=0; i<n; i++){
      if( used[i] != -1 && d[i]<min ){
        min = d[i];
        u = i;
      }
    }
    if(min==std::numeric_limits<int>::max()) break;
    used[u] = -1;

    for(int i=0; i<n; i++){
      if( used[i] != -1 && A[u][i] < d[i]){
        p[i] = u;
        d[i] = A[u][i];
        used[i] = 1;
      }
    }
  }
  int MST=0;
  for(int i=0; i<n; i++){
    if(p[i] != -1) MST += A[i][p[i]];
      }

  std::cout << MST << std::endl;

  return 0;
}



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

int A[100000], n;

int Partition(int p, int r){
	int x = A[r - 1], j = 0;
	for(int i = 0;i < n;i++){
		if(A[i] <= x) {
			int tmp = A[j];
			A[j++] = A[i];
			A[i] = tmp;
		}
	}
	return j - 1;
}

main(){
    scanf("%d", &n);
    for(int i = 0;i < n;i++)scanf("%d", &A[i]);
	int j = Partition(0, n);
	for(int i = 0;i < n - 1;i++){
		if(i)printf(" ");
		if(i == j)printf("[");
		printf("%d", A[i]);
		if(i == j)printf("]");
	}
	printf(" %d\n", A[n - 1]);
}

Measured memory_bytes: 3476
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int gcd(int x,int y){
	
	if(x%y==0){
		return y;
	}else{
		return gcd(y,x%y);
	}
	
}

int main() {
	
	int N;
	int sum=0;
	cin>>N;
	vec(A)
	fx(N){
		vecp(A)
		sum+=A.at(x);
	}
	bool can=true;
	fx(N){
		if(sum<=2*A.at(x)){
			can=false;
			break;
		}
	}
	if(can){
		ce("Yes")
	}else{
		ce("No")
	}
	
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
    int A, B;
    int ans = 0;
    int a[5];
    scanf("%d %d", &A, &B);
    for (int i = A; i <= B; i++) {
        int copyI = i;
        for (int j = 0; j < 5; j++) {
            a[j] = copyI % 10;
            copyI /= 10;
        }
        if (a[0] == a[4] && a[1] == a[3]) {
            ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
n,a,b,c=map(int,input().split())
r=[a,b,c]
d=[int(input()) for i in range(n)]
ans=99999999
for i in range(4**n):
    s=Base_10_to_n(i,4)
    s="0"*(n-len(s))+s
    tmp=[[0,0],[0,0],[0,0]]
    for j in range(n):
        if s[j] in '012':
            tmp[int(s[j])][0]+=d[j]
            tmp[int(s[j])][1]+=1
    t=0
    for j in range(3):
        if tmp[j][0]==0:
            break
        t+=abs(r[j]-tmp[j][0])+max((tmp[j][1]-1)*10,0)
    else:
        if ans>t:
            ans=t
print(ans)

Measured memory_bytes: 3064
main = interact $ unlines . map (show . circles_intersection . (map read) . words) . tail . lines
circles_intersection [xa,ya,ra,xb,yb,rb]
 | ra > sqrt ((xb-xa)^2+(yb-ya)^2) + rb = 2
 | rb > sqrt ((xa-xb)^2+(ya-yb)^2) + ra = -2
 | ra + rb >= sqrt ((xa-xb)^2+(ya-yb)^2) = 1
 | otherwise = 0

Measured memory_bytes: 4360
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <cassert>
#include <iomanip>      
#define pb push_back
#define x first
#define y second
#define mp make_pair
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
using namespace std;
 
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
 
typedef pair<int, int> point;
 
const string FILENAME = "input";

int A, B;
int s = 2;
int d[11][11];
int X[11][11], Y[11][11], D[11][11];

int lenX[101], lenY[101], lenXY[101];
set<pair<pair<int, int>, int>> edge;

int main() {
	ios::sync_with_stdio(0);
	srand(time(0));
	//read(FILENAME);
	cin >> A >> B;
	for (int i = 1; i <= A; ++i) {
		for (int j = 1; j <= B; ++j) {
			cin >> d[i][j];
		}
	}
	for (int i = 1; i <= A; ++i) {
		for (int j = 1; j <= B; ++j) {
			int cnt = 0;
			X[i][j] = -1;
			for (int fX = 0; (fX * i) <= d[i][j];  ++fX) {
				for (int fY = 0; (fX * i + fY * j) <= d[i][j]; ++fY) {
					int fD = d[i][j] - fX * i - fY * j;
					bool OK = true;
					for (int a = 1; a <= A; ++a) {
						for (int b = 1; b <= B; ++b) {
							++cnt;
							if (a * fX + b * fY + fD < d[a][b]) {
								OK = false;
								a = b = 1e9;
							}
						}
					}
					if (OK) {
						X[i][j] = fX;
						Y[i][j] = fY;
						D[i][j] = fD;
						//cout << cnt << endl;
						//cout << i << ' ' << j << ' ' << fX << ' ' << fY << ' ' << fD << endl;
						fX = fY = d[i][j] + 1;
					}
				}
			}
			if (X[i][j] == -1) {
				cout << "Impossible" << endl;
				return 0;
			}
		}
	}
	lenXY[0] = s;
	++s;
	lenXY[50] = 0;
	for (int i = 1; i < 50; ++i) {
		lenXY[i] = s++;
	}
	for (int i = 0; i < 50; ++i) {
		edge.insert({{lenXY[i + 1], s}, -2});
		edge.insert({{s, lenXY[i]}, -1});
		++s;
	}
	lenX[0] = lenY[0] = 1; 
	lenX[100] = lenY[100] = 0;
	for (int i = 1; i < 100; ++i) {
		lenX[i] = s++;
		lenY[i] = s++;
	}
	for (int i = 0; i < 99; ++i) {
		edge.insert({{lenX[i + 1], lenX[i]}, -1});
		edge.insert({{lenY[i + 1], lenY[i]}, -2});
	}
	for (int i = 1; i <= A; ++i) {
		for (int j = 1; j <= B; ++j) {
			if (X[i][j] >= Y[i][j]) {
				edge.insert({{lenXY[50 - Y[i][j]], lenX[X[i][j] - Y[i][j]]}, D[i][j]});
			} else {
				edge.insert({{lenXY[50 - X[i][j]], lenY[Y[i][j] - X[i][j]]}, D[i][j]});
			}
		}
	}
	cout << "Possible" << endl;
	cout << s << ' ' << edge.size() << endl;
	for (auto i : edge) {
		cout << i.x.x + 1 << ' ' << i.x.y + 1 << ' ';
		if (i.y < 0) {
			if (i.y == -1) cout << "X";
			else cout << "Y";
		} else {
			cout << i.y;
		}
		cout << endl;
	}
	cout << 1 << ' ' << 2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;




ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int digNum(ll x, int n){
    ll num = pow(10, n - 1);
    num = x / num;
    num %= 10;
    return num;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}



int main(){
    //頭から1引いて残りを9で埋めたやつ
    ll N;
    cin >> N;
    vector<int> a;
    int k = keta(N);
    for(int i = 0; i < k; i++){
        a.push_back(digNum(N, k - i));
    }
    int ans1 = 0;
    rep(i, k){
        ans1 += a[i];
    }
    int ans2 = a[0] - 1;
    rep(i, k - 1)ans2 +=9;
    cout << max(ans1, ans2) << endl;

}


Measured memory_bytes: 256