akhauriyash/Code-Regression huggingface dataset:
void main()
{
    long t1, t2;
    rdVals(t1, t2);
    long a1, a2;
    rdVals(a1, a2);
    long b1, b2;
    rdVals(b1, b2);

    long diff1 = b1 - a1, diff2 = b2 - a2;
    long sign1 = diff1 / diff1.abs, sign2 = diff2 / diff2.abs;
    if (sign1 != sign2)
    {
        long len1 = diff1 * t1, len2 = diff2 * t2;
        long diff = len1 + len2;
        if (diff == 0) "infinity".writeln;
        else if (sign1 > 0 && diff > 0) 0.writeln;
        else if (sign1 < 0 && diff < 0) 0.writeln;
        else
        {
            long d = len1.abs / diff.abs, r = len1.abs % diff.abs;
            writeln(2 * d + (r != 0));
        }
    }
    else 0.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=(n);i>=0;--i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  string S, T;
  in(S); in(T);
  int N = S.length(), M = T.length();

  rrep(i, N-M) {
    bool flag = true;
    rep(j, M) {
      if (!(S[i+j] == T[j] || S[i+j] == '?'))
        flag = false;
    }
    if (!flag)
      continue;
    rep(k, N) {
      if (k == i) {
        cout << T;
        k += M - 1;
      } else
        cout << (S[k] == '?' ? 'a' : S[k]);
    }
    cout << "\n";
    return 0;
  }
  out("UNRESTORABLE");

  return 0;
}


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

int main () {
  int n;
  cin >> n;
  int ans = 1;
  while((ans << 1) <= n) ans = (ans << 1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
function BFS(x){
   var obj={};
   var bfs=[[x,0]];
   obj[x]=true;
   while(true){
      if(bfs.length==0){ans="NA";break;}
      var leaf=bfs.shift();
      var str=leaf[0];
      var cnt=leaf[1];
      if(/^0+$|^1+$|^2+$/.test(str)){ans=cnt;break;}
      for(var i=0;i<str.length-1;i++){
         if(str[i]==str[i+1])continue;
         var arr=str.split("");
         var color=3-(+arr[i])-(+arr[i+1]);
         arr[i]=color;
         arr[i+1]=color;
         var Str=arr.join("");
         if(obj.hasOwnProperty(Str)==false){
            bfs.push([Str,cnt+1]);
            obj[Str]=true;
         }
      }
   }
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var rgb=Arr.shift();
   if(rgb=="0")break;
   rgb=rgb.replace(/r/g,"0").replace(/g/g,"1").replace(/b/g,"2")
   var ans;
   BFS(rgb);
   console.log(ans);
}

Measured memory_bytes: 51800
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, ll> P;
#define MOD (1000000007ll)
#define l_ength size

int main(void){
	int n,m;
	cin >> n >> m;
	cout << ((n-1)*(m-1)) << endl;
	return 0;
}

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

int main(){
  int h, w, k; cin >> h >> w >> k;
  char s[h][w];
  bool exist[h], first = true;
  int firsti;
  rep(i, h){
    exist[i] = false;
    rep(j, w){
      cin >> s[i][j];
      if(s[i][j] == '#'){
        exist[i] = true;
        if(first) firsti = i;
        first = false;
      }
    }
  }


  int a[h][w];

  int cnt = 1;
  rep(i, h){
    if(!exist[i]) continue;
    int j = 0;
    while(s[i][j] == '.'){
      a[i][j] = cnt;
      j++;
    }
    a[i][j] = cnt;
    j++;
    for(;j < w; j++){
      if(s[i][j] == '#') cnt++;
      a[i][j] = cnt;
    }
    cnt++;
  }

  for(int i = 0; i < h && !exist[i]; i++){
    rep(j, w){
      a[i][j] = a[firsti][j];
    }
  }

  for(int i = firsti + 1; i < h; i++){
    if(exist[i]) continue;
    rep(j, w){
      a[i][j] = a[i - 1][j];
    }
  }

  rep(i, h){
    rep(j, w){
      if(j == 0) cout << a[i][j];
      else cout << " " << a[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 4008
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

using ll = long long;
using Pll = pair<ll, ll>;

constexpr ll INF = 1LL << 60;

class ConvexHullTrick {
    public:
    int n = 0;
    deque<Pll> lines;
    
    ConvexHullTrick() {}

    bool check(Pll line1, Pll line2, Pll line3) {
        return (line3.second-line2.second)*(line1.first-line2.first) > (line2.second-line1.second)*(line2.first-line3.first);
    }

    // 直線の傾きの降順に直線が与えられる前提
    void add(ll grad, ll intercept) {
        while(n >= 2 && !check(lines[n-2], lines[n-1], {grad, intercept})) {
            lines.pop_back();
            --n;
        }
        lines.emplace_back(grad, intercept);
        ++n;
    }

    ll f(ll i, ll x) {
        return lines[i].first*x + lines[i].second;
    }

    ll get_min(ll x) {
        while(n > 1 && f(0, x) >= f(1, x)) {
            lines.pop_front();
            --n;
        }
        return f(0, x);
    }
};

int main() {
    int N, M, D, X;
    cin >> N >> M >> D >> X;
    vector<ll> p(N);
    for(int i=0;i<N;++i) cin >> p[i];

    vector<ll> lines(M);
    ll a, b;
    for(int i=0;i<M;++i) {
        cin >> a >> b;
        if(b > 0) {
            lines[i] = a-b-X;
        } else {
            lines[i] = a+b-X;
        }
    }
    sort(lines.begin(), lines.end());

    vector<vector<ll>> w(D, vector<ll>(N, 0));
    for(int d=0;d<D;++d) {
        int li = 0;
        for(int i=0;i<N;++i) {
            while(li < M && X*(d+1)+lines[li] < p[i]) ++li;
            w[d][i] = M-li;
        }
    }

    vector<vector<ll>> dp(D+1, vector<ll>(N, INF));
    dp[0][0] = 0;
    for(int d=1;d<=D;++d) {
        ConvexHullTrick cht = ConvexHullTrick();
        for(int i=0;i<N;++i) {
            if(dp[d-1][i] != INF) cht.add(w[d-1][i], dp[d-1][i]-w[d-1][i]*p[i]);
            dp[d][i] = cht.get_min(p[i]);
        }
    }

    cout << dp[D][N-1] << endl;
}


Measured memory_bytes: 18728
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

ll pow_mod(ll n, ll p, ll mod) {
    if (p == 0) {
        return 1;
    } else if (p % 2 == 1) {
        return pow_mod(n, p - 1, mod) * n % mod;
    } else {
        ll s = pow_mod(n, p / 2, mod);
        return s * s % mod;
    }
}

template<typename T>
T calc_mod(string s, T d) {
    T r = 0;
    REP(i, sz(s)) r = (r * 2 + (s[i] - '0')) % d;
    return r;
}

void solve() {
    int n;
    string x;
    cin >> n >> x;
    int q = 0;
    REP(i, n) if (x[i] == '1') q++;
    int u = 0;
    if (q - 1 > 0) u = calc_mod(x, q - 1);
    int v = calc_mod(x, q + 1);
    REP(i, n) {
        string y = x;
        bool b = x[i] == '0';
        if (b) y[i] = '1'; else y[i] = '0';
        int p = q;
        p += (b ? 1 : -1);
        if (p <= 0) {
            cout << 0 << endl;
            continue;
        }
        int ans = 1;
        int z = pow_mod(2, n - i - 1, p);
        // cout << "? " << z << " : " << y << "%" << p << endl;
        if (b) {
            z = (v + z) % p;
        } else {
            z = (u - z + p) % p;
        }
        while (z > 0) {
            ans++;
            int pc = __builtin_popcount(z);
            z %= pc;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3828
use proconio::input;

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a

fn main() {
    input! {
        n: usize,
        mut a: [i64; n],  // Vec<(i32, i32, i32)>
    }

    let mut money: i64 = 1000;
    let mut kabu: i64 = 0;

    for i in 0..n - 1 {
        if a[i] < a[i + 1] {
            if money >= a[i] {
                kabu = money / a[i];
                money = money - kabu * a[i];
            }
        } else if a[i] > a[i + 1] {
            if kabu > 0 {
                money = money + kabu * a[i];
                kabu = 0;
            }
        }
    }

    if kabu > 0 {
        money = money + kabu * a[n - 1];
        kabu = 0;
    }

    println!("{}", money);
}


Measured memory_bytes: 2116
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(n*a<b){
      System.out.println(n*a);
    }
    else{
	  System.out.println(b);
    }
  }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    char a, b;
    cin >> a >> b;
    if( a == 'H' ) cout << b;
    else {
        if( b == 'H' ) cout << 'D';
        else cout << 'H';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n;
    cin >> n;
    int d[n][2];
    for(int i=0;i<n;i++){
        for(int j=0;j<2;j++){
            cin >> d[i][j];
        }
    }
    int sum = 0;
    for(int i=0;i<=n-3;i++){
        if(d[i][0] == d[i][1] && d[i+1][0] == d[i+1][1] && d[i+2][0] == d[i+2][1]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3652
def main():
    a, b, k = [int(abk) for abk in input().split(" ")]

    for i in range(k):

        if i % 2 == 0:

            if a % 2 == 1:
                a = present_for_b = (a - 1) / 2

            else:
                a = present_for_b = a / 2

            b = b + present_for_b

        else:

            if b % 2 == 1:
                b = present_for_a = (b - 1) / 2

            else:
                b = present_for_a = b / 2

            a = a + present_for_a

    print("{a} {b}".format(a=str(int(a)), b=str(int(b))))


if __name__ == "__main__":
    main()


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

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

// a + b = (a xor b) + (a & b) * 2

// cf) abc129E
static const int mod = 1e9+7;

int dp[100005][2];
// dp[i][j]
// i: 上からi桁目までみた
// j: a+bを上からi桁目までみて1: L以下であることが確定, 0: i桁目までLと一致だがL以下確定ではない

int main() {
  string s;
  cin >> s;
  int n = s.size();
  dp[0][0] = 1;
  rep(i, 0, n) {
    { // a+b = 0 (a+bの上からi桁目が0を想定)
      if (s[i] == '0') {
        dp[i+1][0] = dp[i][0];
        dp[i+1][1] = dp[i][1];
      } else { // s[i] == '1' -> L以下のみ考える, a+b = 0なので一致し得ない
        dp[i+1][1] = (dp[i][0] + dp[i][1]) % mod;
      }
    }
    { // a+b = 1 (a+bの上からi桁目が1を想定)
      if (s[i] == '0') { // dp[i][0]はL以下の条件を満たすことが不可能なので考える必要がない
        (dp[i+1][1] += dp[i][1] * 2 % mod) %= mod;
      } else {
        (dp[i+1][0] += dp[i][0] * 2 % mod) %= mod;
        (dp[i+1][1] += dp[i][1] * 2 % mod) %= mod;
      }
    }
  }

  int ans = (dp[n][0] + dp[n][1]) % mod;
  cout << ans << endl;

  return 0;
};


Measured memory_bytes: 1280
#include <cstdio>
#define min(x,y) ((x)<(y)?(x):(y))

int main()
{
    unsigned long long q,h,s,d,n;
    unsigned long long cost; 
    scanf("%llu %llu %llu %llu\n%llu",&q,&h,&s,&d,&n);

    h=min(q*2,h);
    s=min(h*2,s);
    d=min(s*2,d);
    cost=(n/2)*d+(n%2)*s;

    printf("%llu",cost);
}

Measured memory_bytes: 128
class UnionFind:
    def __init__(self, n):
        self.v = [-1 for _ in range(n)]  # 根(負): 連結頂点数 * (-1) / 子(正): 根の頂点番号(0-indexed)

    def find(self, x):  # xを含む木における根の頂点番号を返す
        if self.v[x] < 0:  # (負)は根
            return x
        else:  # 根の頂点番号
            self.v[x] = self.find(self.v[x])  # uniteでは, 旧根に属する頂点の根が旧根のままなので更新
            return self.v[x]

    def unite(self, x, y):  # 違う根に属していたらrankが低くなるように連結
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if -self.v[x] < -self.v[y]:  # size比較, 　(-1) * (連結頂点数 * (-1)), (正)同士の大小比較
            x, y = y, x  # 連結頂点数が少ない方をyにすると, findでの更新回数が減る？
        self.v[x] += self.v[y]  # 連結頂点数の和を取る, 連結頂点数 * (-1)
        self.v[y] = x  # 連結頂点数が少ないy(引数yの根の頂点番号)の根をx(引数xの根の頂点番号)にする

    def root(self, x):
        return self.v[x] < 0  # (負)は根

    def same(self, x, y):
        return self.find(x) == self.find(y)  # 同じ根に属するか

    def size(self, x):
        return -self.v[self.find(x)]  # 連結頂点数を返す


N, M = map(int, input().split())
uf = UnionFind(N * 2)
for _ in range(M):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    if z % 2 == 0:
        uf.unite(x, y)
        uf.unite(x + N, y + N)
    else:
        uf.unite(x, y + N)
        uf.unite(x + N, y)

# print(uf.v)

ans = 0
for i in range(N):
    if uf.root(i):
        ans += 1
print(ans)


Measured memory_bytes: 121476
import java.util.*;

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

        for (;;) {
            int h = scanner.nextInt(), w = scanner.nextInt();

            if (h == 0 && w == 0) {
                return;
            }

            for (int j = 0; j < h; ++j) {
                StringBuilder builder = new StringBuilder();
                for (int k = 0; k < w; ++k) {
                    if(j == 0 || j == h - 1 || k == 0 || k == w - 1)
                        builder.append("#");
                    else
                        builder.append(".");

                }
                System.out.println(builder.toString());
            }
            System.out.println();

        }
    }
}


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

ll c[10][10];

int main() {
    int N;
    cin >> N;
    ll ans = 0;
    for (int i=1; i<=N; ++i) {
        string tmp = to_string(i);
        int s = tmp[0] - '0', t = tmp[tmp.size()-1] - '0';
        c[s][t]++;
    }
    for (int i=0; i<=9; ++i) for (int j=0; j<=9; ++j) {
        ans += c[i][j] * c[j][i];
    }
    cout << ans << endl;
}


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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define FORR(i, a, b) for(int i=(b-1);i>=(a);--i)
#define FORRE(i, a, b) for(int i=(b);i>=(a);--i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define repr(i, n) for(int i=(n-1);i>=0;--i)
#define repre(i, n) for(int i=(n);i>=0;--i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<int, int> P;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, m, c;
	cin >> n >> m >> c;
	int b[m];
	rep(i, m) cin >> b[i];
	int cnt = 0;
	rep(i, n) {
		int a[m];
		rep(j, m) cin >> a[j];
		int sum = 0;
		rep(j, m) sum += a[j] * b[j];
		sum += c;
		if (sum > 0) cnt++;
	}
	
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long w[100001],c[100001];
long long f[1001][100001]={0};
int main()
{
	long long n,m,i,j;
	scanf("%lld %lld",&n,&m);
	for(i=1;i<=n;i++)
	{
		scanf("%lld %lld",&w[i],&c[i]);
	}
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			f[i][j]=f[i-1][j];
			if(j>=w[i])
			{
				f[i][j]=max(f[i][j],f[i-1][j-w[i]]+c[i]);
			}
		}
	}
	printf("%lld",f[n][m]);
	return 0;
}

Measured memory_bytes: 81408
// G++ MACRO.CPP -STD=C++17
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair
 
 
int main(){
  CIN(n);VC1(n,a);

  int cent = n / 2 - 1;
  vector<P> v;
  REP(i,n)
    v.pb(mp(a[i],i));
  sort(ALL(v),greater<P>());
  V taiou(n,0);
  REP(i,n)
    taiou[v[i].second] = i;
  
  REP(i,n){
    int t = cent;
    if(taiou[i] <= cent)t++;
    COUT(v[t].first);
  }

  return 0;
}

Measured memory_bytes: 8940
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 201

int to_num(string s){
  char c[5] = "mcxi";
  int t[4] = {1000,100,10,1};

  int ret = 0;
  
  for(int i=0;i<s.size();i++){
    for(int j=0;j<4;j++){
      if(s[i]==c[j]){
	if(i==0 || !('0'<=s[i-1] && s[i-1]<='9')) ret += t[j];
	else ret += t[j] * (s[i-1]-'0');
      }
    }
  }
  
  return ret;
}

string to_mcxi(int a){
  char c[5] = "ixcm";
  string ret;
  
  for(int i=0;i<4;i++){
    if(a%10>0) ret += c[i];
    if(a%10>1) ret += '0'+(a%10);

    a/=10;
  }

  reverse(ret.begin(),ret.end());
  
  return ret;
}

bool calc(){
  string a,b;

  cin >> a >> b;

  cout << to_mcxi(to_num(a)+to_num(b)) << endl;
  
  return true;
}

int main(){
  int m;
  
  scanf("%d",&m);
  
  for(int i=0;i<m;i++){
    calc();
  }
  
  return 0;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    string ans = "Yes";
    if (a * b % 2 == 0)
        ans = "No";
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int n;
V<double> p;
V<V<double>> memo;

double dp(int i, int j) {
	if (memo[i][j] <= 1)return memo[i][j];
	if (j == 0)return 1;
	if (i == 0)return 0;
	
	double ret = p[i - 1] * dp(i - 1, j - 1) + (1 - p[i - 1]) * dp(i - 1, j);
	memo[i][j] = ret;
	return ret;
}

int main() {

	cin >> n;
	p.resize(n);
	rep(i, n)cin >> p[i];
	memo.assign(n + 1, V<double>(n + 1, INF));

	cout << fixed << setprecision(12);
	cout << dp(n,n/2+1) << endl;

}

Measured memory_bytes: 70912
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define lp(i, n) for (z i = 0; i < n; i++)
using z=long long;
int main(){z N,Q;cin>>N>>Q;fenwick_tree<z> b(N);lp(i,N){z a;cin>>a;b.add(i,a);}lp(i,Q){z w,e,r;cin>>w>>e>>r;if(w)cout<<b.sum(e,r)<<"\n";else b.add(e,r);}}

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

ss = []
for i in range(n):
	ss.append(sorted(str(input())))

sm = sorted(ss)
c = 0
ans = 0
for i in range(n-1):
	if sm[i] == sm[i+1]:
		c += 1
		ans += c
	else:
		c = 0
print(ans)

Measured memory_bytes: 25420
import java.util.Scanner;

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

        if (a <= b) {
            System.out.println(a);
        } else {
            System.out.println(a - 1);
        }
    }
}

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

int W, H, C;
int field[9][9];
bool visited[9][9];

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

void recolor(int x, int y, int org, int col)
{
    field[x][y] = col;
    
    for(int i=0; i<4; i++) {
	int tx = x + dx[i];
	int ty = y + dy[i];

	if(tx < 0 || ty < 0 || tx >= W || ty >= H) continue;

	if(field[tx][ty] == org)
	    recolor(tx,ty,org,col);
    }
}

int comb(int x, int y)
{
    visited[x][y] = true;
    int res = 1;

    for(int i=0; i<4; i++) {
	int tx = x + dx[i];
	int ty = y + dy[i];

	if(tx < 0 || ty < 0 || tx >= W || ty >= H) continue;

	if(visited[tx][ty]) continue;
	if(field[0][0] != field[tx][ty]) continue;
	
	res += comb(tx,ty);
    }

    return res;
}


int solve(int cnt)
{
    int res = 0;

    int tfield[9][9];
    
    if(cnt == 5) {
	if(field[0][0] != C) return 0;

	memset(visited, 0, sizeof(visited));
	return comb(0,0);
    }
    
    for(int i=1; i<=6; i++) {
	if(field[0][0] == i) continue;

	memcpy(tfield, field, sizeof(field));

	recolor(0,0,field[0][0],i);

	res = max(res, solve(cnt + 1) );

	memcpy(field, tfield, sizeof(field));	
    }

    return res;
}

int main()
{
    while(cin >> H >> W >> C, (H||W||C)) {
	for(int i=0; i<H; i++)
	    for(int j=0; j<W; j++)
		cin >> field[j][i];

	cout << solve(0) << endl;
    }
}

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

const int INF = 2e9;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll mon = 1000LL;
    ll k = 0LL;
    rep(i,n-1){
        if(a[i] < a[i+1]){
            k += mon/a[i];
            mon %= a[i];
        }
        else{
            mon += k*a[i];
            k = 0;
        }
    }
    mon += k*a[n-1];
    cout << mon << endl;
}

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

#define rep(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define vec(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)

int main()
{
    //------------,----
    int n, k;
    cin >> n >> k;
    vec(int, n, h, 0);
    rep(i, n) cin >> h[i];

    sort(h.begin(), h.end(), greater<int>());

    int minN = 1000000100;
    rep(i, n)
    {
        if (i + k > n)
            break;
        minN = min(minN, h[i] - h[i + k - 1]);
    }
    cout << minN << endl;
    //----------------
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return (t % M) * (t % M) % M;
    }
    return (N % M) * (RepeatSquaring(N, P-1, M) % M) % M;
}

//二項係数 mod p
ll modinv(ll n, ll p) {
  ll a = p, u = 1, v = 0;
  while (a) {
    ll t = n / a;
    n -= t * a;
    swap(n, a);
    u -= t * v;
    swap(u, v);
  }
  u %= p;
  if (u < 0) u += p;
  return u;
}

ll ncr(ll n, ll r, ll p) {
  r = min(r, n - r);
  ll ans = 1;
  for (ll i = 0; i < r; i++) {
    ans *= (n - i) % p;
    ans %= p;
  }
  for (ll i = 0; i < r; i++) {
    ans *= modinv(i + 1, p);
    ans %= p;
  }
  return ans;
}

int main() {
  ll n, a, b, p = 1000000007;
  cin >> n >> a >> b;

  ll ans = RepeatSquaring(2, n, p) - 1;
  if (ans < 0) ans += p;
  ll aa = ncr(n, a, p);
  ll bb = ncr(n, b, p);
  ans -= aa;
  if (ans < 0) ans += p;
  ans -= bb;
  if (ans < 0) ans += p;
  cout << ans << endl;
}

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

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

int main() {
    ll K;
    ll sum = 0;
    cin >> K;
    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            for (int k = 1; k <= K; k++) {
                sum += GCD(GCD(i, j), k);
            }
        }
    }

    cout << sum << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define STR_MAX 4000
#define BUF_SIZE (STR_MAX+10)

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

enum {
    ENUM_RED = 0,
    ENUM_GREEN,
    ENUM_BLUE,
    ENUM_ALL
};

char table[256] = {
    ['R'] = ENUM_RED,
    ['G'] = ENUM_GREEN,
    ['B'] = ENUM_BLUE,
};

#define TYPE_ALL ((1<<ENUM_ALL)-1)

int main(void) {
    int len = get_int(); // length
    char str[BUF_SIZE];
    get_str(str, BUF_SIZE);
    int i, j;
    char type[BUF_SIZE] = {0};
    for(i = 0; i < len; i++) {
        type[i] = table[str[i]];
    }
    uint64_t sum[3] = {0};
    // cumulative
    for(i = 0; i < ENUM_ALL; i++) {
        for(j = 0; j < len; j++) {
            sum[i] += (type[j] == i);
        }
    }

    uint64_t cnt = sum[0] * sum[1] * sum[2];

    uint64_t exclude = 0;
    int dist;
    for(dist = 1; dist < len; dist++) {
        for(i = 0; i < len; i++) {
            if(i + dist*2 >= len) continue;
            int tp = (1<<type[i]) | (1<<type[i+dist]) | (1<<type[i+dist*2]);
            if(tp == TYPE_ALL) exclude++;
        }
    }
#ifdef DEBUG
    printf("%llu - %llu\n", cnt, exclude);
#endif
    printf("%llu\n", cnt - exclude);

    return 0;
}

Measured memory_bytes: 1752
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
  
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   
   ll i,n,t;
   cin>>n;
    
   if(n==0) cout<<1<<endl;
   if(n==1) cout<<0<<endl;
}

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

int main() {
    int N; cin >> N;
    long long K; cin >> K;
    vector<long long> A(N); for (int i = 0; i < N; i++) cin >> A[i]; sort(A.begin(), A.end());
    vector<long long> F(N); for (int i = 0; i < N; i++) cin >> F[i]; sort(F.begin(), F.end(), greater<int>());
    long long ll = -1; long long lr = 1e12; long long lc;
    while (lr - ll > 1) {
        lc = (ll + lr) / 2;
        long long t = 0;
        for (int j = 0; j < N; j++) {
            if (lc < A[j] * F[j]) {
                t += (A[j] - (lc / F[j]));
            }
        }
        if (t > K) {
            ll = lc;
        } else {
            lr = lc;
        }
    }
    cout << lr << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;

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

    int n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    ll x=0,y=0,z=0;
    ll ans=1;
    for(int i=0;i<n;i++){
        ll cnt=0;
        if(x==a[i])cnt++;
        if(y==a[i])cnt++;
        if(z==a[i])cnt++;
        if(x==a[i]){
            x++;
        }else if(y==a[i]){
            y++;
            if(y>x)swap(y,x);
        }else if(z==a[i]){
            z++;
            if(z>y)swap(z,y);
            if(y>x)swap(y,x);
        }
        ans*=cnt;
        ans%=MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4364
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    int buka[N] = {};
    REP(i, 1, N) {
        int a; cin >> a;
        buka[--a]++;
    }
    REP(i, 0, N) {
        cout << buka[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4400
def main():
    n = int(input())
    a = list(map(int, input().split()))
    
    s = sum(a)
    minx = s
    sum_a = 0

    for i in range(n):
        sum_a += a[i]
        minx = min(minx, abs(sum_a - (s - sum_a)))

    print(minx)


if __name__ == "__main__":
    main()

Measured memory_bytes: 31592
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  vector<vector<char>> C(2,vector<char>(3));
  rep(i,2) rep(j,3) cin>>C[i][j];
  if(C[0][0]==C[1][2] && C[0][1]==C[1][1] && C[0][2]==C[1][0])
    cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	long n, x, total=0;
	vector<long> a;
	long tmp;
	cin >> n >> x;
	for (int i=0; i < n; i++){
		cin >> tmp;
		total += tmp;
		a.push_back(tmp);
	}
	if (total==x){
		cout << n << endl;
		return 0;
	}else if(total < x){
		cout << n-1 << endl;
		return 0;
	}else{
	    sort(a.begin(), a.end());
		for (int i=0; i < n; i++){
			if(x >= a[i]){
				x -= a[i];
			}else{
				cout << i << endl;
				return 0;
			}
		}
	}
}


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

int main(){
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  
  long long x1, x2, y1, y2;
  x1 = a*c;
  x2 = a*d;
  y1 = b*c;
  y2 = b*d;
  
  cout << max(max(x1, x2), max(y1, y2)) << endl;
     
  
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int A,B;
    cin >> A >> B;
    if(A%3 == 0 || B%3 == 0 || (A+B)%3 == 0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}


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

int main(){
    float a;
float count = 0;
float pro;
    cin >> a;
    for(int i = 1; i < a + 1; i++){
        if(i % 2 != 0)
        count++;
    }
pro = count / a;
cout << pro << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);

	//1063
	static class WatchinTVA {
		void print_max_watchNum() {
			for(;;) {
				int n = sc.nextInt();
				if(n == 0) break;
				List<Program> list = new ArrayList<Program>();
				for(int i=0; i<n; i++) {
					String name = sc.next();
					int weekDay = sc.nextInt();
					int end = sc.nextInt() + 30;
					list.add(new Program(name, toTime(weekDay, end)));
				}
				Collections.sort(list, new ProgramComparator());

				int p = sc.nextInt();
				List<Program> favList = new ArrayList<Program>();
				for(int i=0; i<p; i++) {
					String fav = sc.next();
					for(Program l:list) {
						if(fav.equals(l.name)) {favList.add(l);}
					}
				}
				Collections.sort(favList, new ProgramComparator());

				boolean ans = true;
				for(int i=1; i<p; i++) {
					if(favList.get(i).end - favList.get(i-1).end < 30) ans = false;
				}

				if(!ans) {
					System.out.println(-1);
				}else {
					int num=0, lastP=0;
					for(int i=0; i<n; i++) {
						boolean judge = true;
						for(Program f:favList) {
							if(Math.abs(f.end - list.get(i).end) < 30)
								judge = false;
						}
						if(judge) {
							if(Math.abs(lastP - list.get(i).end) >= 30) {
								num++;
								lastP = list.get(i).end;
							}
						}
					}
					System.out.println(num + p);
				}
			}
		}

		int toTime(int wd, int s) {
			int h = s / 100; int m = s % 100;
			if(h >= 24) {
				h -= 24;
				wd++;
			}
			return (wd*60*24) + (h*60) + m;
		}
	}

	static class Program {
		public String name;
		public int end;
		public Program(String name, int end) {
			this.name = name;
			this.end = end;
		}
	}

	static class ProgramComparator implements java.util.Comparator<Program> {
		public int compare(Program f, Program s) {
			return f.end - s.end;
		}
	}

	public static void main(String[] args) {
		//1063
		WatchinTVA wt = new WatchinTVA();
		wt.print_max_watchNum();
	}
}

Measured memory_bytes: 13000
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#include <cstring>
#include <cstdio>
#include <stack>
#define INF 1000000000
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;
typedef long long int ll;

vector<ll> p(1000001);

void era(){
    for (int i=2; i<1000001; i++) {
        if(p[i]==0)continue;
        int j=i;
        while (j<1000001) {
            j+=i;
            if(j>=1000001)break;
            p[j]=0;
        }
    }
}

int main(){
    rep(i, 1000001) p[i]=i;
    era();
    for(;;){
        int a,d,n;
        cin >> a >> d >> n;
        if(!a and !d and !n)break;
        int ans,i=0,h=a-d;
        while (true) {
            h+=d;
            if(p[h]!=0 and i<n and p[h]!=1)i++;
            if(i==n){
                ans = p[h];
                break;
            }
        }
        cout << ans <<endl;
    }
}

Measured memory_bytes: 8792
fn main() {
    let a = read::<u32>();
    let b = read::<u32>();
    let h = read::<u32>();
    println!("{}", (a + b) * h / 2);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
def main():
    N, K = map(int, input().split())
    D = K.bit_length()
    to = [[0] * D for _ in range(N)]

    for i, a in enumerate(map(int, input().split())):
        to[i][0] = a - 1

    for j in range(D - 1):
        for i in range(N):
            to[i][j+1] = to[to[i][j]][j]

    v = 0
    for i in reversed(range(D)):
        if (K >> i) & 1:
            v = to[v][i]

    print(v + 1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 207096
use std::io;


/// https://beta.atcoder.jp/contests/abc086/tasks/abc086_b
fn main() {
    let (a, b) = {
        let i = read::<u32>();
        (i[0], i[1])
    };
    let sq = a * 10u32.pow(digit(b)) + b;
    for i in 0..317 {
        if i * i == sq { println!("Yes"); return; }
    }
    println!("No");
}

fn digit(n: u32) -> u32 {
    let mut x = n;
    let mut dig = 0;
    while x > 0 {
        dig += 1;
        x = x / 10;
    }
    dig
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
X = [max(V, C) for V, C in zip(V, C) if V > C]
Y = [min(V, C) for V, C in zip(V, C) if V > C]
print(sum(X) - sum(Y))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H, N;
  cin >> H >> N;
  for(int i = 0; i < N; i++){
    int A;
    cin >> A;
    H -= A;
  }
  if(H <= 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 384
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        mut a: u64,
        mut b: u64,
        k: u64,
    }
    if k <= a {
        a -= k;
    } else if k <= a + b {
        b -= k - a;
        a = 0;
    } else {
        a = 0;
        b = 0;
    }
    println!("{} {}", a, b);
}


Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define repr3(i,n) for(int i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF1  100012101;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
 


int main(){
    int N,M,X,count=0;
    cin>>N>>M>>X;
    X--;
    int A[M];
    rep(i,M){
        cin>>A[i];
        A[i]--;
    }
    int left=0,right=0;
    rep(i,N){
        if(i==A[count]){
            count++;
            if(i<X){
                left++;

            }
            else{
                right++;
            }
        }
    }

cout<<min(left,right)<<endl;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,t[1005];
bool flg[10000];


int main(){
  for(int i=0;i<10000;i++)flg[i]=false;

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

  for(int i=0;i<n;i++){
    int num=0;
    for(int j=0;j<4;j++){
      if(i+j>=n)break;
      num=num*10+t[i+j];
      flg[num]=true;
    }
  }
  
  int ans=0;
  while(flg[ans])ans++;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1176
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
#define int ll
signed  main(){
    int a,b; cin>>a>>b;
    if(a>=b/2){cout<<b/2<<endl; return 0;}
    cout<<a+(b-2*a)/4<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

using ll = long long;

int main(){
    string s; cin >> s;
    for(ll i = 0; i < s.length(); i += 2){
        if(s[i] == 'L'){
            cout << "No";
            return 0;
        }
    }
    for(ll i = 1; i < s.length(); i += 2){
        if(s[i] == 'R'){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main( ){

  int N=0,i,key,A[100],j,z;
 
  scanf("%d",&N);


  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
    
  }
  
  for(z=0;z<N-1;z++){
    printf("%d ",A[z]);

  }

  printf("%d\n",A[z]);

    


  

for(i=1;i<N;i++){

  key=A[i];
    
  j=i-1;


  while(j>=0&&A[j]>key){
      
    A[j+1]=A[j];
    j--;
  }
    A[j+1]=key;


  for(z=0;z<N-1;z++){
    printf("%d ",A[z]);

  }

  printf("%d\n",A[z]);

    
 }

return 0;
}
      

  

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

int main() {
  int h,w;
  cin>>h>>w;
  vector<vector<int>>p(10,vector<int>(10));
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      cin>>p.at(i).at(j);
    }
  }
  
  for (int k = 0; k < 10; k++){       // 経由する頂点
    for (int i = 0; i < 10; i++) {    // 始点
      for (int j = 0; j < 10; j++) {  // 終点
        p[i][j] = min(p[i][j], p[i][k] + p[k][j]);
      }
    }
  }
  int Z=0;
  for(int i=0;i<h*w;i++){
    int a;
    cin>>a;
    if(a!=-1){
      Z+=p.at(a).at(1);
             }
  }
      cout<<Z<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

ll k;
const int V=100000;
using P=pair<int,int>;
vector<P> G[V];
int dist[V];
bool used[V];
void dijkstra(){
  fill_n(dist,V,INF);
  fill_n(used,V,false);
  priority_queue<P,vector<P>,greater<P>> q;
  q.push(P(1,1));
  while(!q.empty()){
    int d; int t;
    tie(d,t)=q.top();q.pop();
    if(used[t])continue;
    used[t]=true;dist[t]=d;
    int next=t*10;
    next%=k;
    int value=d;
    if(dist[next]<=value){
      //pass
    }else{
      q.push(P(value,next));
    }
    FOR(i,1,10){
      next=t+i;
      next%=k;
      value=d+i;
      if(dist[next]<=value)continue;
      q.push(P(value,next));
    }
  }
}

int main(){
  cin>>k;
  dijkstra();
  cout<<dist[0]<<endl;
  return 0;
}

Measured memory_bytes: 9200