akhauriyash/Code-Regression huggingface dataset:
n=int(input())
v=list(map(int,input().split()))
ans=0
x=dict()
y=dict()
z=dict()
for i in range(n):
    if v[i] in z:
        z[v[i]]+=1
    else:
        z[v[i]]=1
    if i%2==0:
        if v[i] in x:
            x[v[i]]+=1
        else:
            x[v[i]]=1
    else:
        if v[i] in y:
            y[v[i]]+=1
        else:
            y[v[i]]=1
c=len(z)
if c==1:
    ans=n//2
else:
    m1=0
    m2=0
    count=0
    flag=False
    for idx in y:
        if m1<y[idx]:
            tmp=idx
        m1=max(y[idx],m1)
    for idx in y:
        if m1==y[idx]:
            if tmp!=idx:
                flag=True
    for idx in x:
        if flag:
            m2=max(x[idx],m2)
        else:
            if idx!=tmp:
                m2=max(x[idx],m2)
    #print(m1)
    #print(m2)
    ans=(n//2-m1)+(n//2-m2)
    m1=0
    m2=0
    flag=False
    tmp=-1
    for idx in x:
        if m1<x[idx]:
            tmp=idx
        m1=max(x[idx],m1)
    for idx in x:
        if m1==x[idx]:
            if tmp!=idx:
                flag=True
    for idx in y:
        if flag:
            m2=max(y[idx],m2)
        else:
            if idx!=tmp:
                m2=max(y[idx],m2)
    ans=min(n-m1-m2,ans)
print(ans)

Measured memory_bytes: 69100
//////// Don't_be_late 
// https://atcoder.jp/contests/abc177/tasks/abc177_a
// date: 2020-08-29T21:00:28.777315
// memo: 
    
//<editor-fold desc="my macro">

#include<bits/stdc++.h>
#ifdef LOCAL
    #include<my/dump.h>
#else
    #define dump(...) 42 
    #define dumpi(x) 42 
#endif

typedef long long ll;
using namespace std;

#define repe(x, a) for(auto& (x) : (a))
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rep3(i, a, b) for(ll i=a, i##_len=(b);i<i##_len;i++)
#define _rep2(i, n) _rep3(i,0,n)
#define repd(...) _overload3(__VA_ARGS__,_repd3,_repd2,)(__VA_ARGS__)
#define _repd3(i, a, b) for(ll i=b-1, i##_len=(a);i>=i##_len;i--)
#define _repd2(i, n) _repd3(i,0,n)
#define loop(...) _overload3(__VA_ARGS__,,_loop2,_loop1)(__VA_ARGS__)
#define _loop2(i, a) for(ll i=a;; i++)
#define _loop1(i) _loop2(i,0)

#define all(x) x.begin(),x.end()
#define SIZE(x) ((ll)(x).size())

#define F first
#define S second
#define vec vector
#define umap unordered_map
#define uset unordered_set

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

#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define inrange(x,start,stop) ((start) <= (x) && (x) < (stop))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <typename Cont, typename Func>
Cont fmap(const Cont &container, Func functor) {
    Cont result(container.size());
    std::transform(container.begin(), container.end(), result.begin(), functor);// [](int x){return x * 2;}
    return result;
}
template <typename Cont, typename Pred>
Cont filter(const Cont &container, Pred predicate) {
    Cont result;
    std::copy_if(container.begin(), container.end(), std::back_inserter(result), predicate);// [](int x){return x == 2;}
    return result;
}   

template<typename T, typename ...Args>
void ci(T& first, Args&... args) {
    ((cin >> first), ..., (cin >> args)); //C++17
}

template<char Sep, typename T, typename ...Args>
void print_seq(const T& first, const Args&... args) {
    ((cout << first), ..., (cout << Sep << args)); //C++17
}

void co(){ cout << endl; }
template<typename... Words>
void co(Words... words) {
    print_seq<' '>(words...);
    cout << endl;
}
#define coi(x) cout<<(x)<<" "

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define sankou(n,a,b) cout << ((n) ? (a) : (b) ) << endl

#define asrt(expr...) assert((expr))
//</editor-fold>

#define INF 1e19
#define MOD 1e9+7
#define MAXR 1e5

int solve() {
    ll D,T,S;
    ci(D,T,S);
    Yes(D <= T * S );
    return 0;
}

int main(){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    
    solve();
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>

int main(void){
    register int i;
    long n;
    scanf("%ld",&n);
    char res[n][4];
    static long acc,wac,tlec,rec;
    for(i = 0;i < n;i++)scanf("%s",res[i]);
    for(i = 0;i < n;i++)
        if(!strcmp("AC",res[i]))acc++;
        else if(!strcmp("WA",res[i]))wac++;
        else if(!strcmp("TLE",res[i]))tlec++;
        else rec++;
    printf("AC x %ld\nWA x %ld\nTLE x %ld\nRE x %ld",acc,wac,tlec,rec);
}

Measured memory_bytes: 2120
#include<cstdio>
namespace QiFeng233{
	const int maxn=310,matsiz=20,inf=0x3f3f3f3f;
	int A,B,d[matsiz][matsiz],f[maxn][maxn];
	int max(int a,int b){
		return a>b?a:b;		
	}
	int min(int a,int b){
		return a<b?a:b;
	}
	void solve(){
		scanf("%d%d",&A,&B);
		for(int i=1;i<=A;++i)
			for(int j=1;j<=B;++j)
				scanf("%d",&d[i][j]);
		for(int i=0;i<=100;++i)
			for(int j=0;j<=100;++j)
				for(int x=1;x<=A;++x)
					for(int y=1;y<=B;++y)
						f[i][j]=max(f[i][j],d[x][y]-i*x-j*y);
		for(int x=1;x<=A;++x)
			for(int y=1;y<=B;++y){
				int dxy=inf;
				for(int i=0;i<=100;++i)
					for(int j=0;j<=100;++j)
						dxy=min(dxy,i*x+j*y+f[i][j]);
				if(dxy!=d[x][y]){
					printf("Impossible\n");
					return;
				}
			}
		printf("Possible\n");
		printf("202 10401\n");
		for(int i=1;i<=100;++i)printf("%d %d X\n",i,i+1);
		for(int i=102;i<=201;++i)printf("%d %d Y\n",i,i+1);
		for(int i=0;i<=100;++i)
			for(int j=0;j<=100;++j)
				printf("%d %d %d\n",1+i,202-j,f[i][j]);
		printf("1 202\n");
	}
}
signed main(){
	QiFeng233::solve();
	return 0;
} 

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,t,k=1;
    cin>>n;
    for(int i=1; i<=9; i++)
    {
        if(n%i==0)
        {
            t=n/i;
            if(t<=9)
            {
                cout<<"Yes"<<endl;;
                k=0;
                break;
            }
            else
            {
                k=1;
            }
        }
    }
    if(k==1)
        cout<<"No"<<endl;
}


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

int main()
{
int X;
int b;
int A;
int iMax;

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

	cin >> X;
	if( X < 4 )
	{
		cout << 1 << endl;

		return 0;
	}

	iMax = 1;
	for( b = 2; b * b <= X; b++ )
	{
		A = b;
		A *= b;
		while( A <= X )
		{
			if( iMax < A ) iMax = A;

			A *= b;
		}

	}

	cout << iMax << endl;

	return 0;
}



Measured memory_bytes: 256
n,q=map(int, input().split())
s=input()
cum = [0] * (n+1)

for i in range(n):
    cum[i+1] = cum[i] + (1 if s[i:i+2] == 'AC' else 0)

for i in range(q):
    l, r = map(int, input().split())
    print(cum[r-1] - cum[l-1])

Measured memory_bytes: 9284
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}
int dp[501][501];
int a[501];
int n;
int solve(int l,int r)
{
    if(l==r)
        return 0;
    int &res=dp[l][r];
    if(res!=-1)
        return res;
     res=1e18;
    for(int i=l;i<r;++i)
    {
        res=min(res,a[r]-a[l-1]+solve(l,i)+solve(i+1,r));
    }
    return res;
}
int32_t main()
{
    IOS
     
           
           
                memset(dp,-1,sizeof(dp));
                cin>>n;
                for(int i=1;i<=n;++i)
                    cin>>a[i];
                a[0]=0;
                for(int i=1;i<=n;++i)
                    a[i]+=a[i-1];
                cout<<solve(1,n)<<endl;

           

}


Measured memory_bytes: 2304
n, k = gets.split.map(&:to_i) # 整数半角区切り,非配列
x = [];  n.times {x <<  gets.chomp.to_i}   # 整数半角区切り,複数行
x.sort!
min = 10**10
for i in 0..(n-k)
	tmin =  x[i+k-1] - x[i]
	min = tmin < min ? tmin:min
end
p min 

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int BASE = 9000;
const int MAX = 4100;

bool check(char a, char b) {
  return a == '?' || b == '?' || a == b;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string a, b, c;
  cin >> a >> b >> c;
  vector<bool> ab(BASE*2, true), ac(BASE*2, true), bc(BASE*2, true);
  for (int i = -BASE; i < BASE; i++) {
    if (i+(int)b.size()-1 >= BASE)
      break;
    rep(j, b.size()) {
      if (i+j >= 0 && i+j < (int)a.size() && !check(a[i+j], b[j])) {
        ab[i+BASE] = false;
        break;
      }
    }
  }
  for (int i = -BASE; i < BASE; i++) {
    if (i+(int)c.size()-1 >= BASE)
      break;
    rep(j, c.size()) {
      if (i+j >= 0 && i+j < (int)a.size() && !check(a[i+j], c[j])) {
        ac[i+BASE] = false;
        break;
      }
    }
  }
  for (int i = -BASE; i < BASE; i++) {
    if (i+(int)c.size()-1 >= BASE)
      break;
    rep(j, c.size()) {
      if (i+j >= 0 && i+j < (int)b.size() && !check(b[i+j], c[j])) {
        bc[i+BASE] = false;
        break;
      }
    }
  }
  int ans = INF;
  for (int i = -MAX; i < MAX; i++) {
    for (int j = -MAX; j < MAX; j++) {
      if (ab[i+BASE] && ac[j+BASE] && bc[j-i+BASE]) {
        int l = min({i, j, 0});
        int r = max({(int)a.size(), i+(int)b.size(), j+(int)c.size()});
        chmin(ans, r-l);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

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

    cout << min(a * n, b) << '\n';
    return 0;
}

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

// Begin {{{
using namespace std;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, b, e) for (i64 i = (b); i <= (e); ++i)
#define repr(i, b, e) for (i64 i = (b); i >= (e); --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
inline i64 sigma(i64 n) { return n * (1 + n) >> 1; }
inline i64 updiv(i64 n, i64 d) { return (n + d - 1) / d; }
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;
#ifndef DEBUG
#define dump(...)
#endif

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
  cin >> head;
  input(forward<Tail>(tail)...);
}

inline void outs() { cout << "\n"; }
template <class Head, class... Tail>
inline void outs(Head&& head, Tail&&... tail) {
  cout << head << (sizeof...(tail) ? " " : "");
  outs(forward<Tail>(tail)...);
}

template <class T>
inline void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e == &vec.back()]; }

template <class T>
inline void outs(vector<vector<T>> &df) { for (auto &vec : df) outs(vec); }

inline void outl() { cout << "\n"; }
template <class Head, class... Tail>
inline void outl(Head&& head, Tail&&... tail) {
  cout << head << (sizeof...(tail) ? "\n" : "");
  outl(forward<Tail>(tail)...);
}

template <class T>
inline void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

inline void outn() {}
template <class Head, class... Tail>
inline void outn(Head&& head, Tail&&... tail) {
  cout << head;
  outn(forward<Tail>(tail)...);
}

template <class T>
inline void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
  return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
  return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}
// }}} End

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

  var(int, N);
  var(string, s);

  auto dp = make_v(0, N + 10, N + 10);

  repr(i, N - 1, 0) repr(j, N - 1, 0) {
    if (s[i] == s[j]) dp[i][j] = dp[i+1][j+1] + 1;
  }

  int maxv = 0;
  rep(i, N) rep(j, N) {
    if (i >= j) continue;
    int now = min<i64>(dp[i][j], j - i);
    chmax(maxv, now);
  }

  outl(maxv);

  return 0;
}


Measured memory_bytes: 98432
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

ll a[1000005],s=0,pre=0,ans=1e18;

int main()
{ios_base::sync_with_stdio(false);
int n;
gl(n);
rep(i,0,n-1)
{
	cin>>a[i];
	s+=a[i];
}

rep(i,0,n-2)
{
	pre+=a[i];
	ans=min(ans,abs(s-2*pre));
}
ol(ans);
return 0;
}



Measured memory_bytes: 1792
def resolve():
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    a, b, c = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    flag = False
    for i in range(1, b+1):
        if (a * i) % b == c:
            flag = True
            break

    if flag == True:
        print("YES")
    else:
        print("NO")


resolve()

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) 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 rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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


struct UnionFind{
    vector<int> par;
    UnionFind(int32 n){
        par = vector<int>(n, -1);
    }

    int root(int x){
        if(par[x] < 0)return x;
        return par[x] = root(par[x]);
    }

    bool unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y)return false;
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }

    int deg(int x){
        return -par[root(x)];
    }
};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  vector<pair<pii,int32>> ps(n);
  REP(i,n){
    int32 x,y;
    cin >> x >> y;
    --x;--y;
    ps[i] = make_pair(pii(x,y),i);
  }
  sort(all(ps));
  UnionFind uf(n);
  set<pii> st;
  REP(i,n){
    bool flg = false;
    vector<pii> eraselist;
    for(auto [y,k] : st){
      if(y > ps[i].fi.se)break;
      if(uf.unite(k,ps[i].se)){
        flg = true;
      }
    }
    if(!flg){
      st.emplace(ps[i].fi.se,ps[i].se);
    }
  }
  REP(i,n)ANS(uf.deg(i));
  return 0;
}

Measured memory_bytes: 16236
use std::io::*;
use std::str::FromStr;

fn main() {
    let stdin = stdin();
    let mut lock = stdin.lock();
    let mut str1 = String::new();
    lock.read_to_string(&mut str1).unwrap();
    let num = str1.trim().split_whitespace().map(|x| u32::from_str(x).unwrap()).next().unwrap();
    println!("{}", 48 - num);
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

std::map<std::string, int> mp;

int main(void){
	int n,i;
	std::string s,t[4]={"AC","WA","TLE","RE"};
	std::cin >> n;
	for(i=0; i<n; ++i){
		std::cin >> s;
		++mp[s];
	}
	for(i=0; i<4; ++i){
		std::cout << t[i] << " x " << mp[t[i]] << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3632
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    auto S = sread();
    long N = S.to!long;
    long s = S.map!"a-'0'"().sum();
    writeln(N % s == 0 ? "Yes" : "No");
}


Measured memory_bytes: 256
A,B = map(int,input().split())
h,w = 100,100

Grid = [list('#'*w) for _ in range(50)] + [list('.'*h) for _ in range(50)]

A -= 1
B -= 1
for i in range(0,50,2):
    for j in range(0,100,2):
        if A > 0:
            Grid[i][j] = '.'
            A -= 1
        else:
            break
    else:
        continue
    break

for i in range(99,50,-2):
    for j in range(0,100,2):
        if B > 0:
            Grid[i][j] = '#'
            B -= 1
        else:
            break
    else:
        continue
    break

print(100,100)
for i in range(100):
    print(''.join(Grid[i]))


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
 
 
 
 
 
 
 









int main()
{
     ll a,b;
     cin>>a>>b;
     ll res1,res2;
     if(a%4==0)res1=a;
     else if(a%4==1)res1=1;
     else if(a%4==2)res1=a+1;
     else res1=0;
     if(b%4==0)res2=b;
     else if(b%4==1)res2=1;
     else if(b%4==2)res2=b+1;
     else res2=0;
     cout<<((res2^res1)^a);
}


























Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,arr[1000],i,j,mx=10000000;
    long long sum[100001]= {0};
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    for(i=1; i<=100; i++)
    {
        for( j=0; j<n; j++)
        {
            sum[i]=sum[i]+(arr[j]-i)*(arr[j]-i);
        }
      if(sum[i]<mx)
            mx=sum[i];
    }
      cout<<mx<<endl;
}


Measured memory_bytes: 1024
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    n = int(input())
    seq = [int(input()) for _ in range(n)][::-1]

    """
    Longest Increasing/Decreasing Subsuquence (LIS, LDS)
    Verified:
        https://atcoder.jp/contests/abc134/tasks/abc134_e
        https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_D
    """


    def longest_subsequence(A: "Array[int]", equals: bool, increasing: bool) -> int:
        """
        Compute the length of LIS or LDS.
        
        Args:
            A ("Array[int]"): a list or tuple to compute.
            equals (bool): permit adjacent numbers in subsequence to equal.
            increasing (bool): compute an increasing subsequence or decreasing one.
        Returns: (int) the length of a subsequence.
        """
        from bisect import bisect_left, bisect_right

        bs = bisect_right if equals else bisect_left
        compare = (lambda x, y: x >= y) if equals else (lambda x, y: x > y)
        if not increasing:
            A = A[::-1]

        dp = [A[0]]  # dp := length of LIS (dp table itself is not LIS)
        for i in A[1:]:
            if compare(i, dp[-1]):
                dp.append(i)
            else:
                dp[bs(dp, i)] = i
        return len(dp)
    
    print(longest_subsequence(seq,True,True))

    
    




resolve()

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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define MOD 1000000007

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  vector<int> b;
  while(!a.empty()){
    int found = 0;
    for(int i = (int) a.size() - 1; i >= 0; i--){
      if(a[i] == i+1){
        b.pb(i + 1);
        a.erase(a.begin()+i);
        found = 1;
        break;
      }
    }
    if(!found){
      cout << -1 << endl;
      return 0;
    }
  }
  reverse(b.begin(),b.end());
  for(int i = 0; i < n; ++i){
    cout << b[i] <<endl;
  }
  return 0;
 }

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var Ai = Sarray();
            var lcm = Ai[0];
            for (var i = 1; i < N; ++i)
            {
                lcm = Lcm(lcm, Ai[i]);
                if (2 * M < lcm)
                {
                    WriteLine(0);
                    return;
                }
            }
            foreach (var a in Ai)
            {
                if (lcm / a % 2 == 0)
                {
                    WriteLine(0);
                    return;
                }
            }
            WriteLine((2 * M / lcm + 1) / 2);
        }
        static long Gcd(long x, long y) => y == 0 ? x : Gcd(y, x % y);
        static long Lcm(long x, long y) => x / Gcd(x, y) * y;
    }
}

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

signed main(){
  map<string,int> m;
  string s,t;cin>>s>>t;
  int a,b;cin>>a>>b;
  m[s]=a;m[t]=b;
  string u;cin>>u;m[u]--;
  cout<<m[s]<<" "<<m[t]<<endl;
}


Measured memory_bytes: 256
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int N=100000+10;

int r,c,n,vis[N];
vector<pair<int,int>> v[5];
int sta[N],top=0;

pair<int,int> check(int x,int y) {
	if (x==0) return make_pair(1,y);
	if (y==c) return make_pair(2,x);
	if (x==r) return make_pair(3,c-y);
	if (y==0) return make_pair(4,r-x);
	return make_pair(0,0);
}

int main() {
	r=read(),c=read(),n=read();
	for (int i=1;i<=n;++i) {
		int x1=read(),y1=read(),x2=read(),y2=read();
		auto t1=check(x1,y1),t2=check(x2,y2);
		if (!t1.first||!t2.first) continue;
		v[t1.first].emplace_back(make_pair(t1.second,i));
		v[t2.first].emplace_back(make_pair(t2.second,i));
	}
	for (int i=1;i<=4;++i) sort(v[i].begin(),v[i].end());
	for (int i=1;i<=4;++i)
		for (auto x:v[i]) {
			int w=x.second;
			if (!vis[w]) sta[++top]=w,vis[w]=1;
			else if (sta[top]!=w) { puts("NO"); return 0; }
			else --top;
		}
	puts("YES");
	return 0;
}

Measured memory_bytes: 5548
#include <stdio.h>
#include <string.h>
int main(void){
    char po[114];
    scanf("%s",po);
    if(strlen(po)>=4&&po[0]=='Y'&&po[1]=='A'&&po[2]=='K'&&po[3]=='I')printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 128
a,b,c = map(int, input().split())
d,e,f = map(int, input().split())
g,h,i = map(int, input().split())
o = p = q = r = 0
if (a - b) == (d - e) == (g - h):
  o = 1
if (b - c) == (e - f) == (h - i):
  p = 1
if (a - d) == (b - e) == (c - f):
  q = 1
if (d - g) == (e - h) == (f - i):
  r = 1
if o == p == q == r == 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
import numpy as np
from scipy.optimize import fmin
from sys import stdin as s
n,k=map(int,s.buffer.readline().split())
Z=np.array(s.buffer.read().split(), np.float64)
X,Y,C=Z[::3],Z[1::3],Z[2::3]
Z=[Z[i*3:i*3+3]for i in range(n)]
def f(x):
  x,y=x
  t=np.sort(C*np.sqrt((X-x)*(X-x)+(Y-y)*(Y-y)))
  return t[k-1]
A=[fmin(f,(x,y),disp=False,ftol=1e-7,initial_simplex=[(x+0.5,y),(x-0.5,y+0.5),(x-0.5,y-0.5)])for x,y,c in Z]
B=list(map(lambda x:f(x),A))
print(min(B))

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

int main (){
  int K, N, x = 1;
  cin >> N >> K;
  for (int i = 0; i < N; i++){
    if (x * 2 > x + K)
      x += K;
    else
      x *= 2;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long long x,t;
	cin>>x>>t;
	if(x-t >= 0) cout<<x-t<<endl;
	else cout<<"0"<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

const ll M = 1000000007;
ll inv[1005], fac[1005], fiv[1005];
ll dp[1005][1005]; // i人をj人未満のグループに分ける時の場合の数

ll comb(int n, int k) {
    return fac[n] * fiv[k] % M * fiv[n-k] % M;
}

ll pow_mod(ll num, ll pow) {
    ll prod = 1;
    num %= M;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % M;
        num = num * num % M;
        pow >>= 1;
    }
    return prod;
}

int main() {
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;

    inv[1] = fac[1] = fiv[1] = inv[0] = fac[0] = fiv[0] = 1;
    for (ll i = 2; i < 1005; i++) {
        fac[i] = fac[i - 1] * i % M; // n!
        inv[i] = inv[M % i] * (M - M / i) % M; // n^-1
        fiv[i] = fiv[i - 1] * inv[i] % M; // (n!)^-1
    }

    dp[0][A] = 1;
    for (int i = 0; i <= N; i++) {
        for (int j = A; j <= B; j++) {
            (dp[i][j + 1] += dp[i][j]) %= M;

            for (int k = C; k <= D; k++) {
                // dp[i][j] -> i人をj人未満のグループに
                // dp[i+k*(j+1)][j+1] -> ↑に加え、j+1人グループをk個作る
                int people = k * j;
                if (i + people > N) break;
                ll tmp = fac[people] * comb(N - i, people) % M * fiv[k] % M * pow_mod(fiv[j], k) % M;
                (dp[i + people][j + 1] += dp[i][j] * tmp % M) %= M;
            }
        }
    }

    cout << dp[N][B+1] << "\n";
    return 0;
}

Measured memory_bytes: 8192
// In the name of god
#include <bits/stdc++.h>
using namespace std;
int a[3];
int main(){
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(a[0]==a[1]&&a[1]<a[2]){
		cout<<"Yes";
	}
	else if(a[1]==a[2]&&a[1]>a[0]){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<long double,long double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<61;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,a,b;

int main(){
	cin>>n>>a>>b;
	cout<<min(n*a,b)<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

		set<int> p;

		for (int i = 0; i < n; i++)
		{
			p.insert(i);
		}

		int s = -1;
		while (p.size() > 1)
		{
			for (int j = 0; j < m;)
			{
				s = (s + 1) % n;
				if (p.count(s))
				{
					j++;
				}
			}
			p.erase(s);
		}

		for (int i = 0; i < n; i++)
		{
			if (p.count(i))
			{
				cout << i + 1 << endl;
			}
		}
	}
}


Measured memory_bytes: 3120
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[100000],dp[100][100];

int main(){
  cin >> n >> s >> m;
  if(s == "+")print(n+m);
  else print(n-m);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b;
    cin >> a >> b;
    if((a + b) % 2 == 0){
        cout << (a+b)/2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}


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

void convert(std::string& result)
{
    size_t n = result.length();

    for (size_t i = 0; i < n; ++i)
    {
        if (result[i] != '-')
        {
            continue;
        }

        if ((i == 0) && (2 <= n))
        {
            result[i] = '1';
        }
        else
        {
            result[i] = '0';
        }
    }
}

bool validate(const std::string& result)
{
    // 先頭が0ならNG
    if ((2 <= result.length()) && (result[0] == '0'))
    {
        return false;
    }
    return true;
}

int main()
{
    int n, m;
    std::cin >> n >> m;

    std::string result(n, '-');

    for (int i = 0; i < m; ++i)
    {
        int s;
        char c;
        std::cin >> s >> c;

        if (result[s - 1] == '-')
        {
            result[s - 1] = c;
        }
        else
        {
            if (result[s - 1] != c)
            {
                std::cout << -1 << std::endl;
                return 0;
            }
        }
    }

    convert(result);

    if (!validate(result))
    {
        std::cout << -1 << std::endl;
    }
    else
    {
        std::cout << result << std::endl;
    }
    return 0;
}


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


int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i,n){
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  int cnt = 0;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      for(int k=j+1; k<n; k++){
        int vi = vec[i], vj = vec[j], vk = vec[k];
        if(vi < vj+vk && vj < vi+vk && vk < vi+vj) cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  string s;
  cin >> s;
  rep(i, s.size()){
    cout << 'x';
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 760
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    
    int X, Y; cin >> X >> Y;
    cout << X+Y/2 << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

void Compute(ll n,ll k)
{
    KAKA
    vector<ll> v(n);
    pragi(0,n)
    {
        cin>>v[i];
    }
    sort all(v);
    ll sum = 0;
    ll siz = n-k;
    if(siz <= 0) cout<<0<<"\n";
    else
    {
        pragi(0,n-k)
        {
            sum+=v[i];
        }
        cout<<sum<<"\n";
    }
    
}
int main()
{
    KAKA
    ll n,k;
    cin>>n>>k;
    Compute(n,k);
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#define int long long

using namespace std;
const int N = 1e5 + 5;

int n, m, v, p;
int a[N], t[N];

bool judge(int x) {
	if (x <= p) return 1;
	if (a[x] + m < a[p]) return 0;
	if (v <= p - 1 && a[x] + m >= a[p]) return 1;
	for (register int i = 1; i <= n; i++)
		t[i] = a[i];
	for (register int i = 1; i < p; i++)
		t[i] += m;
	
	int cost = m * (p - 1);
	for (register int i = n, c = v - p; i > x && c; c--)
		cost += m, t[--i] += m;
	cost += m;
	
	int left = m * v - cost;
	for (register int i = p; i < x; i++) {
		int inc = min(m, max(a[x] + m - a[i], 0ll));
		inc = min(inc, left);
		left -= inc, t[i] += inc;
	}
	
	return a[x] + m >= t[p] && left <= 0;
}

signed main() {
	cin >> n >> m >> v >> p;
	for (register int i = 1; i <= n; i++)
		cin >> a[i];
	
	sort(a + 1, a + 1 + n, greater<int>());
	
	int l = 1, r = n, ret = 0;
	while (l <= r) {
		int mid = (l + r) >> 1;
		if (judge(mid)) ret = mid, l = mid + 1;
		else r = mid - 1;
	}
	
	cout << ret << endl;
	return 0;
}

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

const int N = 2e5 + 5;

int n, m;
map< int, int > e[N];

int main() {
	scanf("%d %d", &n, &m);
	while(m--) {
		int u, v; scanf("%d %d", &u, &v);
		e[u][v] = e[v][u] = 1;
	}

	for (int i = 2; i < n; ++i) if (e[1][i] && e[n][i]) {
		cout << "POSSIBLE\n"; return 0;
	}
	cout << "IMPOSSIBLE\n";
}

Measured memory_bytes: 37760
awk '$0=NR%2FS$NF' RS=\ |sort|uniq -c|sort -n|awk '$2{b=a;s+=a=$1;c=$3}!$2{e=d;s+=d=$1;f=$3}END{print s-(c~f?a+e<b+d?b+d:a+e:a+d)}'

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

#define fi first
#define se second
typedef pair<int,int> PII;

int n, k, a[1<<17], ans, dp[1<<17];
vector <int> g[1<<17];

void dive(int u) {
    int val = 1;
    for (auto v : g[u]) if (v != u) {
        dive(v);
        val = max(val, dp[v] + 1);
    }
    if (val == k && a[u] != 1) dp[u] = 0, ans++;
    else dp[u] = val;
}

int main() {
    cin >> n >> k;
    cin >> a[1];
    for (int i = 2; i <= n; i++) {
        cin >> a[i];
        g[a[i]].push_back(i);
    }
    if (a[1] != 1) ans++, a[1] = 1;

    dive(1);
    cout << ans;
}


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

typedef long long ll;
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
#define rep(i, n) for(int i = 0; i < n; i++)
#define fogg(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i >= (b); i--)
#define test int t; cin >> t; while(t--)
#define debug(x) cout << '>' << #x << ':' << x << "\n";
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair



int main() {
	
	ll k,n,sum=0,mx=0,mn=1e9+7;
	cin >> k >>n;
	ll a[n];
	for(int i=0;i<n;i++) {
		cin >> a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n-1;i++) {
		sum+=(a[i+1]-a[i]);
		mx = max(a[i+1]-a[i],mx);
	}
	mx = max(a[0]-0+k-a[n-1],mx);
	sum+=a[0]-0+k-a[n-1];

	cout << sum-mx;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000;
const int MOD = (int)1e9 + 7;
template <class T>
inline T in()
{
    T x;
    cin >> x;
    return x;
}

struct Tree
{
    int num;
    vector<int> con;
    bool visited;
};

signed main()
{
    int n = in<int>();
    vector<int> result(n, 0);
    vector<Tree> trees;
    map<vector<int>, int> m;
    for (int i = 0; i < n; i++)
    {
        Tree tree = {i + 1, vector<int>{}, false};
        trees.push_back(tree);
    }
    for (int i = 0; i < n - 1; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        m[vector<int>{u, v}] = w;
        m[vector<int>{v, u}] = w;
        trees[u - 1].con.push_back(v);
        trees[v - 1].con.push_back(u);
    }
    queue<Tree> q;
    q.push(trees[0]);
    int currentTree = trees[0].num;
    while (q.size())
    {
        Tree t = q.front();
        q.pop();
        currentTree = t.num;
        trees[currentTree - 1].visited = true;
        for (auto &&c : t.con)
        {
            if (trees[c - 1].visited)
            {
                continue;
            }
            q.push(trees[c - 1]);
            if (m[vector<int>{c, currentTree}] % 2 == 0)
            {
                result[c - 1] = result[currentTree - 1];
            }
            else
            {
                result[c - 1] = result[currentTree - 1] == 0 ? 1 : 0;
            }
        }
    }
    for (auto &&x : result)
    {
        cout << x << "\n";
    }
}

Measured memory_bytes: 31724
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc127/tasks/abc127_b

r, d, x = [int(x) for x in input().split()]
ans = [x]
for _ in range(10):
    ans.append(ans[-1] * r - d)
ans.pop(0)
for _ in range(len(ans)):
    print(ans.pop(0))


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;

ll n;
ll a[100010];
ll kaijo[100010];
ll inv[100010];

ll expo(ll x,ll power) {
	ll res = 1;
	ll k = power;
	ll y = x;
	while (k) {
		if (k & 1)res = (res*y) % N;
		y = (y%N*y%N) % N;
		k /= 2;
	}
	return res;
}

void init(){
   for(ll i=0;i<100010;i++){
       if(i==0){
           kaijo[0]=1;
           inv[0]=1;
       }
       else{
           kaijo[i]=(kaijo[i-1]*i)%N;
           inv[i] = expo(i,N-2);
       }
   } 
}

int main(void){
    cin>>n;
    ll ans = 0;
    init();
    for(ll i=2;i<=n;i++){
        inv[i] +=inv[i-1];
        inv[i] = inv[i]%N;
    }
    for(ll i=1;i<=n;i++){
        cin>>a[i];
        ll tmp = (inv[i]+inv[n-i+1]-1+N)%N;
        ans = (ans+a[i]*tmp)%N;
    }
    cout<<(ans*kaijo[n])%N<<endl;
    return 0;

}


Measured memory_bytes: 2560
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt(),c=0;List<Integer> A=new ArrayList<>();
		for(int i=0;i<n;i++)A.add(cin.nextInt());
		
		boolean flag=true;
		while(flag) {
			flag=false;
			for(int i=n-1;i>0;i--) {
				if(A.get(i)<A.get(i-1)) {
					Collections.swap(A, i, i-1);
					c++;
					flag=true;
				}
				
			}
		}
		
		
		for(int i=0;i<n;i++) {
			System.out.print(A.get(i));
			if(i!=n-1)System.out.print(" ");
		}
		System.out.println();
		System.out.println(c);
	}

}



Measured memory_bytes: 26376
import java.util.*;
public class Main {
	static final int N = 1000000;
	public static void main(String[] args) {
//		boolean[] sieve = new boolean[N+1];
//		Arrays.fill(sieve, true);
//		for(long i = 2; i <= N; i++) {
//			if(sieve[(int)i]) {
//				for(long j = i*i; j <= N; j += i) {
//					sieve[(int)j] = false;
//				}
//			}
//		}
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long g = gcd(a, b);
		if(g == 1) {
			System.out.println(1);
		}
		else {
			int res = 0;
			for(long i = 2; i*i <= g; i++) {
				if(g % i == 0) {
					res++;
					while(g % i == 0) g /= i;
				}
			}
			if(g > 1) res++;
			System.out.println(res+1);
		}
	}
//	static boolean isPrime(long k) {
//		for(long i = 2; i*i <= k; i++) {
//			if(k % i == 0) return false;
//		}
//		return true;
//	}
	static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		else if(b == 0) return a;
		else return gcd(b, a % b);
	}
}


Measured memory_bytes: 23764
def get_dist(cur, nxt):
    return abs(cur[0] - nxt[0]) + abs(cur[1] - nxt[1])


H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

pos = {}
for i in range(H):
    for j in range(W):
        pos[A[i][j]] = (i, j)

acc = [0] * (H * W + 1)
for i in range(D + 1, H * W + 1):
    acc[i] = acc[i - D] + get_dist(pos[i - D], pos[i])

Q = int(input())
for _ in range(Q):
    ans = 0
    L, R = map(int, input().split())
    print(acc[R] - acc[L])


Measured memory_bytes: 27368