akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define maxn 2000005
#define mod 998244353
using namespace std;

ll n, m;
ll fac[maxn];

ll power(ll x, ll y)
{
    ll res = 1;
    while (y)
    {
        if (y & 1)
            res = res * x % mod;
        x = x * x % mod;
        y /= 2;
    }
    return res;
}
ll inv(ll x)
{
    return power(x, mod - 2);
}

ll cal(ll N, ll T)
{
    ll res = 0;
    for (int k = 0; k <= m; k++)
    {
        if ((T - k) % 2 != 0)
            continue;
        if (N < k || T < k)
            break;
        ll now = N * inv(fac[k]) % mod * inv(fac[N - k]) % mod;
        now = now * fac[N + (T - k) / 2 - 1] % mod * inv(fac[(T - k) / 2]) % mod;
        res = (res + now) % mod;
    }
    return res;
}

int main()
{
    fac[0] = 1;
    for (int i = 1; i < maxn; i++)
        fac[i] = fac[i - 1] * i % mod;

    cin >> n >> m;
    ll ans = cal(n, 3 * m);
    ll mi = (cal(n, m) + mod - cal(n - 1, m)) % mod;
    mi = n * mi % mod;
    ans = (ans + mod - mi) % mod;
    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 15872
s = input()
ans = [-1, -1]
for i in range(len(s)-2):
    if s[i] == s[i+2]:
        ans = [i+1,i+2+1]
        break
    if s[i] == s[i+1]:
        ans = [i+1,i+2]
        break
if s[len(s)-2] == s[len(s)-1]:
    ans = [len(s)-1,len(s)]

print(ans[0],ans[1])


Measured memory_bytes: 39408
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6,inf=1e9;
int mt[5][5];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  for(int i=1;i<=3;i++)
  {
    for(int j=1;j<=3;j++)
      cin>>mt[i][j];
  }
  int q;cin>>q;
  while(q--)
  {
    int x;cin>>x;
    for(int i=1;i<=3;i++)
    {
      for(int j=1;j<=3;j++)
        if(mt[i][j]==x)mt[i][j]=-1;
    }
  }
  int f=0;
  for(int i=1;i<=3;i++)
  {
    if(mt[i][1]==-1&&mt[i][2]==-1&&mt[i][3]==-1)f=1;
    if(mt[1][i]==-1&&mt[2][i]==-1&&mt[3][i]==-1)f=1;
  }
  if(mt[3][1]==-1&&mt[2][2]==-1&&mt[1][3]==-1)f=1;
  if(mt[1][1]==-1&&mt[2][2]==-1&&mt[3][3]==-1)f=1;
  if(f)cout<<"Yes\n";else cout<<"No\n";
  return 0;
}

Measured memory_bytes: 256
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
from collections import deque
y_drct = [-1,0,1,0]
x_drct = [0,1,0,-1]
def wall(y,x,i):
    if i==0:
        if yw[y-1][x] == 0:return 1
        else: return 0
    if i==2:
        if yw[y][x] == 0:return 1
        else: return 0
    if i==1:
        if tw[y][x] == 0:return 1
        else: return 0
    if i==3:
        if tw[y][x-1] == 0:return 1
        else: return 0
while 1:
    w,h = mi()
    if w == 0 and h == 0:
        break
    tw = []
    yw = []
    for i in range(h-1):
        tw.append(li())
        yw.append(li())
    tw.append(li())
    b = [[-1]*w for i in range(h)]
    l = deque()
    l.append((0,0))
    b[0][0] = 1
    while len(l) > 0:
        cy,cx = l.popleft()
        if cy == h-1 and cx == w-1:
            break
        for i in range(4):
            ny,nx = cy+y_drct[i],cx+x_drct[i]
            if 0 <= ny < h and 0 <= nx < w:
                if b[ny][nx] == -1:
                    if wall(cy,cx,i):
                        l.append((ny,nx))
                        b[ny][nx] = b[cy][cx]+1
    if b[h-1][w-1]==-1:
        print(0)
    else:
        print(b[h-1][w-1])




Measured memory_bytes: 6016
#include<iostream>
#define rep(i,n)for(int i=0;i<n;i++)
#define l int64_t
using namespace std;l q,x,y,f[99]={0,1},m=1e9+7;main(){cin>>q;rep(i,97)f[i+2]=f[i]+f[i+1];rep(i,q){cin>>x>>y;if(x>y)swap(x,y);if(y<=2){cout<<1<<" "<<(y==1?1:x==1?2:4)<<" ";continue;}rep(j,99){if(x<f[j]||y<f[j+1]){l a=x==1?2:1;rep(k,j-2){l n=f[j-1]+f[j-3-k]*f[k+2],m=f[j]+f[j-2-k]*f[k+2];if(n<=x&&m<=y)a+=(y-m)/n+1;}if(f[j]<=x){a++;rep(k,j-2)a+=(x-f[j])/(f[j-2-k]*f[k+2]);}cout<<j-2<<" "<<a%m<<" ";j=99;}}}}

Measured memory_bytes: 4316
#include<stdio.h>
int main(){
int n,a,b,i;
while(1){
b=0;
scanf("%d",&n);
if(n==0)break;
for(i=0;i<n/4;i++){
scanf("%d",&a);
b+=a;
}
printf("%d\n",b);
}return 0;
}

Measured memory_bytes: 0
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(pair<int, int> a, pair<int, int> b) {
	return a.first < b.first;
}
int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<long long, long long> > drinks(n);
	for (int i = 0; i < n; ++i) {
		cin >> drinks[i].first >> drinks[i].second;
	}
	sort(drinks.begin(), drinks.end(), cmp);
	long long ans = 0;
	for (int i = 0; i < n; ++i) {
		if (drinks[i].second <= m) {
			m -= drinks[i].second;
			ans += drinks[i].first * drinks[i].second;
		} else {
			ans += drinks[i].first * m;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/math/common_factor_rt.hpp>

template <class... Args>
struct tuple_input_impl;
template <std::size_t i, std::size_t... tail>
struct tuple_input_impl<std::index_sequence<i, tail...>>
{
    template <class... Args>
    static void f(std::tuple<Args...>& x)
    {
        std::cin >> std::get<i>(x);
        tuple_input_impl<std::index_sequence<tail...>>::f(x);
    }
};
template <>
struct tuple_input_impl<std::index_sequence<>>
{
    static void f(...) {}
};

template <class... Args>
std::istream& operator>>(std::istream& in, std::tuple<Args...>& x)
{
    tuple_input_impl<std::index_sequence_for<Args...>>::f(x);
    return in;
}
template <class T1, class T2>
std::istream& operator>>(std::istream& in, std::pair<T1, T2>& x) { return in >> x.first >> x.second; }

template <class T>
T read()
{
    T res;
    std::cin >> res;
    return res;
}
template <class T>
std::vector<T> read(std::size_t n)
{
    std::vector<T> res(n);
    for (std::size_t i = 0; i < n; ++i) std::cin >> res[i];
    return res;
}

template <class T>
void out_impl(T&& v) { std::cout << std::forward<T>(v); }
template <class T, class... Args>
void out_impl(T&& v, Args&&... args)
{
    std::cout << std::forward<T>(v) << ' ';
    out_impl(std::forward<Args>(args)...);
}
template <class... Args>
void out(Args&&... args)
{
    out_impl(std::forward<Args>(args)...);
    std::cout << '\n';
}
template <class... Args>
void out_noreturn(Args&&... args) { out_impl(std::forward<Args>(args)...); }

template <class T>
void print(const T& container)
{
    bool first = true;
    for (auto&& x : container) {
        if (!first) std::cout << ' ';
        std::cout << x;
        first = false;
    }
    std::cout << '\n';
}

void prog()
{
    auto p = read<int>(read<int>());
    std::sort(std::begin(p), std::end(p));
    p.back() /= 2;
    auto sum = std::accumulate(std::begin(p), std::end(p), 0);
    out(sum);
}

int main()
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    prog();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char str[100005];
int ans[3];
int main(void)
{
    scanf("%s",str);
    int l = strlen(str);
    memset(ans,0,sizeof(ans));
    for(int i = 0;i < l;i++)
    ans[str[i] - 'a']++;
    int cn = 0;
    for(int i = 0;i < 3;i++)
    {
    	if(ans[i])
    	cn++;
	}
	if(cn == 1)
	{
		if(l >= 2)
		printf("NO\n");
		else printf("YES\n");
	}
	else if(cn == 2)
	{
		if(l >= 3)
		printf("NO\n");
		else printf("YES\n");
	}
	else 
	{
		sort(ans,ans+3);
		if(ans[2] > ans[0] + 1||ans[2] > ans[1] + 1)
		printf("NO\n");
		else printf("YES\n");
	}
	return 0;
}

Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a[5];
    rep(i, 5) {
        cin >> a[i];
    }

    int c;
    rep(i, 5) {
        if(!a[i]) c = i;
    }

    cout << c+1 << endl;
}

Measured memory_bytes: 3536
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int q = sc.nextInt();
        for(int i = 0; i < q; i++){
            String order = sc.next();
            int a = sc.nextInt();
            int b = sc.nextInt();
            if(order.equals("print")){
                if(b == str.length() - 1){
                    System.out.println(str.substring(a));
                }else{
                    System.out.println(str.substring(a, b + 1));
                }
            }else if(order.equals("reverse")){
                if(b == str.length() - 1){
                    StringBuffer sb = new StringBuffer(str.substring(a));
                    sb = sb.reverse();
                    str = str.substring(0, a) + sb.toString();
                }else{
                    StringBuffer sb = new StringBuffer(str.substring(a, b + 1));
                    sb = sb.reverse();
                    str = str.substring(0, a) + sb.toString() + str.substring(b + 1);
                }
            }else if(order.equals("replace")){
                String p = sc.next();
                if(b == str.length() - 1){
                    str = str.substring(0, a) + p;
                }else{
                    str = str.substring(0, a) + p + str.substring(b + 1);
                }
            }
        }
    }
}


Measured memory_bytes: 29964
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef pair< int , int > pi;
typedef set< int > se;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define Fn 1.618033987
int main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll mod=1e9+7;
    ll num[1998];
    ll a=3;
    REP(i,0,1997)
    {
        num[i]=a;
        ++a;
    }
    ll S;
    cin>>S;
    if(S<=2)
    {
        cout<<0<<'\n';
    }
    else{
    vector< ll >ways(S+1,0);
    ways[0]=1;
    REP(i,1,S)
    {
        for(int X:num)
        {
            if(i-X>=0)
            {
                ways[i]=((ways[i]%mod)+(ways[i-X]%mod))%mod;   
            }
        }
    }
    cout<<ways[S]<<'\n';
    }
    return 0; 
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    ll N;
    cin >> N;
    vector<ll> A(N);
    for(size_t i=0;i<N; i++)
    {
        cin >> A[i];
    }
    sort(A.rbegin(), A.rend());
    ll comfortable = A[0];
    for(size_t i=1;i<N/2; i++)
    {
        comfortable += A[i]*2;
    }
    if(N%2==1) comfortable += A[N/2];
    cout << comfortable << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 4712
#include <iostream>
#include <stdio.h>
#include <vector>
#include <math.h>

#define inf 2147483647

using namespace std;

int main() {
    int n, tmp;
    vector<int> a;
    cin >> n;
    cin >> tmp;
    a.push_back(tmp);
    cin >> tmp;
    a.push_back(tmp);
    for (int i = 1; i < n; ++i) {
        cin >> tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    //--n;
    //vector<vector<int>> m(n + 1, vector<int>(n + 1, 0));
    //vector<vector<int>> s(n, vector<int>(n + 1, 0));
    int m[1001][1001];
    int s[1001][1001];
    for (int l = 2; l <= n; ++l) {
        for (int i = 1; i <= n - l + 1; ++i) {
            int j = i + l - 1;
            m[i][j] = inf;
            for (int k = i; k <= j - 1; ++k) {
                int q = m[i][k] + m[k + 1][j] + a[i - 1] * a[k] * a[j];
                if (q < m[i][j]) {
                    m[i][j] = q;
                    s[i][j] = k;
                }
            }
        }
    }
    cout << m[1][n] << endl;
    return 0;
}


Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<=n;i++)
typedef long long ll;
typedef vector<int> vec;
long min(long a,long b){
if(a>b)return b;
  return a;
}
long max(long a,long b){
if(a>b)return a;
  return b;
}

int main(){
  long a,b,n,ans=0,t,memo=0,f; cin>>a>>b>>n;
    bool ok=false;
  
  if(n<=1000000){
  
    t=min(1000000,n);
  
    rep(i,t){
    ans=max(ans,(a*i)/b - a*(i/b));
    }
  }
  
  else{
    for(int i=0;i<=n;i+=1000000){
      f=(a*i)/b - a*(i/b);
      if(ans>f){ok=true; memo=i; break;}
      else ans=f;

      if(n-i<1000000){ok=true; memo=i; break;}
    }
    
    if(ok){
      t=min(memo+1000000,n);
      for(int i=memo;i<=t;i++){ans=max(ans,(a*i)/b - a*(i/b));}
    }
  }
  

  cout<<ans<<endl;

}

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
const int mod = 1000000007;
#define ll long long

struct edge {
	int to;
	ll cost;
};
vector<edge> G[100010];
ll point[100010];
ll ans[100010];
void dfs(int v, int parent) 
{
	for (int i = 0; i < G[v].size(); i++) {
		if (G[v][i].to == parent) {
			continue;
		}
		point[G[v][i].to] = point[v] + G[v][i].cost;
		dfs(G[v][i].to, v);
	}
}

int main()
{
	int N, Q, K;
	cin >> N;
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		ll c;
		cin >> a >> b >> c;
		G[a].push_back({ b,c });
		G[b].push_back({ a,c });
	}
	cin >> Q >> K;
	dfs(K, -1);
	for (int i = 0; i < Q; i++) {
		int x, y;
		cin >> x >> y;
		ans[i] = point[x] + point[y];
	}
	for (int i = 0; i < Q; i++) {
		cout << ans[i] << endl;
	}
}



Measured memory_bytes: 16640
from collections import deque

def bfs(maze, a):
  queue = deque([1])

  while queue:
    x = queue.popleft()
    for i in maze[x - 1]:
      if(a[i - 1] == -1):
        a[i - 1] = x
        queue.append(i)
      
if __name__ == '__main__':
  n, m = map(int, input().split())
  maze = [[] for i in range(n)]
  for i in range(m):
    a, b = map(int, input().split())
    maze[a - 1].append(b)
    maze[b - 1].append(a)

  visit = [(-1)] * n
  visit[0] = 0

  bfs(maze, visit)

if(-1 in maze):
  print('No')
else:
  print("Yes")
  for i in range(1, n):
    print(visit[i])


Measured memory_bytes: 34044
#include <stdio.h>
int main(){
	int a,b,c;
	int x5=0,x7=0;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
  
  	switch(a){
      case 5:
        x5++;
        break;
      case 7:
        x7++;
    }
  
   	switch(b){
      case 5:
        x5++;
        break;
      case 7:
        x7++;
    }
  
   	switch(c){
      case 5:
        x5++;
        break;
      case 7:
        x7++;
    }
  
  if(x5==2 && x7==1){
    	printf("YES");
  } else {
    	printf("NO");
  }
}

Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class BPowerSocket {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int a, b; cin >> a >> b;
      int r = ((b-1)+(a-2))/(a-1);
      cout << r << endl;
    }
};

signed main() {
  BPowerSocket solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("-Ofast","-funroll-all-loops","-ffast-math")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <cmath>
#include <chrono>
#include <cstring>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <bitset>
#include <cassert>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define endl '\12'
#define eb emplace_back
#define SZ(a) int32_t(a.size())
#define ALL(x) (x).begin(),(x).end()
#define trav(a,x) for (auto& a: x)
#define LOG(FMT...) fprintf(stderr, FMT)
#define close std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define CASET int ___T; cin>>___T; for(int __CS=1;__CS<=___T;__CS++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
constexpr int mod = 1e9+7;
constexpr int Erica = 998244353;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count()); 
int rnd(int x) { return mrand() % x;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ex_gcd(ll a, ll b, ll& x, ll& y){if(!b){x=1;y=0;return a;}ll ret=ex_gcd(b,a%b,y,x);y-=a/b*x;return ret;}
LL bin(LL x, LL n, LL MOD) {LL ret = MOD != 1;for (x %= MOD; n; n >>= 1, x = x * x % MOD)if (n & 1) ret = ret * x % MOD;return ret;}
int norm(int x) { return x >= mod ? (x - mod) : x; }
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
inline ll get_inv(ll a) { ll x, y; ex_gcd(a, mod, x, y); return norm(x + mod);}
template<class T>inline void umin(T &x, T y) {x = x > y ? y : x;}
template<class T>inline void umax(T &x, T y) {x = x < y ? y : x;}
template<class T>inline void dec(T &x, T y) {x -= y; if(x < 0) x += mod;}
template<class T>inline void add(T &x, T y) {x += y; if(x >= mod) x -= mod;}
const double PI = acos(-1.0);
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr ull base=2333, P_1=19260817, P_2=999998639;
constexpr int maxn = 1e6+10; // remember to calculate. if tle, check maxn first.
vi ans;
ll a[maxn];
int main()
{
    ll n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll s = 0;
    for(int i = 0; i < n; i++){
        if(i & 1){
            s-=a[i];
        }else {
            s+=a[i];
        }
    }
    ans.eb(s);
    for(int i = 0; i < n-1; i++){
        ans.eb(2*a[i]-ans.back());
    }
    for(int i = 0; i < n; i++){
        cout << ans[i] << " \n"[i == n-1];
    }
    return 0;
}

Measured memory_bytes: 4612
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        Map<Integer, Set<Integer>> tree = new HashMap<>();
        for (int i = 1; i < n; i++) {
            int a = scanner.nextInt() - 1;
            int b = scanner.nextInt() - 1;
            tree.computeIfAbsent(a, key -> new HashSet<>()).add(b);
            tree.computeIfAbsent(b, key -> new HashSet<>()).add(a);
        }

        int[] c = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            c[i] = scanner.nextInt();
            sum += c[i];
        }
        Arrays.sort(c);

        System.out.println(sum - c[n - 1]);

        int[] a = new int[n];
        boolean[] visited = new boolean[n];

        Deque<Integer> deque = new ArrayDeque<>();
        deque.add(0);
        int index = n - 2;
        visited[0] = true;
        a[0] = c[n - 1];
        while (!deque.isEmpty()) {
            int i = deque.poll();
            for (int j : tree.get(i)) {
                if (!visited[j]) {
                    a[j] = c[index--];
                    visited[j] = true;
                    deque.add(j);
                }
            }
        }

        for (int i : a) {
            System.out.println(i);
        }
    }
}

Measured memory_bytes: 47632
def extgcd(a, b):
    if b == 0:
        return a, 1, 0
    else:
        d, y, x = extgcd(b, a%b)
        y -= a // b * x
        return d, x, y
a, b = map(int, input().split())
_, x, y = extgcd(a, b)
print(x, y)


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

using namespace std;

int main() {

	long k, s;
	cin >> k >> s;

	long counter = 0;
	for (long i = 0; i <= k; i++) {
		for (long j = 0; j <= k; j++) {
			if (s - i - j >= 0 && s - i - j <= k) { counter++; }
		}
	}
	cout << counter << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
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;}

const int INF = 100000; 

int main(){
    int a, b, c;
    cin >> a >> b >> c;

    if(a == b){
        cout << c << endl;
    }else if(a == c){
        cout << b << endl;
    }else{
        cout << a << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N,A,B;

int sumdig(int n){
	int ans = 0;
	while(n!=0){
		ans += (n%10);
		n/=10;
	}
	return ans;
}
int ans;
int main(){
	scanf("%d%d%d",&N,&A,&B);
	for(int i=1;i<=N;i++){
		if(sumdig(i) >= A && sumdig(i) <= B) ans += i;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{   
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    int cnt = 0;
    int even_cnt = 0;
    rep(i,n) if(a[i]%2==0) ++even_cnt;

    while(even_cnt==n)
    {
        even_cnt = 0;
        rep(i,n)
        {
            a[i] /= 2;
            if(a[i]%2==0) ++even_cnt;
        }
        ++cnt;
    }
    
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
string s;
int K;
ll dp[110][2][5] = {0};
int main(void){
    cin >> s >> K;

    dp[0][0][0] = 1;

    //cout << s.size() << endl;

    for(int i = 0; i < s.size(); i++){
        int now = s[i] - '0';
        for(int j = 0; j < 2; j++){
            for(int k = 0; k <= 3; k++){
                for(int l = 0; l <= (j?9:now); l++){
                    if(k == 3){
                        if(l != 0) break;
                        dp[i + 1][j||(l < now)][k] += dp[i][j][k];
                        break;
                    }
                    dp[i + 1][j||(l < now)][(l==0?k:k + 1)] += dp[i][j][k];
                }
            }
        }
    }

    cout << dp[s.size()][0][K] + dp[s.size()][1][K] << endl;
}

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

using namespace std;

int main() {
	int n, k, q; cin >> n >> k >> q;
	vector<int> num(n);
	for (int i = 0; i < q; ++i) {
		int a;
		cin >> a;
		num[a - 1]++;
	}
	for (int i = 0; i < n; ++i) {
		if (k - (q - num[i]) > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;
}

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

using namespace std;

const int inf = 1e9 + 10;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<int> dp(n, inf);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= k; j++) {
      if (i + j < n) {
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
      }
    }
  }
  cout << dp[n - 1] << "\n";
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << s1[0] << s2[1] << s3[2] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int n,m,o;
  scanf("%d",&n);
  scanf("%d",&m);
  scanf("%d",&o);
  if(n==m && m==o)
  {
    printf("No");
  }
  else if(n!=m && m!=o && n!=o)
  {
      printf("No");
  }
  else
  {
      printf("Yes");
  }
  return 0;
}


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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main ()
{
    fastio
    lli num ;
    cin >> num ;
    if (num % 2 == 0)
        cout << num ;
    else if (num % 2 == 1)
        cout << num * 2 ;

    // 1 2 3 4 5 6 7 8 9 10 11 12

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */



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

    int n, k; cin >> n >> k;
    vector<int> p(n);
    rep(i, n) cin >> p[i];

    double ans = 0.0;
    double tmp = 0.0;
    rep(i, k) tmp += (p[i]+1) / 2.0;
    ans = tmp;
    repr(i, k, n) {
        tmp += (p[i]+1) / 2.0;
        tmp -= (p[i-k]+1) / 2.0;
        chmax(ans, tmp);
    }
    cout << fixed << setprecision(10) << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
using namespace std;
#define reg register
typedef unsigned long long ll;
const int N=1010,p=1e9+7;
int T,ans1,ans2;
int inc(int x,int y){x+=y;return x>=p?x-p:x;}
struct seq{
	ll f[N];
	int cnt,ans1,ans2;
	void init(int start){
		for (cnt=start+1;f[cnt-1]+f[cnt-2]<=1e18;cnt++)
			f[cnt]=f[cnt-1]+f[cnt-2];
		cnt--;
		for (int i=cnt+1;i<N;i++) f[i]=2e18+1;
	}
	inline int rank(reg ll x){
		reg int l=1,r=cnt,mid;
		while (l<r){
			mid=(l+r)>>1;
			if (f[mid+1]<=x) l=mid+1;else r=mid;
		}
		return l;
	}
	inline void calc(reg ll x,reg ll y){
		reg int a=rank(x);
		if (y<f[a+1]){
			ans1=--a;
			ans2=((y-f[a-1])/f[a]+(x-f[a-1])/f[a])%p;
		}
		else{
			ans1=a;
			ans2=(y-f[a-1])/f[a]%p;
		}
	}
}A[N];
ll n,m,fib[N];
int times[N][N],Max[N][N],cnt[N][N];
void init_times(){
	for (int i=1;i<N;i++)
	for (int j=1;j<N;j++){
		int x=i,y=j;
		if (x<y) swap(x,y);
		times[i][j]=times[y][x%y]+1;
		Max[i][j]=max(times[i][j],max(Max[i-1][j],Max[i][j-1]));
		if (Max[i][j]==times[i][j]) cnt[i][j]++;
		if (Max[i][j]==Max[i-1][j]) cnt[i][j]+=cnt[i-1][j];
		if (Max[i][j]==Max[i][j-1]) cnt[i][j]+=cnt[i][j-1];
		if (Max[i][j]==Max[i-1][j-1]) cnt[i][j]-=cnt[i-1][j-1];
	}
}
ll read(){
	ll x=0;char ch=getchar();
	while (ch>'9'||ch<'0') ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
void print(int x){
	if (!x) return void(putchar('0'));
	static char str[30];
	int l=0;
	for (;x;x/=10) str[++l]=x%10;
	while (l) putchar(str[l--]+'0');
}
int main()
{
	init_times();
	fib[0]=fib[1]=1;
	for (int i=2;i<=87;i++) fib[i]=fib[i-1]+fib[i-2];
	for (int i=1;i<=87;i++){
		for (int j=0;j<=i+1;j++) A[i].f[j]=fib[j];
		A[i].f[i+1]+=fib[i];
		A[i].init(i+1);
	}
	scanf("%d",&T);
	while (T--){
		n=read();m=read();
		if (n>m) swap(n,m);
		/*if (n<N&&m<N){
			printf("%d %d\n",Max[n][m],cnt[n][m]);
			continue;
		}*/
		if (n==1){
			printf("1 %d\n",int(m%p));
			continue;
		}
		if (n==2&&m==2){
			puts("1 4");
			continue;
		}
		A[87].calc(n,m);
		ans1=A[87].ans1;
		ans2=A[87].ans2;
		for (int i=86;i;i--) A[i].calc(n,m);
		for (int i=86;i;i--)
			if (A[i].ans1==ans1&&ans1>i)
				ans2=inc(ans2,A[i].ans2);
		print(ans1);
		putchar(' ');
		print(ans2);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 18304
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    int m, d;
    cin >> m >> d;

    int ans = 0;
    for (int i = 1; i <= d; ++i) {
        int a = i%10, b = i/10;
        if (a < 2 || b < 2) continue;
        int c = a*b;
        if (c <= m) ++ans;
    }

    cout << ans << endl;

    return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

vector<pii> xy;

double dist(pii a, pii b){
    double x1,y1,x2,y2;
    tie(x1,y1) = a;
    tie(x2,y2) = b;
    double dx = x1 - x2;
    double dy = y1 - y2;
    return sqrt(dx * dx + dy * dy);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    xy.resize(n);
    REP(i,n)cin >> xy[i].first >> xy[i].second;
    vector<int32> a(n);
    REP(i,n)a[i] = i;
    double ans = 0;
    do{
        REP(i,n-1)
            ans += dist(xy[a[i]], xy[a[i+1]]);
    }while(next_permutation(ALL(a)));
    FOR(i,1,n+1)ans /= i;
    printf("%.10f\n",ans);
    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int h, w;
int c[10][10];

int main() {
    ios_base::sync_with_stdio(false);
    cin >> h >> w;
    forn(i, 10) forn(j, 10) cin >> c[i][j];
    forn(k, 10) forn(i, 10) forn(j, 10) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    }
    int ans = 0;
    forn(i, h) forn(j, w) {
        int x;
        cin >> x;
        if (x != -1) {
            ans += c[x][1];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<queue>
using namespace std;
typedef long double ld;
typedef long long int ll;
const ll INF = (1LL << 63);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define rep(i,n) for(int i = 0; i < n;i++)
const int MAX = 1000000010;
const ll MOD = 1000000007;
int st[1010][1010];
int main() {
    ll n, k; cin >> n >> k;
    ll sum = 1LL * n * n;
    if (k == 0) {
        cout << sum << endl;
        return 0;
    }
    for (int b = 1; b <= n; b++) {
        if (b > k) sum -= n / b * k + min(k, n % b + 1) - 1;
        else sum -= n;
    }cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String s = sc.next();
		char[] S = s.toCharArray();
		boolean key = true;
		if (N%2 == 0) {
			for (int i = 0; i < S.length/2; i++) {
				if (S[i] != S[S.length/2+i]) {
					key = false;
				}
			}
		} else {
			key = false;
		}
		System.out.println(key? "Yes" : "No");
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T1, class T2>
bool chmax(T1 &a, const T2 b){if(a < b){a = b; return true;} return false;}
template <class T1, class T2>
bool chmin(T1 &a, const T2 b){if(a > b){a = b; return true;} return false;}
ll pow2(const int n){return (1LL << n);}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (const T &i : v) os << i << ' ';
    return os;
}
void co() { cout << '\n'; }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    cout << head << ' ';
    co(forward<Tail>(tail)...);
}
void ce() { cerr << '\n'; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    cerr << head << ' ';
    ce(forward<Tail>(tail)...);
}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1000000001;
constexpr ll LINF = 1000000000000000001;
constexpr ll MOD = 1000000007;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

int main(void) {
    ll n, k;
    cin >> n >> k;
    Vec2<ll> a(n, Vec(n));
    rep(i, n) rep(j, n) cin >> a[i][j];

    const ll sz = n * n + 2 * n + 2, n2 = n * n;
    mcf_graph<int, ll> mcf(sz);
    mcf.add_edge(sz - 2, sz - 1, n * k, INF);
    rep(i, n){
        mcf.add_edge(sz - 2, n2 + i, k, 0);
        mcf.add_edge(n2 + n + i, sz - 1, k, 0);
        rep(j, n){
            mcf.add_edge(n2 + i, i * n + j, 1, INF - a[i][j]);
            mcf.add_edge(i * n + j, n2 + n + j, 1, 0);
        }
    }

    auto p = mcf.flow(sz - 2, sz - 1, n * k);
    co(n * k * INF - p.second);

    vector<string> ans;
    string s;
    rep(i, n) s += '.';
    rep(i, n) ans.push_back(s);
    auto edges = mcf.edges();
    for (auto e : edges) {
        if(e.to >= 0 && e.to < n2){
            if (e.flow) ans[e.to / n][e.to % n] = 'X';
        }
    }
    rep(i, n) co(ans[i]);

    return 0;
}

Measured memory_bytes: 4288
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    double a = Math.sqrt(n);

    //System.out.println(a);
    for(int i = (int)a; i > 0 ; i--){
        if(n % i == 0){
            System.out.println(i + (n/i) - 2);
            System.exit(0);
        }
    }
    
    
	}
}

Measured memory_bytes: 22612
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int A[1010][1010];

int main() {
    int n;
    scanf("%d", &n);
    int t = 1;
    while(t <= n) n -= t++;
    t--;
    if(n) {
        puts("No");
        return 0;
    }
    puts("Yes");
    printf("%d\n", t + 1);
    int cnt = 0;
    for(int i = 1; i <= t + 1; i++)
        for(int j = i + 1; j <= t + 1; j++)
            A[i][j] = (A[j][i] = ++cnt);
    for(int i = 1; i <= t + 1; i++) {
        printf("%d ", t);
        for(int j = 1; j <= t + 1; j++)
            if(i != j) printf("%d ", A[i][j]);
        putchar('\n');
    }
}

Measured memory_bytes: 3072
import java.util.Scanner;

enum Order{
	print,
	reverse,
	replace
};

class Main {
  public static void main(String args[]) {
	Scanner scanner = new Scanner(System.in);
	String  inp = scanner.next();
  	String order;
  	Order  change;
  	int num = scanner.nextInt();
  	int count = 0;
  	boolean Judge = true;
  	
  	//change = Order.print;
  	change = null;
  	
  	while( Judge ){
  		order = scanner.next();

  		//命令判別
  		if( order.equals("print") ) {
  			change = Order.print;
  		}
  		if( order.equals("reverse") ) {
  			change = Order.reverse;
  		}
  		if( order.equals("replace") ) {
  			change = Order.replace;
  		}
  		
  		//命令ごとに処理
  		if( change != null ) {
	  		switch(change) {
	  		case print:
	  			print(inp,scanner);
	  			break;
	  		case reverse:
	  			inp = reverse(inp,scanner);
	  			break;
	  		case replace:
	  			inp = replace(inp,scanner);
	  		}
  		}
  		
  		count ++;
  		if(count >= num) {
  			Judge = false;
  			break;
  		}
  			
  	}
  	
	
  	//後処理
	scanner.close();
  }
  
  public static void print( String inpData ,Scanner scanner){
		int sta = scanner.nextInt();
		int end = scanner.nextInt();
		
  		String substr = inpData.substring(sta, end + 1);
		//出力
		System.out.println(substr);
  }
  
  public static String reverse( String inpData ,Scanner scanner){
		int sta = scanner.nextInt();
		int end = scanner.nextInt();
  		//入れ替え
  		String substr = inpData.substring(sta, end + 1);
		StringBuffer sb = new StringBuffer(substr);
  		String repstr = sb.reverse().toString();
		inpData = inpData.replaceFirst(substr, repstr);
		
		return inpData;
  }
  
  public static String replace( String inpData , Scanner scanner){
		int sta = scanner.nextInt();
		int end = scanner.nextInt();
		
		String rep = scanner.next();
		//置換
		StringBuilder stb = new StringBuilder(inpData);
		StringBuilder repstr = stb.replace(sta, end + 1 , rep );
		String str = new String(repstr);
		//inpData = inpData.substring(sta, end + 1).replace(substr, rep);
		inpData = str;
		
		return inpData;
  }
  
}




Measured memory_bytes: 30644
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}
int main()
{
    ld A,B;
    cin>>A>>B;
    ll C=floor(A*B);
    cout<<C<<endl;
}

Measured memory_bytes: 3772
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();
	int d,r;
	double f;
	
	d = a/b;
	r = a%b;
	f = (double)a/b;
	
	System.out.printf("%d %d %f\n" ,d,r,f);
	sc.close();
	}
}



Measured memory_bytes: 26536
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
w,h,x,y=IL()
if w%2==0 and h%2==0 and x==w//2 and y==h//2:
    print(w*h/2,"1")
else:
    print(w*h/2,"0")

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
    int n;
    cin >> n;
    vector<int> arr(n, 0);
    for(int& val: arr)
        cin >> val;
    int GCD = arr[0];
    for(int i = 1; i < arr.size(); i++) {
        GCD = __gcd(GCD, arr[i]);
    }
    int ans = 0;
    while (GCD % 2 == 0) {
        GCD /= 2;
        ans += 1;
    }
    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
//#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n  ;
    cin >> n;
    string l;
    cin >> l;
    if(l.size() <= n) {
        cout << l << '\n';
    } else {
        vector<char> a(n+3);
        for(int i = 0; i<n; i++) {
            a[i] = l[i];
        }
        a[n] = '.';
        a[n+1] = '.';
        a[n+2] = '.';
        for(int j = 0; j<n+3;j++) {
        cout << a[j];
    }
    cout <<'\n';
    }
    
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

long C(int a, int b){
  int i,j;
  long x[2000][2000];
  x[0][0]=1;
  for(i=1;i<2000;i++) x[0][i]=0;
  for(i=1;i<=a;i++){
    x[i][0]=1;
    for(j=0;j<=b;j++){
      x[i][j]=(x[i-1][j-1]+x[i-1][j])%1000000007;
    }
  }
  return x[a][b];
}

int main()
{
  int i,n,k,v;
  long blue,red,ans;
  scanf("%d%d", &n, &k);
  v=n-k;
  for(i=1;i<=k;i++){
    if(i>v+1){
      printf("0\n");
    }else{
      //blue=fact(k-1)/fact(k-i)/fact(i-1);
      blue=C(k-1,i-1);
      //red=fact(v+1)/fact(v+1-i)/fact(i);
      red=C(v+1,i);
      ans=blue*red;
      //printf("%d %d %d\n", blue,red,ans%1000000007);
      printf("%ld\n", ans%1000000007);
    }
  }
  return 0;
}

Measured memory_bytes: 30976
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define MXN 200005
#define FOR(i, a, b) for (int i=a; i<(b); i++)
/*long long pow(long long a, long long b) {

    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;*/

/*ll dfs(ll i,ll cnt,bool vis[],vector<ll>v[]){
if(v[i].size()==1&&i!=1){vis[i]=1;return pow(4,cnt,r);}
ll j=0;ll res=0;vis[i]=1;
while(j< v[i].size()){
 if(vis[v[i][j]]==0){
    res=res%r+(dfs(v[i][j],cnt+1,vis,v))%r;

 }


 j++;
}
return res;

}*/
/*ll b_s(vector<ll> b,ll l,ll r){
    ll m=(l+r)/2;
if(l>r)return 0;
else if(r>=l){
    ll cnt=0;
    for(ll i=0;i<b.size();i++){
        cnt=cnt+b[i]/m;
    }
    if(cnt>=k){c.pb(m); return b_s(b,m+1,r);}
    else if(cnt<k) return b_s(b,l,m-1);
}

}
*/


ll dp[10][10][10][10];
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    //FOR(i,0,10){FOR(j,0,10){FOR(p,0,10){FOR(q,0,10){dp[i][j][p][q]=10000ll;}}}}
    ll n;cin>>n;ll arr[n];vector<ll>v;
    for(ll i=0;i<n;i++){cin>>arr[i];}
    v.pb(arr[0]-1);bool f=false;
    for(ll i=1;i<n;i++){
        if(v[i-1]<arr[i]){
            v.pb(arr[i]-1);
        }
        else if(v[i-1]==arr[i])v.pb(arr[i]);
        else if(v[i-1]>arr[i]){f=true;break;}
    }
if(f)cout<<"No";
else cout<<"Yes";
}



Measured memory_bytes: 2168