akhauriyash/Code-Regression huggingface dataset:
int main(){
    int x,y;
    int I=0,J=0;
    int num[12]={1,3,5,7,8,10,12,4,6,9,11,2};
    scanf("%d%d",&x,&y);
    for(int i=0;i<12;i++){
        if(x==num[i])I=i;
        if(y==num[i])J=i;
    }
    if((I<=6&&J<=6)||(I>=7&&I<=10&&J>=7&&J<=10))printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;
 
int main() {
    int n, p[20],ans=0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    for (int i = 1;i < n - 1;i++) {
        if (p[i - 1] < p[i] && p[i] < p[i + 1] || p[i + 1] < p[i] && p[i] < p[i - 1]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) for(auto &i:vec)fprintf(stderr,"%ld ",i);puts("");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	ll n;
	scanf("%ld", &n);
	std::map<std::string, ll> mp;
	rep(i, 0, n){
		std::string s;
		std::cin >> s;
		std::sort(be(s));
		mp[s]++;
	}
	ll ans = 0;
	for(auto p: mp) ans += p.second * (p.second-1) / 2;
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I=ll(A);I<ll(B);++I)

int main(){
	string s;
	while(cin>>s){
		if(s=="-")break;
		int n,h,l=s.size();
		cin >> n;
		FOR(i,0,n){
			cin >> h;
			s = s.substr(h,l-h)+s.substr(0,h);
		}
		cout << s << "\n";
	}
}


Measured memory_bytes: 3164
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools





def main():
    s = list(input())
    t = list(input())

    ans = 0
    for i in range(3):
        if s[i] == t[i]:
            ans += 1
    print(ans)




if __name__ == '__main__':
    main()



Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    int N;
    cin >> N;
    cout << ( N >= 1000 ? "ABD" : "ABC" ) << endl;
    return 0;
}

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

using ll = long long;

const int maxN = 1e5 + 10;

int N, W, v[111], w[111];
ll mem[111][maxN];

ll dp(int i, int cap)
{
    if (i == N)
        return 0;

    if (mem[i][cap] != -1)
        return mem[i][cap];

    ll path1 = dp(i + 1, cap);
    ll path2 = 0;

    if (cap + w[i] <= W)
        path2 = v[i] + dp(i + 1, w[i] + cap);

    return mem[i][cap] = max(path1, path2);
}

int main()
{
    memset(mem, -1, sizeof(mem));

    scanf("%d%d", &N, &W);

    for (int i = 0; i < N; i++)
        scanf("%d%d", &w[i], &v[i]);

    printf("%lld", dp(0, 0));
}

Measured memory_bytes: 87040
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

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

const ll base = 1000005;

ll N;
ll a[60], d[60];
std::vector<P> ps;
ll ma = 0, mi = 1ll<<60, mai, mii;

int main()
{
  std::cin >> N;

  rep( i, N )
  {
    std::cin >> a[i];

    if( chmax( ma, a[i] ) )
      mai = i;

    if( chmin( mi, a[i] ) )
      mii = i;
  }

  if( ma > -mi )
  {
    rep( i, N )
    {
      if( a[i] < 0 )
        ps.emplace_back( P( mai, i ) );
    }
  
    rep( i, N-1 )
      ps.emplace_back( P( i, i+1 ) );
  }
  else
  {
    rep( i, N )
    {
      if( a[i] > 0 )
        ps.emplace_back( P( mii, i ) );
    }

    for( int i = N-1; i > 0; --i )
      ps.emplace_back( P( i, i-1 ) );
  }

  std::cout << ps.size() << std::endl;

  for( auto p : ps )
    std::cout << p.first+1 << ' ' << p.second+1 << std::endl;

  return 0;
}

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

long long n,ans=LLONG_MAX;

int main()
{
	cin>>n;

	int r=sqrtl(n);
	for(int i=1;i<=r;i++)
	{
		if(n%i) continue;
		long long d1=i,d2=n/i;
		ans=min(ans,d1+d2-2);
	}
	cout<<ans;
}

Measured memory_bytes: 3704
using System;
using System.Collections;
using System.Linq;
class Program
{
    static int Main()
    {
        //int n = int.Parse(Console.ReadLine());
        //string[] s = Console.ReadLine().Split(' ');

        string s = Console.ReadLine();
        if (s == "abc" || s == "acb" || s == "bac" || s == "bca" || s == "cab" || s == "cba")
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
        return 0;
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

Int calc(vector<Int>& a, Int b, Int N) {
	Int sum = 0;
	for (Int i = 0; i < N; i++) {
		sum += abs(a[i] - b);
	}
	return sum;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	vector<Int> Man(N);

	Int temp = 0;
	for (Int i = 0; i < N; i++) {
		cin >> temp;
		Man[i] = temp - (i + 1);
	}

	sort(Man.begin(), Man.end());

	Int ans = 0;
	if (N % 2) {
		ans = calc(Man, Man[N / 2], N);
		cout << ans << endl;
		return 0;
	}

	ans = min(calc(Man, Man[N / 2], N), calc(Man, Man[N / 2 - 1], N));
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        char a = scan.next().charAt(0);
        char b = scan.next().charAt(0);

        if (a == b) {
            System.out.println("H");
        } else {
            System.out.println("D");
        }
    }
}

Measured memory_bytes: 23124
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
#sys.stdin = open("input.txt", "r")
#sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


    


N,M=l()
g=[[]  for i in range(N+1)]
for i in range(M):
    a,b=l()
    g[a].append(b)
    g[b].append(a)
pos=0
for j in g[1]:
    if(N in g[j]):
        pos=1
        break
if(N in g[1] or pos):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


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

int main(){
  ll a, b, c;  cin >> a >> b >> c;
  ll ans = 0LL;
  if(b >= c) ans += b + c;
  else {
    ans += 2 * b + 1;
    c -= b + 1;
    ans += min(a, c);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  long long ans;
  if(n != 1)
    ans = k * pow((k-1LL), (n-1LL));
  else
    ans = k;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
def main():
    N = int(input())
    *A, = map(int, input().split())

    money = 1000

    low = A[0]
    high = -1
    for x in A:
        if high < x:
            high = x
            continue

        if high > x:
            money += (high - low) * (money // low)
            low = high = x

    money += max(0, high - low) * (money // low)

    print(money)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9160
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
using namespace std;

int main()
{
	while (1) {
		int n, m; cin >> n >> m;
		if (n == 0)break;

		vector<int>h(n + 1), w(m + 1);
		for (int i = 0; i < n; i++)cin >> h[i + 1];
		for (int i = 0; i < m; i++)cin >> w[i + 1];
		for (int i = 1; i <= n; i++)h[i] += h[i - 1];
		for (int i = 1; i <= m; i++)w[i] += w[i - 1];

		vector<int>hs(1500001), ws(1500001);

		for (int i1 = n; i1 >= 0; i1--) {
			for (int j1 = i1 + 1; j1 < n + 1; j1++) {
				hs[h[j1] - h[i1]]++;
			}
		}

		for (int i2 = m; i2 >= 0; i2--) {
			for (int j2 = i2 + 1; j2 < m + 1; j2++) {
				ws[w[j2] - w[i2]]++;
			}
		}

		long long ans = 0;
		for (int i = 1; i <= 1500000; i++) {
			ans += hs[i] * ws[i];
		}

		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 14564
#include <bits/stdc++.h>
#define int long long
#define all(c) (c).begin(),(c).end()
#define pii pair<long long,long long>
#define endl '\n'

using namespace std;

signed main(){
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--){
        int n,m;
        cin >> n>>m;
        vector <int> H(n+1,0);
        for(int i=1;i<=n;i++){
            cin >> H[i];
        }
        vector <vector<int>> A(n+1);
        for(int i=0;i<m;i++){
            int a,b;
            cin >> a >> b;
            A[a].push_back(b);
            A[b].push_back(a);
        }
        int ans=0;
        for(int i=1;i<=n;i++){
            bool f=true;
            for(int j=0;j<A[i].size();j++){
                if(H[i]<=H[A[i][j]]){
                    f=false;
                    break;
                }
            }
            if(f){
                ans++;
            }
        }
        cout<< ans;
    }
}

Measured memory_bytes: 9768
#include <iostream>
#include <vector>
#include <algorithm>

using vi = std::vector<int>;
using vvi = std::vector<vi>;

int step(const vvi &g, vi &q, vi &marked) {
    vi q2;
    int r = 0;
    for (auto a : q) {
        if (!marked[a]) {
            marked[a] = 1;
            r++;
            for (auto b : g[a]) {
                if (!marked[b]) q2.push_back(b);
            }
        }
    }
    q.clear();
    std::swap(q, q2);
    return r;
}

int main() {
    int n; std::cin >> n;
    vvi g(n + 1);
    for (int i = 0; i < n-1; i++) {
        int a, b; std::cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vi marked(n + 1);
    vi q1 = {1}, q2 = {n};
    int c1 = 0, c2 = 0;

    while (!(q1.empty() || q2.empty())) {
        c1 += step(g, q1, marked);
        c2 += step(g, q2, marked);
    }
    while (!q1.empty()) c1 += step(g, q1, marked);
    while (!q2.empty()) c2 += step(g, q2, marked);

    std::cout << (c1 > c2 ? "Fennec" : "Snuke") << std::endl;
}


Measured memory_bytes: 6400
#include<iostream>
#include<cstdio>
using namespace std;
int Q,C,A,N;
int ans;
int main()
{
 scanf("%d",&Q);
 for(int i=0;i<Q;i++){
  ans=0;
  scanf("%d%d%d",&C,&A,&N);
  while(C>0&&A>0&&N>0){
   C--;A--;N--;ans++;
  }
  while(C>1&&A>0){
   C-=2;A-=1;ans++;
  }
  while(C>2){
   C-=3;ans++;
  }
  printf("%d\n",ans);
 }
 return 0;
}

Measured memory_bytes: 1188
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, sta, n) for (int i = sta; i < n; ++i)

using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<ll> a;
    ll s = 0;
    rep(i, n) {
        ll ai;
        cin >> ai;
        if ((i%2)==0) s += ai;
        else s -= ai;
        a.push_back(ai);
    }
    ll ans;
    ll pre;
    rep(i, n) {
        if (i == 0) {
            ans = s;
            pre = s / 2;
            cout << ans << " ";
            continue;
        } else {
            pre = (a[i-1] - pre);
            ans = pre * 2;
            cout << ans << " ";
        }
    }
    cout << endl;
    return 0;
}


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

int main() {
	int k, a, b;
	cin >> k >> a >> b;
	int m = a % k;
	if (m == 0) {
		cout << "OK" << endl;
		return 0;
	}
	int n = k - m;
	int l = a + n;
	if (a <= l && l <= b)cout << "OK" << endl;
	else cout << "NG" << endl;
}

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

int main(){
    int N, L[200];
    cin >> N;
    for(int i=0;i<2*N;i++){
        cin >> L[i];
    }
    sort(L, L+2*N);

/*
    for (int i=0; i<2*N;i++){
        cout << L[i] << " " ;
    }
*/
    int s=0;
    for(int i=0;i<N;i++){
        s+=L[2*i];
    }
    cout << s <<endl;
}


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



int main(){
    string s;
    cin >> s;
    int x=s.length()-2;
    char a=s.front();
    char b=s.back();
    cout << a << x << b << endl;
    return 0;
}

Measured memory_bytes: 384
n, m = map(int, input().split())
lst = list(map(int, input().split()))
dp = {}
dp[0] = 1
a, s = 0, 0
for i in lst:
    a += i
    a %= m
    if a in dp:
        s += dp[a]
        dp[a] += 1
    else:
        dp[a] = 1
print(s)

Measured memory_bytes: 14252
#include<iostream>
#include<algorithm>
using namespace std; 
int main()
{
	int L,R,d; 
	scanf("%d %d %d",&L,&R,&d);
	if(L%d ==0)
		printf("%d\n",R/d-L/d+1);
	else
		printf("%d\n",R/d-L/d);
	return 0; 
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF 1e15

#define MAX_N 1000

int n,k,t,v1,v2,l;
bool ari[11111];

int main(){
	cin.sync_with_stdio(false);
	cin>>n>>k>>t>>v1>>v2>>l;
	rep(i,n){
		int d;
		cin>>d;
		ari[d]=true;
	}
	int dista=0,distb=0;
	int cnt=0;
	int restd=0;
	rep(a,l){
		if(ari[a]){
			cnt++;
			if(cnt>k){
				cnt=k;
				restd=t*v2;
			}
		}
		if(restd==0&&cnt>0){
			cnt--;
			restd=t*v2;
		}
		if(restd>0){
			restd--;
			distb++;
		}else{
			dista++;
		}
	}
	printf("%.10f\n", (double)dista/v1+(double)distb/v2);
	return 0;
}

Measured memory_bytes: 3244
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{

    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i != 0)
            continue;
        ll cnt = 0;
        while (n % i == 0)
        {
            n /= i;
            cnt++;
        }
        ll cut = 1;
        while (cut <= cnt)
        {
            ans++;
            cnt -= cut;
            cut++;
        }
    }
    if (n > 1)
        ans++;
    cout << ans;
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

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

    ll ans=0;
    sort(all(a));
    rep(i,n){
        if(x-a[i]<0) break;
        if(i==n-1 && x-a[i] != 0) break;
        x-=a[i];
        ++ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3576
a, b, c, x, y = map(int, input().split())

t1 = a*x + b*y
t2 = max(x, y)*2 * c

if x > y:
    t3 = y*2 * c + (x-y) * a
else:
    t3 = x*2 * c + (y-x) * b
    
print(min(t1, t2, t3))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int r, g, b;
  cin >> r >> g >> b;
  int ans = r * 100 + g * 10 + b;
  if (ans % 4)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    double h, m;
    double pi = acos(-1.0);
    double l, ls, wl, ws;
    cin >> l >> ls>> h >> m ;
    wl = 2*pi/12 * (h + m/60);
    ws = 2*pi/60 * m;
    double th = abs(wl - ws);
    if(th > pi) th = 2*pi - th;
    double c2 = l * l + ls * ls - 2 * l * ls * cos(th);
    printf("%.20lf\n", sqrt(c2));
    return 0;   
}

Measured memory_bytes: 4152
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int a[100010];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n,x;
    long long ans=0;
    cin>>n>>x;
    for(int i=1;i<=n;i++) a[i]=gi();
    if(a[1]>x) ans+=a[1]-x,a[1]=x;
    for(int i=2;i<=n;i++)
	if(a[i]+a[i-1]>x) ans+=a[i]+a[i-1]-x,a[i]=x-a[i-1];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7,INF=1e17;
const int iINF=1e9;
bool comp(int a,int b){
    return a<b;
}
int main(){
    ll n,ans=0;
    cin>>n;
    vector<int>a(n+1),b(n);
    for(int i=0;i<n+1;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];

    for(int i=n-1;i>=0;i--){

        if(a[i+1]>=b[i]){
            ans+=b[i];
            a[i+1]-=b[i];
            b[i]=0;
        }
        else {
            ans+=a[i+1];
            b[i]-=a[i+1];
        }

        if(a[i]>=b[i]){
            ans+=b[i];
            a[i]-=b[i];
        }
        else {
            ans+=a[i];
            a[i]=0;
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 1024
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<int> cnt(N, 0);
  int mn = N, mx = 0;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    ++cnt[a];
    mn = min(mn, a);
    mx = max(mx, a);
  }
  bool res = false;
  if (mx - mn <= 1) {
    if (mx == mn) {
      res |= mx == N - 1;
      res |= N >= 2 * mx;
    } else {
      int k = mx, u = cnt[mn];
      if (k > u) {
        res |= N - u >= 2 * (k - u);
      }
    }
  }
  cout << (res ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <math.h>
#include <iomanip>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;


int const static n_max = 100000;
int n,m,x[n_max+10],l[n_max+10];

int main(){
  cin>>n>>m;
  rep(i,m)cin>>x[i];

  if ( n>=m){
    cout << 0 << endl;
    return 0;
  }

  sort(x,x+m);

  for(int i=1;i<m;i++){
    l[i-1] = x[i]-x[i-1];
  }

  sort(l,l+m-1);

  int sum = 0;
  for(int i=m-1-1;i > m-n-1;i--){
    sum += l[i];
  }
  cout << ((x[m-1]-x[0]) - sum) << endl;
  
}

Measured memory_bytes: 1024
#define MAX 2000000
#define INF 99999999
int h,A[MAX+1];

void maxHeapify(int i){
  int tmp,largest,l,r;

  l=2*i;
  r=2*i+1;

  if(l<=h && A[l]>A[i]) largest=l;
  else largest=i;
  if(r<=h && A[r]>A[largest]) largest=r;
  if(largest!=i){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(largest);
  }
}

int extractmax(){
  int max_v;
  if(h<1) return -INF;
  max_v=A[1];
  A[1]=A[h--];
  maxHeapify(1);
  return max_v;
}

void increaseKey(int i,int key){
  int tmp;
  if(key<A[i]) return;
  A[i]=key;
  while(i>1 && A[i/2]<A[i]){
    tmp=A[i];
    A[i]=A[i/2];
    A[i/2]=tmp;
    i/=2;
  }
}

void insert(int key){
  h++;
  A[h]=-INF;
  increaseKey(h,key);
}

int main(){
  int key;
  char ch[7];
  while(1){
    scanf("%s",ch);
    if(ch[0]=='e' && ch[1]=='n'){break;}
    if(ch[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }
    else printf("%d\n",extractmax());
  }
  return 0;
}


Measured memory_bytes: 5680
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	//freopen("input.txt", "r", stdin); // redirects standard input
	//freopen("output.txt", "w", stdout); // redirects standard output

	long long n, i, j, k, x, a, b;
	n = 500;
	vector<long long> v(n + n);
	for (i = 0; i < n; i++) {
		v[i] = i * i * i * i * i;
		v[i + n] = - i * i * i * i * i;
	}

	cin >> x;
	for (i = 0; i < n + n; i++) {
		for (j = 0; j < n + n; j++) {
			if (v[i] - v[j] == x) {
				if (i < n) cout << i << " ";
				else cout << -(i - n) << " ";
				if (j < n) cout << j << "\n";
				else cout << -(j - n) << "\n";

				goto outer;
			}
		}
	}
outer:;

	return 0;
}

Measured memory_bytes: 3188
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()


n = int(arr_data[0][0])

res=math.sqrt(n)


print(int(math.pow(math.floor(res),2)))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i = 0; i < n; i++)
const int INF = 1e9;
const int N = 2e5+9;

int a[N];

int main(){

  ll n,T; cin >> n >> T;
  ll left = 0,right = 0,cnt = 0;
  REP(i,n){
    ll left; cin >> left;
    if(right >= left){
      right = left + T;
    }
    else {
      cnt += left - right;
      right = left + T;
    }
    //cout << left << " " << right << endl;
  }
    cout << right - cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
using namespace std;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    cout << s[0] << n-2 << s[n-1] << endl;
    return 0; 
}


Measured memory_bytes: 256
using DataStructures
function main()
    H,W = reads(Int,Int)
    c = reads(Int,Int)
    d = reads(Int,Int)
    kabe = zeros(Bool, H,W)
    for i in 1:H
        s = pread(String)
        for j in 1:W
            kabe[i,j] = s[j] == '.'
        end
    end
    reachable = false
    wcs = zeros(Int, H, W)
    wcs[c...] = 1
    st = PriorityQueue{Tuple{Int,Int},Int}()
    enqueue!(st, c=>1)
    while !isempty(st)
        p = dequeue!(st)
        if p == d
            reachable = true
            break
        end
        for sa in [(-1,0),(1,0),(0,-1),(0,1)]
            sp = p.+sa
            if 0 < sp[1] <= H && 0 < sp[2] <= W
                if (wcs[sp...]==0 || wcs[sp...] > wcs[p...]) && kabe[sp...]
                    wcs[sp...] = wcs[p...]
                    st[sp] = wcs[sp...]
                end
            end
        end
        for ij in [(-2,-2),(-2,-1),(-2,0),(-2,1),(-2,2),(-1,-2),(-1,-1),(-1,1),(-1,2),(0,-2),(0,2),(1,-2),(1,-1),(1,1),(1,2),(2,-2),(2,-1),(2,0),(2,1),(2,2)]
            i,j = ij
            rp = p[1]+i,p[2]+j
            if 0 < rp[1] <= H && 0 < rp[2] <= W && kabe[rp...] && (wcs[rp...] == 0 || wcs[rp...] > wcs[p...]+1)
                wcs[rp...] = wcs[p...]+1
                st[rp]=wcs[rp...]
            end
        end
    end
    println(reachable ? wcs[d...]-1 : -1)
end

import Base.parse
import Base.StringVector

parse(::Type{String},  str::AbstractString) = str
isdelim(x::UInt8, xs::Set{UInt8}) = x in xs
const delimset = Set([0x0a, 0x20])

function myreaduntil(s::IO, delims::Set{UInt8})::Vector{UInt8}
    out = StringVector(0)
    c::UInt8 = 0x00
    while !eof(s)
        c = read(s, UInt8)
        !isdelim(c, delims) && break
    end
    push!(out, c)
    eof(s) && return out
    while !eof(s)
        c = read(s, UInt8)
        isdelim(c, delims) && break
        push!(out, c)
    end
    return out
end

function readword(io::IO = stdin, delims = delimset)::String
    word = myreaduntil(io, delims)
    i = length(word)
    if i == 0 || word[i] != 0x0a
        return String(word)
    elseif i < 2 || word[i-1] != 0x0d
        return String(resize!(word,i-1))
    else
        return String(resize!(word,i-2))
    end
end

pread(ty) = parse(ty, readword())

reads(tys...)::Tuple{tys...} = Tuple{tys...}(pread(ty) for ty in tys)

function readvec(tys::Tuple , len::Signed)::Tuple{map(x -> Vector{x},tys)...}
    rv = Tuple{map(x -> Vector{x},tys)...}(Vector{ty}(undef,len) for ty in tys)
    for i in 1:len
        for j in 1:length(tys)
            @inbounds rv[j][i] = pread(tys[j])
        end
    end
    rv
end

readvec(ty::Type, len::Signed)::Vector{ty} = @inbounds ty[pread(ty) for i in 1:len]

function readmat(ty::Type, s...)::Matrix{ty}
    v = Matrix{ty}(undef, s...)
    @inbounds for i in 1:s[1]
        v[i,:] = readvec(ty, s[2])
    end
    v
end

main()


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


int main(){
	int n;
	cin >> n;
	
	
	priority_queue<int> que;
	rep(i,n){
		int p;
		cin >> p;
		que.push(p);
	}
	
	int res = que.top()/2;
	que.pop();
	while(!que.empty()){
		res += que.top();
		que.pop();
	}
	
	cout << res << endl;
	return 0;
}

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

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

//ll gcd(ll a, ll b)
//{
//    if (a < b) swap(a, b);
//    if (a % b == 0) return b;
//    return gcd(a, a%b);
//}

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

    ll a, b;

    //cout << gcd(4, 18) << endl;
    //cout << gcd(24, 18) << endl;
    //cout << gcd(17, 1) << endl;

    cin >> a >> b;

    ll _gcd = gcd(a, b);

    //cout << _gcd << endl;

    vector<ll> factors;
    for (ll i=2; i*i<=_gcd; ++i)
    {
        if (_gcd % i)
            continue;
        factors.push_back(i);
        while (_gcd%i == 0)
            _gcd /= i;
    }
    if (_gcd != 1) factors.push_back(_gcd);

    //for(auto i: factors)
    //    cout << i << ' ';
    //cout << endl;

    cout << factors.size() + 1 << endl;

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
// using namespace std;
typedef long long ll;
const int N=1e2+5;
int l[N];
int main(){
    // ios::sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0);
    // freopen("a.in","r",stdin);
    // int T;scanf("%d",&T);for(int tttt=1;tttt<=T;tttt++){
    if(true){
    // while(~scanf("%d",&n)){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",l+i);
    std::sort(l+1,l+1+n);
    int ans=0;
    for(int i=1;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<=n;k++){
                if(l[i]+l[j]>l[k]&&l[i]!=l[j]&&l[j]!=l[k]&&l[i]!=l[k]) ans++;
            }
        }
    }
    printf("%d\n",ans);
    }return 0;
}


Measured memory_bytes: 3800
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
// set<int>st{ 3,1,4,1,5,9,2,6,5,3,5 };
//     for (auto itr = st.begin(); itr != st.end(); ++itr) {
//         cout << *itr;
//     }
#include <bits/stdc++.h>
#include <regex>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
    string s,t;
    cin>>s>>t;
    vector<char>ss(s.size());
    rep(i,s.size()){
        ss.at(i)=s.at(i);
    }
    sort(all(ss));
    vector<char>tt(t.size());
    rep(i,t.size()){
        tt.at(i)=t.at(i);
    }
    sort(all(tt));
    reverse(all(tt));
    if(ss.at(0)<tt.at(0)){
        cout<<"Yes"<<endl;
        return 0;
    }
    else if(ss.at(0)==ss.at(s.size()-1)&&tt.at(0)==tt.at(t.size()-1)&&s.size()<t.size()){
            cout<<"Yes"<<endl;
            return 0;            
    }else{
        cout<<"No"<<endl;
        return 0;
    }
 
}

Measured memory_bytes: 3584
#include<stdio.h>

int main(void){
	int K,S;
	int x,y,z;
	int count = 0;

	scanf("%d %d",&K,&S);

	for(x=0;x<=K;x++){
		for(y=0;y<=K;y++){
			int z = S-x-y;
			if(0 <= z && z <= K){
				count++;
			}
		}
	}

	printf("%d\n",count);

return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
inline void read (int &x) {
    char ch = getchar(); int f = 0; x = 0;
    while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); }
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); if (f) x = -x;
} const int N = 2e5 + 5;
int n, a[N], c[N]; long long res;
signed main() {
    read (n);
    for (int i = 1; i <= n; ++i) read (a[i]), ++c[a[i]];
    for (int i = 1; i <= n; ++i) res += c[i] * (c[i] - 1) / 2;
    for (int i = 1; i <= n; ++i) printf ("%lld\n", res - c[a[i]] + 1);
    return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int main(){
	ll N, X;
	cin >> N >> X;
	ll a = N-X; ll b = X;
	if(a < b) swap(a, b);
	ll res = N;
	while(a % b){
		res += 2 * (a / b) * b;
		a %= b;
		if(a < b) swap(a, b);
	}
	res += a * 2 - b;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import re
import math
import collections
import itertools
import functools

DEBUG = True
DEBUG = False

def dbg(*args):
    if DEBUG:
        print("DBG: ", file=sys.stderr, end="")
        print(*args, file=sys.stderr)



def main():
    N = int(input())
    print("ABC{:03d}".format(N))

if __name__ == "__main__": main()


Measured memory_bytes: 4468
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdbool.h>
int main(){
    int s[]={0,0,0,0,0};
    
    int i,j,k,h,l;
    bool a=true;
    
    for (i=0;i<5;i++){
        scanf("%d",&s[i]);
    }
    scanf("%d",&l);
    for (j=0;j<5;j++){
        for (k=0;k<5;k++){
            if (j<k){
                if (abs(s[k]-s[j])>l){
                    a=false;
                }
            }
        }
    }
    if (a==true) printf("Yay!");
    else printf(":(");
    return 0;
}

Measured memory_bytes: 1716
#include<bits/stdc++.h>
using namespace std;
int n;
pair<int,int> jobs[200002];
bool cmp(pair<int,int> x,pair<int,int> y){
	if(x.second==y.second) return x.first<y.first;
	return x.second<y.second;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++) cin>>jobs[i].first>>jobs[i].second;
	sort(jobs,jobs+n,cmp);
	long long t=0;
	for(int i=0;i<n;i++){
		t+=jobs[i].first;
		if(t>jobs[i].second){
			cout<<"No\n"<<endl;
			return 0;
		}
	}
	cout<<"Yes\n"<<endl;
	return 0;
}

Measured memory_bytes: 1792
def main():
    N, M = map(int, input().split())
    S = list(map(int, input().split()))
    T = list(map(int, input().split()))
    MOD = 10 ** 9 + 7
    dp = [[0] * (M + 5) for _ in range(N + 5)]
    for i in range(N+1):
        dp[i][0] = 1
    for j in range(M+1):
        dp[0][j] = 1

    for i in range(1,N+1):
        for j in range(1,M+1):
            if S[i-1] == T[j-1]:
                dp[i][j] += dp[i-1][j-1]
            dp[i][j] += dp[i-1][j]
            dp[i][j] += dp[i][j-1]
            dp[i][j] -= dp[i-1][j-1]
            dp[i][j] %= MOD

    print(dp[N][M])


if __name__ == "__main__":
    main()

Measured memory_bytes: 72796
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

string isstable(vector< pair<int, char> >& orig, vector< pair<int, char> >& A, int N){
  for(int i=0;i<N;){
	int d = A[i].first;
	queue<char> buf;
	while(i < N && A[i].first == d){
	  buf.push(A[i++].second);
	}
	REP(j,N)
	  if(orig[j].first == d){
		if(orig[j].second != buf.front())
		  return "Not stable";
		else
		  buf.pop();
	  }
  }
  return "Stable";
}
  
void bubble(vector< pair<int, char> > A, int N){
  vector< pair<int, char> > orig = A;
  REP(i,N)
	for(int j=N-1;j>i;--j)
	  if(A[j-1].first > A[j].first)
		swap(A[j-1], A[j]);

  cout << A[0].second << A[0].first;
  REP(i,N-1)
	cout << " " << A[i+1].second << A[i+1].first;
  cout << endl;
  cout << isstable(orig, A, N) << endl;
}

void selection(vector< pair<int, char> > A, int N){
  vector< pair<int, char> > orig = A;
  REP(i,N){
	int minj = i;
	FOR(j,i,N)
	  if(A[j].first < A[minj].first)
		minj = j;
	swap(A[i], A[minj]);
  }
  
  cout << A[0].second << A[0].first;
  REP(i,N-1)
	cout << " " << A[i+1].second << A[i+1].first;
  cout << endl;
  cout << isstable(orig, A, N) << endl;
}

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

  int N; cin >> N; cin.ignore();
  string line; getline(cin, line);

  vector<pair<int, char> > A(N);
  REP(i,N){
	A[i].first = line[i*3+1] - '0';
	A[i].second = line[i*3];
  }

  bubble(A, N);
  selection(A, N);
  
  return 0;
}

Measured memory_bytes: 1228
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

count=0
for i in range(n):
    if b[i]<a[i]:
        count+=b[i]
    else:
        count+=a[i]
        b[i]-=a[i]
        if b[i]<a[i+1]:
            count+=b[i]
            a[i+1]-=b[i]
        else:
            count+=a[i+1]
            a[i+1]=0

print(count)

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

int main(void){
    int i,j;
    int H,W;
    cin >> H >> W;
    char array[H+2][W+2];
    string ans = "Yes";

    for(i=0; i<=H+1; i++){
        for(j=0; j<=W+1; j++){
            array[i][j] = '.';
        }
    }
    
    for(i=1; i<=H; i++){
        for(j=1; j<=W; j++){
            cin >> array[i][j];
        }
    }


    for(i=1; i<=H; i++){
        for(j=1; j<=W; j++){
            if(array[i][j] == '#'){
                if(array[i-1][j] == '.' && array[i][j-1] == '.' && array[i+1][j] == '.' && array[i][j+1] == '.'){
                    ans = "No";
                    break;
                }
            }
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n;
    int i, j, k, l;
    int cnt;
    int tmp;

    while (scanf("%d", &n) != EOF){
        cnt = 0;

        for (i = 0; i < 10; i++){
            for (j = 0; j < 10; j++){
                for (k = 0; k < 10; k++){
                    tmp = n - i - j - k;
                    if (0 <= tmp && tmp < 10){
                        cnt++;
                    }
                }
            }
        }

        printf("%d\n", cnt);
    }

    return (0);
}

Measured memory_bytes: 596
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
  -- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Applicative
import           Debug.Trace


readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons

modulus :: Int64
modulus = 10^9+7

addMod :: Int64 -> Int64 -> Int64
addMod x y = (x + y) `mod` modulus
subMod :: Int64 -> Int64 -> Int64
subMod x y = (x - y) `mod` modulus
mulMod :: Int64 -> Int64 -> Int64
mulMod x y = (x * y) `mod` modulus


main = do
  [n,m] <- map read . words <$> getLine :: IO [Int]
  as <- replicateM m $ readLn :: IO [Int]

  print . VU.last $ modelAnswer n as

ans (Just n) = n `mod` (10^9 + 7)
ans  Nothing = 0


solve n as = loop as 0 1
  where
    loop [] nowPlace ways = Just $ ways * (test (n+1) nowPlace)
    loop [a] nowPlace ways = loop [] (a+1) (ways * (test a nowPlace))
    loop (aNext:aNextNext:aList) nowPlace ways = if aNextNext == (aNext+1)
                                       then Nothing
                                       else loop (aNextNext:aList) (aNext+1) (ways * (test aNext nowPlace))


test aNext nowPlace = moveWays
  where
    target = aNext - 1
    l = target - nowPlace
    maxTwoStepTimes = l `div` 2
    moveWays = foldl' (\n m -> n + (f m)) 0 [0..maxTwoStepTimes]
    f m = comb (small+m) m
        where
          small = l - (2*m)

comb x y = (loop1 x y 1) `div` (loop2 y 1)
  where
    loop1 _ 0 n' = n'
    loop1 n r n' = loop1 (n-1) (r-1) (n*n')
    loop2 0 n' = n'
    loop2 n n' = loop2 (n-1) (n*n')

modelAnswer :: Int -> [Int] -> VU.Vector Int64
modelAnswer n as = VU.create $ do
  dp <- VUM.replicate (n+1) 0
  VUM.write dp 0 (1 :: Int64)
  -- VUM.write dp 1 (1 :: Int64)

  oks <- VUM.replicate (n+1) True
  forM_ as $ \j -> do
    VUM.write oks j False

  forM_ [0..(n-1)] $ \now -> do
    forM_ [(now+1)..(min n $ now+2)] $ \next -> do
      b <- VUM.read oks next
      when b $ do
        nowf <- VUM.read dp now
        VUM.modify dp (\n -> n `addMod` nowf) next

    -- f'  <- VUM.read dp (next-1)
    -- f'' <- VUM.read dp (next-2)
    -- VUM.write dp next (f' `addMod` f'')
  --   VUM.write dp n 0
  return dp


Measured memory_bytes: 33148
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_variables)]
        #[allow(unused_mut)]
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("parse error")
    };
}

fn main() {
    input!{
        a: i32,
        b: i32,
        c: i32,
        d: i32,
    }
    let mut a = a;
    let mut c = c;
    while a > 0 && c > 0 {
        c = c - b;
        a = a - d;
    }
    println!("{}", if c <= 0 {"Yes"} else {"No"});
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
 
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1000000007
#define hell2 1000000009
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll unsigned long long
#define ld long double 
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cerr << (#x) << " is " << (x) << endl
#define INF 1e13
#define LL_MAX 1e18
// memset(array, -1, sizeof(array[0][0]) * row * count)
using namespace std;
 
ll mult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll multbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=multbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;}
ll add(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll sub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int isPowerof2(ll x) { return (x && !(x & x-1)); } 
ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; } 
bool isPerfectSquare(long double x) {long double sr = sqrt(x); return ((sr - floor(sr)) == 0); }
bool check(ll i,ll j,ll n){return (i>=0 && i<n && j>=0 &&  j<n);} //matrix boundary checking
 
 
ll ceil(const ll &a, const ll &b){return (a - 1)/b + 1;}
 
// max({a, b, c, d})
// cout << fixed for removing e notation
 
bool comp(pair<ll, ll>a, pair<ll, ll>b)
{
    if(a.se*b.fi + b.se > b.se*a.fi + a.se) return true;
    else return false;
}
 
void convert(int arr[], int n) 
{ 
    int temp[n+1];
    for(int i=1;i<=n;i++)
        temp[i] = arr[i]; 
    // memcpy(temp, arr, n*sizeof(int)); 
  
    sort(temp+1, temp+n+1);   
    unordered_map<int, int> umap;
    int val = 1; 
    for (int i = 1; i <= n; i++) 
        umap[temp[i]] = val++;
    for (int i = 1; i <= n; i++) 
        arr[i] = umap[arr[i]]; 
}
 
bool prime[10000005];
void SieveOfEratosthenes(int n) 
{
    memset(prime, true, sizeof(prime)); 
    prime[0] = prime[1] = 0;
    for (int p=2; p*p<=n; p++) 
    {
        if (prime[p] == true) 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
    }
}

int foo(int a, int b, int c)
{
    return (abs(a-b) + abs(b-c) + abs(a-c));
}


ll getFirstSetBitPos(ll n) 
{ 
    return log2(n & -n) + 1; 
} 

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

    ld ans;
    int m = n;
    m = ceil(n, 2);

    ans = (ld)m/n;

    cout << prec(9);
    cout << ans << "\n";
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc107/tasks/abc107_b
h, w = [int(i) for i in input().split()]
grid = []

for _ in range(h):
    line = list(input())
    if "#" in line:
        grid.append(line)

ans = [[] for _ in range(len(grid))]

for i in range(w):
    for j in range(len(grid)):
        if grid[j][i] == "#":
            break
    else:
        continue
    for k in range(len(grid)):
        ans[k].append(grid[k][i])

for line in ans:
    print("".join(line))


Measured memory_bytes: 65884
ma = lambda :map(int,input().split())
n,u,v = ma()
u,v = u-1,v-1
tree = [[] for i in range(n)]
import collections

for i in range(n-1):
    a,b = ma()
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
que = collections.deque([(v,0)])
vis = [False]*n
dist_v = [0]*n
while que:
    now,c = que.popleft()
    vis[now] = True
    dist_v[now] = c
    for node in tree[now]:
        if not vis[node]:
            que.append((node,c+1))
que = collections.deque([(u,0)])
vis = [False]*n
dist_u = [0]*n
while que:
    now,c = que.popleft()
    vis[now] = True
    dist_u[now] = c
    for node in tree[now]:
        if not vis[node]:
            que.append((node,c+1))
ans = 0
for i in range(n):
    if dist_u[i] < dist_v[i]:
        ans = max(ans,dist_v[i])
print(ans-1)


Measured memory_bytes: 30236