akhauriyash/Code-Regression huggingface dataset:
using System.Collections.Generic;
using System;

public class P
{
    public int x1 { get; set; }
    public int y1 { get; set; }
    public int x2 { get; set; }
    public int y2 { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            var ps = new List<P>();
            string[] line = Console.ReadLine().Trim().Split(' ');
            var gx = int.Parse(line[0]);
            var gy = int.Parse(line[1]);
            var p = int.Parse(Console.ReadLine().Trim());
            for (int j = 0; j < p; j++)
            {
                line = Console.ReadLine().Trim().Split(' ');
                var x1 = int.Parse(line[0]);
                var y1 = int.Parse(line[1]);
                var x2 = int.Parse(line[2]);
                var y2 = int.Parse(line[3]);
                ps.Add(new P { x1 = x1, y1 = y1, x2 = x2, y2 = y2 });
            }
            var dp = new int[gx + 1, gy + 1];
            dp[0, 0] = 1;
            goDPpre(ps, dp);
            goDP(ps, dp);
            if (dp[gx, gy] == 0) Console.WriteLine("Miserable Hokusai!");
            else Console.WriteLine(dp[gx, gy]);
        }
    }
    public static void goDP(List<P> ps, int[,] dp)
    {
        var w = dp.GetLength(0);
        var h = dp.GetLength(1);
        for (int i = 1; i < w; i++)
            for (int j = 1; j < h; j++)
            {
                var a = checkP(ps, i, j, i - 1, j);
                var b = checkP(ps, i, j, i, j - 1);
                if (!a && !b) dp[i, j] = dp[i - 1, j] + dp[i, j - 1];
                else if (a && !b) dp[i, j] = dp[i, j - 1];
                else if (!a && b) dp[i, j] = dp[i - 1, j];
                else dp[i, j] = 0;
            }
    }
    public static void goDPpre(List<P> ps, int[,] dp)
    {
        var w = dp.GetLength(0);
        for (int i = 1; i < w; i++)
        {
            if (checkP(ps, i, 0, i - 1, 0)) dp[i, 0] = 0;
            else dp[i, 0] = dp[i - 1, 0];
        }
        var h = dp.GetLength(1);
        for (int i = 1; i < h; i++)
        {
            if (checkP(ps, 0, i, 0, i - 1)) dp[0, i] = 0;
            else dp[0, i] = dp[0, i - 1];
        }
    }
    public static bool checkP(List<P> ps, int x1, int y1, int x2, int y2)
    {
        foreach (var a in ps)
        {
            if (x1 == a.x1 && y1 == a.y1 && x2 == a.x2 && y2 == a.y2) return true;
            if (x2 == a.x1 && y2 == a.y1 && x1 == a.x2 && y1 == a.y2) return true;
        }
        return false;
    }
}


Measured memory_bytes: 9396
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

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

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    string s; cin>>s;
    string head = s.substr(0, n);
    string tail = s.substr(n, n);
    reverse(tail.begin(), tail.end());
    
    map<pair<string, string>, ll> head_paint, tail_paint;
    for(int bit=0; bit<(1<<n); bit++){
        string ha, hb, ta, tb;
        for(int i=0; i<n; i++){
            if(bit & (1 << i)){
                ha += head[i];
                ta += tail[i];
            }
            else{
                hb += head[i];
                tb += tail[i];
            }
        }

        reverse(hb.begin(), hb.end());
        reverse(tb.begin(), tb.end());

        head_paint[make_pair(ha, hb)]++;
        tail_paint[make_pair(ta, tb)]++;
    }

    ll ans = 0;
    for(auto i : head_paint){
        ans += i.second * tail_paint[make_pair(i.first.first, i.first.second)];
    }

    cout << ans << endl;
}

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

int main(){
  ll n,m;
  cin >> n >> m;
  vector<ll> a(n+1),v(n+1,0);
  for(int i=1; i<=n; i++) cin >> a[i];
  int c=0,x=1;
  while(m){ //m回繰り返す
    x = a[x];c++;m--;
    if(v[x]) break;
    v[x] = c; //v[x]は、最初にxに飛ぶまでにワープした回数
  }
  if(m == 0) cout << x << endl;
  else{
    ll p = c - v[x]; //右辺のcは最初にループするまでにワープした回数、pはループの周期
    m %= p; //m%p==0ならxをそのまま出力すればよい
    while(m){x = a[x];m--;}
    cout << x << endl;
  }
}


Measured memory_bytes: 6404
#include<bits/stdc++.h>
using namespace std;
bool check(int i){
	int geshu=0;
	for(int j=1;j<=i;j++){
		if(i%j==0){
			geshu++;
		}
	}
	if(geshu==8){
		return true;
	}
	else{
		return false;
	}
}
int main(){
	int n;
	int tot=0;
	cin>>n;
	for(int i=2;i<=n;i++){
		if(check(i)&&i%2==1){
			tot++;
		}	
	} 
	cout<<tot<<endl; 
} 

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  char a[n][n], b[m][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      cin >> b[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i + m - 1 >= n || j + m - 1 >= n) {
        continue;
      }
      bool f = true;
      for (int s = 0; s < m; s++) {
        for (int t = 0; t < m; t++) {
          if (a[i + s][j + t] != b[s][t]) {
            f = false;
          }
        }
      }
      if (f) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

template<typename F> long long discrete_binary_search(long long ok, long long ng, const F &check) {
    while (abs(ok - ng) > 1) {
        long long mid = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    return ok;
}

template<typename T>
struct cumulative_sum {
    int n;
    T ZERO;
    std::vector<T> data;
    template<typename I> cumulative_sum(I begin, I end, T ZERO = T())
        : n(end - begin), ZERO(ZERO), data(n + 1, ZERO) {
        std::copy(begin, end, data.begin() + 1);
        for (int i = 0; i < n; i++) { data[i + 1] += data[i]; }
    }
    T get_sum(int l, int r) const {
        if (l >= r || l > n || r < 0) { return ZERO; }
        if (l < 0) { l = 0; }
        if (r > n) { r = n; }
        return data[r] - data[l];
    }
};

int N, M;
int A[110000];
signed main() {
    cin >> N >> M;
    rep(i, N) { cin >> A[i]; }
    sort(A, A + N);
    int th = discrete_binary_search(0, 300000, [&](int x) {
        int cnt = 0;
        rep(i, N) { cnt += A + N - lower_bound(A, A + N, x - A[i]); }
        return cnt >= M;
    });
    cumulative_sum<int> cs(A, A + N);
    int ans = 0, cnt = 0;
    rep(i, N) {
        int gidx = lower_bound(A, A + N, th - A[i]) - A;
        cnt += N - gidx;
        ans += A[i] * (N - gidx) + cs.get_sum(gidx, N);
    }
    ans -= th * (cnt - M);
    cout << ans << endl;
}


Measured memory_bytes: 1792
s=input()
ans=""
for i in range(len(s)):
    if s[i]=="0":
        ans=ans+"0"
    elif s[i]=="1":
        ans=ans+"1"
    elif s[i]=="B":
        if ans=="":
            pass
        
        else:
            ans=ans[:len(ans)-1]
    #print(str(ans))
print(str(ans))


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int a, b, c;
    char t;
    int rectangles = 0, lozengres = 0;
    while (cin >> a >> t >> b >> t >> c)
    {
        if (a * a + b * b == c * c)
        {
            rectangles++;
            if (a == b)
            {
                lozengres++;
            }
        }
        else if (a == b)
        {
            lozengres++;
        }
    }
    OP(rectangles)
    OP(lozengres)
    return 0;
}


Measured memory_bytes: 3000
#include<stdio.h>
#include<string.h>
int main()
{
	int count,k,i,x;
	char a[10000];
	scanf("%d",&k);
	scanf("%s",a);
	x=strlen(a);
	
	if (x<=k)
	{
		printf("%s",a);
		
	}
	else 
	{
		for(i=0;i<k;i++)
	{
		printf("%c",a[i]);
	}	printf("...");
	
	}
	
	return 0;
	
}



Measured memory_bytes: 1732
#include<stdio.h>
#define MAX 100000
int main(){
  int S[MAX],T[MAX],n,q,i,left,right,mid,count=0,j;
  scanf("%d",&n);
  for(i=0; i<n; i++){
     scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&T[i]);
  }
  for(i=0; i<q; i++){
    left=0;
    right=n;
    while(left<right){
        mid=(left+right)/2;
        if(S[mid]==T[i]){
            count++;
            break;
        }
        else if(T[i]<S[mid])right=mid;
        else left=mid+1;
     }
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2376
fun main(args: Array<String>) {
    val scn = java.util.Scanner(System.`in`)
    val n = scn.nextInt()
    val m = scn.nextInt()

    val a = IntArray(n*m) { 0 }

    var c = 0
    for (i in 1..n) {
        val k = scn.nextInt()
        for (j in 0..k-1) {
            a[c++] = scn.nextInt()
        }
    }

    c = 0
    for (j in 1..m) {
        var count = 0
        for (i in 0..m*n-1) {
            if (a[i] == j) count++
        }
        if (count == n) c++
    }
    println(c)
}

Measured memory_bytes: 29612
""" dpはi桁,あまりj
[[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
"""
MOD = 10**9+7

S = str(input())
S = S[::-1]
n = len(S)

dp = [[0]*(13) for _ in range(n+1)]
dp[0][0]=1 #0を割ったあまりは0

q = 1 # はじめの1桁のときはあまりは1

# i桁目のあまりが何通りあるか
for i in range(1,n+1): # 「1-n」桁まで
  s = S[i-1]
  for j in range(13): # 13で割ったあまり
    
    if s == '?': # ?の場合は0-9を計算する
      for k in range(10):
        dp[i][(j+k*q)%13] += dp[i-1][j] # i-1桁目からi桁目 +=を忘れずに！
    else:
      k = int(s)
      dp[i][(j+k*q)%13] += dp[i-1][j] # i-1桁目からi桁目
  for m in range(13):
    dp[i][m] %= MOD
  q = (10*q)%13 # 「10^iをqで割ったあまり」

print(dp[n][5] % MOD)


Measured memory_bytes: 61404
#include <stdio.h>
int main (void){
    int a,b,i,n,aa,bb;
    for(;;){
        aa=0,bb=0;
        scanf("%d",&n);
        if(n==0)break;
        for(i=0;i<n;i++){
            scanf("%d%d",&a,&b);
            if(a>b){
                aa=aa+a+b;
            }
            else if(a<b){
                bb=bb+a+b;
            }
            else if(a==b){
                aa=aa+a;
                bb=bb+b;
            }
        }
        printf("%d %d\n",aa,bb);
    }
return 0;
}

Measured memory_bytes: 600
import java.util.*;

public class Main {
    public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		S += S;
		if (S.contains(T)) {
		    System.out.println("Yes");
		} else {
		    System.out.println("No");
		}
	}
}

Measured memory_bytes: 21972
// Copyright: lzt
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<iostream>
#include<queue>
#include<string>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long,long long> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,j,k)  for(register int i=(int)(j);i<=(int)(k);i++)
#define rrep(i,j,k) for(register int i=(int)(j);i>=(int)(k);i--)
#define Debug(...) fprintf(stderr, __VA_ARGS__)

ll read(){
	ll 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;
}

inline ll c1(ll n, ll x, ll y) {
	ll nw = n / x;
	ll rem = n - nw * x;
	return rem + nw * y;
}

inline ll c2(ll n, ll x, ll y, ll a, ll b) {
	if ((y - x) * a < (b - a) * x) swap(x, a), swap(y, b);
	ll mx = n / x;
	ll ret = 0;
	rrep(i, mx, 0) {
		ll nw = i * y + c1(n - i * x, a, b);
		ret = max(ret, nw);
		if ((n - i * x) % a == 0) break;
	}
	return ret;
}

inline ll c3(ll n, ll x, ll y, ll a, ll b, ll c, ll d) {
	if ((y - x) * a < (b - a) * x) swap(x, a), swap(y, b);
	if ((y - x) * c < (d - c) * x) swap(x, c), swap(y, d);
	if ((b - a) * c < (d - c) * b) swap(a, c), swap(b, d);
	ll mx = n / x;
	ll ret = 0;
	rrep(i, mx, 0) {
		ll nw = i * y + c2(n - i * x, a, b, c, d);
		ret = max(ret, nw);
		if ((n - i * x) % a == 0) break;
	}
	return ret;
}

void work() {
	ll n, ga, sa, ba, gb, sb, bb;
	n = read();
	ga = read(); sa = read(); ba = read();
	gb = read(); sb = read(); bb = read();
	if (gb > ga) {
		if (sb > sa) {
			if (bb > ba) {
				n = c3(n, ga, gb, sa, sb, ba, bb);
			} else {
				n = c2(n, ga, gb, sa, sb);
			}
		} else {
			if (bb > ba) {
				n = c2(n, ga, gb, ba, bb);
			} else {
				n = c1(n, ga, gb);
			}
		}
	} else {
		if (sb > sa) {
			if (bb > ba) {
				n = c2(n, sa, sb, ba, bb);
			} else {
				n = c1(n, sa, sb);
			}
		} else {
			if (bb > ba) {
				n = c1(n, ba, bb);
			}
		}
	}
	swap(ga, gb); swap(sa, sb); swap(ba, bb);
	if (gb > ga) {
		if (sb > sa) {
			if (bb > ba) {
				n = c3(n, ga, gb, sa, sb, ba, bb);
			} else {
				n = c2(n, ga, gb, sa, sb);
			}
		} else {
			if (bb > ba) {
				n = c2(n, ga, gb, ba, bb);
			} else {
				n = c1(n, ga, gb);
			}
		}
	} else {
		if (sb > sa) {
			if (bb > ba) {
				n = c2(n, sa, sb, ba, bb);
			} else {
				n = c1(n, sa, sb);
			}
		} else {
			if (bb > ba) {
				n = c1(n, ba, bb);
			}
		}
	}
	printf("%lld\n", n);
}

int main(){
	#ifdef LZT
		freopen("in","r",stdin);
	#endif

	work();

	#ifdef LZT
		Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
	#endif
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <ctime>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

bool in(ll y, ll x, ll h, ll w){
    return 0 <= y && y < h && 0 <= x && x < w;
}

bool removed[505][505];

int main(){
    ll n; cin >> n;
    ll N = n * n;
    vl p(N); rep(i,N) cin >> p[i];
    vvl a(n,vl(n,linf));
    rep(i,n){
        rep(j,n){
            chmin(a[i][j], i);
            chmin(a[n-i-1][j], i);
            chmin(a[j][i], i);
            chmin(a[j][n-i-1], i);
        }
    }
    ll ans = 0;
    rep(i,N){
        p[i]--;
        ll sy = p[i] / n;
        ll sx = p[i] % n;
        ans += a[sy][sx];
        removed[sy][sx] = true;
        queue<P> q;
        q.emplace(sy,sx);
        while(!q.empty()){
            P p = q.front(); q.pop();
            ll y = p.first;
            ll x = p.second;
            rep(j,4){
                ll ny = y + dy[j];
                ll nx = x + dx[j];
                if(in(ny,nx,n,n) && a[ny][nx] > a[y][x] + !removed[y][x]){
                    a[ny][nx] = a[y][x] + !removed[y][x];
                    q.emplace(ny,nx);
                }
            }
        }
    }
    cout << ans << "\n";
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
  ll a,b,c,k; cin>>a>>b>>c>>k;
  if(a+b<k)cout<<a-(k-b-a)<<endl;
  else if(a<k)cout<<a<<endl;
  else cout<<k<<endl;
}


Measured memory_bytes: 3624
//abc171_c.cpp
//Sun Jun 21 20:54:55 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

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

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

	vector<char> ans;
	int flag = 0;

	ll base[12];
	base[0] = 0;
	for (int i=1;i<12;i++){
		base[i] = pow(26,i)+base[i-1];
		// cout << i << " " << base[i] << endl;
	}

	int keta = 0;
	for (int i=11;i>=0;i--){
		 // cout << n << " " << base[i] << endl;
		if (n-base[i]>0){
			keta = i+1;
			n = n-base[i]-1;
			while (n>0){
				char tmp = 'a'+n%26;
				ans.push_back(tmp);
				n = n/26;
			}
			break;
		}
	}

	for (int i=0;i<keta-ans.size();i++){
		cout << 'a';
	}

	for (int i=ans.size()-1;i>=0;i--){
		cout << ans[i];
	}
	printf("\n");
}

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

#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    cin.tie(0); //cinとcoutの同期切り
    ios::sync_with_stdio(false); //iostreamとstdioの同期切り

    int a, b;
    cin >> a >> b;

    if(a <= b) cout << a << endl;
    else cout << a-1 << endl;

    return 0;
}

/*****************************************************************************/
/*****   1秒間で処理できるfor文ループの回数                                 *****/
/*****   → 10^8 = 100,000,000 回程度                                      *****/
/*****                                                                   *****/
/*****   sort(a, a+N, greater<int>()); // a[0:N) を大きい順にソート        *****/
/*****                                                                   *****/
/*****                                                                   *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3"                *****/
/*****   std::cout << std::fixed;                                        *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3.00"             *****/
/*****                                                                   *****/
/*****************************************************************************/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;


int main() {
 int N;
  in(N);
  int a = N/1000;
  int b = (N%1000)/100;
  int c = (N%100)/10;
  int d = (N%10);
  if(a+b+c+d==7) printf("%d+%d+%d+%d=%d",a,b,c,d,7);
  else if(a+b+c-d==7)printf("%d+%d+%d-%d=%d",a,b,c,d,7);
  else if(a+b-c-d==7)printf("%d+%d-%d-%d=%d",a,b,c,d,7);
  else if(a+b-c+d==7)printf("%d+%d-%d+%d=%d",a,b,c,d,7);
  else if(a-b+c+d==7)printf("%d-%d+%d+%d=%d",a,b,c,d,7);
  else if(a-b+c-d==7)printf("%d-%d+%d-%d=%d",a,b,c,d,7);
  else if(a-b-c+d==7)printf("%d-%d-%d+%d=%d",a,b,c,d,7);
  else if(a-b-c-d==7)printf("%d-%d-%d-%d=%d",a,b,c,d,7);
  cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

int main(){
  ll a, b;
  cin >> a >> b;
  ll x = a + b;
  ll y = a - b;
  ll z = a * b;
  chmax(x, y);
  chmax(x, z);
  print(x);
}

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

int N, K;
vector<int> d;
vector<vector<int>> A;
void input()
{
    cin >> N >> K;
    d.resize(K);
    A.resize(K, vector<int>());
    for (int i = 0; i < K; i++)
    {
        cin >> d[i];
        A[i].resize(d[i]);
        for (int j = 0; j < d[i]; j++)
        {
            cin >> A[i][j];
        }
    }
}

void solve()
{
    int ans = 0;
    for (int i = 1; i <= N; i++)
    {
        bool have = false;
        for (auto v : A)
        {
            for (auto p : v)
            {
                //cout << p << " ";
                if (p == i)
                   have = true;
            }
        }
        if (!have)
            ans++;
    }
    cout << ans << endl;
}

int main()
{
    input();
    solve();
}


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

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

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

// 最大公約数
ll GCD(ll a,ll b){if(a%b==0)return b;return GCD(b,a%b);}

// 最小公倍数
ll LCM(ll a,ll b){return a*(b/GCD(a,b));}

int main(void){

    int n;
    cin >> n;
    vector<ll> t(n);
    roop(i, n) cin >> t[i];

    ll ans = t[0];

    for(int i = 1;i < n;i++){
        ans = LCM(ans, t[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int f[2097200],n,a[22][22],mx,mod=1000000007;
inline int getbit(int x){int ans=0;while(x) {if(x&1) ans++;x>>=1;} return ans;}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
    scanf("%d",&a[i][j]);
    mx=1<<n;
    f[0]=1;
    for(int i=1;i<mx;i++){
        int cr=getbit(i);
        for(int j=0;j<n;j++)
        if((i&(1<<j))&&a[cr-1][j])
        f[i]=(f[i]+f[i^(1<<j)])%mod;
    }
    printf("%d",f[mx-1]);
    return 0;
}

Measured memory_bytes: 8448
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<cstdio>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
int main(){
	int a,b,c;
	while(cin>>a>>b>>c){
		if(a==b){
			if(a!=c) cout<<"Yes"<<endl;
			else cout<<"No"<<endl; 
		}
		else if(a==c){
			if(a!=b) cout<<"Yes"<<endl;
			else cout<<"No"<<endl; 
		}
		else if(b==c){
			if(a!=b) cout<<"Yes"<<endl;
			else cout<<"No"<<endl;
		}
		else cout<<"No"<<endl;
	} 
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String t = sc.nextLine();
		int dp[][] = new int[s.length()+1][t.length()+1];
		int g[][] = new int[s.length()+1][t.length()+1];
		
		for (int i=1;i<=s.length();i++)
			for (int j=1;j<=t.length();j++) {
				char a = s.charAt(i-1);
				char b = t.charAt(j-1);
				dp[i][j] = dp[i-1][j];
				if (dp[i][j] < dp[i][j-1]) {
					dp[i][j] = dp[i][j-1];
					g[i][j] = 1;
				}
				
				if (a==b && dp[i][j] < dp[i-1][j-1]+1) {
					dp[i][j] = dp[i-1][j-1]+1;
					g[i][j] =2;
				}
			}
		int i = s.length();
		int j = t.length();
		String r = "";
		while (i>0 || j>0) {
			if (g[i][j]==2) {
				r=s.charAt(i-1)+r;
				i--;
				j--;
			} 
			if (g[i][j]==1) j--;
			if (g[i][j]==0) i--;
			if (i<0 || j<0) break;
		}
		System.out.println(r);
	}
}


Measured memory_bytes: 130004
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int sum = a+b+c;
  if(sum==a*2||sum==b*2||sum==c*2){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
//priority_queue<long long, vector<long long>, greater<long long>> pq;

const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);


int n, m;
int h[100005];
vector<int> e[100005];

int main() {
  //auto start_clock = clock();
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &h[i]);
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    bool flag = true;
    for (auto v : e[i]) {
      if (h[v] >= h[i]) {
        flag = false;
      }
    }
    if (flag) {
      ans += 1;
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 9360
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

//nCr mod m
#define MOD 998244353
#define M 2200000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}


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

	string s;
	cin>>s;
	if(s=="ARC")cout<<"ABC"<<endl;
	else cout<<"ARC"<<endl;

}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

vector<int> V[100005];
vector<int> pathforward;
vector<int> pathbackward;
bool vis[100005];
bool dfs(int n){
    if(vis[n])
        return false;
    vis[n]=1;
    pathforward.push_back(n);
    bool ans=1;
    for(int i=0;i<V[n].size();++i){
        if(dfs(V[n][i])){
            break;
        }
    }
    return true;

}
bool dfs2(int n){
    if(vis[n])
        return false;
    vis[n]=1;
    pathbackward.push_back(n);
    bool ans=1;
    for(int i=0;i<V[n].size();++i){
        if(dfs2(V[n][i])){
            break;
        }
    }
    return true;
}
int main(){
    int n,m;cin >> n >> m;
    for(int i=1;i<=m;++i){
        int a,b;scanf("%d %d",&a,&b);
        V[a].push_back(b);
        V[b].push_back(a);
    }
    dfs(1);
    vis[1]=0;
    dfs2(1);
    cout << pathbackward.size()+pathforward.size()-1 << endl;
    for(int i=pathbackward.size()-1;i>=0;--i){
        printf("%d ",pathbackward[i]);

    }
    for(int i=1;i<pathforward.size();++i)
        printf("%d ",pathforward[i]);
    cout << endl;
    return 0;
}


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


int main() {
	int n;
	scanf("%d",&n);
	vector<int> v(n),p(n);
	for( int i = 0; i < n; i++) {
		scanf("%d",&v[i]);
		p[i] = v[i];
		if( i > 0 ) p[i] = max(p[i-1],p[i]);
	}
	long long ans = 0;
	for( int i = n-1; i > 0; i--) {
		ans += p[i] - v[i];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4840
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(15) << << endl;
#include <cassert>
//#include "atcoder/all"

using namespace std;
//using namespace atcoder;

typedef long long ll;

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define P pair<int,int>

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
ll mod = 1000000007;


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

    int n; cin >> n;
    vector<pair<int,int>> red(n),blue(n);
    rep(i,n) cin >> red[i].first >> red[i].second;
    rep(i,n) cin >> blue[i].second >> blue[i].first;
    sort(red.rbegin(),red.rend());
    sort(blue.begin(),blue.end());

    int ans = 0;
    vector<bool> b(n,false);

    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < n; ++j)
        {
            if(red[i].first < blue[j].second && red[i].second < blue[j].first && !b[j])
            {
                b[j] = true;
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3668
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

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

	sort(A, A + N);

	long b; // median

	if (N % 2) {
		b = A[N / 2];
	}
	else {
		b = (A[N / 2 - 1] + A[N / 2]) / 2;
	}

	long ans = 0;

	for (int i = 0; i < N; ++i)
		ans += abs(A[i] - b);

	cout << ans;

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) (x.begin()),(x.end())
#define sz(x)  ((ll)x.size())
#define FAST_IO ios_base :: sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
#ifdef LOCAL
#include "uj.h"
#endif
void tokenize(string str,const char delim,vector<string> & res){
	stringstream p(str);
	string token;
	while(getline(p,token,delim)){
		res.push_back(token);
	}
	return;
}

// Your workSpace ...

	
	
ll N;	
void test_case(){
	cin >> N;
	if(N >= 30) cout << "Yes" << endl;
	else cout << "No" << endl; 
}
	





int main(){
	FAST_IO;
	int tt;
	//cin>>tt;
	tt = 1;
	while(tt--){
		test_case();
	}
#ifndef ONLINE_JUDGE
 	cerr << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;

struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};

int main(void) {
  long long N, M;
  cin >> N >> M;
  vector<P> edges;
  for (int i = 0; i < M; i++) {
    long long A, B;
    cin >> A >> B;
    A--;
    B--;
    edges.push_back(P(A, B));
  }

  UnionFind uf(N);
  vector<long long> ans(M + 1);
  ans[0] = N * (N - 1) / 2LL;
  for (int i = 0; i < M; i++) {
    P edge = edges[M - i - 1];
    if (uf.find(edge.first) == uf.find(edge.second)) {
      ans[i + 1] = ans[i];
    } else {
      long long size1 = uf.size(edge.first);
      long long size2 = uf.size(edge.second);
      ans[i + 1] = ans[i] - size1 * size2;
      uf.unite(edge.first, edge.second);
    }
  }

  for (int i = 0; i < M; i++) {
    cout << ans[M - i - 1] << endl;
  }
  return 0;
}

Measured memory_bytes: 4080
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<lint> a;
    vector<lint> s;
    lint ans = 0;
    while(true){
        a.resize(n);
        s.resize(n+1);
        ans = 0;
        for (int i=0; i<n; ++i){
            cin >> a[i];
        }
        s[0] = 0;
        for (int i=1; i<=n; ++i){
            s[i] = s[i-1] + a[i-1];
        }
        for (int i=0; i<n-k; ++i){
            ans = max(ans, s[i+k] - s[i]);
        }
        cout << ans << endl;
        cin >> n >> k;
        if(n == 0 && k == 0){
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 4396
def main():
    n, u, v = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in [0]*(n-1)]
    u -= 1
    v -= 1
    g = [[] for _ in [0]*n]
    [g[a-1].append(b-1) for a, b in ab]
    [g[b-1].append(a-1) for a, b in ab]
    da = [-1]*n
    dt = [-1]*n
    dt[u] = 0
    da[v] = 0
    q = [u]
    cnt = 0
    while q:
        cnt += 1
        qq = []
        for i in q:
            for j in g[i]:
                if dt[j] == -1:
                    dt[j] = cnt
                    qq.append(j)
        q = qq
    q = [v]
    cnt = 0
    while q:
        cnt += 1
        qq = []
        for i in q:
            for j in g[i]:
                if da[j] == -1:
                    da[j] = cnt
                    qq.append(j)
        q = qq
    #print(da, dt)
    priority = sorted([[i, j] for i, j in enumerate(da)], key=lambda x: -x[1])
    # print(priority)
    # path = {u}
    # now = u
    # for i in range(da[v]):
    #    for j in g[now]:
    #        if da[j] > da[now] and dt[j] < dt[now]:
    #            now = j
    #            path.add(now)
    #            break
    for i, j in priority:
        if da[i] > dt[i]:
            #print(da[i], dt[i])
            print(da[i]-1)
            return 0


main()


Measured memory_bytes: 96984
# thought greedy was better i am noob
# classical problem no explanation needed
def main():
	n = int(input())
	dp = [0 for i in range(n+4)]
	dp[0]=0
	for i in range(1, n+2):
		p = 1
		dp[i]=1000000000000000
		while i>=p:
			dp[i]=min(dp[i] , dp[i-p]+1)
			p =p*9
		p=1
		while i>=p:
			dp[i]=min(dp[i] , dp[i-p]+1)
			p = p*6
	print(dp[n])
if __name__=="__main__":
	main()

Measured memory_bytes: 79120
n = int(input())

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


sums = [0 for i in range(len(arr))]

sums[0] = arr[0]

for i in range(1, len(sums)):
    sums[i] = sums[i-1] + arr[i]

# print(sums)
sums.insert(0, 0)
dp = []

for i in range(n):
    temp = []
    for j in range(n):
        temp.append(0)
    
    dp.append(temp)


for i in range(1, n):
    for j in range(0, n-i):
        start = j
        end = start + i

        min_ = float('inf')
        for k in range(start, end):
            min_ = min(min_, dp[start][k] + dp[k+1][end] + sums[end+1] - sums[start])
        
        dp[start][end] = min_

# print(dp)
print(dp[0][n-1])

Measured memory_bytes: 75352
#!/usr/bin/python
# -*- coding: utf-8 -*-

n, x =  [int(i) for i in raw_input().split()]
xx = [int(i) for i in raw_input().split()]

s = []
for i in xx:
    a = x - i
    if a < 0:
        s.append(-a)
    else:
        s.append(a)

import fractions
v = s[0]
for b in s[1:]:
    v = fractions.gcd(b, v)
print v

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

int main() {
    int N; cin >> N;
    vector<double> V(N);
    rep(i, 0, N) cin >> V[i];
    sort(V.begin(), V.end());
    rep(i, 0, N - 1) {
        V[i + 1] = (V[i + 1] + V[i]) / 2;
    }
    cout << V[N - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
set<int> dp[15][15];
int num;
bool used[15][15];
vector<int> v;
void dfs(string s,int l,int r){
  //cout<<s<<" "<<l<<"-"<<r<<endl;
  if(used[l][r]) return;
  used[l][r]=1;
  if(l+1==r){
    dp[l][r].insert(v[l]);
    return;
  }
  int op=0,cnt=0;
  while(s.front()=='('&&s.back()==')'){
    for(int i=1;i<(int)s.size()-1;i++){
      if(s[i]=='(') op++;
      if(s[i]==')') op--;
      if(op<0) break;
    }
    if(op<0) break;
    s.erase(s.begin());
    s.pop_back();
  }
  op=0;
  for(int i=0;i<(int)s.size();i++){
    if(s[i]=='(') op++;
    if(s[i]==')') op--;
    if(isdigit(s[i])){
      cnt++;
      while(i<(int)s.size()&&isdigit(s[i])) i++;
      i--;
    }
    if(op) continue;
    if(s[i]=='+'||s[i]=='-'||s[i]=='*'||s[i]=='/'){
      dfs(s.substr(0,i),l,l+cnt);
      dfs(s.substr(i+1,s.length()-i-1),l+cnt,r);
      for(int p:dp[l][l+cnt]){
	for(int q:dp[l+cnt][r]){
	  if(s[i]=='+') dp[l][r].insert(p+q);
	  if(s[i]=='-') dp[l][r].insert(p-q);
	  if(s[i]=='*') dp[l][r].insert(p*q);
	  if(!q) continue;
	  if(s[i]=='/') dp[l][r].insert(p/q);
	}
      }
    }
  }
  //cout<<s<<" "<<l<<"-"<<r<<endl;
  //for(auto i:dp[l][r]) cout<<i<<endl;
}
signed main(){
  string s;
  while(cin>>s,s!="#"){
    //cout<<s<<":";
    for(int i=0;i<15;i++)
      for(int j=0;j<15;j++)
	dp[i][j].clear();
    v.clear();
    for(int i=0;i<(int)s.size();i++){
      if(s[i]=='+') num++;
      if(s[i]=='-') num++;
      if(s[i]=='*') num++;
      if(s[i]=='/') num++;
      if(isdigit(s[i])){
	int tmp=0;
	while(i<(int)s.size()&&isdigit(s[i])){
	  tmp=tmp*10+s[i]-'0';
	  i++;
	}
	//cout<<tmp<<endl;
	v.push_back(tmp);
	i--;
      }
    }
    num=v.size();
    memset(used,0,sizeof(used));
    dfs(s,0,num);
    //for(auto i:dp[0][num]) cout<<i<<endl;
    cout<<dp[0][num].size()<<endl;
  }
  return 0;
}

Measured memory_bytes: 3228
import numpy as np
N=int(input())
A=list(map(int,input().split()))
SUM=sum(A)
Q=int(input())
List=np.array([0 for _ in range(10**5+1)])
for a in A:
    List[a]+=1
for q in range(Q):
    B,C=map(int,input().split())
    SUM-=B*List[B]
    SUM+=C*List[B]
    List[C]+=List[B]
    List[B]=0
    print(SUM)

Measured memory_bytes: 38224
#include <iostream>

using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"
const int MOD = 1e9+7;

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

  IN(N); IN(M);

  if (N < M) {
    int tmp = N;
    N = M;
    M = tmp;
  }
  if (N - M > 1) {
    OUT(0);
    return 0;
  }
  if (N == M) {
    ll ans = 1;
    for (int  n = N, m = M; n > 0 && m > 0; --n, --m) {
      ans *= n; ans %= MOD;
      ans *= m; ans %= MOD;
    }
    OUT((2 * ans) % MOD);
    return 0;
  }

  ll ans = 1;
  for (int  n = N, m = M; n > 0 && m > 0; --n, --m) {
    ans *= n; ans %= MOD;
    ans *= m; ans %= MOD;
  }
  OUT(ans);

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int ma,mb;
int dp[425][425];
const int INF = 1252183025;

int main(){
  scanf("%d%d%d",&n,&ma,&mb);
  REP(i,425)REP(j,425)dp[i][j]=INF;
  dp[0][0] = 0;
  REP(i,n){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    FORR(i,0,425)FORR(j,0,425){
      if(i+a>=425)continue;
      if(j+b>=425)continue;
      CHMIN(dp[i+a][j+b],dp[i][j]+c);
    }
  }
  int ans = INF;
  int ca = ma;
  int cb = mb;
  while(ca<425&&cb<425){
    CHMIN(ans,dp[ca][cb]);
    ca+=ma;
    cb+=mb;
  }
  if(ans==INF)ans=-1;
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 896
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

get_numbers(0, []).
get_numbers(N, [X|Xs]) :- 
    get_number(X), 
    N2 is N - 1, 
    get_numbers(N2, Xs).

put_numbers([]).
put_numbers([X|Xs]) :-
    writeln(X),
    put_numbers(Xs).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    length(S, L),
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==

    between(L,U,X): L <= X <= U
    nth0(I, Xs, Y), nth1(I, Xs, Y): (Xs,Y) -> I, (I, Xs) -> Y 

    sort(Key, Order, List, Sorted): Keyは通常0?, Orderは=なしが重複削除，=は重複保持
    \+ P(X) : not P(X)

    sum_list(Xs, Sum)
*/

f(0, S, S).
f(N, S, Z) :- N mod 3 =\= 0 , N mod 5 =\= 0, S2 is S + N, N2 is N - 1, f(N2, S2, Z), !.
f(N, S, Z) :- N2 is N - 1, f(N2, S, Z).

main :-
    get_number(N),
    f(N, 0, Z),
    writeln(Z).


Measured memory_bytes: 99924
package main

import (
	"fmt"
	"sort"
)

func main() {
	var k int
	n := make([]int, 5)

	for i := 0; i < 5; i++ {
		fmt.Scanln(&n[i])
	}

	fmt.Scanln(&k)

	fmt.Println(logic(n, k))
}

func logic(n []int, k int) string {
	sort.Ints(n)

	if n[len(n)-1]-n[0] <= k {
		return "Yay!"
	}
	return ":("
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n,a,b;
    cin>>n>>a>>b;
    int ans1=min(a,b);
    int ans2=0;
    if(n-a-b<0)ans2=-(n-a-b);
    cout<<ans1<<" "<<ans2<<endl;
}

Measured memory_bytes: 256
import sys
inputs = sys.stdin.readlines()

S = inputs[0].strip()
K = int(inputs[1])

if len(set(S)) == 1:
    print(len(S)*K // 2)

elif S[0] != S[-1]:
    counts = []
    count = 1
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            count += 1
        else:
            counts.append(count)
            count = 1
    counts.append(count)
    print(K*sum(map(lambda x: x//2, counts)))
else:
    counts = []
    count = 1
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            count += 1
        else:
            counts.append(count)
            count = 1
    counts.append(count)
    if counts[0] % 2 == 1 and counts[-1] % 2 == 1:
        t = 1
    else:
        t = 0
    counts[0] += counts.pop()
    print(K*sum(map(lambda x: x//2, counts)) - t)

Measured memory_bytes: 3192