akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define ull unsigned long long
#define ll long long
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}


int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int n;
	int m;
	cin >> n;
	int x;
	ll res = 0;
	ll three_n = 1; ll two_m =  1;
	for(int i=0;i<n;++i) {
		cin >> x;
		if(x%2 == 0) {
			++m;
			two_m *= 2;
		}
		three_n *= 3;
	}
	cout << three_n - two_m << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,k,f[10001],mod=1000000007;
long long f1(long long p)
{
	if(p==0)
		return 1;
	long long tmp=f1(p/2)%mod;
	tmp=(tmp*tmp)%mod;
	if(p%2==1)
		tmp=(tmp*2)%mod;
	return tmp;
}
int main()
{
	scanf("%lld%lld",&n,&k);
	f[0]=1;
	for(int i=1; i<n; i++)
	{
		for(int j=i; j>0; j--)
			f[j]=(f[j+1]+f[j-1])%mod;
		f[0]=f[1];
	}
	printf("%lld",f[n-k]*f1(n-k-1)%mod);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int n, x; cin >> n >> x;
    int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a+n);
    int ans = 0;
    while (true) {
        if (ans == n-1) { if (x == a[n-1]) ans++; break; }
        if (x >= a[ans]) x -= a[ans++];
        else break;
    }
    cout << ans << endl;
        
}


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

const int N = (int)1e5 + 7;

int pr[N];
int a[N], sum[N];
int dif[N];

int find_dsu (int a) {
    if (pr[a] == a) return a;
    return pr[a] = find_dsu(pr[a]);
}

void connect (int a, int b) {
    a = find_dsu(a);
    b = find_dsu(b);
    if (a != b) {
        pr[a] = b;
        sum[b] += sum[a];
    }
}

main() {
    string s; cin >> s;
    int n; scanf ("%d", &n);
    int len = s.size();
    for (int i = 0; i < len; i++) {
        a[i + 1] = s[i] - 'a';
        pr[i + 1] = i + 1;
    }
    for (int i = 0; i <= len; i++) {
        if (a[i] <= a[i + 1]) {
            dif[i] = a[i + 1] - a[i];
        } else {
            dif[i] = (26 - a[i]) + a[i + 1];
        }
        sum[i] = dif[i];
    }
//    for (int i = 0; i <= len; i++) {
//        printf ("%d ", dif[i]);
//    }
//    puts("");
    for (int i = 0; i <= len; i++) {
        connect(i, len - i);
    }
    for (int i = 1; i <= n; i++) {
        int l, r; scanf ("%d %d", &l, &r);
        l--;
        connect(l, r);
    }
    for (int i = 0; i <= len; i++) {
        if (pr[i] == i && sum[i] % 26 != 0) {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
}


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

using usize = ::std::size_t;
//using u64 = ::std::int_least64_t;
using u64 = int;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;

const int MAXN = 100000;
int primes[MAXN], cnt;
map<int, int> factors;
void sieve(int *primes, int n, int &cnt)
{
    cnt = 0;
    memset(primes, 1, n * sizeof(int));

    for (int i = 2; i < n; i++)
    {
        if (primes[i]) primes[cnt++] = i;
        for (int j = 0; j < cnt && i * primes[j] < n; j++)
        {
            primes[i * primes[j]] = 0;
            if (i % primes[j] == 0) break;
        }
    }
}


int main(int argc, char *argv[])
{
    
 
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;
    cin >> Q;
    
    sieve(primes, MAXN, cnt);
    
    int sprimes[MAXN], cnt1 = 0;
    
    for (int i = 0; i < MAXN; i++) {
        sprimes[i] = Inf;
    }
    
    
    for (int i = 1; i < cnt; i++) {
        int target = (primes[i] + 1) / 2;
        if(binary_search(primes, primes + cnt, target)) sprimes[cnt1++] = primes[i];
    }
    
    while (Q--) {
        int l, r;
        cin >> l >> r;
        int left = upper_bound(sprimes, sprimes + cnt1, l - 1) - sprimes - 1;
        int right = upper_bound(sprimes, sprimes + cnt1, r) - sprimes - 1;
        cout << right - left << endl;
    }
    
    return 0;
}


Measured memory_bytes: 4452
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
 int X;cin >> X;
 if(X >= 30)
   cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3560
#include<iostream>
using namespace std;
void fswap(int *x, int *y) {
	int tmp;
	tmp = *x;
	*x = *y;
	*y = tmp;
}
int main() {
	int n, a[100], cnt = 0;
	cin >> n;
	for (int i = 0; i<n; ++i) cin >> a[i];
	bool flag = true;
	while (flag) {
		flag = false;
		for (int i = n - 1; i >= 1; --i) {
			if (a[i]<a[i - 1]) {
				fswap(&a[i], &a[i - 1]);
				++cnt;
				flag = true;
			}
		}
	}
	for (int i = 0; i<n; ++i) {
		if (i) cout << " ";
		cout << a[i];
	}
	cout << endl << cnt << endl;
	return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll N, K;
  cin >> N >> K;
  vector<Pll> ab(N);
  vll c(N+1, 0);
  for(int i = 0; i < N; i++){
    cin >> ab.at(i).first >> ab.at(i).second;
  }
  sort(ALL(ab));
  for(int i = 0; i < N; i++){
    c.at(i+1) = c.at(i) + ab.at(i).second;
  }
  auto ite = lower_bound(ALL(c), K);
  int num = distance(c.begin(), ite);
  cout << ab.at(num-1).first << endl;
}

Measured memory_bytes: 2560
def main():

    N, W = map(int, input().split())
    cur = dict()
    cur[0] = 0
    for _ in range(N):
        w, v = map(int, input().split())
        temp = cur.copy()
        for w1 in temp:
            if w1 + w <=W:
                if w1+w not in cur:
                    cur[w1+w] = temp[w1] + v
                else:
                    cur[w1+w] = max(cur[w1+w], temp[w1]+v)
    return max(cur.values()) 


if __name__ == '__main__':
    print(main())

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

using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;

    int ans = 0;
    for (int i = 0; i < 2; i++)
    {
        if (A > B)
        {
            ans += A;
            A--;
        }
        else
        {
            ans += B;
            B--;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	string s,t;
	cin>>s>>t;
	int n=s.size();
	int ans=1e9;
	for(int i=0;i+t.size()<=n;i++){
		int cnt=0;
		for(int j=0;j<t.size();j++)if(t[j]!=s[i+j])cnt++;
			ans=min(ans,cnt);
	}
	cout<<ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3644
#include <iostream>

int ask(int x) {
  std::string res;
  std::cout << x << "\n";
  std::cin >> res;

  if (res[0] == '0') {
    return 0;
  } else if (res[0] == 'M') {
    return 1;
  } else {
    return -1;
  }
}

bool judge(int left, int right, int left_x, int right_x) {
  if (left_x == right_x) {
    return (right - left) % 2 == 1;
  } else {
    return (right - left) % 2 == 0;
  }
}

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

  std::string res;
  int left = 0, right = N - 1;
  int left_x, right_x;

  int x = ask(left);
  if (x == 0) {
    return 0;
  }
  left_x = x;

  x = ask(right);
  if (x == 0) {
    return 0;
  }
  right_x = x;

  while (right - left > 1) {
    int mid = (left + right) / 2;
    x = ask(mid);
    if (x == 0) {
      return 0;
    }
    if (judge(left, mid, left_x, x)) {
      right = mid;
      right_x = x;
    } else {
      left = mid;
      left_x = x;
    }
  }

  return 0;
}

Measured memory_bytes: 3860
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define MAXN 3000
using namespace std;
struct node
{
	int to;
	node *nxt;
}edges[MAXN*2+5];
node *ncnt=&edges[0],*Adj[MAXN+5];
int n,a[MAXN+5];
vector<int> ans;
void AddEdge(int u,int v)
{
	node *p=++ncnt;
	p->to=v;
	p->nxt=Adj[u];
	Adj[u]=p;
	
	node *q=++ncnt;
	q->to=u;
	q->nxt=Adj[v];
	Adj[v]=q;
}
bool DFS(int u,int fa)
{
	for(node *p=Adj[u];p!=NULL;p=p->nxt)
	{
		int v=p->to;
		if(v==fa)
			continue;
		if(a[u]>a[v]&&DFS(v,u)==false)
			return true;
	}
	return false;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int u,v;
	for(int i=1;i<n;i++)
	{
		scanf("%d %d",&u,&v);
		AddEdge(u,v);
	}
	for(int i=1;i<=n;i++)
		if(DFS(i,-1)==true)
			ans.push_back(i);
	for(int i=0;i<(int)ans.size();i++)
		if(i==(int)ans.size()-1)
			printf("%d\n",ans[i]);
		else
			printf("%d ",ans[i]);
	return 0;
}

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



int main(){
    string s,t;
    cin >> s >> t;
    ll res=1e9;
    for(ll i=0;i<=s.size()-t.size();i++){
        ll count=0;
        for(ll j=0;j<t.size();j++){
            if(t[j]!=s[i+j]) count++;
        }
        res=min(res,count);
    }
    cout << res << endl;
    return 0;
}  


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

using namespace std;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    int n , k;
    cin >> n >> k;

    vector<int> a(n);
    for (int &x : a)
        cin >> x;


    auto sum = [&] (int n) {
        return n * (n + 1) / 2;
    };

    double exp = 0;
    for (int i = 0 ;i < k ;i++)
        exp += sum(a[i]) / double(a[i]);

    double mx = exp;
    for (int i = k ;i < n ;i++) {
        exp += sum(a[i]) / double(a[i]);
        exp -= sum(a[i - k]) / double(a[i - k]);
        mx = max(mx , exp);
    }

    cout << fixed << setprecision(12) << mx;
}


Measured memory_bytes: 3964
N, K = map( int, input().split())
A = [ [0]*2 for _ in range(N)]
for i in range(N):
    A[i] = list(map( int, input().split()))
A.sort()
L = 0
for i in range(N):
    L += A[i][1]
    if L >= K:
        print(A[i][0])
        break

Measured memory_bytes: 27824
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(string, S;)
    YES(S == "ABC", "ARC", "ABC");
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
  int N;
  cin >> N;
  map<int, int> mp;
  for(int i=0; i<N; i++){
    ll tmp;
    cin >> tmp;
    if(tmp%4 == 0) mp[2]++;
    else if(tmp%2 == 0) mp[1]++;
    else mp[0]++;
  }
  
  bool tf = true;
  
  int pre = 2;
  for(int i=0; i<N; i++){
    if(pre == 2){
      if(mp[0] >= 1){
        mp[0]--;
        pre = 0;
      }else if(mp[1] >= 1){
        mp[1]--;
        pre = 1;
      }else if(mp[2] >= 1){
        mp[2]--;
        pre = 2;
      }else{
        tf = false;
        break;
      }      
    }else if(pre == 1){
      if(mp[1] >= 1){
        mp[1]--;
        pre = 1;
      }else if(mp[2] >= 1){
        mp[2]--;
        pre = 2;
      }else{
        tf = false;
        break;
      }      
    }else{
      if(mp[2] >= 1){
        mp[2]--;
        pre = 2;
      }else{
        tf = false;
        break;
      }      
    }    
  }
    
  if(tf) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
 
        int N = sc.nextInt();
        int M = sc.nextInt();
 
        int A[][] = new int[N][M];
        int B[] = new int[M];
 
        for(int row = 0; row < N; row++){
            for(int col = 0; col < M; col++){
                A[row][col] = sc.nextInt();
            }
        }
 
        for(int row = 0; row < M; row++){
            B[row] = sc.nextInt();
        }
 
        int ans;
 
        for(int row = 0; row < N; row++){
            ans = 0;
            for(int col = 0; col < M; col++){
                ans += A[row][col]*B[col];
            }
            System.out.printf("%d\n", ans);
        }
    }
}


Measured memory_bytes: 40768
A, B, C, X, Y = map(int, input().split())

AB = A + B

num_A = 0
num_B = 0
num_C = 0
ans_cost = 5000 * 2 * 10**5
if 2 * C > AB:
    num_A = X
    num_B = Y
    num_C = 0
    ans_cost = int(A*num_A + B*num_B + C*num_C)
else:
    min_C = min(X,Y) *2
    max_C = max(X,Y) *2
    for i in range(min_C, max_C+1, 2):
        num_A = X - i / 2
        num_B = Y - i / 2
        if num_A < 1:
            num_A = 0
        if num_B < 1:
            num_B = 0
        
        total_cost = int(A*num_A + B*num_B + C*i)
    
        if total_cost < ans_cost:
            ans_cost = total_cost

print(ans_cost)

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
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; }
//template end

int mod=998244353;
struct Mint {
    int val;
    Mint inv() const{
        int tmp,a=val,b=mod,x=1,y=0;
        while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
        return Mint(x);
    }
public:
    Mint():val(0){}
    Mint(ll x){if((val=x%mod)<0)val+=mod;}
    Mint pow(ll t){Mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
    Mint& operator+=(const Mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
    Mint& operator-=(const Mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
    Mint& operator*=(const Mint& x){val=(ll)val*x.val%mod; return *this;}
    Mint& operator/=(const Mint& x){return *this*=x.inv();}
    Mint operator+(const Mint& x) const{return Mint(*this)+=x;}
    Mint operator-(const Mint& x) const{return Mint(*this)-=x;}
    Mint operator*(const Mint& x) const{return Mint(*this)*=x;}
    Mint operator/(const Mint& x) const{return Mint(*this)/=x;}
};
struct factorial {
    vector<Mint> Fact, Finv;
public:
    factorial(int maxx){
        Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
        Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
    }
    Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
    Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
    Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};

int main(){
    int n; scanf("%d",&n);
    vector<int> x(n),y(n);
    rep(i,0,n)scanf("%d%d",&x[i],&y[i]);
    Mint pw[210]; pw[0]=1;
    rep(i,0,205)pw[i+1]=pw[i]*2;
    Mint res=pw[n]-1-n-Mint(n*(n-1)/2);
    bool used[210][210]={};
    rep(i,0,n)rep(j,i+1,n)if(!used[i][j]){
        vector<int> a={i,j};
        int cnt=2,x1=x[j]-x[i],y1=y[j]-y[i];
        rep(k,0,n)if(k!=i&&k!=j){
            int x2=x[k]-x[i],y2=y[k]-y[i];
            if(x1*y2==y1*x2){
                a.push_back(k); cnt++;
            }
        }
        sort(ALL(a));
        rep(k,0,a.size())rep(l,k,a.size())used[a[k]][a[l]]=1;
        if(cnt>=3)res-=(pw[cnt]-1-cnt-Mint(cnt*(cnt-1)/2));
    }
    printf("%d\n",res.val);
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
int main(void)
{
	int a, b, c, t;
	
	scanf("%d %d %d", &a, &b, &c);
    
    if(a>b) t = a, a = b, b = t;
    if(b>c) t = b, b = c, c = t;
    if(a>b) t = a, a = b, b = t;
	printf("%d %d %d\n", a, b, c);

return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
int main(){
  int n=1e9,m=1e9,s=0,a,i;
  for(i=0;i<4;i++){
    scanf("%d",&a);
    s+=a;
    if(a<n)n=a;
  }
  for(i=0;i<2;i++){
    scanf("%d",&a);
    s+=a;
    if(a<m)m=a;
  }
  printf("%d\n",s-n-m);
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rlcfpoj(x) scanf("%I64d",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define plcfpoj(x) printf("%I64d",x)
#define lfd() printf("\n")
#define sp() printf(" ")
#define inrep(x) int x;scanf("%d",&x);while(x--)
vector<int> rl;
string s;
int cnt[100100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>s;
	for(int i=0;i<s.size()-1;i++)
		if(s[i]=='R'&&s[i+1]=='L')
			rl.push_back(i);
	rl.push_back(1e9);//缓冲 
	for(int i=0;i<s.size();i++){
		int dir=(s[i]=='R'?1:-1);
		int pos;
		if(dir==1)
			pos=lower_bound(rl.begin(),rl.end(),i)-rl.begin();
		else
			pos=lower_bound(rl.begin(),rl.end(),i)-rl.begin()-1;
		int dist=abs(i-rl[pos]);
		dist%=2;
		if(dist==1)
			cnt[rl[pos]+1]++;
		else
			cnt[rl[pos]]++;
	}
	for(int i=0;i<s.size();i++)
		cout<<cnt[i]<<' ';
	return 0;
}


Measured memory_bytes: 1232
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ctime>
#include <set>
#include <sstream>
#include <bitset>
#include <queue>
#define ll long long
using namespace std;
const int mod = 1e9 + 7;

int main(){
    ll n, k;
    cin >> n >> k;
    ll sum = 0;
    for (ll i = k; i < n + 2; i++) {
        ll minn = (i - 1) * i / 2;
        ll maxx = ((n + (n - i + 1)) * i) / 2;
        ll m = (maxx - minn + 1) % mod;
        sum = (sum + m) % mod;
    }
    cout<<sum;
}


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

using namespace std;
int main(){
	int a,b,c;
	
	cin>>a>>b;
	c=a*b;
	if(c%2==0){
		cout<<"Even"<<endl;
	}else{
		cout<<"Odd"<<endl;
	}



	return 0;
}

Measured memory_bytes: 256
main :: IO ()
main = do ls <- getContents
          putStr (compose ls)

compose :: String -> String
compose = unlines . fmap unlines . rect . fmap (toTupleofInts . take 2 . words) . lines
          where
            toTupleofInts =  (\[x,y] -> (x,y)) . fmap (\x -> read x::Int)

rect :: [(Int, Int)] -> [[String]]
rect [] = []
rect ((m, n):xs) | m == 0 && n == 0 = []
                 | otherwise = replicate m (replicate n '#') : rect xs

Measured memory_bytes: 5152
N = int(input())
s = []
for i in range(N):
    s.append(input())
M = int(input())
t = []
for j in range(M):
    t.append(input())

A = list(set(s))
B = []

for k in range(len(A)):
    B.append(s.count(A[k])-t.count(A[k]))

C = max(B)

if C>0:
    print(C)
else:
    print("0")

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


int main() {
	string s;
	char owo1='q', owo2='q';
	int uwu1=0, uwu2=0;
	cin>>s;
	
	for (int i=0; i<s.size();i++)
	{
		if (uwu1==0 )
		{
			owo1=s[i];
			uwu1++;
			continue;
		}
		
		if (s[i]==owo1)
		{
			uwu1++;
			continue;
		}
		
		
		if (uwu2==0 )
		{
			owo2=s[i];
			uwu2++;
			continue;
		}
		
		if (s[i]==owo2)
		{
			uwu2++;
			continue;
		}
		
		
		
		
	}
	
	if (uwu1==2 && uwu2==2)
	cout<<"Yes";
	else
	cout <<"No";
	
	return 0;
}

Measured memory_bytes: 256
W,H,N=map(int,input().split())
D=[list(map(int,input().split()))for _ in range(N)]
sx=0
sy=0
lx=W
ly=H
for d in D:
  if d[2]==1:
    sx=max(sx,d[0])
    #左側から作るイメージ(値が大きいなら拡張)
  elif d[2]==2:
    lx=min(lx,d[0])
    #右側から作る(値が小さい方が拡張)
  elif d[2]==3:
    sy=max(sy,d[1])
  else:
    ly=min(ly,d[1])
if lx<=sx or ly<=sy:
  print(0)
else:
  print((lx-sx)*(ly-sy))

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

#define endl "\n"

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

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

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

//動的計画法で役に立つ関数
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; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

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

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k] ) % MOD;
    }
  }
  return v;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int N, K; cin >> N >> K;
    vector<vector<long long> > v = comb(N);
    for (int i=1; i<=K; i++)
    {
        cout << ((v[N-K+1][i] % MOD)*(v[K-1][i-1]) % MOD) % MOD  << endl;
    }
    return 0;
}



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

int main(){
  int n;
  cin >> n;
  long long a, sum[n+1], m = 1, counter = 0;
  sum[0] = 0;
  for(int i=1; i<=n; i++){
    cin >> a;
    sum[i] = sum[i-1] + a;
  }
  sort(sum, sum+n+1);
  for(int i=0; i<n+1; i++){
    if(sum[i] != sum[i+1]){
      counter += (m * (m -1)) / 2;
      m = 1;
    }else{
      m++;
    }
  }
  cout << counter << endl;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();

        int result = (int)Math.pow(k/2, 2);
        if (k % 2 == 1) result = (k/2) * (k/2+1);
        System.out.println(result);
    }
}


Measured memory_bytes: 35688
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);

  for (ll i = 0; i < N; i++) {
    cin >> a[i];
  }

  ll next = 1;
  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    if (a[i] != next) {
      ans++;
      continue;
    } else {
      next++;
    }
  }

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

  return 0;
}


Measured memory_bytes: 1920
N = int(input())
A = [[x - 1 for x in list(map(int, input().split()))] for i in range(N)]

def can_match(i, A, next_set):
	if not A[i]:
		return
	j = A[i][-1]
	if A[j][-1] == i:
		if i < j:
			next_set.add((i, j))
		else:
			next_set.add((j, i))
		
 
next_set = set()
for i in range(N):
	can_match(i, A, next_set)
 
day = 0
battle = 0
while next_set:
	day += 1
	current_set = next_set.copy()
	next_set = set()
	for match in current_set:
		battle += 1
		del A[match[0]][-1]
		can_match(match[0], A, next_set)
		del A[match[1]][-1]
		can_match(match[1], A, next_set)
 
if battle == N*(N-1) // 2:
	print(day)
    
else:
	print(-1)

Measured memory_bytes: 35596
#include <stdio.h>

int main(void)
{
  int m[10];
  int i, j, tmp;

  for(i = 0; i < 10; i++){
    scanf("%d", &m[i]);
  }

  for(i = 0; i < 10; i++){
    for(j = 10; j > i; j--){
      if(m[j] < m[j-1]){
        tmp = m[j];
        m[j] = m[j-1];
        m[j-1] = tmp;
      }
    }
  }

  for(i = 9; i > 6; i--){
    printf("%d\n", m[i]);
  }

  return (0);
}

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

int main() {
	string S;
	cin >> S;

	int cnt = 1;
	char ch;
	for (int i = 0; i < S.size(); i++) {
		if (!i) {
			ch = S.at(i);
			if (count(S.begin(), S.end(), ch) == S.size()) {
				cout << 0 << endl;
				return 0;
			}
		}
		else {
			if (ch != S.at(i)) {
				cnt++;
				ch = S.at(i);
			}
		}
	}

	cout << cnt - 1 << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i,a,b) for(int(i)=(a);(i)<(b);++(i))
#define RREP(i,a,b) for(int(i)=(a)-1;(i)>=(b);--(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

int main()
{
  int N,M;
  cin >> N >> M;
  vector<int> k(M);
  // vector<vector<int>> s(M, vector<int>(M));
  int s[20][20];
  vector<int> p(M);
  REP(i,0,M) {
    cin >> k[i];
    REP(j,0,k[i]) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  REP(i,0,M) cin >> p[i];

  int ans = 0;   //組み合わせ数
  REP(mask,0,1<<N) {  // N個のスイッチの状態
    bool flag = true;  // 全ての電球が付く
    REP(i,0,M) {  // 電球iが点灯するか？
      // 電球iに，繋がっているスイッチのうち何個がonか
      int x = 0;
      REP(j,0,k[i]) {
        // スイッチ s[i][j]がonか？
        if (mask & (1<<s[i][j])) ++x;
      }
      // 電球iが点灯する
      if (x % 2 == p[i]) continue;
      else {
        flag = false;
        break;
      }
    }
    if (flag) ++ans;
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007
 
int main(){
    ll x,y;
    cin >> x >> y;
    ll num = INF;
    ll a = y - x;
    if(a>=0) num = min(num,a);
    ll b = y + x + 1;
    if(b>=0) num = min(num,b);
    ll c = - y - x + 1;
    if(c>=0) num = min(num,c);
    ll d = -y + x + 2;
    if(d>=0) num = min(num,d);
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 3604
void main()
{
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], k = tmp[1];

    writeln((n + 1) / 2 >= k ? "YES" : "NO");
}

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

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

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int dp[1010][5000];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m), c(m, 0);
    for(int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];

        for(int j = 0; j < b[i]; j++) {
            int tmp;
            cin >> tmp;
            c[i] = c[i] | (1 << (tmp - 1));
        }
    }
    for(int i = 0; i < 1010; i++) {
        for(int j = 0; j < 5000; j++) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    for(int i = 0; i < m; i++) {
        for(int S = 0; S < (1 << n); S++) {
            int next = S | c[i];
            chmin(dp[i + 1][S], dp[i][S]);
            chmin(dp[i + 1][next], dp[i][S] + a[i]);
        }
    }
    int ans = dp[m][(1 << n) - 1];
    cout << (ans == INF ? -1 : ans) << endl;
}

Measured memory_bytes: 19968
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// 042C

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> d(k);
    rep(i, k) cin >> d[i];
    int ans = n;
    bool flag = true;

    while(flag){
        string tmp = to_string(ans);
        int nn = tmp.size();
        flag = false;
        rep(i, nn){
            rep(j, d.size()){
                if(tmp[i]-'0' == d[j]){
                    flag = true;
                    break;
                }
            }
            if(flag) break;
        }
        if(!flag) break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <algorithm>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <cmath>
#include <limits>
#include <queue>

#define pv(val) cerr << #val << '=' << (val) << endl
#define pvn(name, val) cerr << name << '=' << (val) << endl
#define pl cerr << '@' << __LINE__ << endl

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template <class T>
ostream &operator<<(ostream &os, vector<T> const &vec)
{
    if (vec.empty())
    {
        os << "{}";
    }
    else
    {
        os << '{';
        for (size_t i = 0; i < vec.size() - 1; i++)
            os << vec[i] << ", ";
        os << vec.back() << '}';
    }
    return os;
}

template <class T, size_t S>
ostream &operator<<(ostream &os, array<T, S> const &arr)
{
    if (arr.empty())
    {
        os << "{}";
    }
    else
    {
        os << '{';
        for (size_t i = 0; i < arr.size() - 1; i++)
            os << arr[i] << ", ";
        os << arr.back() << '}';
    }
    return os;
}

template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

namespace math
{
ll gcd(ll u, ll v)
{
    while (v != 0)
    {
        ll r = u % v;
        u = v;
        v = r;
    }
    return u;
}
ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;

    return ((m / math::gcd(m, n)) * n);
}

ull gcd(ull u, ull v)
{
    while (v != 0)
    {
        ull r = u % v;
        u = v;
        v = r;
    }
    return u;
}
ull lcm(ull m, ull n)
{
    if ((0 == m) || (0 == n))
        return 0;

    return ((m / math::gcd(m, n)) * n);
}
} // namespace math



int main(void)
{
    int H, W;
    cin >> H >> W;

    vector<vector<bool>> visited(H, vector<bool>(W, false));
    vector<string> S(H);
    for(int i = 0; i < H; i++)
        cin >> S[i];
    
    array<pair<int, int>, 4> const diff = {
        pair<int, int>{-1, 0}, {1, 0}, {0, -1}, {0, 1}
    };

    ll ans = 0;
    for(int y = 0; y < H; y++){
        for(int x = 0; x < W; x++){
            if(visited[y][x]) continue;
            queue<pair<int, int>> q;
            q.push({y, x});
            ll nBlack = 0;
            ll nWhite = 0;
            while(!q.empty()){
                auto p = q.front();
                q.pop();
                if(visited[p.first][p.second])
                    continue;

                visited[p.first][p.second] = true;

                if(S[p.first][p.second] == '#') nBlack++;
                else nWhite++;

                for(auto d : diff){
                    if(p.first + d.first < 0 || p.first + d.first >= H || p.second + d.second < 0 || p.second + d.second >= W)
                        continue;
                    if(S[p.first][p.second] == S[p.first + d.first][p.second + d.second])
                        continue;
                    
                    q.push({p.first + d.first, p.second + d.second});
                }
            }
            ans += nBlack * nWhite;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1016
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    ll m = sqrt(n);
    vector<vector<ll>> dp(k+1,vector<ll>(100005,0));
    vector<ll> mov;
    rep(i,1,m){
        mov.push_back(n/i-n/(i+1));
        //PRINT(mov[i-1]);
    }
    reverse(all(mov));
    ll d = n/m;
    dp[0][0] = 1;
    rep(i,k){
        rep(j,d){
            dp[i+1][min(d+m-j-1,n/(j+1))] -= dp[i][j];
            dp[i+1][0] += dp[i][j];
        }
        rep(j,m-1){
            dp[i+1][m-j-1] -= dp[i][d+j]*mov[j]%MOD;
            dp[i+1][0] += dp[i][d+j]*mov[j]%MOD;
        }
        rep(j,m+d-1){
            dp[i+1][j+1] += dp[i+1][j];
            dp[i+1][j] %= MOD;
        }
        //array_output(dp[i+1].begin(),dp[i+1].begin()+m+d-1);
    }
    ll ans = 0;
    rep(i,d){
        ans += dp[k][i];
        ans %= MOD;
    }
    rep(i,m-1){
        ans += dp[k][d+i]*mov[i]%MOD;
        ans %= MOD;
    }
    PRINT(ans);
}


Measured memory_bytes: 80256
use proconio::input;
use std::cmp;

fn main() {
    input! {
        n : usize,
        a : [i64; n]
    };
    let mut dp : [[i64;3];200010] = [[-(1 << 50); 3]; 200010];
    dp[0][0] = a[0];
    dp[1][1] = a[1];
    if n >= 3 {
        dp[2][2] = a[2];
    }
    for i in 0..n {
        for j in 0..3 {
            for k in 0..3 {
                if i+k+2 >= n || j+k >= 3 { break;}
                dp[i+k+2][j+k] = cmp::max(dp[i+k+2][j+k], dp[i][j] + a[i+k+2]);
            }
        }
    }
    let res = if n%2 == 1 {
        cmp::max(dp[n-1][2], cmp::max(dp[n-2][1], dp[n-3][0]))
    } else {
        cmp::max(dp[n-1][1], dp[n-2][0])
    };
    println!("{}", res);
}


Measured memory_bytes: 10464
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;
using vi=vector<int>;
using ll=long long;



int is_ok(vi& h, int a, int b, int t)
{
	int n=h.size();
	int c=a-b;
	int x;
	ll r=0;

	for(int i=0;i<n;i++)
	{
		x=(h[i]-(ll)b*t+c-1)/c;
		r+=max(0, x);
	}
	return r<=t;
}


int main(void)
{
	int n, a, b;

	while(scanf("%d%d%d", &n, &a, &b)==3)
	{
		int h_max=0;
		vi h(n);
		int s, e, c, ans;

		for(int i=0;i<n;i++)
		{
			scanf("%d", &h[i]);
			h_max=max(h_max, h[i]);
		}

		s=1;
		e=(h_max+b-1)/b;
		ans=e;
		while(s<=e)
		{
			c=(s+e)/2;
			if(is_ok(h, a, b, c))
			{
				e=c-1;
				ans=c;
			}
			else
			{
				s=c+1;
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>

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

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	while (1) {
		ll N; scanf("%lld", &N);
		if (N == 0) break;
		ll res = 0;
		for (ll i = 1; i <= N / 2; i++) {
			ll now = i;
			ll sum = 0;
			while (sum < N) {
				sum += now;
				now++;
			}
			if (sum == N) res++;
		}
		printf("%lld\n", res);
	}
	return 0;
}


Measured memory_bytes: 3204
#include <iostream>
#include <cstdio>
#include <cstring>
#define min(a, b) a < b ? a : b
using namespace std;
int f[100000];
int dp[100000];
int abs(int a) {
    return a < 0 ? -a : a;
}
int main() {
	int n, k;
	cin >> n >> k;
	memset(dp, 0x3f, sizeof(dp));
	for(int i=0; i<n; i++) {
		scanf("%d", &f[i]);
	}
	dp[0] = 0;
	for(int i=1; i<k; i++) {
		for(int j=i; j>=0; j--) {
			dp[i] = min(dp[i], dp[i - j] + abs(f[i] - f[i - j]));
		}
	}
	for(int i=k; i<n; i++) {
		for(int j=1; j<=k; j++) {
			dp[i] = min(dp[i], dp[i - j] + abs(f[i] - f[i - j]));
		}
	}
	cout << dp[n - 1] << endl;
    return 0;
}

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


int H,W;
string R[107];
int main(){
    // 入力
    cin >> H >> W;
    for(int i = 0;i < H;i++){
        cin >> R[i];
    }
    
    for(int i = 0;i < H;i++){
        cout << R[i] << endl;
        cout << R[i] << endl;
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  rep(i,5){
    ll a;cin >> a;
    if(a==0){
      cout << i+1 << endl;
      return 0;
    }
  }
}

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

int main(){

    int M,K;
    cin >> M >> K;
    if(M==1){
        if(K == 0){
            cout <<"0 0 1 1"<<endl;
        }else{
            cout << -1 <<endl;
        }
        return 0;
    }
    
    int MX = 1<<M;
    if(K >= MX){
        cout << -1 <<endl; 
        return 0;
    }
    vector<int> ans;
    for(int i = 0; i < MX;i++)if(i!=K)ans.push_back(i);
    ans.push_back(K);
    for(int i = MX-1; i >= 0;i--)if(i!=K)ans.push_back(i);
    ans.push_back(K);
    for(int i = 0; i < ans.size();i++){
        if(i==ans.size()-1)cout << ans[i] <<endl;
        else cout << ans[i] <<" ";
    }
    return 0;
}


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

string S, T;

bool solve() {
  int N = S.length();

  int c = 1;
  vector<int> ss(N);
  map<char, int> mp;
  for (int i = 0; i < N; ++i) {
    if (mp[S[i]] > 0) {
      ss[i] = mp[S[i]];
    } else {
      ss[i] = c;
      mp[S[i]] = c;
      ++c;
    }
  }

  c = 1;
  vector<int> ts(N);
  mp = {};
  for (int i = 0; i < N; ++i) {
    if (mp[T[i]] > 0) {
      ts[i] = mp[T[i]];
    } else {
      ts[i] = c;
      mp[T[i]] = c;
      ++c;
    }
  }

  for (int i = 0; i < N; ++i) {
    if (ss[i] != ts[i]) return false;
  }
  return true;
}

int main() {
  cin >> S >> T;
  cout << ( (solve()) ? "Yes" : "No" ) << endl;
  return 0;
}


Measured memory_bytes: 2312
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    As = sorted(A)
    print(As[-1] - As[0])

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    public static void Main()
    {
        int N = NextInt();
        int K = NextInt();
        int[] A = LineInt();
        Array.Sort(A);
        if (A.All(v => v % 2 == 1))
        {
            if (A[N - 1] >= K) { Console.WriteLine("POSSIBLE"); }
            else { Console.WriteLine("IMPOSSIBLE"); }
            return;
        }
        else if (A.All(v => v % 2 == 0))
        {
            long min = A[0];
            for (int i = 1; i < N; i++) min = GCD(min, A[i]);
            bool f = false;
            for (int i = 0; i < N; i++)
            {
                if (A[i] < K) continue;
                if ((A[i] - K) % min == 0) f = true;
            }
            if (f) { Console.WriteLine("POSSIBLE"); }
            else { Console.WriteLine("IMPOSSIBLE"); }
            return;
        }
        else {
            long min = A[0];
            for (int i = 1; i < N; i++) min = GCD(min, A[i]);
            bool f = false;
            for (int i = 0; i < N; i++)
            {
                if (A[i] < K) continue;
                if ((A[i] - K) % min == 0) f = true;
            }
            if (f) { Console.WriteLine("POSSIBLE"); }
            else { Console.WriteLine("IMPOSSIBLE"); }
            return;
        }
    }
    public static long GCD(long a, long b)
    {
        if (a < b) GCD(b, a);
        long d = a % b;
        while (b != 0)
        {
            d = a % b;
            a = b;
            b = d;
        }
        return a;
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 18656