akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

const int INF = 1e8;

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

struct Node{
	int dis;
	bool used;
	Node() : dis(INF), used(false) { }
	Node(int d, bool f) : dis(d), used(f) { }
};

typedef vector<vector<Edge>> graph;

vector<Node> dijkstra(graph g, int s, int n){
	vector<Node> node(n);
	priority_queue<int, vector<pair<int, int>>, greater<pair<int, int>>> q;

	q.push(make_pair(0, s));
	node[s] = Node{0, true};

	while(not q.empty()){
		int dis, pos;
		tie(dis, pos) = q.top(); q.pop();
		node[pos].used = true;

		for(auto e : g[pos]){
			if(node[e.to].used == true) continue;
			if(node[e.to].dis > dis + e.cost){
				node[e.to].dis = dis + e.cost;
				q.emplace(node[e.to].dis, e.to);
			}
		}
	}
	return node;
}


pair<int,int> e[3005];
int d[3005];
int t[305];

int input(int n, int m){
	map<string,int> id;

	string src, dist;
	cin >> src >> dist;
	id[src] = id.size();
	id[dist] = id.size();

	rep(i,n){
		string c1, c2;
		cin >> c1 >> c2 >> d[i];
		if(not id.count(c1)) id[c1] = id.size();
		if(not id.count(c2)) id[c2] = id.size();
		e[i] = make_pair(id[c1], id[c2]);
	}

	rep(i,m){
		string s;
		cin >> s;
		if(not id.count(s)) id[s] = id.size();
		t[i] = id[s];
	}

	t[m] = id[src];
	t[m + 1] = id[dist];
	return id.size();
}

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

	int n, m, cap;
	while(cin >> n >> m >> cap, n||m||cap){
		cap *= 10;

		int v = input(n, m) + 5;

		graph g(v), ng(v);
		rep(i,n){
			int x = e[i].first, y = e[i].second;
			g[x].emplace_back(y, d[i]);
			g[y].emplace_back(x, d[i]);
		}

		rep(i,m + 2){
			int x = t[i];
			auto dis = dijkstra(g, x, v);
			rep(j,m + 2){
				int y = t[j];
				if(dis[y].dis > cap) continue;
				ng[x].emplace_back(y, dis[y].dis);
			}
		}

		//rep(i,v){
		//	rep(j,v){
		//		if(ng[i][j] == 1e8) cout << "_ ";
		//		else cout << ng[i][j] << ' ';
		//	}
		//	cout << endl;
		//}

		int ans = dijkstra(ng, t[m], v).at(t[m + 1]).dis;
		cout << (ans == 1e8 ? -1 : ans) << endl;
	}
}



Measured memory_bytes: 5248
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N; cin >> N;
  int cnt = 0, minA = N+1, A;

  rep(i,N){
    cin >> A;
    if (A <= minA) minA = A, cnt++;
  }  


  cout << cnt << endl;

  // cout << fixed << setprecision(6);
  return 0;
}


Measured memory_bytes: 256
# import itertools


def solve(N):
    ans = 0
    for i in range(1, N + 1):
        if len(str(i)) % 2 == 1:
            ans += 1
    return ans


N = int(input())
# S = input()
# A, B = map(int, input().split())
# A = list(map(int, input().split()))

# P = []
# S = []
# for i in range(N):
#     pp, ss  = map(int, input().split())
#     P.append(pp)
#     S.append(ss)

print(solve(N))


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
	private StringTokenizer st;
	private BufferedReader bf;
	private int w;
	
	Main() {
		readData();
		


	}
	

	private void readData() {
		try {
			bf = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(bf.readLine());
			
			int[] h = new int[10];
			for (int i=0;i<10;i++) {
				h[i] = nextInt();
			}

			Arrays.sort(h);
			
			for (int i=9;i>6;i--) {
				System.out.println(h[i]);
			}

			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	
	private String next() throws IOException {
		if (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(bf.readLine());
		return st.nextToken();
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Main m = new Main();
	}

}

Measured memory_bytes: 16864
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  cin >> N;
  string s;
  int a = 0;
  for (int i = 0; i < N; i++) {
    cin >> s;
    if (s == "Y")
      a = 1;
  }
  if (a == 1) 
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
    
}

Measured memory_bytes: 3620
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  // string s;
  // cin >> s;

  // if (s[2] == s[3] && s[4] == s[5]) {
  //   cout << "Yes" << endl;
  // } else {
  //   cout << "No" << endl;
  // }

  ll X;
  cin >> X;

  ll ans = 0;
  ans += (X / 500) * 1000;

  X = X % 500;

  ans += (X / 5) * 5;
  X = X % 5;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import Counter

n = int(input())
D = list(map(int, input().split()))

num = 998244353

if D[0] != 0:
    print(0)
    exit()

if D.count(0) != 1:
    print(0)
    exit()


D_cnt = dict(Counter(D))
D_list = list(D_cnt)
D_list.sort()
ans = 1
# print(D_list == list(range(len(D_list))))
# print(list(range(len(D_list))))
if D_list != list(range(len(D_list))):
    print(0)
    exit()

for i in range(1, len(D_list) - 1):
    n = D_cnt[i]
    m = D_cnt[i + 1]

    ans *= (n ** m)
    ans %= num
print(ans % num)



Measured memory_bytes: 23004
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0:i < (n);i++)
typedef long long ll;
using namespace std;
int main(){
  int n,r=0;
  cin >> n;
  vector<int> h(n,0);
  cin >> h[0];
  int s=0,g=0,k=0;
  for(int i=1;i<n;i++){
    cin >> h[i];
    if(h[i] <= h[i-1]){ r++;g=i;}
    else{ 
      r = 0;
      g=i;s=i;
    }
    k = max(k,g-s);
  }  
  cout << k << endl;
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 2e5+5;
const double PI = acos(-1);
int m, sx, sy, tx, ty, rx, ry;
int n, a[N], b[N], px[N], py[N], t[N], k;
vector<int> s[N];
double ans;
void change(int x, int d) { for( ; x <= n; x += x&-x) t[x] = max(t[x], d); }
int ask(int x) { int ret = 0; for( ; x; x -= x&-x) ret = max(ret, t[x]); return ret; }
int main()
{
    sx = read(), sy = read(), tx = read()-sx, ty = read()-sy, m = read(), rx = ry = 1;
    if(tx < 0) rx = -1, tx = -tx; if(ty < 0) ry = -1, ty = -ty;
    for(int i = 1; i <= m; ++i)
    {
        int x = rx*(read()-sx), y = ry*(read()-sy);
        if(0 <= x&&x <= tx&&0 <= y&&y <= ty) px[++n] = x, a[n] = x, py[n] = y, b[n] = y;
    }
    sort(a+1, a+1+n), sort(b+1, b+1+n);
    for(int i = 1; i <= n; ++i)
        px[i] = lower_bound(a+1, a+1+n, px[i])-a,
        py[i] = lower_bound(b+1, b+1+n, py[i])-b,
        s[py[i]].push_back(px[i]);
    for(int i = 1; i <= n; ++i)
    {
        sort(s[i].begin(), s[i].end());
        reverse(s[i].begin(), s[i].end());
        for(int j = 0; j < s[i].size(); ++j) change(s[i][j], ask(s[i][j]-1)+1);
    }
    ans = 100.0*(tx+ty)+(5*PI-20)*(k = ask(n));
    if(k == min(tx, ty)+1) ans += 5*PI;
    printf("%.12lf\n", ans);
    return 0;
}

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


int main(){
    ll X, Y;
    cin >> X >> Y;
    ll cnt = 0;
    while(X <= Y){
        X *= 2;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    static boolean[][] used;
    static int[] ans;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        char[] s = sc.next().toCharArray();
        int ans = 0;
        for(char c : s){
            if(c == '1'){
                ans++;
            }
        }
        System.out.println(ans);
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 20944
max = [gets.to_i]
size = 0
readlines.map(&:chomp).each{|line|
  arr = line.split(",").map(&:to_i)
  old_max = max.clone
  max = []
  if size < arr.size
    arr.size.times{|i|
      if i > 0
        max[i] = old_max[i-1,2].max + arr[i]
      else
        max[i] = old_max[i] + arr[i]
      end
    }
    size = arr.size
  else
    arr.size.times{|i|
      max[i] = old_max[i,2].max + arr[i]
    }
    size = arr.size
  end
}
puts max

Measured memory_bytes: 8756
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;
// ||

int main() {
  ll x; cin >> x;
  ll i = 1, total = 0;
  while (total < x) total += i++;
  cout << i-1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define il inline

namespace io {

#define in(a) a = read()
#define out(a) write(a)
#define outn(a) out(a), putchar('\n')

#define I_int ll
inline I_int read() {
    I_int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}
char F[200];
inline void write(I_int x) {
    if (x == 0) return (void) (putchar('0'));
    I_int tmp = x > 0 ? x : -x;
    if (x < 0) putchar('-');
    int cnt = 0;
    while (tmp > 0) {
        F[cnt++] = tmp % 10 + '0';
        tmp /= 10;
    }
    while (cnt > 0) putchar(F[--cnt]);
}
#undef I_int

}
using namespace io;

using namespace std;

#define N 5010

int n, a[2][N], f[2][N];

int main() {
	in(n);
	for(int j = 0; j < 2; ++j) for(int i = 1; i <= n; ++i) in(a[j][i]);
	for(int i = 0; i < 2; ++i) {
		for(int j = 1; j <= n; ++j) {
			f[i][j] = max(f[i][j - 1] + a[i][j], f[i][j]);
			if(i == 1) f[i][j] = max(f[i][j], f[i - 1][j] + a[i][j]);
		}
	}
	printf("%d\n", f[1][n]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
        

fast();
//ll t;cin>>t;while(t--)
{
    ll n,profit=1000,mx=0,cost=0,stock=0;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]<a[i+1]&&i+1<n)
        {
            ll x=profit/a[i];
            profit-=(x*a[i]);
            stock+=x;
            cost=a[i];
        }
        if(a[i]>cost)
        {
            profit+=(stock*a[i]);
            stock=0;

        }
    }
    cout<<max(1000ll,profit)<<endl;

}
return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int a[5000];

int main()
{
    for(int i=1;i<5000;i++){
        a[i]=i+a[i-1];
    }
    int n;
    scanf("%d",&n);
    int to;
    while(n>0){
        to=lower_bound(a,a+5000,n)-a;
        printf("%d\n",to);
        n-=to;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;

int main(){
	ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	double n,m;
	cin>>n>>m;
	//int t=n/m;
	cout<<(ceil)(n/m)<<endl;	
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n=int(input())
es=[[] for i in range(n)]
l=[list(map(int,input().split())) for i in range(n-1)]
for i in range(n-1):
   l[i][0]-=1
   l[i][1]-=1
   l[i][0],l[i][1]=min(l[i][0],l[i][1]),max(l[i][0],l[i][1])
   es[l[i][0]].append(l[i][1])
   es[l[i][1]].append(l[i][0])
dic={}
use=[1]*n
def dfs(v,k):
    cnt=0
    use[v]=0
    for i in es[v]:
        if use[i]:
            if cnt==k:
                cnt+=1
            dic[(min(v,i),max(v,i))]=cnt
            dfs(i,cnt)
            cnt+=1
dfs(0,-1)
ans=[0]*(n-1)
k=0
for i in range(n-1):
    ans[i]=dic[l[i][0],l[i][1]]+1
    k=max(k,ans[i])
print(k)
for i in ans:
    print(i)

Measured memory_bytes: 81276
N = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(N):
  minj = i
  for j in range(i, N):
    if a[j] < a[minj]:
      minj = j
  if a[i] != a[minj]:
    a[minj], a[i] = a[i], a[minj]
    count += 1
print(*a)
print(count)

Measured memory_bytes: 7724
s = input()

n = 3
sum = 0

for i in range(1 << n):
  u = []
  t = list(s)
  
  for j in range(n):
    if((i >> j) & 1):
      u.append(1)
    else:
      u.append(0)
  
  for j in range(3):
    if(u[j] == 1):
      t.insert(((2*(j+1))-1),'+')
    else:
      t.insert(((2*(j+1))-1),'-')
  if(eval(''.join(t))==7):
    print(''.join(t)+'=7')
    break

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int H,W;
    scanf("%d%d",&H,&W);
    string S;
    string A;
    S='#';
    for(int i=0;i<W+1;i++){
        S=S+'#';
    }
    cout<<S<<endl;
    for(int i=0;i<H;i++){
        cin>>A;
        cout<<"#"<<A<<"#"<<endl;
    }
    cout<<S<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 220
// 44

using namespace std;

string str;

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int n;
    ios::sync_with_stdio(false);
    cin >> n;
    cin >> str;
    int cnte = 0, cntw = 0;
    for(auto it : str) {
        if(it == 'W') {
            cntw++;
        }
        else {
            cnte++;
        }
    }
    int ans = n;
    int cnt1 = 0, cnt2 = 0;
    for(auto it : str) {
        cnt2 += (it == 'E');
        ans = min(ans, cnt1 + cnte - cnt2);
        cnt1 += (it == 'W');
    }
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

bool check(int x) {
	if (x > 12) return true;
	if (x == 0) return true;
	return false;
}

signed main() {
	string s;
	cin >> s;
	
	int x = (s[0] - '0') * 10 + (s[1] - '0');
	int y = (s[2] - '0') * 10 + (s[3] - '0');
	
	if (check(x) && check(y)) {
		cout << "NA" << endl;
	}
	else if (check(x)) {
		cout << "YYMM" << endl;
	}
	else if (check(y)) {
		cout << "MMYY" << endl;
	}
	else {
		cout << "AMBIGUOUS" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll x, y;
    vector<ll> v1, v2;
    for(int i=0;i<n;i++){
        cin >> x >> y;
        v1.pb(x + y);
        v2.pb(x - y);
    }
    sort(be(v1));
    sort(be(v2));
    cout << max(v1[n - 1] - v1[0], v2[n - 1] - v2[0]) << endl; 
    return 0;
}


Measured memory_bytes: 6668
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

LL n, k, q, c[100000];

int main() {
	cin >> n >> k >> q;
	inc(qq, q) {
		int a;
		cin >> a;
		a--;
		c[a]++;
	}
	
	inc(i, n) {
		cout << (k - (q - c[i]) > 0 ? "Yes" : "No") << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int D;
    cin >> D;
    ll c[26];
    rep(i, 26) cin >> c[i];
    ll s[D][26];
    rep(i, D){
        rep(j, 26) cin >> s[i][j];
    }
    int pre[26];
    fill(pre, pre+26, -1);
    int t[D];
    rep(i, D){
        ld tmp[26];
        rep(j, 26){
            tmp[j] = s[i][j] + c[j]*(i-pre[j])*((ld)(D-i)/(ld)(26));
        }
        int res = -1;
        ld m = -INF;
        rep(j, 26){
            if(chmax(m, tmp[j])) res = j;
        }
        pre[res] = i;
        t[i] = res;
        //cout << res+1 << endl;
    }
    ll tmp = 0;
    set<int> ids[26];
    rep(i, 26) ids[i].insert(-1);
    rep(i, D){
        //cin >> t[i]; t[i]--;
        tmp += s[i][t[i]];
        pre[t[i]] = i;
        ids[t[i]].insert(i);
        rep(j, 26){
            tmp -= c[j]*(i-pre[j]);
        }
    }
    rep(i, 26) ids[i].insert(D);
    rep(k, 10){
        rep(i, D){
            rep(j, 26){
                int d, q;
                //cin >> d >> q;
                d = i, q = j;
                int p = t[d];
                ll ans = tmp-s[d][p]+s[d][q];
                set<int>::iterator it1, it2;
                it1 = ids[p].upper_bound(d);
                it2 = ids[q].upper_bound(d);
                int a1, a2, b1, b2;
                b1 = *it1, b2 = *it2;
                it1--, it1--, it2--;
                a1 = *it1, a2 = *it2;
                ans -= c[p]*(b1-d)*(d-a1);
                ans += c[q]*(b2-d)*(d-a2);
                if(chmax(tmp, ans)){
                    t[d] = q;
                    ids[p].erase(d);
                    ids[q].insert(d);
                }
            }
        }
    }
    rep(i, D) cout << t[i]+1 << endl;
}

Measured memory_bytes: 3720
N,M = map(int,input().split())
cnt = [0] * M

for i in range(N):
  A = list(map(int, input().split()))
  for j in range(1,A[0] + 1):
    cnt[A[j] - 1] += 1

ans = 0
for i in range(M):
  if(cnt[i] == N):
    ans += 1

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {

	int N,X, A;
	cin >>N>> X ;
	A = 0;
	int cou = 1;
	vector<int> vec(N);
	rep(i,N) {
		cin >> vec.at(i);
		A += vec.at(i);
		if (A < X + 1) {
			cou++;
		}

	}
	
	cout << cou << endl;


}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a){cout<<((a)?"Yes":"No")<<endl;}
void YESNO(int a){cout<<((a)?"YES":"NO")<<endl;}
void AorB(int a,string b,string c){cout<<((a)?b:c)<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    string s;
    cin>>s;
    int x=0;
    REP(i,0,s.size()) if(s[i]=='x') x++;
    YESNO(x<=7);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<set>
typedef long long int ll;
using namespace std;

int main(){
    int N;
    int a[100];
    cin >> N;
    int ave=0;
    for(int n=0;n<N;n++){
        cin >> a[n];
        ave += a[n];
    }
    ave = ave/N;
    int cost1=0;
    int cost2=0;
    int cost3=0;
    for(int n=0;n<N;n++){
        cost1 += (a[n]-ave)*(a[n]-ave);
        cost2 += (a[n]-ave-1)*(a[n]-ave-1);
        cost3 += (a[n]-ave+1)*(a[n]-ave+1);
    }
    int ans;
    ans = min(cost1,cost2);
    ans = min(ans,cost3);
    cout << ans << endl;
    return 0;
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Graph;
const int M = 1e9 + 7;
const ll INF = 1e9;
const int MAX_V = 100000 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(m);
  vector<string> s(m);
  rep(i, m) cin >> p[i] >> s[i];
  int ac_cnt = 0;
  int pena_cnt = 0;
  vector<int> acc(n, 0);
  vector<bool> lock(n, false);
  rep(i, m) {
    int num = p[i] - 1;
    string res = s[i];
    if (res == "AC" && !lock[num]) {
      ac_cnt++;
      lock[num] = true;
      pena_cnt += acc[num];
    } else {
      acc[num]++;
    }
  }
  cout << ac_cnt << " " << pena_cnt << endl;
}


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

int main() {
  int n;
  cin >> n;
  
  bool p=false,y=false,w=false,g=false;
  
  for (int i = 0; i < n; i++){
    string s;
    cin >> s;
    if (s == "P") {
      p = true;
    }
    if (s == "Y") {
      y = true;
    }
    if (s == "W") {
      w = true;
    }
    if (s == "G") {
      g = true;
    }
  }
  
  if (p && y && w && g) {
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  }
}

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

int main(){
	ll h,a; cin >> h >> a;
	if(h%a != 0)cout << h/a + 1 << endl;
	else cout << h/a << endl;
}

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



#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))

using namespace std;
string s;

int main(){
  int ans = 10000;
  cin >> s;
  REP(i,s.size()-2){
    int k = (s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
    ans = min(ans,abs(k-753));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: str):
    sum = 0
    for i in range(len(N)) :
        sum += int(N[i])
    if(sum % 9 == 0):
        print(YES)
    else :
        print(NO)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = next(tokens)  # type: str
    solve(N)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9296
#include <iostream>
#include <cmath>
using namespace std;
int jie[10]={1,1,2,6,24,120,720,5040,40320,362880};
int a[10];
int b[10];
int n;
int qiu(int aa[])
{
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int xx=0;
        for(int j=i+1;j<n;j++)
        {
            if(aa[i]>aa[j])
            {
                xx++;
            }

        }
        ans+=xx*jie[n-1-i];
    }
    return ans;

}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>b[i];
    }
    int ax=qiu(a);
    int bx=qiu(b);
    cout<<abs(ax-bx);
    return 0;
}


Measured memory_bytes: 3568
#include<stdio.h>
int main(void){
	int a,b;
	scanf("%d %d",&a,&b);
	while(1){
		if(a==0&&b==0){
			break;
		}
		if(a>b){
			printf("%d %d\n",b,a);
		}
		else{
			printf("%d %d\n",a,b);
		}
		scanf("%d %d",&a,&b);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (n); i++)
 
int main(){
    long long N;
    cin >> N;
    long long res = 0;
    for(long long i=1;i*i<=N;i++){
        if(N % i == 0){
            long long j = i-1;
            long long k = N / i - 1;
            if(j && N/j == N%j) res += j;
            if(i * i != N && k && N/k == N%k) res += k;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n,i,a;
	
	scanf("%d",&n);
	int b[n];
	
	for(i=0;i<n;++i){
		b[i]=0;
	}
	
	for(i=0;i<n-1;++i){
		scanf("%d",&a);
		b[a-1]++;
	}
	
	for(i=0;i<n;++i){
		printf("%d\n",b[i]);
	}
	return 0;
}

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

alphabets = 'abcdefghijklmnopqrstuvwxyz'

def dfs(s, max_idx):
  if len(s) == N:
    print(s)
    return
  else:
    for i in range(0, max_idx+2, 1):
      t = s
      t = t + alphabets[i]
      dfs(t, max(i, max_idx))
    
dfs("", -1)

Measured memory_bytes: 4404
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	cout << n * n * n << endl;
}

Measured memory_bytes: 256
N = int(input())
l = list(map(int, input().split()))
l.sort()
l.reverse()
s = l[0]
if N%2==0:
  c = N//2-1
  for i in range(c):
    s = s + l[i+1]*2
  
else:
  d = (N-3)//2
  for i in range(d):
    s = s + l[i+1]*2
  s = s + l[(N-1)//2]
print(s)


Measured memory_bytes: 31752
from sys import stdin


def main() -> int:
    n = next_int()
    m = next_int()
    dic = [0] * n

    for _ in range(m):
        a, b = map(lambda x: int(x) - 1, input().split())

        dic[a] += 1
        dic[b] += 1

    for i in range(n):
        print(dic[i])

    return 0


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int n;
  while (cin >> n) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    bool allEven = true;
    for (int x : a) {
      allEven &= (x % 2 == 0);
    }
    cout << (allEven ? "second" : "first") << endl;
  }
  return 0;
}


Measured memory_bytes: 640
import sys
import time
import math
import itertools as it
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------

N, M = inpl()
dp = [-1] * N
for _ in range(M):
    s, c = inpl()
    s -= 1
    if dp[s] not in [-1, c]:
        print(-1)
        sys.exit()
    dp[s] = c
for i in range(N):
    if N == 1:
        if dp[i] == -1:
            print(0, end='')
        else:
            print(dp[i], end='')
    else:
        if i == 0:
            if dp[i] == -1:
                print(1, end='')
            elif dp[i] == 0:
                print(-1)
                sys.exit()
            else:
                print(dp[i], end='')
        else:
            if dp[i] == -1:
                print(0, end='')
            else:
                print(dp[i], end='')
                
print()
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


Measured memory_bytes: 9204
using System;

namespace ConsoleAppITP1_5_C
{
    class Program
    {
        static void Main(string[] args)
        {
            for (; ; )
            {
                String[] input = Console.ReadLine().Split(' ');
                var h = Int32.Parse(input[0]);
                var w = Int32.Parse(input[1]);

                if (h == 0 && w == 0) break;
                else
                {
                    for (var j = 1; j <= h; j++)
                    {
                        for (var i = 1; i <= w; i++)
                        {
                            if (j % 2 == 0)
                            {
                                if (i % 2 == 0)
                                    Console.Write("#");
                                else
                                    Console.Write(".");
                            }
                            else
                            {
                                if (i % 2 == 0)
                                    Console.Write(".");
                                else
                                    Console.Write("#");
                            }
                        }
                    Console.WriteLine();
                    }
                Console.WriteLine();
                }
            }
        }
    }
}



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

using namespace std;


int main(){
	
	while(1){
		int h,w;
		cin >> h >> w;
		if(h==0 and w==0) break;
		
		int b,a=h*h+w*w;
		int ty=150,tx=150;
		for(int i=1;i<=150;i++){
			for(int j=i+1;j<=150;j++){
				b=i*i+j*j;
				if((a<b) or (a==b and h<i)){
					if((b<ty*ty+tx*tx) or (b==tx*tx+ty+ty and i<ty)){
						ty=i;tx=j;
					}
				}
			}
		}
		cout << ty << " " << tx << endl;
	}
	
	return 0;
}


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

long long cnt;
vector <int> g;

void insertionSort(int A[],int n,int g){
    for(int i=g;i<n;i++){
        for(int j=i-g;j>=0&&A[j+g]<A[j];j-=g){
            swap(A[j+g],A[j]);
            cnt++;
        }
    }
}

void shellSort(int A[],int n){
    for(int i=1;i<=n;i=i*3+1){
        g.push_back(i);
    }
    for(int i=g.size()-1;i>=0;i--){
        insertionSort(A,n,g[i]);
    }
}

int main(void){

    int n;

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

    cnt = 0;

    shellSort(A,n);

    cout<<g.size()<<endl;

    for(int i=g.size()-1;i>=0;i--){
        cout<<g[i];
        if(i)cout<<" ";
    }
    cout<<endl;
    cout<<cnt<<endl;

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

    return 0;
}


Measured memory_bytes: 7072
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,0,a.size()){
        cin>>a[i];
    }
    vector<int> f;
    vector<int> r;
    int x = a[0];
    rep(i,0,a.size()){
        x = __gcd(a[i],x);
        f.pb(x);
    }
    x = a[a.size()-1];
    repr(i,a.size()-1,0){
        x = __gcd(a[i],x);
        r.pb(x);
    }
    reverse(all(r));
    int ans = 0;
    rep(i,0,f.size()){
        if ( i == 0 ){
            ans = max(ans,r[i+1]);
        }
        else if ( i == f.size()-1 ){
            ans  = max(ans,f[i-1]);
        }
        else{
            int x = __gcd(f[i-1],r[i+1]);
            ans = max(ans,x);
        }
    }

    cout<<ans<<endl;
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

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



Measured memory_bytes: 6280
n = int(input())
v = []
i = 6
while i<=n:
    v.append(i)
    i *= 6
i=9
while i <= n:
    v.append(i)
    i *= 9
v.sort()
dic = dict()
def dp(i, N):
    if N == 0:
        return 0
    if i < 0:
        return N
    if (i, N) not in dic:
        dic[(i, N)] = min(dp(i, N-v[i])+1, dp(i-1, N)) if N-v[i] >= 0 else dp(i-1, N)
    return dic[(i, N)]
print(dp(len(v)-1, n))

Measured memory_bytes: 13636
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

int n,a[100005] = {},b[100005] = {};


int main(){
    
    cin >> n ;

    rep(i,1,n+1)cin >> a[i];

    ll ans = 0;
    rep(i,1,n+2){
        ans += abs(a[i-1] - a[i]);

        b[i] = abs(a[i-1] - a[i+1]) - (abs(a[i-1] - a[i]) + abs(a[i] - a[i+1]));
    }

    rep(i,1,n+1)P(ans + b[i]);
	return  0;
}

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


int main(){
    int N,K;
    cin >> N >> K;
    
    int maximum = (N-1)*(N-2)/2;
    if(K > maximum){
        cout << -1 << "\n";
        return 0;
    }
    
    vector<pair<int, int>> v;
    int over = maximum - K;
    int M = 0;
    for(int i = 2; i <= N; i++){
        v.push_back({1, i});
        M++;
    }
    
    while(over > 0){
        for(int i = 2; i <= N; i++){
            if(over <= 0)
                break;
            for(int j = i + 1; j <= N; j++){
                if(over <= 0)
                    break;
                v.push_back({i, j});
                M++;
                over--;
            }
        }
    }
    
    int size = v.size();
    cout << M << "\n";
    for(int i = 0; i < size; i++)
        cout << v[i].first << " " << v[i].second << "\n";
    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] p = new int[N];
        int counter = 0;
        
        for(int i = 0; i < N; i++){
            p[i] = sc.nextInt();
            if(p[i] != i + 1){
                counter++;
            }
        }
        
        if(counter == 0 || counter == 2){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 23124
#include <cstdio>
int n,a,b,c,d,i;
int main(void){
  scanf("%d",&n);
  while(n){
    c=0;d=0;
    for(i=0;i<n;i++){
      scanf("%d%d",&a,&b);
      if(a>b)c+=a+b;
      else if(a<b)d+=a+b;
      else{
        c+=a;d+=b;
      }
    }
    printf("%d %d\n",c,d);
    scanf("%d",&n);
  }
  return 0;
} 

Measured memory_bytes: 1028
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();

        System.out.println(N % 2 == 0 ? 0.5 : (float) (N / 2 + 1) / N);

    }
}





Measured memory_bytes: 21588
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e12)
#define PI (acos(-1))

#define amari(x) ((x) % 1000000007)

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end());
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>());
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin();
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin();

#define rep(i,n) for(int i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

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

  long n;

  cin >> n;

  vector<long> h(n);
  fillLong(h, n);
  
  long m = 0;
  int res = 0;

  rep(i, n) {
    if (h[i]>=m) res++;
    m = max(h[i], m);
  }
  cout << res << endl;


  return 0;
}


Measured memory_bytes: 256