akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

int main(){
	int K,A,B;
	cin>>K>>A>>B;
	
	int r = B-A;
	
	if(r<=2){
		cout<<1+K<<endl;
		return 0;
	}
	if(K-A+1<0){
		cout<<1+K<<endl;
		return 0;
	}
	K-=A-1;
	long long ans=A;
	ans+=(long long)r*(K/2);
	K%=2;
	if(K==1)ans++;
	cout<<ans<<endl;
	
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define long long long
using namespace std;
template<class A, class B>inline bool chmax(A &a, const B &b){return (a<b)?a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return (a>b)?a=b,1 : 0;}
using pii = pair<int,int>;

int N;
int h[105];

int main()
{
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> h[i];
  }

  int ans = 0;
  while(true)
  {
    bool on = false;
    bool modified = false;

    for(int i = 0; i < N; ++i) {
      if(h[i] > 0) {
        if (!on) {
          on = true;
          ++ans;
          modified = true;
        }
      } else {
        on = false;
      }

      if (on) --h[i];
    }

    if (!modified) break;
  }

  cout << ans << endl;

  return 0;
}


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

int main()
{
	long long N;
	cin >> N;
	int var = 0;
	for (long long int i = 1; i <= 3500; i++) {
		for (long long int j = i; j <= 3500; j++) {
			if ( (4 * i*j - N*i - N*j) > 0&& (N*i*j) % (4 * i*j - N*i - N*j) == 0) {
				cout << i <<" "<< j <<" "<< (long long )((N*i*j) / (4 * i*j - N*i - N*j));
				var = 1;
				break;
			}
		}
		if (var == 1)break;
	}
//	system("pause");
    return 0;
}


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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dy = ty - sy, dx = tx - sx;
    string ans = "";
    rep(i, dy){
        ans += "U";
    }
    rep(i, dx){
        ans += "R";
    }
    rep(i, dy){
        ans += "D";
    }
    rep(i, dx+1){
        ans += "L";
    }
    rep(i, dy+1){
        ans += "U";
    }
    rep(i, dx+1){
        ans += "R";
    }
    ans += "DR";
    rep(i, dy+1){
        ans += "D";
    }
    rep(i, dx+1){
        ans += "L";
    }
    ans += "U";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;


#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod
#define MUL(a,b) a=(a*b)%mod

ll N;
ll d[16][3];
ll mx[40000][16], my[40000][16];

ll MX(ll a, ll k){
    if(mx[a][k]>=0) return mx[a][k];
    if(!a) return mx[a][k]=abs(d[k][0])*d[k][2];
    vec f;
    rep(i,N) if((1<<i) & a) {
        f.pb(i);
        if(i==k) return mx[a][k]=0;
    }
    ll P=MX(a-(1<<f[0]),k);
    return mx[a][k]=min(P,abs(d[k][0]-d[f[0]][0])*d[k][2]);
}

ll MY(ll a, ll k){
    if(my[a][k]>=0) return my[a][k];
    if(!a) return my[a][k]=abs(d[k][1])*d[k][2];
    vec f;
    rep(i,N) if((1<<i) & a) {
        f.pb(i);
        if(i==k) return my[a][k]=0;
    }
    ll P=MY(a-(1<<f[0]),k);
    return my[a][k]=min(P,abs(d[k][1]-d[f[0]][1])*d[k][2]);
}
ll ans[16];

void Solve(ll a){
    ll F=N;
    ll A=a;
    ll xx=0,yy=0;
    rep(i,N){
        if(A%3==1) xx+=(1<<i);
        if(A%3==2) yy+=(1<<i);
        if(A%3==0) F--;
        A/=3;
    }
    ll ret=0;
    rep(i,N) ret+=min(MX(xx,i),MY(yy,i));
    //cout<<a<<' '<<ret<<endl;
    ans[F]=min(ret,ans[F]);
    return;
}

ll ruijou(ll n, ll k){
    if(!k) return 1;
    ll a=ruijou(n,k/2);
    a=(a*a);
    return k%2 ? (a*n): a;
}


int main(){
    rep(i,40000) rep(j,16){
        mx[i][j]=-INF; my[i][j]=-INF;
    }
    rep(j,16) ans[j]=INF;
    cin>>N;
    rep(i,N) rep(j,3) cin>>d[i][j];
    //cout<<"ARRIVED"<<endl;
    rep(i,ruijou(3,N)) Solve(i);
    rep(i,N+1) cout<<ans[i]<<endl;


}

Measured memory_bytes: 13624
// 個数制限付きナップサック問題
// i番目の品物はmi個まで選べる
// 参照: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2119650#1

#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <climits>
#include <cassert>

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

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair

// N: 品物の個数
// W: ナップサックの容量
// v: 品物の価値
// w: 品物の重さ
// m: 品物の最大個数
ll knapsack(ll N, ll W, vector<ll>& v, vector<ll>& w, vector<ll>& m) {
    vector<ll> dp(W+1);
    dp[0] = 0;

    // ある品物を1, 2, 4, 8...個選んだときの<価値,重さ>
    // これらを新たな品物としてみなしていることに相当する
    vector<pair<ll,ll>> vec;
    REP(i, N) {
        int cnt = 1;
        while (m[i] > 0) {
            if (cnt > m[i]) { // 端数
                vec.pb(mp(m[i]*v[i], m[i]*w[i]));
                break;
            }
            vec.pb(mp(cnt*v[i], cnt*w[i]));
            m[i] -= cnt;
            cnt += 2;
        }
    }
    REP(i, SIZE(vec)) {
        for(ll j = W; j >= vec[i].second; j--) {
            dp[j] = max(dp[j], dp[j - vec[i].second] + vec[i].first);
        }
    }
    ll maxn = 0;
    REP(i, W+1) {
        maxn = max(maxn, dp[i]);
    }
    return maxn;
}

int main(){
    ll N, W;
    cin >> N >> W;
    vector<ll> v(N);
    vector<ll> w(N);
    vector<ll> m(N);
    REP(n, N) cin >> v[n] >> w[n] >> m[n];
    auto ans = knapsack(N, W, v, w, m);
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3304
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <climits>
#include <map>
#include <queue>
#include <cmath>

using namespace std;

using int64 = long long;


int main() {
    int64 n;
    cin >> n;
    vector<int> a(n,0);
    for (int i=0; i<n; i++) cin >> a[i];
    int64 ans = 0;
    map<int64,int64> mp;
    for (int i=0; i<n; i++) {
       ans += mp[a[i]]++;
    }


    for (int i=0; i<n; i++) {
        cout << ans - mp[a[i]] + 1 << endl;
    }
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll a, b, c; cin >> a >> b >> c;
    ll sa = a, sb = b, sc = c;
    ll cnt = 0;
    while(true){
        // cout << a << " " << b << " " << c << endl;
        if(a %2 == 1 || b %2 == 1 || c %2 == 1) break;
        ll ta = a, tb = b, tc = c;
        a = (tb + tc) / 2;
        b = (tc + ta) / 2;
        c = (ta + tb) / 2;
        cnt++;
        if(a == sa && b == sb && c == sc){
            cnt = -1;
            break;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
N = int(input())
MOD = 10**9 + 7

prime=[]
for n in range(2, 1001):
    for i in range(2,n):
        if n % i == 0:
            break
    else:
        prime.append(n)
#print(prime)

bucket={}
for p in prime:
    bucket[p]=0
#print(bucket)

for i in range(2, N+1):
    for p in prime:
        if p > i:
            break
        #print(i,p)
        while i % p == 0:
            i //= p
            bucket[p] += 1

#print(bucket)

ans=1
for p in prime:
    ans = (ans * (bucket[p] + 1)) % MOD

print(ans)



Measured memory_bytes: 3064
#include<stdio.h>
#include<limits.h>

#define N 500000

int s[N],count=0;

void Merge(int left, int mid, int right){
  int n_l,n_r;
  int i,j,k;

  n_l=mid-left;
  int L[n_l];
  
  n_r=right-mid;
  int R[n_r];

  for(i=0;i<=n_l-1;i++){
    L[i]=s[left+i];
  }

  for(i=0;i<=n_r-1;i++){
    R[i]=s[mid+i];
  }

  L[n_l]=INT_MAX;
  R[n_r]=INT_MAX;
  i=0;
  j=0;

  for(k=left;k<=right-1;k++){
    if(L[i]<=R[j]){
      count++;
      s[k]=L[i];
      i=i+1;
    }
    else {
      count++;
      s[k]=R[j];
      j=j+1;
    }
  }

}

void MergeSort(int left, int right){
  int mid;

  if(left+1 < right){
    mid=(left+right)/2;
    MergeSort(left,mid);
    MergeSort(mid,right);
    Merge(left,mid,right);
  }
}



int main(){
  int n,i;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&s[i]);

  MergeSort(0,n);

  for(i=0;i<n;i++){
    if(i==n-1){
      printf("%d\n",s[i]);
      printf("%d\n",count);
    }
    else    printf("%d ",s[i]);
  }

  return 0;
}



Measured memory_bytes: 5632
#include <bits/stdc++.h>
#include <ctype.h>
#include <string>
#include <math.h>
#include <iomanip> 
#include <queue>
using namespace std;

int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false); 

	
	int n, k, ans = 0;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++){
		k--;
		ans+=a[i];
		if (k == 0){
			break;
		}
	}

	cout << ans;
	


}

Measured memory_bytes: 3532
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int maxn = 2e5 + 10;
const int maxnum = 1e6 + 10;
const int lx = 998244353;

int mu[maxnum];
int p[maxn];
bool isp[maxnum];
int c[maxnum];
int sum[maxnum];
int g[maxnum] , v[maxnum];
int cnt = 0; 

void init(){
	memset(isp , 1 , sizeof isp);
	isp[1] = 0;
	mu[1] = 1;
	for(int i = 2 ; i <= 1000000 ; ++ i){
		if(isp[i]){
			++ cnt;
			p[cnt] = i;
			mu[i] = lx - 1;
		}
		for(int k = 1 ; k <= cnt && i * p[k] <= 1000000 ; ++ k){
			isp[i * p[k]] = 0;
			if(i % p[k] == 0){
				mu[i * p[k]] = 0;
				break;
			}
			mu[i * p[k]] = (lx - mu[i]) % lx;
		}
	}
	for(int t = 1 ; t <= 1000000 ; ++ t)
		for(int z = t ; z <= 1000000 ; z += t)
			g[z] = (1ll * z / t * mu[z / t] + g[z]) % lx;
	for(int t = 1 ; t <= 1000000 ; ++ t)
		g[t] = 1ll * t * g[t] % lx;
}

int n;
int main(){
	cin >> n;
	for(int i = 1 ; i <= n ; ++ i){
		int h;
		cin >> h;
		v[h] ++;
	}
	init();
	for(int t = 1 ; t <= 1000000 ; ++ t)
		for(int z = t ; z <= 1000000 ; z += t)
			c[t] = (c[t] + 1ll * (z / t) * v[z]) % lx;
	int ans = 0;
	for(int t = 1 ; t <= 1000000 ; ++ t)
		ans = (ans + 1ll * g[t] * c[t] % lx * c[t]) % lx;
	for(int i = 1 ; i <= 1000000 ; ++ i)
		ans = (ans + lx - 1ll * v[i] * i % lx) % lx;
	ans = 1ll * ans * ((lx + 1) / 2) % lx;
	cout << ans << endl;
	return 0;
}

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

int main() {

  long long N, A, B;
  cin >> N >> A >> B;

  long long answer =(long long) N / (A + B) * A;
  
  long long a = N % (A + B);

  if(a < A) {
    answer += a;
  } else {
    answer += A;
  }

  cout << answer << endl;

  return 0;

}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M);
  vector<int> b(M);
  vector<int> n(N);
  
  for(int i = 0; i < M; i++){
    cin >> a.at(i) >> b.at(i);
  }
  
  for(int i = 0; i < M; i++){
    n.at(a.at(i) - 1)++;
    n.at(b.at(i) - 1)++;
  }
  
  for(int i = 0; i < N; i++){
    cout << n.at(i) << endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s, n) for(int i = s; i < (int)(n); i++)
#define co(x) cout<<x<<endl
#define SQvec(i,j) vector<vector<int>> data(i, vector<int>(j))
#define mod 1000000000+7
typedef long long int lint;

int main() {
  string S,ans = "";
  int w;
  cin >> S >> w;
  rep(i,0,S.size()){
    if(i%w == 0){ans += S[i];}
  }
  co(ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>/*toupperとかが入っている*/
#include<vector>/*可変長配列vectorのインクルード*/

const int MOD=1000000007;/* 1,000,000,007 で割った余りを出力する　のとき使う*/
using namespace std;/*標準名前空間を利用する。cinやcoutはこれによって利用可能になる*/

long long int A,B,C,D;

/*XとYの最大公約数*/
long long int gcd(long long int X, long long int Y){
  if(Y==0) return X;
  else return gcd(Y, X%Y);
}

long long int lcm(long long int X, long long int Y){
  return X*Y/gcd(X,Y);
}

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

  long long int Ayakusuu = (A-1)/C + (A-1)/D - (A-1)/lcm(C,D);
  long long int Byakusuu = B/C + B/D - B/lcm(C,D);

  cout << (B-Byakusuu) - ((A-1)-Ayakusuu) << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
#define mem(x,n) memset(x,n,sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\n"

int main()
{
	faster;
	
	string s;
	cin >> s;
	cout << ((s[2] == s[3] && s[4] == s[5]) ? "Yes" : "No") << endl;
	
	return 0;
}

Measured memory_bytes: 3560
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;

int main() {
	vector<int> a;
	vector<bool> flag;
	int N;
	int n;
	int count = 0;

	cin >> N;
	
	for (int i = 0; i < N;i++) {
		cin >> n;
		a.push_back(n);
		flag.push_back(false);
	}
	n = 0;
	while (1) {
		if (flag[n]) {
			count = -1;
			break;
		}
		flag[n] = true;
		n = a[n] - 1;
		count++;
		if (n == 1) {
			break;
		}
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#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())

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

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

  int n, t;
  cin >> n >> t;

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

  vector<int> buy(n, INF);
  vector<int> sell(n, 0);

  int b = a[0];
  rep(i, n) {
    if (a[i] < b) b = a[i];
    buy[i] = b;
  }

  int s = a[n-1];
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] > s) s = a[i];
    sell[i] = s;
  }

  vector<int> p(n);
  int max_p = 0;
  rep(i, n) {
    p[i] = sell[i] - buy[i];
    chmax(max_p, p[i]);
  }

  set<pair<int, int>> c;
  rep(i, n) {
    if (p[i] == max_p) c.insert(make_pair(buy[i], sell[i]));
  }

  cout << c.size() << endl;  

  
  return 0;
}


Measured memory_bytes: 4224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	private static int[] que;
	private static int count;
	public static void main(String[] args)throws IOException{
		que = new int[2000000];
		count =0;
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String[] str=br.readLine().split(" ");
			if(str[0].equals("end")) break;
			else if(str[0].equals("extract")) extract();
			else if(str[0].equals("insert")){
				int n=Integer.parseInt(str[1]);
				insert(n);
			}
		}
	}
	
	private static void extract(){
		int max=que[1];
		que[1]=que[count];
		count--;
		maxHeap(1);
		System.out.println(max);
	}
	
	private static void insert(int n){
		count++;
		que[count]=Integer.MIN_VALUE;
		que[count] = n;
        int i = count;
        while (i > 1 && que[i/2] < que[i]) {
        	swap(i,i/2);
            i = i/2;
        }
	}
	
	private static void maxHeap(int i){
		int l=2*i;
		int r=2*i+1;
		int max;
		if(l<=count && que[l]>que[i]) max=l;
		else max=i;
		if(r<=count && que[r]>que[max]) max=r;
		
		if(max!=i){
			swap(i,max);
			maxHeap(max);
		}
	}
	
	   private static void swap(int i, int j) {
	        int tmp = que[i];
	        que[i] = que[j];
	        que[j] = tmp;
	    }
}

Measured memory_bytes: 175056
import java.util.*;

public class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),a=sc.nextInt();
        n=n%500;
        System.out.println(a>=n?"Yes":"No");
    }
}


Measured memory_bytes: 21204
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class3
    {
        static void Main()
        {
            var XA = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int X = XA[0];
            int A = XA[1];
            Console.WriteLine(X < A ? "0" : "10");
        }
    }
}


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

int main(){

    int d,n;
    cin >> d >> n;
    if(n == 100) n = 101;
    if(d == 0){
        
        cout << n << endl;
    }
    else if(d == 1){
        cout << n*100 << endl;
    }
    else{
        cout << n*10000 << endl;
    }


    return 0;
}

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

int main(){
    int N = 0;
    cin >> N;
    int ans = 0;
    for (int i = 0; i < N; i++){
        int l,r;
        cin >> l >> r;
        ans += r-l+1;
    }
    cout << ans << endl;
}

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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll N;
	cin>>N;
    ll a;
    string ans = "APPROVED";
    rep(i,N){
        cin>>a;
        if(a%2==0){
            if(a%3!=0&&a%5!=0){
                ans = "DENIED";
                break;
            }           
        }
    }
    cout<<ans<<"\n";
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
c = list(map(int, input().split()))
ans=1
max =10**18

if 0 in c:
    ans =0
else:
    for i in range(n):
        if ans< max:
            ans=ans*c[i]
            if ans > max:
                ans =-1
                break
        else:
            ans = -1
            break
print(ans)

Measured memory_bytes: 21780
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
  for(i=0;i < VMAX+1;i++){
    C[i]=0;
  }
  for(i=0;i<n;i++){
    scanf("%d",&A[i+1]);
    C[A[i+1]]++;
  }
  for(i=1;i<VMAX+1;i++){
    C[i]=C[i]+C[i-1];
    
    }
  
  for(j=1;j<n+1;j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  
  for(i=1;i<n+1;i++){



    if(i>1 && i<n+1){
      printf(" ");
    }
      printf("%d",B[i]);
  }  
  printf("\n");
  
    return 0;
  }



Measured memory_bytes: 9552
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <unordered_map>
#include <iterator>
#include <functional>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n, m;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	scanf("%d", &n);
	map<int, ll> a;
	REP(i, n){
		int x;
		scanf("%d", &x);
		a[x] += x;
	}
	a[0] = 0;
	auto it=a.begin();
	auto pt=a.begin();
	++it;
	for(;it!=a.end();++it,++pt){
		it->second += pt->second;
	}
	scanf("%d", &m);
	vector<ll> b(m), c(m);
	REP(i, m) scanf("%lld", &b[i]);
	REP(i, m) scanf("%lld", &c[i]);
	REP(i, m){
		auto it = a.upper_bound(b[i]);
		--it;
		ll ans = it->second;
		puts(ans >= c[i] ? "Yes" : "No");
	}
	return 0;
}

Measured memory_bytes: 21276
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
  ll H, W;
  cin >> H >> W;
  ll ans = 0;
  ans += ((W + 1) / 2) * ((H + 1) / 2);
  ans += (W / 2) * (H / 2);
  if(H == 1 || W == 1)
    ans = 1;
  cout << ans << endl;
}


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

using namespace std;

int main(void) {
  int n;
  cin >> n;
  vector <int> a;
  for(int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }

  int Alice = 0, Bob = 0;
  sort(a.rbegin(), a.rend());
  for(int i = 0; i < n; i++) {
    if(i % 2 == 0) {
      Alice += a[i];
    }
    else {
      Bob += a[i];
    }
  }

  cout << Alice - Bob << endl;
}

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

int main() {
	int n;
	while (scanf("%d", &n), n) {
		int Max = INT_MIN, cnt = 0;
		rep(i, n) {
			int a; scanf("%d", &a);
			if (cnt < 0)cnt = a;
			else cnt += a;
			Max = max(Max, cnt);
		}
		printf("%d\n", Max);
	}
}

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

using namespace std;

typedef long long ll;
typedef pair < int, int > ii;

const int N = 3e5 + 5;
const int mod = 998244353;

inline int add(int x, int y) {
  return x + y >= mod ? x + y - mod : x + y;
}

inline int mul(int x, int y) {
  return (ll) x * y % mod;
}

inline int fe(int x, int k) {
  int res = 1;
  while(k) {
    if(k & 1)
      res = mul(res, x);
    x = mul(x, x);
    k >>= 1;
  }
  return res;
}

inline int dv(int x, int k) {
  return mul(x, fe(k, mod - 2));
}

int n, a, b;
ll k;
int fact[N], inv[N], invFact[N];

int C(int n, int m) {
  return mul(fact[n], mul(invFact[m], invFact[n - m]));
}

int main() {

  fact[0] = inv[0] = invFact[0] = 1;

  for(int i = 1; i < N; i++) {
    fact[i] = mul(fact[i - 1], i);
    inv[i] = fe(i, mod - 2);
    invFact[i] = fe(fact[i], mod - 2);
  }

  scanf("%d %d %d %lld", &n, &a, &b, &k);

  int ans = 0;

  for(int i = 0; i <= n; i++) {
    ll rem = k - (ll) i * a;
    if(rem >= 0 and rem % b == 0 and rem / b <= n) {
      int j = rem / b;
      // printf("i = %d j = %d\n", i, j);
      ans = add(ans, mul(C(n, i), C(n, j)));
    }
  }

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

  return 0;

}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
const int N = 2e5 + 87;
int n, c[N], lt[N], rt[N], tp, sz[N];
vector<int> g[N], g2[N];
vector<tuple<int, int, int>> t[N];
void dfs(int u, int p)
{
    auto it = find(g[u].begin(), g[u].end(), p);
    if (it != end(g[u]))
        g[u].erase(it);
    lt[u] = tp++;
    sz[u] = 1;
    for (int v : g[u])  {
        dfs(v, u);
        sz[u] += sz[v];
    }
    rt[u] = tp;
}
void build_g2(vector<tuple<int, int, int>> & a)
{
    sort(a.begin(), a.end());
    vector<int> st;
    g2[0].clear();
    st.emplace_back(0);
    int pa = 0;
    auto in = [&] (int u, int i) {
        return lt[st[i]] <= lt[u] && rt[u] <= rt[st[i]];
    };
    auto pop = [&] () {
        st.pop_back();
    };
    for (auto [l, r, u] : a) {
        int la = st.size() - 1;
        if (in(u, la)) {
            pa = la;
        } else if (in(u, pa)) {
        } else {
            while (!in(u, st.size() - 1))
                pop();
            pa = st.size() - 1;
        }
        //cerr << "pa, u " << st[pa] << ' ' << u << endl;
        g2[st[pa]].push_back(u);
        st.emplace_back(u);
    }
}
bool in (int u, int v)
{
    return lt[v] <= lt[u] && rt[u] <= rt[v];
}
ll gao(int u)
{
    ll ret = 0;
    int i = 0;
    ll s = g[u].size() ? sz[g[u][0]] : 0;
    for (int v : g2[u]) {
        while (i < g[u].size() && !in(v, g[u][i])) {
            ret += s * (s + 1) / 2;
            ++i;
            if (i < g[u].size())
                s = sz[g[u][i]];
        }
        s -= sz[v];
        ret += gao(v);
    }
    while (i < g[u].size()) {
        ret += s * (s + 1) / 2;
        ++i;
        if (i < g[u].size())
            s = sz[g[u][i]];
    }
    return ret;
}
ll solve(vector<tuple<int, int, int>> & a)
{
    build_g2(a);
    return n * (n + 1ll) / 2 - gao(0);
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> c[i];
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    g[0].push_back(1);
    dfs(0, 0);
    for (int i = 1; i <= n; ++i)
        t[c[i]].emplace_back(lt[i], -rt[i], i);
    for (int i = 1; i <= n; ++i)
        cout << solve(t[i]) << '\n';
}


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

using ll=long long; 

void solve(){
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int sum=a+b+c;
	int maxv=max(a,max(b,c));
	sum-=maxv;
	for(int i=0; i<k; i++){
		maxv*=2;
	}	
	cout<<sum+maxv<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
			// TODO 自動生成されたメソッド・スタブ
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int A[] = new int[N];
			for (int i = 0;i < N;i++) {
				A[i] = sc.nextInt();
			}
			//max
			int max = 0;
			for(int i = 0;i < N;i++) {
				max = Math.max(max, A[i]);
			}

			int min = max;
			for(int i = 0;i < N;i++) {
				min = Math.min(min, A[i]);
			}
			System.out.println(max-min);


	}
}

Measured memory_bytes: 21716
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I LOVE CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
void solve()
{
 int a,b,c,d;cin>>a>>b>>c>>d;
 int flag=1;
 while(a>0&&c>0)
 {
     if(flag)
     {
         c-=b;
         flag=0;
     }
     else
     {
         a-=d;
         flag=1;
     }
 }
 if(flag)cout<<"No\n";
 else cout<<"Yes\n";
}
int main()
{
   fastio
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


Measured memory_bytes: 3660
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
M=0
for i in range(N):
    M+=min(A[i],B[i])
    B[i]-=min(A[i],B[i])
    M+=min(A[i+1],B[i])
    A[i+1]-=min(A[i+1],B[i])
print(M)

Measured memory_bytes: 19116
def SumOfDegit(x):
  sum = 0
  while x > 0:
    sum += x % 10
    x //= 10
  return sum
 
n = int(input())
degits_sum = []
for a in range(1,n):
  degits_sum.append(SumOfDegit(a) + SumOfDegit(n-a))
print(min(degits_sum))

Measured memory_bytes: 3864
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <list>
#include <cmath>
using namespace std;
#define rep(i,m,n) for (int i = (int) (m); i < (int) (n); i++)
#define rep1(i,m,n) for (int i = (int) (m); i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
long long int Max(long long int a,long long int b){
    if(a>=b)return a;
    else return b;
}
long long int comb(long long int n,long long int r){
    vector<vector<long long int> > v(n+1,vector<long long int>(n+1,0));
    long long int i,j;
    rep(i,0,n+1){
        v.at(i).at(0)=1;
        v.at(i).at(i)=1;
    }
    rep(i,0,n+1){
        rep(j,0,i)v.at(i).at(j)=v.at(i-1).at(j-1)+v.at(i-1).at(j);
    }
    return v.at(n).at(r);
}
int main(void){
    long long int N,K,i,sum=0;
    cin>>N>>K;
    vector<int> data(N);
    rep(i,0,N)cin>>data.at(i);
    sort(all(data));
    rep(i,0,N-K)sum+=data.at(i);
    cout<<sum<<endl;
}

Measured memory_bytes: 1024
using System;
using System.Globalization;
using System.IO;
using System.Text;
using static Scanner;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Solve();
        Console.Out.Flush();
    }
    static void Solve() {
        var N = ScanInt();
        var answer = 0;
        var temp = ScanInt();
        var count = 0;
        for (int i = 1; i < N; i++) {
            var H = ScanInt();
            if (temp >= H) count++;
            else { answer = Math.Max(answer, count); count = 0; }
            temp = H;
        }
        Console.WriteLine(Math.Max(answer, count));
    }
}

public static class Scanner
{
    static readonly Stream stream = Console.OpenStandardInput();
    static readonly byte[] buffer = new byte[1024];
    static int length, p;
    static bool isEof;
    private static byte ConsoleIn() {
        if (isEof) return 0;
        if (p < length) return buffer[p++];
        p = 0;
        if ((length = stream.Read(buffer, 0, 1024)) > 0) return buffer[p++];
        isEof = true;
        return 0;
    }
    public static char GetChar() {
        var by = ConsoleIn();
        while ((by < '!' || '~' < by) && !isEof) by = ConsoleIn();
        return (char) by;
    }
    public static int ScanInt() {
        var temp = 0;
        for (var ch = GetChar(); '0' <= ch && ch <= '9'; ch = (char) ConsoleIn()) {
            temp = temp * 10 + ch - '0';
        }
        return temp;
    }
}

Measured memory_bytes: 23724
import sys
w=input()
#wの要素を取得
w_set=set(w)
w_l=list(w_set)
for i in range(len(w_l)):
    if w.count(w_l[i])%2==0:
        pass
    else:
        print("No")
        sys.exit(0)
print("Yes")

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n;
	while(cin>>n,n!=0){
		int ans=0;
		repi(l,1,n+1){
			repi(r,1,n+1){
				if(r*(r+1)/2-l*(l-1)/2==n)ans++;
			}
		}
		cout<<ans-1<<endl;
	}
	return 0;
}


Measured memory_bytes: 2976
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;


vector<int> adj[100004];
vector<int> blk[100004];

vector<int> com;
vector<set<int> > b;
int sz;
int cur = 0;

void dfs(int u) {
	com[u] = cur;
	sz++;
	for (int v : adj[u]) {
		if (com[v]==0)
			dfs(v);
	}

	for (int v: blk[u]) {
		if (com[v]==cur) {
			b[u].insert(v);
			b[v].insert(u);
		}
	}
}
void testcase() {
    int n, m, k;
    cin >> n >> m >> k;
    com.clear();
    com.resize(n+1, 0);
	b.clear();
    b.resize(n+1);
    rep (i, 1, n)  {
    	adj[i].clear();
    	blk[i].clear();
    }

    while (m--) {
    	int a, b; cin >> a >> b;
    	adj[a].push_back(b);
    	adj[b].push_back(a);
    }

    while (k--) {
    	int c, d; cin >> c >> d;
    	blk[c].push_back(d);
    	blk[d].push_back(c);
    }

    unordered_map<int, int> ct;
    rep (i, 1, n) {
    	if (com[i]==0) {
    		sz = 0;
    		++cur;
    		dfs(i);
    		ct[cur] = sz;
    	}
    }

    rep (i, 1, n) {
    	//db3(i, com[i], ct[com[i]]);
    	int com_size = ct[com[i]];
    	int ct = com_size - 1 - adj[i].size();

    	ct -= b[i].size();
    	cout << ct << " ";
    }
    cout << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 26404
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int n = sc.nextInt();
      int d = sc.nextInt();

      int[][] x = new int[n+1][d+1];
      int z = 10;
      int s = 0;
      int count = 0;

      for (int j = 1; j<=n; j++) {
      for (int i = 1; i<=d; i++) {
        x[j][i] = sc.nextInt();
      }
    }

      for (int j = 1;j<n ;j++ ) {
        for (int k = 0;k+j<n ;k++) {
         s = 0;
        for (int i = 1;i<=d ;i++ ) {
             s = s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]);
        }
        double a = Math.sqrt(s);

        if(a==(int)a){
          count++;
        }
      }
    }


      System.out.println(count);
}
}


Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 100010
typedef long long ll;
const int mx=100000;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,qwq,w[N<<2],v[N<<2],Q,lim;
ll dp[1025][N];
void dfs(int u,int dep){
	if(u>n) return ;
	if(dep>qwq/2)return;
	lim=max(lim,u);
	for(int i=mx;i>=w[u];--i){
		dp[u][i]=max(dp[u>>1][i],dp[u>>1][i-w[u]]+v[u]);
	}
	for(int i=w[u]-1;i>=0;--i){
		dp[u][i]=dp[u>>1][i];
	}
	dfs(u<<1,dep+1);
	dfs(u<<1|1,dep+1);
	for(int i=1;i<=mx;++i){
		dp[u][i]=max(dp[u][i],dp[u][i-1]);
	}
}
int main(){
	n=read();
	for(int i=1;i<=n;++i){
		v[i]=read(),w[i]=read();
	}
	qwq=0;
	while((1<<qwq)<=n)qwq++;
	dfs(1,1);
	Q=read();
	while(Q--){
		int u=read(),L=read();
		if(u<=lim){
			printf("%lld\n",dp[u][L]);
			continue;
		}
		static int p[233],tot=0;
		tot=0;
		while(u>lim){
			p[++tot]=u;
			u>>=1;
		}
		ll ans=0;
		for(int i=0;i<(1<<tot);++i){
			ll d=0,sum=0;
			for(int j=1;j<=tot;++j){
				if((i>>(j-1))&1){
					d+=w[p[j]],sum+=v[p[j]];
				}
			}
			if(d>L)continue;
			ans=max(ans,dp[u][L-d]+sum);
		}
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 405084
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vl a(4,0);
	rep(i,6){int t;cin>>t;a[t-1]++;}
	sort(all(a));
	YN(a==vl{1,1,2,2});
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

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

    char c[100] = {};
    char *p = c + 99;

    int t = n;
    while (t) {
        *--p = '0' + (t & 1);
        if (t & 1) t--;
        t /= -2;
    }

    cout << p << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+10,mod=1e9+7;
int n,m,k,t;
double d1,x;
int main(){
    int i,j;
    scanf("%d%lf%lf",&n,&d1,&x);
    double ret=0,all=2.*n;
    for(i=1;i<=n;i++)
    {
        ret+=(d1+d1+(all-1)*x)*all/2./all;
        d1=(d1*(all+2)+5*x)/all;
        x=((all+4)*x)/all;
        all-=2;
    }
    printf("%.15f\n",ret);
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<utility>
#include<algorithm>
#include<bitset>
using namespace std;


int main(){
  int x,y;
  cin>>x>>y;
  if(x%y==0)cout<<-1<<endl;
  else{
    int a=x*2;
    while(a%y==0){
      a+=x;
    }
    cout<<a<<endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
int a[10][10000];
int main(){
	int r,c;

	while(true){

	cin>>r>>c;
	if(r==0&&c==0)
		break;
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			cin>>a[i][j];
		}
	}

	double rrr=r;
	int best=0;

	for(int i=0;i<pow(2,rrr);i++){
		int count=0;

		for(int j=0;j<c;j++){
			int o=0;
			for(int k=0;k<r;k++)
				o+=a[k][j];
			count+=max(o,r-o);
		}
		if(count>best){
			best=count;
		}

		for(int j=0;j<r;j++){
			double jjj=j;
			int jjjjj=pow(2,jjj);
			if((i+1)%jjjjj==0){
				for(int k=0;k<c;k++){
					a[j][k]=(a[j][k]+1)%2;
				}
			}
		}

	}

	cout<<best<<endl;
	}
    return 0;
}

Measured memory_bytes: 1588
import java.util.Scanner;

class Main{
	public static void main(String[]args){
	Scanner sc = new Scanner(System.in);
	
        String W = sc.nextLine();
        int count = 0;

	while(true){
        String T = sc.next();
        if(T.equals("END_OF_TEXT"))
           break;
        
        	W= W.toUpperCase( );
        	T= T.toUpperCase( );
           if(T.equals(W))
           count++;
		}
           System.out.println(count);
	}
}


Measured memory_bytes: 26316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
ll modpow(ll a,ll b){
    a%=mod;
    if(b==0)return 1;
    if(b&1)return a*modpow(a,b-1)%mod;
    ll k=modpow(a,b/2);
    return k*k%mod;
}
int main(){
    bool b=true;
    int n;cin>>n;
    rep(i,n){
        int a;cin>>a;
        if(a%2)continue;
        if(a%3&&a%5)b=false;
    }
    if(b)out("APPROVED");
    else out("DENIED");
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

A, B, Q = MAP()
s = [-INF] + [INT() for _ in range(A)] + [INF]
t = [-INF] + [INT() for _ in range(B)] + [INF]

for _ in range(Q):
	x = INT()
	idx_s = bisect(s, x)
	idx_t = bisect(t, x)

	ans = INF
	for S, T in product([idx_s, idx_s-1], [idx_t, idx_t-1]):
		if min(s[S], t[T]) <= x <= max(s[S], t[T]):
			tmp = abs(s[S]-t[T]) + min(abs(x-s[S]), abs(x-t[T]))
		else:
			tmp = max(abs(x-s[S]), abs(x-t[T]))
		ans = min(ans, tmp)

	for S in [idx_s, idx_s-1]:
		for T in [idx_t, idx_t-1]:
			tmp = min(abs(x-s[S])+abs(s[S]-t[T]), abs(x-t[T])+abs(s[S]-t[T]))
			ans = min(ans, tmp)

	print(ans)



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

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N) cin >> C[i];

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    ll ans = 0;
    rep(i, N) {
        ll now = 1;
        now *= C.end() - upper_bound(C.begin(), C.end(), B[i]);
        now *= lower_bound(A.begin(), A.end(), B[i]) - A.begin();

        ans += now;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1536
from collections import Counter

def computeComb(C):
  #print(C)
  total = 0
  sub = {}
  for n in C:
    if C[n] >= 2:
      total += C[n] * (C[n] - 1) // 2
      sub[n] = C[n] - 1
    else:  # C[n] < 2
      sub[n] = 0
  return total, sub

if __name__ == '__main__':
  
  N = int(input())
  A = list(map(int, input().split()))
  C = Counter(A)
  
  total, sub = computeComb(C)
  #print(total, sub)

  for i in range(N):
    print(total - sub[A[i]])

Measured memory_bytes: 32156
#include <iostream>

using namespace std;

string canCreateHaiku(int* tab, int length) {
	int nb7 = 0;
	int nb5 = 0;
	for(int iT = 0; iT < length; iT++) {
		if(tab[iT] == 7)
			nb7++;
		if(tab[iT] == 5)
			nb5++;
	}
	if(nb7 == 1 && nb5 == 2)
		return "YES";
	else
		return "NO";
}

int main() {
	int* phrases = (int*)malloc(3 * sizeof(int));
	scanf("%d %d %d", &phrases[0],&phrases[1], &phrases[2]);
	cout << canCreateHaiku(phrases, 3);
	return 0;
}



Measured memory_bytes: 256