akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define dump(x) cout << (x) << endl
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

typedef struct {
    double x, y;
} p_t;

int main() {
    Int n;
    cin >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(all(a));
    if (a.back() - a.front() > 1) {
        dump("No");
        return 0;
    }
    if (a.front() == a.back()) {
        if (n - 1 == a.front() or n % a.front() == 0) {
            dump("Yes");
            return 0;
        }
        else {
            dump("No");
            return 0;
        }
    }
    vector<pair<Int, Int>> b;
    b.emplace_back(a.front(), 1);
    for (Int i = 1; i < n; i++) {
        if (b.back().fi == a[i]) {
            b.back().se++;
        }
        else {
            b.emplace_back(a[i], 1);
        }
    }
    if (b.front().se > b.front().fi) {
        dump("No");
        return 0;
    }
    Int x = b.back().fi - b.front().se;
    if (b.back().se / x >= 2 and b.back().se % x == 0) {
        dump("Yes");
    }
    else {
        dump("No");
    }
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	Scanner sc = new Scanner(System.in);
	String n;
	public void run(){
		n = sc.next();
		solve();
	}
	public void solve(){
		int ans = 700;
		for(int i = 0; i < 3; i++){
			String s = n.substring(i, i+1);
			if(s.equals("o")){
				ans += 100;
			}
		}
		System.out.println(ans);
	}
	
	public static void main(String[] args){
		new Main().run();
	}
	
	static class Pair {
        int first,second;
        public Pair(int a,int b) {
            this.first = a;
            this.second = b;
        }
    }	
}


Measured memory_bytes: 21840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<vector<pii>> a(n,vector<pii>());
	rep(i,n){
		int A;cin >> A;
		rep(j,A){
			int x,y;cin >> x >> y;
			x--;
			a.at(i).pb(mp(x,y));
		}
	}
	int ans = 0;
	rep(i,(1 << n)){
		int cnt = 0;
		vector<bool> p(n);
		rep(j,n){
			if(i & (1 << j)){
				cnt++;
				p.at(j) = true;
			}
		}
		bool ok = true;
		rep(j,n){
			if(p.at(j)){
				rep(k,a.at(j).size()){
					if((a[j][k].second && !p[a[j][k].first]) || (!a[j][k].second && p[a[j][k].first])) ok = false;
				}
			}
		}
		if(ok) ans = max(ans,cnt);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
/*
[abc120] C - Unification
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;

int N;
string S;

ll solve() {
    int cnt[2];
    cnt[0] = cnt[1] = 0;
    for (int i = 0; i < N; i++) {
        cnt[S[i] - '0']++;
    }

    return min(cnt[0], cnt[1]) * 2;
}

int main() {
    cin >> S;
    N = S.size();

    cout << solve() << endl;

    return 0;
}


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

using ll=long long;
const ll MOD=1000000007;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  ll cnt=0;
  while(cnt<10000&&(a-1)*(b-1)*(c-1)%2!=0){
    cnt++;
    ll A=a,B=b,C=c;
    a=(b+c)/2;
    b=(A+c)/2;
    c=(A+B)/2;
    //cout << a << " " <<  b << " " << c << endl;
  }
  if(cnt==10000){
    cout << -1 << endl;
  }
  else
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < n; i++) {
    	for (int j = i + 1; j < i + 2; j++) {
    		for (int k = j + 1; k < j + 2; k++) {
    			if (s[i] == 'A' && s[j] == 'B' && s[k] == 'C') ans++;
    		}
    	}
    }
    cout << ans << endl;
}   


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
int main() {
    int d, t, s;
    cin >> d >> t >> s;
    if(t * s >= d)
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
const int MAX = 1000000;


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int x, y;
    cin >> x >> y;
    cout << x + y/2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
 
using namespace std;
 
signed main()
{
    fast;
    int h,w,n;
    cin>>h>>w>>n;
    int x = max(h,w);

    if ( n % x == 0 )
    {
        cout<<n/x<<endl;
    }
    else
    {
        cout<<(n/x)+1<<endl;
    }
    return 0;
}

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

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)

constexpr ll mod = 998244353;

ll pow(ll x, ll m)
{

    ll re = 1, y = 1;

    for (int i = 0; i < 60; ++i)
    {
        if (m & y)
            re = re * x % mod;
        x = x * x % mod;
        y *= 2;
    }

    return re;
}

ll inv(ll x)
{

    return pow(x, mod - 2);
}

class mint
{
    ll num = 0;

public:
    mint(ll x = 0) : num(x) {}

    mint operator+(const mint &rhs) const
    {
        return (num + rhs.num) % mod;
    }
    mint operator*(const mint &rhs) const
    {
        return num * rhs.num % mod;
    }
    mint operator-(const mint &rhs) const
    {
        return (num - rhs.num + mod) % mod;
    }
    mint operator/(const mint &rhs) const
    {
        return num * inv(rhs.num) % mod;
    }
    mint operator+=(const mint &rhs)
    {
        return *this = *this + rhs;
    }
    mint operator*=(const mint &rhs)
    {
        return *this = *this * rhs;
    }
    mint operator-=(const mint &rhs)
    {
        return *this = *this - rhs;
    }
    mint operator/=(const mint &rhs)
    {
        return *this = *this / rhs;
    }
    friend std::ostream &operator<<(std::ostream &os, const mint &rhs);
};

std::ostream &operator<<(std::ostream &os, const mint &rhs)
{

    os << rhs.num;

    return os;
}

std::vector<mint> node;

int n, m; //leafのサイズ

void init(int rsiz)
{

    m = 1;

    while (m < rsiz)
        m *= 2;

    node.resize(2 * m - 1);
} //ここで初期化して

void debug()
{

    int x = 0;

    rep(i, 2 * m - 1)
    {
        std::cerr << node[i] << ' ';
        if (x == i)
        {
            std::cerr << std::endl;
            x = x * 2 + 2;
        }
    }
}

void add(int idx, mint val)
{

    idx += m - 1;

    node[idx] += val;

    while (idx > 0)
    {
        idx = (idx - 1) / 2;
        node[idx] = node[2 * idx + 1] + node[2 * idx + 2];
    }
}

mint get(int a, int b, int k = 0, int l = 0, int r = m)
{ //上からだんだんと下へ//[a,b) [l,r)

    if (b < 0)
        return 0;

    if (a < 0)
        a = 0;

    if (r <= a || b <= l)
        return 0; //範囲外

    if (a <= l && r <= b)
        return node[k]; //完全に範囲内

    //部分的に範囲内

    mint lv = get(a, b, 2 * k + 1, l, (l + r) / 2);
    mint rv = get(a, b, 2 * k + 2, (l + r) / 2, r);

    return lv + rv;
}

int main()
{
    int k;

    std::cin >> n >> k;

    init(n);

    std::vector<P> vec(k);

    rep(i, k)
    {
        std::cin >> vec[i].first >> vec[i].second;
    }

    add(0, 1);

    //std::cerr << "DD" << std::endl;
    //debug();
    for (int i = 1; i < n; ++i)
    {
        mint x = 0;
        rep(j, k)
        {
            x += get(i - vec[j].second, i - vec[j].first + 1);
        }
        add(i, x);
        //debug();
    }

    std::cout << node[m - 1 + n - 1] << std::endl;

    return 0;
}

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

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i=(a); i<(n); i++)

int main() {
    string s;
    cin >> s;
    rep(i, s.size()-1) {
        if(s[i] != s[i+1]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int N,L;
priority_queue<int,vector<int>,greater<int>> x;

int main(){
    cin>>N>>L;

    int sum=N*L+N*(N+1)/2-N;
    int ans;
    if(L>=0){
        ans=sum-L;
    }else if(L<=-N){
        ans=sum-(L+N-1);
    }else{
        ans=sum;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define pii pair<ll,ll>
#define ti3 tuple<ll,ll,ll>

struct BIT
{
    std::vector<int> bit;
    
    BIT(int size) : bit(size, 0){ }
    
    void add(int k, int x) {
        while (k < bit.size()) {
            bit[k] += x;
            k += k &-k;
        }
    }
    int sum(int k) {
        int res = 0;
        while (k > 0) {
            res += bit[k];
            k -= k&-k;
        }
        return res;
    }
};

struct UnionFind {
    vector<int> data;
    
    UnionFind(int size) : data(size, -1) { }
    
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y)
        {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

class Compare
{
public:
    bool operator() (pii f, pii s)
    {
        if(f.first != s.first)
        {
            return f.first > s.first;
        }
        return f.second > s.second;
    }
};

priority_queue<pii, std::vector<pii>,Compare> q;

int main(void)
{
    ll s;
    cin >> s;
    s = abs(s);
    double u = sqrt(s);
    ll sum = 0;
    for(ll i = 1;i <= 2 * u;i++)
    {
        sum += i;
        if(sum >= s)
        {
            cout << i << endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;



int main() {
  ll N, M;
  cin >> N >> M;
  P p[MAX];
  ll i;
  
  for(i=0; i<M; i++) {
    ll a, b;
    cin >> a >> b;
    p[i].sc=a;
    p[i].ft=b;
  }
  sort(p, p+M);
  
  
  ll ans=M;
  ll r=p[0].ft;
  for(i=1; i<M; i++) {
    if(r>p[i].sc) ans--;
    else r=p[i].ft;
  }
  
  pt(ans);
}








Measured memory_bytes: 1920
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 200010;

int n, m;
char s[N];
int len[N], dp[N][2];

void upd(int& x, int y) { if (x < y) x = y; }

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  scanf("%s", s + 1);
  n = strlen(s + 1);
  char c = s[1];
  int l = 1;
  for (int i = 2; i <= n; ++i) {
    if (c != s[i]) {
      len[++m] = l;
      l = 1;
      c = s[i];
    } else
      ++l;
  }
  len[++m] = l;
  dp[m + 1][1] = -N;
  for (int i = m; i; --i) {
    if (len[i] == 1) {
      upd(dp[i][0], dp[i + 1][0] + 1);
      upd(dp[i][0], dp[i + 1][1] + 1);
      upd(dp[i][1], dp[i + 1][0]);
    } if (len[i] % 3 == 0) {
      upd(dp[i][0], dp[i + 1][0] + len[i] / 3 * 2);
      upd(dp[i][0], dp[i + 1][1] + len[i] / 3 * 2);
      upd(dp[i][1], dp[i + 1][0] + len[i] / 3 * 2 - 1);
      upd(dp[i][1], dp[i + 1][1] + len[i] / 3 * 2);
    } else if (len[i] % 3 == 1) {
      upd(dp[i][0], dp[i + 1][0] + len[i] / 3 * 2 + 1);
      upd(dp[i][0], dp[i + 1][1] + len[i] / 3 * 2 + 1);
      upd(dp[i][1], dp[i + 1][0] + len[i] / 3 * 2);
      upd(dp[i][1], dp[i + 1][1] + len[i] / 3 * 2);
    } else if (len[i] % 3 == 2) {
      upd(dp[i][0], dp[i + 1][0] + len[i] / 3 * 2 + 1);
      upd(dp[i][0], dp[i + 1][1] + len[i] / 3 * 2 + 2);
      upd(dp[i][1], dp[i + 1][0] + len[i] / 3 * 2 + 1);
      upd(dp[i][1], dp[i + 1][1] + len[i] / 3 * 2 + 1);
    }
  }
  printf("%d\n", dp[1][0]);

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 2688
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#define Max zhi5968
typedef long long ll;
using namespace std;
 
int main ()
{
	int n;
	cin>>n;
	int t1,t2,t3,t4;
	t1=n/1000; n=n%1000;
	t2=n/100; n=n%100;
	t3=n/10; n=n%10;
	t4=n;
	if((t1==t2&&t2==t3)||(t2==t3&&t3==t4))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if 500 * a + 100 * b + 50 * c == X:
                cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;

int main(){
  ll N;
  cin >> N;
  vl A(N);
  rep(i, N) cin >> A[i];

  stable_sort(A.begin(), A.end());

  cout << A[N - 1] - A[0] << "\n";
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main(){
  ll n;
  ll a,b,c,d,e; cin >> n >> a >> b >> c >> d >> e;
  ll p = min(min(min(min(a,b),c),d),e);
  
  cout << ll(((n+p-1)/p)+4) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <map>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

#define x first
#define y second

#define INF 0x3f3f3f3f

using namespace std;

const int maxn = 1e5 + 10;

typedef long long LL;
typedef pair<int,int>PII;

LL n,a,b;

int main(void) {
	cin >> n >> a >> b;
	LL res = a + b;
	if(a == 0) cout << 0 << endl;
	else if(n % res == 0) {
		cout << n / res * a << endl;
	} else {
		LL value = n / res * a;
		LL mod = n % res;
		if(mod >= a) cout << value + a << endl;
		else cout << value + mod << endl;
	}
	return 0;
} 

Measured memory_bytes: 256
#include<cstdio>
#include<utility>
#include<vector>
using namespace std;
#define MP 10005
int main()
{
	int x1,y1,x2,y2,N,R,A[2];
	for(;scanf("%d%d",&N,&R),N;)
	{
		vector<pair<int,int> >S[MP];
		for(int i=0;i<N;i++)
		{
			scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
			x1++;y1++;x2++;y2++;
			S[x1].push_back(make_pair(y1,1));
			S[x1].push_back(make_pair(y2,-1));
			S[x2].push_back(make_pair(y2,1));
			S[x2].push_back(make_pair(y1,-1));
		}
		int dp[2][MP]={0},*p1=dp[0],*p2=dp[1];
		for(int x=A[0]=A[1]=0;x<MP;x++)
		{
			fill(p2,p2+MP,0);
			for(int i=0;i<S[x].size();i++)
			{
				int p=S[x][i].first,v=S[x][i].second;
				p2[p]+=v;
			}
			for(int y=1;y<MP;y++)
				p2[y]+=p2[y-1];
			for(int y=1;y<MP;y++)
				p2[y]+=p1[y];
			for(int y=1;y<MP;y++)
			{
				if(p2[y]>0)A[0]++;
				if((p1[y]==0&&p2[y]>0)||(p1[y]>0&&p2[y]==0))A[1]++;
				if((p2[y-1]==0&&p2[y]>0)||(p2[y-1]>0&&p2[y]==0))A[1]++;
			}
			swap(p1,p2);
		}
		for(int i=0;i<R;i++)printf("%d\n",A[i]);
	}
}

Measured memory_bytes: 1880
#include<bits/stdc++.h>
#define ll long long
#define INF 0
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
char ma[55][55];
int b[55][55];
int h,w;
int bfs(int x,int y){
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            b[i][j]=INF;
        }
    }
    queue<P> que;
    
    que.push(P(x,y));
    b[x][y]=1;
    while(!que.empty()){
        P p = que.front(); que.pop();
        for(int i=0;i<4;i++){
            int nx=dx[i]+p.first,ny=dy[i]+p.second;
            if(nx < 0 || nx > h - 1 || ny < 0 || ny > w - 1 || ma[nx][ny]=='#'){continue;}
            if(b[nx][ny]==INF){
                b[nx][ny]=b[p.first][p.second]+1;
                que.push(P(nx,ny));
            }
        }
    }
    return b[h-1][w-1];
}
int main(){
    cin>>h>>w;
    int cnt=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>ma[i][j];
            if(ma[i][j]=='.'){
                cnt++;
            }
        }
    }
    if(bfs(0,0)==INF){
        cout<<-1<<endl;
    }
    else{
        cout<<cnt-bfs(0,0)<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
n,m = map(int, input().split())
a = list(map(int, input().split()))

from functools import reduce
import fractions
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

def get2(num):
    cnt=0
    while num %2==0:
        cnt+=1
        num//=2
    return cnt

div2=get2(a[0])
for i in range(len(a)):
    if div2 != get2(a[i]):
        print(0)
        exit()

num = lcm(a)
thr = m - num//2

if thr < 0:
    print(0)
else:
    print(thr//num + 1)

Measured memory_bytes: 14356
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
using namespace std;

int main(){
  long long n;
  cin >> n;
  long long a[n+2],d;
  a[0] = 0;
  a[n+1] = 0;
  for(int i=1;i<n+1;i++) cin >> a[i];
  d = 0;
  for(int i=1;i<n+2;i++){
    d += abs(a[i]-a[i-1]);
  }
  long long count;
  for(int i=1;i<n+1;i++){
    count = d-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i+1]-a[i-1]);
    cout << count << endl;
  }

  return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define pb push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr double eps = 1e-14; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

ll f(ll b,ll n){
    if(n<b) return n;
    else return f(b,n/b) + (n%b);
}

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

    if(n==s){
        cout << n+1 << endl;
        return 0;
    }

    for(ll i=2;i*i<=n;i++){
        if(f(i,n)==s){
            cout << i << endl;
            return 0;
        }
    }

    ll d=n-s; 
    ll ans = LINF;

    for(ll x=1;x*x<n;x++) if(x<=s and d%x==0){
        ll y=s-x;
        ll b=d/x+1;
        if(y>=b) continue;
        assert(b*x+y==n);
        ans = min(ans,b);
    }


    if(ans==LINF){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    } 
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A_list = []
for i in range(N):
    A_B = list(map(int, input().split()))
    A_list.append(A_B)
A_list.sort()
ans = 0
for i in range(N):
    ans += A_list[i][0]*A_list[i][1]
    M -= A_list[i][1]
    if M <= 0:
        break
if M==0:
    print(ans)
else:
    rev = 0-M
    print(ans-rev*A_list[i][0])

Measured memory_bytes: 29624
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int b[111][111]={};
	int w,h;
	int dx[4]={1,0,-1,0};
	int dy[4]={0,1,0,-1};
	cin>>h>>w;
	FORQ(i,1,h){
		string s;
		cin>>s;
		FORQ(j,1,w){
			if(s[j-1]=='#')b[i][j]=1;
		}
	}
	FORQ(i,1,h){
		FORQ(j,1,w){
			if(!b[i][j])continue;
			int f=1;
			FOR(d,0,4){
				int ni=i+dx[d],nj=j+dy[d];
				if(b[ni][nj])f=0;
			}
			if(f){
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";
    return 0;
}


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

int main(){
    int x1,x2,x3,x4,x5;

    cin >>x1>>x2>>x3>>x4>>x5;
    
    if(x1 == 0){
         cout << 1 << endl;
    }else if(x2==0){
         cout << 2 << endl;
    }else if(x3==0){
         cout << 3 << endl;
    }else if(x4==0){
         cout << 4 << endl;
    }else if(x5==0){
         cout << 5 << endl;
    }
    
}

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

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

    long long x;
    cin >> x;

    long long y = 0, at = 1;
    while(true){
        y += at;
        if(y >= x){
            cout << at << endl;
            return 0;
        }
        at++;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int A[12][12];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)scanf("%d",&A[i][j]);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			int num=0;
			for(int k=1;k<=m;k++)num+=(A[i][k]-A[j][k])*(A[i][k]-A[j][k]);
			int key=sqrt(num);
			if(key*key==num)ans++;
		}
	}
	cout<<ans;
	return 0;
}

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

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int d[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main() {
    int K;
    cin >> K;
    cout << d[K-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int A[1000000],n;

int binarySearch(int key){
int left = 0;
int right = n;
int mid;
while(left<right){
mid = (left+right)/2;
if(key==A[mid]) return 1;
if (key>A[mid]) left=mid+1;
else if(key<A[mid]) right = mid;
}
return 0;
}

int main(){
    int i,q,k,sum=0;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&k);
        if(binarySearch(k)) sum++;
    }
    printf("%d\n",sum);
    
    return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,ar[110];
cin>>a;
for(int i=0;i<a;++i)
{
cin>>ar[i];
}
sort(ar,ar+a,greater<int>());
int sum1=0,sum2=0;
for(int i=0;i<a;i++)
{
if(i%2==0) sum1+=ar[i];
else sum2+=ar[i];
}
cout<<abs(sum1-sum2)<<endl;
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n;
    int x;
    int count = 1;
    int i;
    int tmp;
    int a[100005] = {};
    
    
    scanf("%d",&n);
    scanf("%d",&a[0]);
    tmp = a[0];
    
    for(i = 1; i < n; i++)
    {
        scanf("%d", &x);
        if(tmp != x)
        {
            tmp = x;
            a[count++] = x;
        }
    }
    
    for(i = 0; i < count - 1; i++)
    {
        printf("%d ", a[i]);
    }
    
    printf("%d\n", a[count - 1]);
    
    return 0;
}



Measured memory_bytes: 3132
#include<stdio.h>
int main(){
  int m, i, j, n;
  m ='X' - 'A';
  char x[1000];
  scanf ( "%s" ,x );
  n = strlen(x);
  for ( i = 0 ; i < n ; i++ ){
    if ( x[i] >= 'D' && x[i] <= 'Z' ){
      x[i] = x[i] - 3;
    }
    else{
      x[i] = x[i] + m;
    }
  }

  printf ( "%s\n" ,x);
  return 0;
}

Measured memory_bytes: 524
#include <stdio.h>

int main(){
  int i;
  int num[4];
  int check[4]={0};
  int count=0;
  
  for(i=0;i<4;i++){
	  scanf("%d",&num[i]);
  }
  
  for(i=0;i<4;i++){
    switch(num[i]){
      case 1:
        if(check[0]==0){
          check[0]++;
        }
        break;
      case 4:
        if(check[1]==0){
          check[1]++;
        }
        break;
      case 7:
        if(check[2]==0){
          check[2]++;
        }
        break;
      case 9:
        if(check[3]==0){
          check[3]++;
        }
        break;
    }
  }
  for(i=0;i<4;i++){
    if(check[i]>0){
      count++;
    }
  }
  if(count==4){
    printf("YES");
  } else {
    printf("NO");
  }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
const int MAX = 2001;
const int MOD = 1000000007;
 
 



 
signed main(){
    int n;
    cin>>n;
    int x1,p[n-1];
    cin>>x1;
    int s,t;
    s=x1;
    for(int i=0;i<n-1;i++){
        cin>>t;
        p[i]=t-s;
        swap(t,s);
    }
    int m,k,a,q[n-1];
    cin>>m>>k;
    for(int i=0;i<n-1;i++)q[i]=i;
    for(int i=0;i<m;i++){
        cin>>a;
        swap(q[a-2],q[a-1]);
    }
    int st=0,s0,s1,count;
    int ban[n-1];
    fill(ban,ban+n-1,-1);
    while(true){
        count=1;
        while(st<n-1&&ban[st]!=-1)st++;
        if(st==n-1)break;
        s0=st;
        while(q[s0]!=st){
            s0=q[s0];
            count++;
        }
        s0=st;
        s1=st;
        count=k%count;
        while(count!=0){
            s1=q[s1];
            count--;
        }
        while(ban[s0]==-1){
            ban[s0]=s1;
            s0=q[s0];
            s1=q[s1];
        }

    }
    cout<<x1<<endl;
    for(int i=0;i<n-1;i++){
        x1+=p[ban[i]];
        cout<<x1<<endl;
    }


    return 0;
}

Measured memory_bytes: 3584
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi x(n),y(n),h(n);
    rep(i,n){
        cin>>x[i]>>y[i]>>h[i];
    }
    rep(i,n-1){
        for(int j=n-1;j>i;j--){
            if(h[j-1]<h[j]){
                swap(x[j-1],x[j]);
                swap(y[j-1],y[j]);
                swap(h[j-1],h[j]);
            }
        }
    }
    rep(cx,101){
        rep(cy,101){
            int a=h[0]+abs(x[0]-cx)+abs(y[0]-cy);
            if(!a)continue;
            bool f=true;
            rep(i,n){
                if(max(a-abs(x[i]-cx)-abs(y[i]-cy),0ll)!=h[i])f=false;
            }
            if(f){
                cout<<cx<<" "<<cy<<" "<<a<<endl;
                return;
            }
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int d[55];
	for (i = 0; i < n; i++)
		scanf("%d", &d[i]);
	d[n] = 0;
	for (i = 0; i < n; i++)
	{
		if (d[i] > d[i + 1])
		{
			d[i] ^= d[i + 1];
			d[i + 1] ^= d[i]; 
			d[i] ^= d[i + 1];
			if (i > 0)
				i -= 2;
		}
	}
	for (i = 0; i <= n; i += 2)
		d[i] *= -1;
	for (i = 0; i < n; i++)
	{
		if (d[i] > d[i + 1])
		{
			d[i] ^= d[i + 1];
			d[i + 1] ^= d[i];
			d[i] ^= d[i + 1];
			if (i > 0)
				i -= 2;
		}
	}
	int s = 50;
	for (i = 0; i < n; i++)
		if (s > d[i + 1] - d[i])
			s = d[i + 1] - d[i];
	if (s > d[0] + 24 - d[n])
		s = d[0] + 24 - d[n];
	printf("%d\n", s);
	return 0;
}

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

using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()



int main()
{
	fastio;
	ll r, d, x;
	cin >> r >> d >> x;
	for(int i=0;i<10;i++)
	{
		x = r*x - d;
		cout << x << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
public class Main {
	public static void main(String[] args) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		//StringBuilder sb = new StringBuilder();
		double r = sc.nextDouble();

		double menseki = r * r * Math.PI;
		double shuu = 2 * r * Math.PI;
		System.out.printf("%.5f %.5f\n",menseki,shuu);
	}
}

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

int main() {
  int n;
  cin >> n;
  ll abs_sum = 0;
  ll abs_min = 1e9;
  int negative_num = 0;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (a < 0) negative_num++;
    abs_min = min(abs(a), abs_min);
    abs_sum += abs(a);
  }

  if (negative_num % 2 == 1) abs_sum -= abs_min * 2LL;

  cout << abs_sum << endl;

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned int ui;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
#define All(v) (v).begin(),(v).end()
#define Rep(i,n) for(int i = 0; i < (int)n; i++)
#define Reps(i,n) for(int i = 1; i <= (int)n; i++)
#define For(i,m,n) for(int i = m; i < n; i++)
#define Fors(i,m,n) for(int i = m; i <= n; i++)
#define Inf 2e9
#define F first
#define S second
#define pb push_back
#define mp make_pair
struct speed{speed(){cin.tie(); ios::sync_with_stdio(false); cout << fixed << setprecision(18);}}speed;

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

ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

ll lcm(ll a, ll b){
    return a*b/gcd(a,b);
}



int main(){
    int n;
    cin >> n;
    vector<int> a(n+1),b(n);
    Rep(i,n+1){
        cin >> a[i];
    }
    Rep(i,n){
        cin >> b[i];
    }
    ll ans = 0;
    Rep(i,n){
        if(a[i] >= b[i]){
            ans += b[i];
        }else{
            ans += a[i];
            b[i] -= a[i];
            if(b[i] <= a[i+1]){
                ans += b[i];
                a[i+1] -= b[i];
            }else{
                ans += a[i+1];
                a[i+1] = 0;
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
	string s;
	int Q;
	cin >> s;
	cin >> Q;

	deque<string> S(s.size());
	for (int i = 0; i < s.size(); i++) {
		S[i] = s[i];
	}

	int T, F;
	string C;
	int parity = 0;
	for (int i = 0; i < Q; i++) {
		cin >> T;
		if (T == 2) {
			cin >> F >> C;
			if ((parity + F) % 2 == 1) {
				S.push_front(C);
			}
			else {
				S.push_back(C);
			}
		}
		else {
			parity++;
		}
	}

	string ans;
	for (string x : S) {
		ans += x;
	}

	if (parity % 2 == 1) {
		reverse(ans.begin(), ans.end());
	}

	cout << ans;
}

Measured memory_bytes: 17540
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let h: usize = sc.read();
    let a: usize = sc.read();
    let ans = (h + a - 1) / a;
    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    int x = N*800;
    int c;
    if(N < 15)
    {
        c = x-0;
        cout << c <<endl;
    }
    else if(N >= 15 && N <  30)
    {
        c = x - 200;
        cout << c <<endl;
    }
    else if( N >= 30 && N < 45)
    {
        c = x - 2*200;
        cout <<c <<endl;
    }
    else if(N >= 45 && N < 60)
    {
        c = x - 3*200;
        cout << c <<endl;
    }
    else if(N >= 60 && N <  75)
    {
        c = x - 4*200;
        cout << c <<endl;
    }
    else if(N >= 75 && N <  90)
    {
        c = x - 5*200;
        cout << c <<endl;
    }
    else if(N >= 90 && N < 105)
    {
        c = x - 6*200;
        cout << c <<endl;
    }
    return 0;

}


Measured memory_bytes: 256
N, K = map(int, input().split())
*h, = map(int, input().split())
dp = [float("inf")] * N
dp[0] = 0
for i in range(1, N):
    for j in range(max(0, i-K), i):
        a = dp[j] + abs(h[i] - h[j])
        dp[i] = min(dp[i], a)
print(dp[-1])

Measured memory_bytes: 89716
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::prelude::BufRead;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufReader, BufWriter, Write};
#[allow(unused_imports)]
use std::mem::swap;
#[allow(unused_imports)]
use std::str::FromStr;

fn main() {
	let line = read_vector::<usize>();
	let (n, d) = (line[0], line[1]);
	let coords = read_matrix::<i64>();
	let mut ans = 0;
	for i in 0..n {
		for j in (i + 1)..n {
			let dist_2 = (0..d).fold(0, |acc, k| acc + (coords[i][k] - coords[j][k]).pow(2));
			let root = (dist_2 as f64).sqrt() as i64;
			if root.pow(2) == dist_2 {
				ans += 1;
			}
		}
	}
	println!("{}", ans);
}


#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err: std::fmt::Debug {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    return buf
        .trim()
        .parse()
        .unwrap();
}

#[allow(dead_code)]
fn read_vector<T>() -> Vec<T> where T: std::str::FromStr, T::Err: std::fmt::Debug {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    return buf
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect();
}

#[allow(dead_code)]
fn read_matrix<T>() -> Vec<Vec<T>> where T: std::str::FromStr, T::Err: std::fmt::Debug {
    use std::io::prelude::*;
    let stdin = stdin();
    return stdin
        .lock()
        .lines()
        .map(|line| line
            .unwrap()
            .split_whitespace()
            .map(|s| s.parse().unwrap())
            .collect())
        .collect();
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

const ll INF = 1e9;
const long long INFL = 1LL<<60;


int main() {
  ll a, b, k;
  cin >> a >> b >> k;
  if (a >= k) {
    printf("%ld %ld\n", a - k, b);
  } else {
    k -= a;
    a = 0;
    if (k <= b) {
      printf("%ld %ld\n", 0, b - k);
    } else {
      printf("%ld %ld\n", 0, 0);
    }
  }

  return 0;
}


Measured memory_bytes: 3712
#include <cstring>
#include <string>
#include <memory>
#include <iostream>

/**
@note prime number and less than 1,000,000
*/
constexpr int max_size()
{
    return 1000003;
}

constexpr int null_val()
{
    return -1;
}

class dictionary {
public:
    dictionary()
        : _data(/*std::make_unique<int[]>(max_size())*/)
    {
        for (int i = 0; i < max_size(); ++i) {
            _data[i] = null_val();
        }
    }

    void insert(const std::string& str) {
        return insert(str2key(str), 0);
        return;
    }

    bool find(const std::string& str) {
        return find(str2key(str), 0);
    }

private:
    int str2int(const char ch) {
        if (ch == 'A') {
            return 1;
        }
        if (ch == 'C') {
            return 2;
        }
        if (ch == 'G') {
            return 3;
        }
        if (ch == 'T') {
            return 4;
        }
        return 0;
    }

    int str2key(const std::string& str)
    {
        int sum = 0;

        for (std::size_t i = 0; i < str.size(); ++i) {
            sum += str2int(str[i]);
            sum *= 5;   //move up;
        }
        
        return sum;
    }

    int base_hash(const int key) const
    {
        return key % max_size();
    }

    int collision_hash(const int key) const
    {
        constexpr int modulo = max_size() + 1;
        return 1 + key % modulo;
    }

    int create_hash(const int key, const int r) const 
    {
        const int base = base_hash(key);
        const int collision = collision_hash(key);
        const int h = (base + r * collision) % max_size();
        return h;
    }

    void insert(const int key, const int r)
    {
        const int h = create_hash(key, r);
        if (is_empty(h)) {
            _data[h] = key;
            return;
        }
        if (_data[h] == key) {
            return;
        }

        insert(key, r + 1);
        return;
    }

    bool find(const int key, const int r) const
    {
        const int h = create_hash(key, r);
        if (is_empty(h)) {
            return false;
        }
        if (_data[h] == key) {
            return true;
        }

        return find(key, r + 1);
    }

    bool is_empty(const int idx) const {
        return _data[idx] == null_val();
    }

private:
    //std::unique_ptr<int[]> _data;
    int _data[max_size()];
};

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

    int n;
    std::cin >> n;
    std::cin.ignore();

    dictionary dict;
    std::string buf;
    for (int i = 0; i < n; ++i) {
        getline(std::cin, buf);
        if (buf.front() == 'i') {
            static const std::size_t size = strlen("insert ");
            const std::string val
                = buf.substr(size, buf.size() - size);
            dict.insert(val);
        }
        else {
            static const std::size_t size = strlen("find ");
            const std::string val
                = buf.substr(size, buf.size() - size);
            if (dict.find(val)) {
                std::cout << "yes" << std::endl;
            }
            else {
                std::cout << "no" << std::endl;
            }
        }
    }

    return 0;
}

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

int main() {
    char c; // 判断文字
    cin >> c;

    switch (c) {
        case 'a':
            cout << "vowel" << endl;
            break;
        case 'e':
            cout << "vowel" << endl;
            break;
        case 'i':
            cout << "vowel" << endl;
            break;
        case 'o':
            cout << "vowel" << endl;
            break;
        case 'u':
            cout << "vowel" << endl;
            break;
        default:
            cout << "consonant" << endl;
    }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
class x{public:long f,s;};using namespace std;x P[1<<17];long c[1<<17],n,a,i,w=1e9;main(){for(cin>>n;i<n;P[i].s=i++)cin>>P[i].f;sort(P,P+n,[](x p,x q){return p.f-q.f?p.f<q.f:p.s>q.s;});for(;i--;)c[w=w>P[i].s?P[i].s:w]+=(n-i)*(P[i].f-P[i-1].f);for(;++i<n;)cout<<c[i]<<endl;}

Measured memory_bytes: 3456
from collections import Counter

n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))

counter1 = Counter(d)
counter2 = Counter(t)

for k, v in counter2.items():
    if counter1[k] < v:
        print('NO')
        exit()
print('YES')


Measured memory_bytes: 57184
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
const int INF = 1000000000;
typedef pair<int, int> P;
const int MAX_N = 1000000;
typedef int64_t ll;
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }


bool solve(const vector<string>& W) {
	const int n = W.size();

	//condition1
	for (int i = 0; i < n-1; i++)
	{
		if (W[i].back()!= W[i+1].front())
		{
			return false;
		}
	}

	//condition2
	for (int i = 0; i < n; i++)
	{
		for (int j = i+1; j < n; j++)
		{
			if (W[i]==W[j])
			{
				return false;
			}
		}
	}
	return true;
}

vector<string> input() {
	int n; cin >> n;
	vector<string> W(n);
	for (int i = 0; i < n; i++)
	{
		cin >> W[i];
	}
	return W;
}

int main() {
	const vector<string> W = input();
	if (solve(W))
	{
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3636
let solve n x =
  let rec aux acc n x =
    if x = 0 then acc - n
    else aux (2*(n/x*x) + acc) x (n mod x) in
  if n > x+x then aux n (n-x) x else aux n x (n-x)

let () = print_int (Scanf.scanf "%d %d" solve)

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int a, b;
	while (cin >> a >> b) {
		if (b > a)swap(a, b);
		int r;
		while (b) {
			r = a%b;
			a = b;
			b = r;
		}
		cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 2988
use std::io::{stdin, Read};
use std::str::FromStr;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let n: usize = read().unwrap();
    let c = 10_i64.pow(9) + 7;
    let ans = (1 ..= (n as i64)).fold(1, |acc, i| {
        let a = (acc * i) % c;
        a
    }
    );
    println!("{}", ans);
}


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

using Int = long long int;
template <class T, class U>
using Pair = std::pair<T, U>;
template <class T>
using Vector = std::vector<T>;

struct Max2 {
    Vector<Pair<Int, Int>> idx;
    // a[i]とiのペア

    Max2& operator+=(const Max2& opp) {
        std::copy(opp.idx.begin(), opp.idx.end(),
                  std::back_inserter(idx));
        std::sort(idx.rbegin(), idx.rend());
        idx.erase(std::unique(idx.begin(), idx.end()), idx.end());
        idx.resize(2);
        return *this;
    }
};

int main() {
    Int n;
    std::cin >> n;
    Vector<Max2> g(1 << n);
    for (Int i = 0; i < (1 << n); ++i) {
        Int a;
        std::cin >> a;
        g[i].idx.emplace_back(a, i);
    }

    // 高速ゼータ変換 (下位集合ver)
    for (Int k = 0; k < n; ++k) {
        for (Int b = 0; b < (1 << n); ++b) {
            if ((b >> k) & 1) {
                g[b] += g[b ^ (1 << k)];
            }
        }
    }

    Int max = 0;
    for (Int b = 1; b < (1 << n); ++b) {
        max = std::max(max, g[b].idx[0].first + g[b].idx[1].first);
        std::cout << max << std::endl;
    }
    return 0;
}


Measured memory_bytes: 33792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j;
    cin>>n;
    int h[n],c[n]={0};
    for(i=0;i<n;i++)
    {
       cin>>h[i];
    }
    c[1]=abs(h[1]-h[0]);
    for(i=2;i<n;i++)
    {
        c[i]=min(c[i-2]+abs(h[i]-h[i-2]),c[i-1]+abs(h[i]-h[i-1]));
    }
    cout<<c[n-1];
}


Measured memory_bytes: 1024