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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
int md = 100000;
#define addm(X, Y) ((X) = ((X) + (Y) % md) % md)

string s;
int cnt_n, cnt_s, cnt_e, cnt_w;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    int n = s.size();
    rep(i, n) {
        if (s[i] == 'N') cnt_n++;
        else if (s[i] == 'S') cnt_s++;
        else if (s[i] == 'E') cnt_e++;
        else cnt_w++;
    }
    if (cnt_n >= 1 && cnt_s == 0 || cnt_n == 0 && cnt_s >= 1) {
        cout << "No" << endl;
    }
    else if (cnt_e >= 1 && cnt_w == 0 || cnt_e == 0 && cnt_w >= 1) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

class Combination{
    long long int maxn;
    long long int mod;
    std::vector<long long int> factorial;
    std::vector<long long int> inverse;

    public:

    Combination(long long int n,long long int m):maxn(n),mod(m){
        factorial.push_back(1);
        inverse.push_back(1);

        for(long long int i = 1; i <= n; i++){
            factorial.push_back((factorial.back()*i)%mod);
            inverse.push_back([&](long long int x,long long int n) -> long long int{
                long long int ret = 1;
                while(n > 0){
                    if(n&1)ret = (ret*x)%mod;
                    x = (x*x)%mod;
                    n >>= 1;
                }
                return ret;
            }(factorial.back(),mod-2));
        }
    }

    long long int comb(long long int n,long long int r){
        return (((factorial[n]*inverse[n-r])%mod)*inverse[r])%mod;
    }
};

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

    LL n,m;
    cin >> n >> m;

    vector<LL> p;
    if(m == 1){
        p.push_back(0);
    }else{
        LL pre = -1;
        LL j = 2;
        while(m > 1){
            if(m%j == 0){
                if(pre == j){
                    p.back()++;
                }else{
                    pre = j;
                    p.push_back(1);
                }
                m /= j;
                j--;
            }
            j++;
        }
    }

    LL t = 0;
    for(int i = 0; i < p.size(); i++){
        t = max(t,p[i]);
    }

    Combination cmb(t+n,MOD);

    LL ans = 1;

    for(int i = 0; i < p.size(); i++){
        ans *= cmb.comb(p[i]+n-1,p[i]);
        ans %= MOD;
    }

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

Measured memory_bytes: 2036
#include<iostream>
using namespace std;
int main() {

    char x, y;
	cin >> x >> y;

	if (x>y) {
		cout << ">" << endl;
	}
	else {
		if (x<y) {
			cout << "<" << endl;
		}
		else {
			cout << "=" << endl;
		}
	}
}



Measured memory_bytes: 256
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});
process.stdin.on('end', () => {
  const [a, b] = content
    .trim()
    .split(' ')
    .map(n => parseInt(n, 10));
  
  const d = Math.floor(a / b);
  const r = a % b;
  const f = a / b;
  console.log("%d %d %s", d, r, f.toFixed(6));
});


Measured memory_bytes: 15564
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = 0
#A[N-1] += A[N]
#for i in range(N-1,-1,-1):
#    if A[i] <= B[i]:
#        ans += A[i]
#    else:
#        A[i] -= B[i]
#        ans += B[i]
#        A[i-1] += A[i]
#

for i in range(N):
    if A[i] >= B[i]:
        ans += B[i]
        B[i] = 0
    else:
        ans += A[i]
        B[i] -= A[i]
        if A[i+1] >= B[i]:
            ans += B[i]
            A[i+1] -= B[i]
            B[i] = 0
        else:
            ans += A[i+1]
            B[i] -= A[i+1]
            A[i+1] = 0

#if A[N] >= B[N-1]:
#    ans += B[N-1]
#else:
#    ans+= A[N]

print(ans)


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


bool isprime(int n);

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

    for(int j=n;j>0;j--){
      if(isprime(j) && isprime(j-2)){
        cout<<j-2<<" "<<j<<endl;
        break;
      }
    }
  }
  return 0;
}

bool isprime(int n){
  for(int i=2;i<min((int)sqrt(n)+1,n);i++){
    if(n%i==0){
      return false;
    }
  }
  return true;
}



Measured memory_bytes: 3016
#include <iostream>
//#include <string>
using namespace std;

int main() {
	int M = 0, D = 0;
	cin >> M >> D;
	int total = 0;

	for (int i = 0; i <= M;  ++i) {
		for (int j = 0; j <= D; ++j) {
			int d10 = j/10;
			int d1 = j % 10;
			if ((d10 <= 1) || (d1 <= 1)) continue;
			if (i == d10 * d1) {
				++total;
				//cout << i << "月:" << j << "日" << endl;
			}
		}
	}

	cout << total << endl;
	return 0;
}

Measured memory_bytes: 256
l=list(map(int,input().split()))
n=l[0]
legs=l[1]
if(n==0 and legs==0):
    print("Yes")
if(legs%2==0 and l[0]*4>=l[1] and l[0]*2<=l[1]):
    print("Yes")
else:
    print("No")
    


Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
    int n; string s; cin >> n >> s;
    int ans = 0;
    for(int i = 1;i < n; i++){
        int cnt = 0;
        for(char j = 'a';j <= 'z';j++){
            bool flag1 = false,flag2 =false;
            for(int k = 0;k < i;k++){
                if(s[k]==j){
                    flag1 = true;
                }
            }
            for(int k = i;k < n;k++){
                if(s[k]==j){
                    flag2 = true;
                }
            }
            
            if(flag1 && flag2){
                cnt++;
            }
        }
        ans = max(ans,cnt);
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    ll l,r,d;
    int main()
    {
      cin>>l>>r>>d;ll cnt=0;
      for(ll i=l;i<=r;i++)
      {
        if(i%d==0)cnt++;
      }
      cout<<cnt<<endl;
    }

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

    class Program
    {
        static void Main(string[] args)
        {
          int h, a;
            string[] str = Console.ReadLine().Split(' ');
          h = int.Parse(str[0]);
          a = int.Parse(str[1]);
          
          int ans = h/a;
          if(h%a!=0){ans++;}
          Console.WriteLine(ans);
        }
    }


Measured memory_bytes: 11092
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		int k = sc.nextInt();
		int n = sc.nextInt();
		int[] aa = new int[n];
		for (int i = 0; i < n; i++)
			aa[i] = sc.nextInt();
		int gap = aa[0] + k - aa[n - 1];
		for (int i = 1; i < n; i++)
			gap = Math.max(gap, aa[i] - aa[i - 1]);
		println(k - gap);
	}
}


Measured memory_bytes: 79156
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[300][300][3100];
int main()
{
    ll sum=(ll)0;
    ll x,y,z;
    ll a[1000];
    cin>>x>>z;
    for(int i=0;i<x;i++)
    {
        cin>>a[i];
    }
    dp[0][0][0]=(ll)1;
    for(int i=0;i<x;i++)
    {
        for(int j=0;j<=i;j++)
        {
            for(int k=0;k<2501;k++)
            {
                dp[i+1][j+1][k+a[i]]+=dp[i][j][k];
                dp[i + 1][j][k] += dp[i][j][k];
            }
        }
    }
    for(int i=1;i<=x;i++)
    {
        sum+=dp[x][i][i*z];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 31872
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.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 (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N, K;
        cin >> N >> K;
        vll x(N);
        rep(i, 0, N) cin >> x[i];

        ll ans = 0;
        rep(i, 0, N) {
                if (abs(K - x[i]) > abs(x[i])) {
                        ans += 2 * x[i];
                } else {
                        ans += 2 * abs(K - x[i]);
                }
        }
        cout << ans << endl;
}

Measured memory_bytes: 3576
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()

x = 0
for v in a:
    x ^= v
b = []
for i in range(n):
    b.append(a[i]^x)
print(" ".join(map(str, b)))


Measured memory_bytes: 124268
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ul unsigned long long int
#define vi vector<int>
#define vl vector<int64_t>
#define all(x) x.begin(),x.end()
#define pb push_back
#define fo(x,a,b) for(int x=a; x<b; x++)
#define rfo(x,a,b) for(int x=a; x>=b; x--)
#define fi first
#define sec second
#define mp make_pair
int sgn(int x) { return x>0 ? 1 : ( x<0 ? -1 : 0); }
typedef pair<int,int> pairs;
double pi = 3.14159265358979323846;
ll mod = 1000000007;

vi adj[100005];
bool vis[100005] = {false};

void connected(int x, int n)
{
    vis[x]=true;
    for(auto ip = adj[x].begin(); ip!=adj[x].end(); ip++)
    {
        if(!vis[*ip]) connected(*ip,n);
    }
}
void solve()
{
    int n,m;
    cin>>n>>m;
    fo(i,0,m)
    {
        int x,y;
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    int ans = 0;
    fo(i,1,n+1)
    {
        if(!vis[i])
        {
            ans++;
            connected(i,n);
        }
    }
    cout<<ans-1;
    fo(i,1,n+1) {adj[i].clear(); vis[i]=false; }
    cout<<"\n";
    return;
}
int main()
{
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    //cin>>t;
    //while(t--)
    {
        solve();
    }
    return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();
            var list = str.Select(x => int.Parse(x.ToString())).ToList();


            list.Sum();


            var a = new List<double>();
            var n = list.Count - 1;
            var count = Math.Pow(2, n);
            for (int i = 0; i < count; i++)
            {
                var t = i;
                var temp = str.Clone() as string;
                for (int j = 0; j < n; j++)
                {
                    if (t % 2 == 0) temp = temp.Insert(n - j, "+");
                    t /= 2;
                }
                a.Add(temp.Split('+').Select(x => double.Parse(x.ToString())).Sum());
            }
            Console.WriteLine(a.Sum());
        }
    }
}




Measured memory_bytes: 11348
N, K = map(int, input().split())
S = input()

left_ac = [0]
right_ac = [0]

prev = ""
for i in range(N):
    s = S[i]
    if s == "L":
        if i - 1 >= 0:
            if S[i - 1] == "L":
                left_ac.append(left_ac[-1] + 1)
            else:
                left_ac.append(left_ac[-1])
        else:
            left_ac.append(left_ac[-1])
        right_ac.append(right_ac[-1])
    else:
        if i + 1 < N:
            if S[i + 1] == "R":
                right_ac.append(right_ac[-1] + 1)
            else:
                right_ac.append(right_ac[-1])
        else:
            right_ac.append(right_ac[-1])
        left_ac.append(left_ac[-1])
left_ac.pop(0)
right_ac.pop(0)
print(min(N-1, right_ac[-1] + left_ac[-1] + 2 * K))


Measured memory_bytes: 7900
n, k = gets.chomp.split(" ").map(&:to_i);

sq = []
n.times do |i|
  r = i + 1.0
  if r > k
    sq << 0
  else
    sq << (Math.log2((k / r))).ceil
  end
end

sum = 0.0
sq.each do |i|
  sum += 1.0 / n / (2**i) 
end

puts sum


Measured memory_bytes: 2684
#include<iostream>
#include<string>
#include<limits>
#include<queue>
#include<stack>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include <algorithm>
#include<utility>
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define vi  vector<int>
#define ll long long
#define pb push_back
#define ff first
#define ss second 
#define rep(n) for(int i=0; i<n ; i++)
#define input(n) for(int i=0; i<n ; i++){cin>>arr[i];}
#define output(n) for(int i=0; i<n ; i++){cout<<arr[i]<<" ";}
#define tc int t; cin>>t; while(t--)
using namespace std;
int32_t main()
{
	int n;
	cin>>n;
	int arr[n];
	input(n);
	vi dp(n,0);

	dp[1] = abs(arr[1]-arr[0]);

	for(int i=2; i<n ; i++)
	{
		dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
	}

	cout<<dp[n-1]<<endl;
	

	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
 int main(void){
    int i, j,H,W;
    while(scanf("%d %d",&H,&W)!=EOF){
     if(H==0&&W==0){
         break;
     }
     for ( i = 0; i < H; i++ ){
     for ( j = 0; j < W; j++ ){
         if((j+i)%2==0){
             printf("#");
         } else {
             printf(".");
         }
     }
     printf("\n");
 }
     printf("\n");
 }
  return(0);// Your code here!
      
 }



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

const int INF = 1e9;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<int> dp(n + k, INF);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= k; j++) {
      dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
    }
  }
  cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int N =sc.nextInt();
    int K=sc.nextInt();
    int x =N;int y=1;
    while(x>=K){
      x=x/K;y=y+1;}
    System.out.println(y);
  }
}

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

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

    cout << b + a << endl;

    return 0;
}

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

int main() {

    string s;
    cin >> s;
    int n = s.size();
    auto c = vector<int>(n);
    for (int i = 0; i < n; i++) {
        c[i] = s[i] - '0';
    }

    auto dp = vector<int>(2019, 0);
    dp[c[0]] = 1;
    auto old = vector<int>(2019, 0);
    ll sum = 0;
    for (int i = 1; i < n; i++) {
        for (int k = 0; k < 2019; k++) old[k] = 0;
        swap(dp, old);
        dp[c[i]] += 1;
        for (int j = 0; j < 2019; j++) {
            int j2 = (10 * j + c[i]) % 2019;
            dp[j2] += old[j];
        }
        sum += dp[0];
    }
    cout << sum << endl;
    return 0;

}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int32 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int32 n, z, w;
vector<int32> a;
vector<map<int32,int32>> memo1;
vector<map<int32,int32>> memo2;

int32 dfs(int32 x, int32 y, bool turn, int32 top){
    if(top == n)return abs(x - y);
    if(turn){
        if(memo1[top].find(y) != memo1[top].end())return memo1[top][y];
        int32 ret = -1;
        FOR(i,top,n){
            ret = max(ret, dfs(a[i],y,false,i+1));
        }
        return memo1[top][y] = ret;
    }else{
        if(memo2[top].find(x) != memo2[top].end())return memo2[top][x];
        int32 ret = INF;
        FOR(i,top,n){
            ret = min(ret, dfs(x,a[i],true,i+1));
        }
        return memo2[top][x] = ret;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> z >> w;
    a = vector<int32>(n);
    memo1 = memo2 = vector<map<int32,int32>>(n);
    REP(i,n)cin >> a[i];
    ANS(dfs(z, w, true, 0));
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k,a,b;
  cin >> k >> a >> b;
  if(a%k==0){
    cout << "OK" << endl;
  }
  else{
    if(a+k-(a%k)<=b)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}

Measured memory_bytes: 3532
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        int a[10]={};
        int b[10]={};
        int dat[10],o=0,s=0;
		for(int j=0;j<10;j++) {
			cin>>dat[j];
		}
        for(int j=0;j<=10;j++){
            if(j==10){
                cout<<"YES"<<endl;
                break;
                        }
            if(s==0||dat[j]>a[s-1]){
                a[s]=dat[j];
                s++;
            }
            else if(o==0||dat[j]>b[o-1]){
                b[o]=dat[j];
                o++;}
            else {
                cout<<"NO"<<endl;
            break;
            }
                    } 
    }
    return 0;
}

Measured memory_bytes: 1156
const int N = 4e5;
const int LG = 21;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <bitset>
#include <deque>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(N);
    __ufact.resize(N);
    __rev.resize(N);
    __rev[1] = 1;
    for (int i = 2; i < N; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < N; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

void __fast_IO()
{
    #ifdef ONLINE_JUDGE
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // ONLINE_JUDGE
}

//##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**
//##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**

ll n, t;
ll ans, cur;

signed main()
{
    __fast_IO();
    cin >> n >> t;
    for (int i = 0; i < n; i++)
    {
        ll a;
        cin >> a;
        if (cur <= a)
        {
            ans += t;
        }
        else
        {
            ans += a + t - cur;
        }
        cur = a + t;
    }
    cout << ans;
}

/* Note:
Check constants at the beginning of the code.
N is set to 4e5 but be careful in problems with large constant factor.
Check corner cases.
No def int long long for now.
*/


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#define INT long long
#define MOD 1000000007
#define oo 987654321
using namespace std;

INT n, t, k, s[200020], e[200020], ans;

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>t;
    for(int i = 0 ; i < n ; i++ ) cin>>s[i], e[i] = s[i]+t;
    ans = e[0]-s[0];
    for(int i = 1 ; i < n ; i++ )
        ans += e[i] - max(s[i], e[i-1]);
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  bool ans = true;
  int y = 0;
  rep(i,n-1) {
    int x = a.at(i+1)-a.at(i);  
    if(x==0) continue;
    else if(x>0) y=0;
    else if(x==-1&&y==0) y=-1;
    else ans = false;
  }
  cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
    ll n,m; cin >> n >> m;
    vector<ll> a(n);
    priority_queue<ll> pq;
    for(int i=0;i<n;i++){
        cin >> a[i];
        pq.push(a[i]);
    }
    for(int i=0;i<m;i++){
        ll cp=pq.top();
        pq.pop();
        cp/=2;
        pq.push(cp);
    }
    ll ans=0;
    while(pq.empty()==false){
        ans+=pq.top();
        pq.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 2168
n = int(input())
s = str(input())
r = 0
g = 0
b = 0
for i in range(n):
    if s[i] == "R":
        r += 1
    elif s[i] == "G":
        g += 1
    else:
        b += 1
p = r*g*b
for i in range(n-2):
    for j in range(int(n/2)+1):
        if i + 2*j >n-1:
            break
        if s[i] != s[i+j] and s[i] != s[i+2*j] and s[i+2*j] != s[i+j]:
            p -= 1
print(p)

Measured memory_bytes: 68268
# -*- coding: utf-8 -*-
# 入力
n = int(input())

# 処理
# i^m (i=1,2,...)を返し続ける関数
def gen_bekis(m):
    n = 1
    while True:
       yield n ** m
       n += 1

ans = 0
m = 2
while True:
    
    beki_max = 0
    for beki in gen_bekis(m):
        if beki > n:
            break
        beki_max = beki

    if ans < beki_max:
        ans = beki_max
    elif beki_max == 1: # 2^mがnを超えた時点で打ち切る
        break

    m += 1

# 出力
print(ans)


Measured memory_bytes: 2940
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val (a, b) = readListOfInt() 
    val isAble = (a % 3 == 0 || b % 3 == 0 || (a+b)%3 == 0)
    println(if(isAble) "Possible" else "Impossible")
    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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 A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e17;


int main(){
	//ios_base::sync_with_stdio(0);
	ll N, ans=0;
	ll Q, H, S, D;

	cin >> Q >> H >> S >> D;
	cin >> N;

	ll dp[3]={};
	Fill(dp, INF);
	chmin(dp[1], Q*4);
	chmin(dp[1], H*2);
	chmin(dp[1], S*1);
	chmin(dp[2], dp[1]*2);
	chmin(dp[2], D);

	ans = INF;
	chmin(ans, dp[1]*N);
	chmin(ans, dp[2]*(N/2) + dp[1]*(N%2));

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
struct edge {
    int to; 
    int weight;
    edge(int t, int w) : to(t),weight(w) {}
};
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;
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; }

int main(){

    int n; cin >> n;
    int A = 0,B = 0,BA = 0;
    ll cnt = 0;

    rep(i,n){
        string s; cin >> s;
        if(s.at(0) == 'B' && s.at(s.size()-1) == 'A') BA++;
        else if(s.at(0) == 'B') B++;
        else if(s.at(s.size()-1) == 'A') A++;
        rep(i,s.size()-1){
            if(s.at(i) == 'A' && s.at(i+1) == 'B') cnt++;
        }
    }
    if(BA == 0){
        cnt += min(A,B);
    }
    else{
        cnt += BA-1;
        if(A >= 1 && B >= 1) cnt += min(A,B)+1;
        else if(A == 0 && B == 0);
        else cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
/*
O(E)
木の高さを求める
木の高さ:各頂点について、そこから最も遠い葉までの距離
verify:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_B&lang=ja
//(spaghetti sourceさんは違った)
http://www.prefield.com/algorithm/graph/tree_height.html
*/
#include <bits/stdc++.h>
using namespace std;
template<class T,class U>constexpr bool chmin(T&a,const U b){if(a<=b)return false;a=b;return true;}
template<class T,class U>constexpr bool chmax(T&a,const U b){if(a>=b)return false;a=b;return true;}


//辺 fromがない
template<typename T >
struct edge{
  int to;
  T cost;
  edge()=default;
  edge(int to, T cost) : to(to), cost(cost) {}
};
template<typename T>
using edges=vector<edge<T>>;
template<typename T>
using WeightGraph=vector<edges<T>>;

template<typename T>
pair<T,int> dfs(const WeightGraph<T> &g,int idx,int par,T dist,vector<T> &table){
    chmax(table[idx],dist);
    
    pair<T,int> ret={dist,idx};
    for(auto &e:g[idx]){
        if(e.to==par) continue;
        auto koho=dfs(g,e.to,idx,dist+e.cost,table);
        chmax(ret,koho);
    }
    return ret;
}

template<typename T>
vector<T> Height(const WeightGraph<T> &g){
    vector<T> ret(g.size(),0);
    pair<T,int> x;
    x.second=0;
    for(int i=0;i<3;i++){
        x=dfs(g,x.second,-1,0,ret);
    }
    return ret;
}

signed main(){
    int n;
    cin>>n;
    WeightGraph<int> g(n);
    for(int i=0;i<n-1;i++){
        int s,t,w;
        cin>>s>>t>>w;
        g[s].emplace_back(t,w);
        g[t].emplace_back(s,w);
    }
    auto ans=Height(g);
    for(int i=0;i<n;i++) cout<<ans[i]<<"\n";
}


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

using namespace  std;

#define ll long long

#define DEBUG(x) cerr << '>' << #x << ':' << x << endl;
int main(){
    
string s,t;
int cnt=0;
for (int i = 0; i < 2; ++i)
{
    cin>>s;
    cin>>t;
}
for (int i = 0; i < 3; ++i)
{
    if(s[i]==t[i]){
        cnt++;
    }
}
cout<<cnt;
 //cerr<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    return 0;
} 

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

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

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

typedef struct {
    double x, y;
} p_t;

int main() {
    Int n;
    cin >> n;
    vector<Int> res = {2, 3, 25};
    vector<bool> used(30001, false);
    used[2] = used[3] = used[25] = true;
    if (n % 2 == 0) {
        res.push_back(30000);
        used[30000] = true;
    }
    for (Int i = 2; i < 30000 - i and res.size() < n; i+=2) {
        if (not used[i] and not used[30000 - i]) {
            used[i] = used[30000 - i] = true;
            res.push_back(i);
            res.push_back(30000 - i);
        }
    }
    for (Int i = 3; i < 30000 - i and res.size() < n; i+=3) {
        if (not used[i] and not used[30000 - i]) {
            used[i] = used[30000 - i] = true;
            res.push_back(i);
            res.push_back(30000 - i);
        }
    }
    for (Int i = 5; i < 30000 - i and res.size() < n; i+=5) {
        if (not used[i] and not used[30000 - i]) {
            used[i] = used[30000 - i] = true;
            res.push_back(i);
            res.push_back(30000 - i);
        }
    }
    if (res.size() == n) {
        for (Int i = 0; i < n; i++) {
            cout << res[i] << " ";
        }
        cout << endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 704
while True:
	n, m, p = map(int, input().split())
	if (n, m, p) == (0, 0, 0):
		break
	x = [int(input()) for i in range(n)]
	if x[m-1] == 0:
		print(0)
	else:
		print(int(sum(x) * (100-p) / x[m-1]))

Measured memory_bytes: 7708
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <map>
#include <string.h>
#define ll long long

using namespace std;

const int MAXN = 2000;

int row, col, q;
char area[MAXN + 5][MAXN + 5];
int pref[5][MAXN + 5][MAXN + 5];

int main(){
	
	cin >> row >> col >> q;
	for(int i = 1; i <= row; i ++){
		for(int j = 1; j <= col; j ++){
			cin >> area[i][j];
		}
	}
	for(int k = 1; k <= 3; k ++){
		for(int i = 1; i <= row; i ++){
			for(int j = 1; j <= col; j ++){
				pref[k][i][j] = pref[k][i - 1][j] 
					+ pref[k][i][j - 1] - pref[k][i - 1][j - 1];
				if(k == 1)pref[k][i][j] += (area[i][j] - '0');
				else if(k == 2){
					if(area[i][j - 1] == '1' && area[i][j] == '1')
						pref[k][i][j] += 1;
				}else{
					if(area[i - 1][j] == '1' && area[i][j] == '1')
						pref[k][i][j] += 1;
				}
			}
		}
	}
	for(int i = 1; i <= q; i ++){
		int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2;
		int ans = 0;
		for(int j = 1; j <= 3; j ++){
			int cur = 0;
			if(j == 1) cur = pref[j][r2][c2] - pref[j][r1 - 1][c2] - 
						pref[j][r2][c1 - 1] + pref[j][r1 - 1][c1 - 1];
			if(j == 2) cur = pref[j][r2][c2] - pref[j][r1 - 1][c2] - 
						pref[j][r2][c1] + pref[j][r1 - 1][c1];
			if(j == 3) cur = pref[j][r2][c2] - pref[j][r1][c2] -
						pref[j][r2][c1 - 1] + pref[j][r1][c1 - 1];
			// cout << j <<" "<< cur << endl;
			if(j == 1)ans += cur;
			else ans -= cur;
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 55552
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    int n;
    cin >> n;
    vi v(n);
    rep(i, n)
    {
        cin >> v[i];
    }
    int ans = 0;
    rep(i, n)
    {
        if (v[i] == i + 1)
        {
            ans++;
            i++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    static public void main(String args[]){
        final long INF = (long)(1e10);
        final int V_MAX = 100000;

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int W = sc.nextInt();

        long[] w = new long[N];
        int[] v = new int[N];
        long[][] dp = new long[N+1][V_MAX+1];

        for(int i = 0 ; i < N ; i++){
            w[i] = sc.nextLong();
            v[i] = sc.nextInt();
        }

        for(int i = 0 ; i <= N ; i++){
            for(int j = 0 ; j <= V_MAX ; j++){
                dp[i][j] = INF;
            }
        }
        dp[0][0] = 0;

        for(int i = 0 ; i < N ; i++){
            for(int j = 0 ; j <= V_MAX ; j++){
                if(j + v[i] <= V_MAX) {
                    dp[i + 1][j + v[i]] = Math.min(dp[i + 1][j + v[i]], dp[i][j]+w[i]);
                }
                dp[i+1][j] = Math.min(dp[i+1][j], dp[i][j]);
            }
        }

        long ans = INF;
        for(int i = V_MAX; i >= 0  ; i--){
            if(dp[N][i] <= W){
                ans = i;
                break;
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 128084
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define ms(a, b)  memset((a), (b), sizeof(a))
//#define LOCAL
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int maxn = 15+10;
const int mod = 1e9+7;
LL a[maxn];
LL cnt (LL n) {
    LL num = 0;
    while(n>0) {
        num++;
        n &=(n-1);
    }
    return num;
}
int main() {
#ifdef LOCAL
    freopen("input.txt" , "r", stdin);
#endif // LOCAL
    LL n, k, i;
    scanf("%lld%lld", &n, &k);
    for(i=0;i<n;i++)   scanf("%lld", &a[i]);
    LL ans = 1000000000000LL;
    for(i=1;i<=(1<<n);i++){
        if(cnt(i)<k)    continue;
        if( i & 1 == 0)     continue;
        LL now = 0;
        LL base = a[0];
        for(LL j=1;j<n;j++){
            if(i & (1<<j)){
                if(a[j] <= base){
                    now += base+1-a[j];
                    base++;
                }
            }
            if(a[j] > base){
                base = a[j];
            }
        }
        if( now < ans )      ans = now;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
set<int>S;
int ans = 1e8;
void simulate(vector<vector<int>>&g){
    map<int,int>cnt;
    for(int i = 0; i < g.size(); ++i){
        for(int j = 0; j < g[i].size(); ++j){
            auto crt = g[i][j];
            if(S.find(crt) == S.end()){continue;}
            cnt[crt]++;
            break;
        }
    }
    int maxim = -1, num = -1;
    for(auto itr : cnt)
        if(maxim < itr.second)
            maxim = itr.second, num = itr.first;
    ans = min(ans,maxim);
    S.erase(num);
    if(not S.empty()) simulate(g);
}
int main(){
    int N,M; cin >> N >> M;
    vector<vector<int>>g(N,vector<int>(M));
    for(auto& v : g)
        for(auto&  e: v) cin >> e;
    for(int i = 1; i <= M; ++i){
        S.insert(i);
    }
    simulate(g);
    cout << ans << endl;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 103;
int n, ans[N];
struct Node {
	string s;
	int val, id;
	inline bool operator < (const Node &o) const {return s < o.s || s == o.s && val > o.val;}
} p[N];
int main(){
	cin >> n;
	for(Rint i = 1;i <= n;i ++){
		cin >> p[i].s >> p[i].val;
		p[i].id = i;
	}
	sort(p + 1, p + n + 1);
	for(Rint i = 1;i <= n;i ++) printf("%d\n", p[i].id);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5])
        cout << "Yes"
             << "\n";
    else
        cout << "No"
             << "\n";
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

int A[100010];

void solve() {
	int n; scanf("%d", &n);
	for(int i=1;i<=n;i++) scanf("%d", A+i);
	sort(A+1, A+1+n);
	if(A[n] - A[1] > 1) {
		puts("No");
		return;
	}
	
	int a = 0;
	for(int i=1;i<=n;i++)if(A[i] == A[1]) ++a;
	int b = n - a;
	if(b == 1) {
		puts("No");
		return;
	}
	if(b == 0){
		int t = A[1];
		if((1 <= t && t <= n/2) || t == n-1) puts("Yes");
		else puts("No");
		return;
	}
	int low = a + 1;
	int high = a + b / 2;
	if(low <= A[n] && A[n] <= high) puts("Yes");
	else puts("No");
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
};

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> dct;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define pi 3.14159265

bool compare(pll a, pll b){
    return (a.first*b.second) < (a.second*b.first);
}

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

ll modexp(ll x,ll n){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%mod,n/2);
    return (x*modexp((x*x)%mod,n/2))%mod;
}
int main(){
    fastio;
    int n,x,u,v;
    cin>>n;
    vii a[15];
    f(i,0,n){
        cin>>x;
        f(j,0,x){
            cin>>u>>v;
            a[i].pb({u-1,v});
        }
    }
    int ans=0;
    f(mask,1,(1<<n)){
        vi vis(n,-1);int flag=1;int d=0;
        f(i,0,n){
            if(mask&(1<<i)){
                vis[i]=1;d++;
            }
            else vis[i]=0;
        }
        f(i,0,n){
            if(mask&(1<<i)){
                fr(j,a[i]){
                    if(vis[j.first]==-1){
                        vis[j.first]=j.second;
                    }
                    else{
                        if(vis[j.first]!=j.second){
                            flag=0;
                            break;
                        }
                    }
                }
            }
            if(flag==0)break;
        }
        if(flag){
            ans=max(ans,d);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[3];
  for(int i=0;i<3;i++){
  cin>>a[i];
  }
  sort(a,a+3);
  cout<<a[2]*10+a[1]+a[0]<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[105];
bool b[105]={0};
	


int main(){
	int x,y;
	cin>>x>>y;
	if(y==0){
		cout<<x<<endl;
		return 0;
	}

	for(int i=1;i<=y;i++){
		cin>>a[i];
		b[a[i]]=true;
	}

	int i=101;
	int max=100005;
	int ans=102;
	for(int n=101;n>=0;n--){
	
		if(!b[i]){
			if(max>=abs(i-x)){
				max=abs(i-x);
				
				if(ans>i){
					ans=i;
				}
				i--;
			}
		}
		else
		{
			i--;
		}
	}
	cout<<ans<<endl;
}

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

int main() 
{ 
 int  hs,ms,ss,hb,mb,sb,hc,mc,sc;
 for(int i=1;i<=3;i++){
  cin>>hs>>ms>>ss>>hb>>mb>>sb;
  hc=0;mc=0;sc=0;
  sc=sb-ss;
  if(sc<0){sc=sc+60;mc--;}
  mc=mb-ms+mc;
  if(mc<0){mc=sc+60;hc--;}
  hc=hb-hs+hc;
  cout<<hc<<' '<<mc<<' '<<sc<<'\n';
   }
 return 0; 
}  

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int mod = 1e9+7;

int p(int a, int b) {
    int res = 1;
    while(b > 0) {
        if (b&1) res = res * a % mod;
        a = a * a % mod;;
        b >>= 1;
    }
    return res;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int ans = p(10, n) - p(9, n) - p(9, n) + p(8, n); ans %= mod; ans = (ans + mod) % mod;
    cout << ans << endl;
}

Measured memory_bytes: 3612
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);

        int n=scan.nextInt();
        int []l=new int [2*n];

        for(int i=0;i<2*n;i++){
            l[i]=scan.nextInt();
        }
        Arrays.sort(l);
        int sum=0;
        for(int i=0;i<n;i++){
             if(l[2*i]>l[2*i+1])
                 sum+=l[2+i+1];
            else
                 sum+=l[2*i];

        }
        System.out.println(sum);


    }
}

Measured memory_bytes: 9804
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    vector<pair<int, int>> p(n); cin >> p;

    SORT(p);
    int ans = p[0].first;
    FOR(i, 1, n)ans += min(p[i].first - p[i - 1].first,
        p[i - 1].second - p[i].second);
    ans += p.back().second;
    cout << ans << "\n";
}

Measured memory_bytes: 1024