akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
const int DIM = 1e5 + 7;
 
bitset <DIM> vis;
 
vector <int> st;
vector <int> v[DIM];
vector <int> res;
 
void dfs(int nod)
{
	vis[nod] = true;
	st.push_back(nod);
	
	for(auto i : v[nod])
		if(i == st[0] && nod != st[0] && (res.size() == 0 || res.size() > st.size()))
		{
			res = st;
		}
		else
			if(vis[i] == 0)
			{
				vis[i] = true;
				dfs(i);
			}
	
	st.pop_back();
}
 
main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	
	for(int i = 1; i <= m; i++)
	{
		int x, y;
		cin >> x >> y;
		
		v[x].push_back(y);
	}
	
	for(int i = 1; i <= n; i++)
	{
		vis.reset();
		dfs(i);
	}
	if(res.size() == 0)
		cout << -1;
	else
	{
		cout << res.size() << '\n';
		
		for(auto i : res)
			cout << i << '\n';
	}
}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int ans;
    if (a == b && b == c && c == a)ans = 1;
    else if (a != b && b != c && c != a) ans = 3;
    else {
        ans = 2;
    }
    cout << ans << endl;




    return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    tmp = input[0].split(" ");
    var s = tmp[0];
    var ss='';
    for(i=0;i<s.length;i++) {var ss =ss+ 'x'; }
  console.log(ss);
    }
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    string s;
    int k;
    cin>>k>>s;
    if(s.size()<=k) cout<<s;
    else{
        rep(i,k) cout<<s[i];
        cout<<"...";
    }
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N,K;
    Scd2(N,K);

    vector<vi> bl(K,vi(K));
    vector<vi> wh(K,vi(K));

    int x,y;
    char s[123];
    Rep(i,N){
        Scd2(x,y);
        Scs(s);
        bool blackwhite = (x/K)%2 xor (y/K)%2;
        x %= K, y %= K;
        ( s[0] == 'B' xor blackwhite ? bl : wh)[y][x]++;
    }

    K++;
    vector<vi> bls(K,vi(K));
    vector<vi> whs(K,vi(K));
    K--;

    Rep(i,K){
        Rep(j,K){
            bls[i+1][j+1] += bls[i+1][j] + bl[i][j];
            whs[i+1][j+1] += whs[i+1][j] + wh[i][j];
        }
    }
    Rep(j,K){
        Rep(i,K){
            bls[i+1][j+1] += bls[i][j+1];
            whs[i+1][j+1] += whs[i][j+1];
        }
    }

    int ans = 0;
    int tmp = 0;
    Rep(i,K+1){
        Rep(j,K+1){
            tmp = 0;
            tmp += bls[i][j];
            tmp += bls[i][j] - bls[i][K] - bls[K][j] + bls[K][K];
            tmp += whs[i][K] - whs[i][j];
            tmp += whs[K][j] - whs[i][j];
            ans = max( ans, tmp );
            tmp = 0;
            tmp += whs[i][j];
            tmp += whs[i][j] - whs[i][K] - whs[K][j] + whs[K][K];
            tmp += bls[i][K] - bls[i][j];
            tmp += bls[K][j] - bls[i][j];
            ans = max( ans, tmp );
        }
    }

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


    return 0;
}





Measured memory_bytes: 16000
n,l = map(int,input().split())

if l*(n+l-1) <= 0:
    print((l+n+l-1)*n//2)
elif l >= 0:
    print((l+n+l-1)*n//2-l)
else:
    print((l+n+l-1)*n//2-(n+l-1))


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

int main() {
    int N; 
    cin >> N;
    vector<int> A(N), B(N), C(N);
    for(int i=0; i<N; i++)
        cin >> A[i] >> B[i] >> C[i];
    long long dp[N][3];
    dp[0][0] = A[0];
    dp[0][1] = B[0];
    dp[0][2] = C[0];
    for(int i=1; i<N; i++) {
        dp[i][0] = max(dp[i-1][1] + A[i], dp[i-1][2] + A[i]);
        dp[i][1] = max(dp[i-1][0] + B[i], dp[i-1][2] + B[i]);
        dp[i][2] = max(dp[i-1][0] + C[i], dp[i-1][1] + C[i]);
    }
    cout << max(dp[N-1][0], max(dp[N-1][1],dp[N-1][2]));
}

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

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  vector<bool> rem(b);
  rep(i, b) {
    int num = a*i%b;
    if (rem[num])
      break;
    else
      rem[num] = true;
  }
  if (rem[c])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  vector<int> a(1000001);
  int k;
  cin>>k;
  a[1]=7%k;
  for(int i=2;i<=k;i++){
    a[i]=(a[i-1]*10+7)%k;
  }
  for(int i=1;i<=k;i++){
    if(a[i]==0){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 6976
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll a[5],k,val=0;
  for(int i=0;i<5;i++){
    cin >> a[i];
  }
  cin >> k;
  val = a[4]-a[0];
  if(k>=val){
    cout <<"Yay!\n";
  }else{
    cout <<":(\n";
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

string S1, S2;

const LL MOD = 1000000007LL;

LL dp[500][20];

LL memo(int idx, int color) {
	if (idx == S1.sz)
		return 1LL;
	LL &ret = dp[idx][color];
	if (ret != -1)
		return ret;
		
	int c1 = color % 3;
	int c2 = color / 3;
	if (!idx)
		c1 = c2 = -1;
	ret = 0;
	FOR (i1, 3)
		FOR (i2, 3) {
			if (S1[idx] == S2[idx] && i1 != i2)
				continue;
			if (S1[idx] != S2[idx] && i1 == i2)
				continue;
			if (idx && S1[idx] == S1[idx - 1] && i1 != c1)
				continue;
			if (idx && S1[idx] != S1[idx - 1] && i1 == c1)
				continue;
			if (idx && S2[idx] == S2[idx - 1] && i2 != c2)
				continue;
			if (idx && S2[idx] != S2[idx - 1] && i2 == c2)
				continue;
			ret += memo(idx + 1, i2 * 3 + i1);
			if (ret >= MOD)
				ret -= MOD;
		}
	return ret;
}

int main() {
	int N;
	cin >> N;
	cin >> S1 >> S2;
	SET(dp, 255);
	cout << memo(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;

int main(){



    vector<int> a(5);
    for(int i=0;i<5;i++){
        cin >> a[i];
    }

    int k;
    cin >> k;

    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++){
            if(a[i] -a [j] > k || a[i] -a [j] < -k){
            cout << ":(" << endl;
            return 0;
            }
        }
    }


    cout << "Yay!" << endl;
}

Measured memory_bytes: 384
//
#include<cstdio>
#include<cmath> 
#include<iostream> 
#include<iomanip>
#include<string>
#include<algorithm>
using namespace std;
int m,n,x,a[102];
char c[102][102];
int main()
{
	//freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
	cin>>m>>n;
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>c[i][j];
			if(c[i][j]=='#')
				x++;
		}
		if(x==0)
		{
			i--;
			m--;
		}
		x=0;
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(c[j][i]=='#')
				x++;
		}
		if(x==0)
		{
			a[i]=1;
		}
		x=0;
	}
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(a[j]==0)
				cout<<c[i][j];
		}
		cout<<endl;
	}
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}

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 R=sc.nextInt();
		String ans;

		if(R <1200){
			ans="ABC";
		}else if(R < 2800){
			ans="ARC";
		}else {
			ans="AGC";
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 27036
#include<bits/stdc++.h> 
using namespace std;
#define ll long long
#define mod 1000000007ll
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define db(x) cout << #x << " = " << x << '\n'
#define sep cout << "\n********************************************\n"
#define fast  ios_base::sync_with_stdio(false), cin.tie(NULL)
int main(int argc, char const *argv[])
{
    fast;
    ll k, a, b;
    cin >> k >> a >> b;
    ll ans = (b / k - (a - 1) / k);
    if (ans)
    	cout << "OK" << '\n';
    else
    	cout << "NG" << '\n';
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <string>
#include <memory.h>
using namespace std;

int n;
int a[36][2];
int b[36][2];
int c[36][2];
char ntos(int i){
    if(i==0) return 'S';
    else if(i==1) return 'H';
    else if(i==2) return 'C';
    else return 'D';
}

int bubble(){
    for(int i=0;i<n;i++){
        for(int j=1;j<n-i;j++){
            if(b[j-1][0] > b[j][0]){
                swap(b[j-1][0], b[j][0]);
                swap(b[j-1][1], b[j][1]);
            }
        }
    }
    cout << ntos(b[0][1]) << b[0][0];
    for(int i=1;i<n;i++){
        cout << ' ' << ntos(b[i][1]) << b[i][0];
    }
    cout << endl;
    cout << "Stable" << endl;
}

int selection(){
    int m;
    for(int i=0;i<n;i++){
        m = i;
        for(int j=i;j<n;j++){
            if(c[m][0] > c[j][0]) m = j;
        }
        swap(c[i][0], c[m][0]);
        swap(c[i][1], c[m][1]);
    }
    cout << ntos(c[0][1]) << c[0][0];
    for(int i=1;i<n;i++){
        cout << ' ' << ntos(c[i][1]) << c[i][0];
    }
    cout << endl;
    for(int i=0;i<n;i++){
        if(c[i][1] != b[i][1]){
            cout << "Not stable" << endl;
            return 0;
        }
    }
    cout << "Stable" << endl;
}
int main(){
    char suit;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> suit >> a[i][0];
        if(suit == 'S') a[i][1] = 0;
        else if(suit == 'H') a[i][1] = 1;
        else if(suit == 'C') a[i][1] = 2;
        else a[i][1] = 3;
    }
    memcpy(b, a, sizeof(a));
    memcpy(c, a, sizeof(a));
    bubble();
    selection();
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>

using namespace std;

typedef long long LL;

template <class T>
struct BinaryIndexedTree/*{{{*/
{
  vector<T> tree;
  const int size;
  BinaryIndexedTree(int s) : tree(s+1), size(s) {}
  // i 番目までの要素の累積和
  T read(int i) const
  {
    T sum = 0;
    while (i > 0) {
      sum += tree[i];
      i -= i & -i;
    }
    return sum;
  }

  // i 番目の要素
  T read_single(int i) const
  {
    T sum = tree[i];
    if (i > 0) {
      const int z = i - (i & -i);
      --i;
      while (i != z) {
        sum -= tree[i];
        i -= (i & -i);
      }
    }
    return sum;
  }

  void add(int i, T v)
  {
    while (i <= size) {
      tree[i] += v;
      i += (i & -i);
    }
  }

  // read(i) == vとなる最小のi。存在しなければ-1。
  int search(T v) {
        int left = 0, right = size;
        while(left+1 < right) {
            const int center = (left+right) / 2;
            if(read(center) < v) {
                left = center;
            } else {
                right = center;
            }
        }
        if(right == size || read(right) != v) return -1;
        return right;
    }
};/*}}}*/

bool solve() {
	int N, Q;
	if(!(cin >> N >> Q)) return false;
	if(!N && !Q) return false;

	vector<LL> scores(N);
	for(int i = 0; i < N; ++i) {
		cin >> scores[i];
	}
	vector<LL> score_index = scores;
	scores.push_back(-1); // sentinel
	scores.push_back(*max_element(begin(scores), end(scores)) + 1); // sentinel
	sort(begin(scores), end(scores));
	scores.erase(unique(begin(scores), end(scores)), end(scores));

	BinaryIndexedTree<int> bit(score_index.size() + 1);
	for(int i = 0; i < N; ++i) {
		score_index[i] = distance(begin(scores), lower_bound(begin(scores), end(scores), score_index[i]));
		bit.add(score_index[i], 1);
	}

	multiset<int> leader_scores;
	while(Q--) {
		string cmd;
		int x;
		cin >> cmd >> x;

		if(cmd == "ADD") {
			bit.add(score_index[x-1], -1);
			leader_scores.insert(score_index[x-1]);
		} else if(cmd == "REMOVE") {
			bit.add(score_index[x-1], 1);
			leader_scores.erase(leader_scores.find(score_index[x-1]));
		} else if(cmd == "CHECK") {
			// Binary search for r
			LL left = -1, right = scores.back();
			bool found = false;
			while(left+1 < right) {
				const LL r = (left + right) / 2;
				int not_in_group = 0;
				LL prev_leader_score = 0;
				for(int leader_score : leader_scores) {
					const LL actual = scores[leader_score];
					const LL lim = actual - r;
					if(scores[prev_leader_score] < lim-1) {
						int lim_idx = distance(begin(scores), lower_bound(begin(scores), end(scores), lim-1));
						if(scores[lim_idx] > lim-1) --lim_idx;
						not_in_group += bit.read(lim_idx) - bit.read(prev_leader_score);
					}
					prev_leader_score = leader_score;
				}
				not_in_group += bit.read(bit.size) - bit.read(prev_leader_score);
				if(not_in_group <= x) {
					right = r;
					found = true;
				} else {
					left = r;
				}
			}
			if(found) {
				cout << right << endl;
			} else {
				cout << "NA" << endl;
			}
		}
	}

	return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 25992
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2*1e5+10;
const int MOD = 1e9 + 7;
const int INF = 1e18 + 10;


void printVector(vector<int> s){
    for(int &x:s){
        cout<<x<<" ";
    }
    cout<<endl;
}

string grid[1000];
int dp[1000][1000];
int h;int w;

bool check(int i , int j){
    if(i>=h || i<0 || j<0 || j>=w){
        return false;
    }
    return true;
}

int dfs(int i , int j){
    if(i==h-1 && j==w-1){
        return 1;
    }
    if(!check(i,j)){
        return 0;
    }
    if(grid[i][j]=='#'){
        return 0;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    return dp[i][j] = (dfs(i+1,j)  +  dfs(i,j+1))%MOD;
}


void solve(){
    cin>>h;
    cin>>w;
    for(int i = 0 ; i < h ; i++){
        cin>>grid[i];
    }
    for(int i = 0 ; i < 1000 ; i++) for(int j = 0 ; j < 1000 ; j++) dp[i][j] = -1;
    cout<<dfs(0,0)<<endl;

}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
//    cin>>t;
    t = 1;
    for(int i = 0 ; i < t ; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 12580
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a>8||b>8)cout<<":(";
	else cout<<"Yay!";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

            double d = 0;
            for (int i = 0; i < N; i++) {
                int a = sc.nextInt();
                d += 1.0 / a;
            }

            System.out.println(1.0 / d);
        }
    }

}


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

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)

const int INF = 1 << 28;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> dp(1 << N, INF);
  dp[0] = 0;
  FOR(i, M) {
    int a, b, add = 0;
    cin >> a >> b;
    FOR(j, b) {
      int c;
      cin >> c;
      add |= 1 << (c - 1);
    }
    FOR(j, 1 << N) dp[j | add] = min(dp[j | add], dp[j] + a);
  }
  cout << (dp[(1 << N) - 1] == INF ? -1 : dp[(1 << N) - 1]) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    set<int> set;
    set.insert(a);
    set.insert(b);
    set.insert(c);
    if(set.size()==2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pa;
char go(string a, int x) {
	char ans;
	if (a[x] == 'a') {
		ans = 'A';
	}
	else if (a[x] == 'b') {
		ans = 'B';
	}
	else if (a[x] == 'c') {
		ans = 'C';
	}
	return ans;
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); //9 90 900 
	string a, b, c; cin >> a >> b >> c;
	int x = 0, y = 0, z = 0;
	char ans = 'A';
	while (1) {
		if (ans == 'A') {
			if (x == a.size()) {
				cout << 'A' << '\n'; return 0;
			}
			ans = go(a, x++);
		}
		else if (ans == 'B') {
			if (y == b.size()) {
				cout << 'B' << '\n'; return 0;
			}
			ans = go(b, y++);
		}
		else {
			if (z == c.size()) {
				cout << 'C' << '\n'; return 0;
			}
			ans = go(c, z++);
		}
	}



}

Measured memory_bytes: 256
object Main extends App {


  val Array(n, k) = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val pArr = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  def solve(): Int = {
    pArr.sorted.take(k).sum
  }

  println(solve())

}


Measured memory_bytes: 54912
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int)(n).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

typedef ll tc;
struct Line{tc m,h;};
struct CHT { // for minimum (for maximum just change the sign of lines)
	vector<Line> c;
	int pos=0;
	tc in(Line a, Line b){
		tc x=b.h-a.h,y=a.m-b.m;
		return x/y+(x%y?!((x>0)^(y>0)):0); // ==ceil(x/y)
	}
	void add(tc m, tc h){ // m's should be non increasing
		Line l=(Line){m,h};
		if(c.size()&&m==c.back().m){
			l.h=min(h,c.back().h);c.pop_back();if(pos)pos--;
		}
		while(c.size()>1&&in(c.back(),l)<=in(c[c.size()-2],c.back())){
			c.pop_back();if(pos)pos--;
		}
		c.pb(l);
	}
	inline bool fbin(tc x, int m){return in(c[m],c[m+1])>x;}
	tc eval(tc x){
		// O(log n) query:
		int s=0,e=c.size();
		while(e-s>1){int m=(s+e)/2;
			if(fbin(x,m-1))e=m;
			else s=m;
		}
		return c[s].m*x+c[s].h;
		// O(1) query (for ordered x's):
		while(pos>0&&fbin(x,pos-1))pos--;
		while(pos<c.size()-1&&!fbin(x,pos))pos++;
		return c[pos].m*x+c[pos].h;
	}
};

ll h[300000], dp[300000];

int main(){FIN;
    ll n,c; cin >> n >> c;
    fore(i,0,n) cin >> h[i];
    CHT xx;
    fore(i,0,n){
        if(i) dp[i] = h[i]*h[i] + xx.eval(h[i]);
        xx.add(-2*h[i], h[i]*h[i]+c+dp[i]);
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 9712
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] lines = line.split(" ");
		int A = Integer.parseInt(lines[0]);
		int B = Integer.parseInt(lines[1]);

		int plus = A + B;
		int minus = A - B;
		int astarisc = A * B;
		int max = -10000;
		if (max < plus) {
			max = plus;
		}
		if (max < minus) {
			max = minus;
		}
		if (max < astarisc) {
			max = astarisc;
		}

		System.out.println(max);
	}

}


Measured memory_bytes: 35936
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    fast_io
    int n, m;
    cin >> n >> m;
    vector<vector<int>> ab(100000);
    int a, b;
    rep(i,n) {
        cin >> a >> b;
        a--;
        ab[a].push_back(b);
    }
    priority_queue<int> que;
    ll ans = 0;
    for (int length = 1; length <= m; length++) {
        int index = length - 1;
        for (int pay: ab[index]) que.push(pay);
        if (que.empty()) continue;
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5632
from collections import deque
n, m = map(int, input().split())
graph = [[] for _ in range(n+1)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

ans = [0]*(n-1)

d = deque()
d.append(1)

while d:
    v = d.popleft()
    for i in graph[v]:
        if ans[i-2] != 0 or i == 1:
            continue
        ans[i-2] = v
        d.append(i)
        
print('Yes')
print(*ans, sep='\n')

Measured memory_bytes: 35668
import itertools

n = int(input())
id = input()[::-1]
count = 0
a = []
odd, even = 0 , 0
tmp = 0
for i in range(1,n+1):
    if id[i-1] == "*":
        if i % 2:
            odd += 1
        else:
            even += 1
    elif i % 2 == 0:
        x = int(id[i-1])
        if x >= 5:
            tmp += (x * 2 - 9)
        else:
            tmp += (x * 2)
    else:
        tmp += (int(id[i-1]))
m = int(input())

data = list(map(int, input().split()))

def sum2(ls):
    ans = 0
    for k in ls:
        if k >= 5:
            ans += (k * 2 - 9)
        else:
            ans += (k * 2)
    return ans

odd_list = list(map(lambda x: (sum(x) % 10),list(itertools.product(data, repeat=odd))))
even_list = list(map(lambda x: ((sum2(x)) % 10),list(itertools.product(data, repeat=even))))
odd_mod = [odd_list.count(i) for i in range(10)]
even_mod = [even_list.count(i) for i in range(10)]
for i in range(10):
    for j in range(10):
        if ((i + j + tmp) % 10) == 0:
            count += odd_mod[i] * even_mod[j]

print(count)



Measured memory_bytes: 64708
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"---------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
						For(_x,L,R)cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> vi;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=100005;
int n,A,B;
int main(){
	n=read(),A=read(),B=read();
	puts((B^A)&1?"Borys":"Alice");
	return 0;
}

Measured memory_bytes: 256
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = n
B = 0
for i in range(1,n):
    a[i] += a[i-1]
    if (a[i]>k):
        A = i
        break
for i in range(1,m):
    b[i] += b[i-1]
ans = A
if (a[0]>k):
        for i in range(m):
            if (b[i]>k):
                print(i)
                exit()
        print(len(b))
        exit()
a = [0] + a
b = [0] + b
while True:
    if (A<0):
        break
    if (B>=m):
        break
    B += 1
    #print(A,B)
    if (a[A]+b[B] >k):
        B -= 1
        A -= 1
    else:
        ans = max(ans,A+B)
print(ans)


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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int maxnumber = max(a, max(b, c));
  int sum = a+b+c;
  int md = sum - maxnumber;
  rep(i, k) {
    maxnumber *= 2;
  }
  int ans = md + maxnumber;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
# -*- coding: utf-8 -*-


def main():
    from collections import Counter

    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    ans = 0

    for index, (key, ai) in enumerate(sorted(Counter(a).items(), key=lambda x: x[1], reverse=True), 1):
        if index > k:
            ans += ai

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39352
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;
ll const MOD = 1000000007;


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

int X,A,B;
cin >> X >> A >> B;

cout << (X-A) % B << endl;

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}


void solve()
{	
	int x, a, b;
	cin >> x >> a >> b;
	if(b - a > x){
		cout << "dangerous";
	}
	else{
		if(b > a){
			cout << "safe";
		}
		else{
			cout << "delicious";
		}
	}
}


 
 
int main()
{
 //	freopen("sparse.in", "r", stdin);
	//freopen("sparse.out", "w", stdout);
	   Red;
  	//int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{

    public static int ReadInt()
    {
        return int.Parse(Console.ReadLine());
    }

    public static int[] ReadInts()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }

    public static void Main()
    {
        var Input = ReadInts();
        var N = Input[0]; //スイッチの数
        var M = Input[1]; //電球の数

        var s = new List<int>[M]; //M個の要素を持つ配列のリスト

        //kとsを分離してsの配列をM個保存
        for(int i = 0; i<M; i++)
        {
            var input2 = ReadInts(); //k s1 s2 s3・・・sk
            var k = input2[0];
            s[i] = new List<int>();　//M個の要素を持つ配列
            for(int j = 0; j < k; j++)
            {
                s[i].Add(input2[j+1] - 1); //s1 - 1,s2 -1,・・・を詰めていく
            }
        }

        var p = ReadInts();
        var count = 0;
        for (int i = 0; i < Math.Pow(2, N); i++)　//すべての電球のonoffの組み合わせについて
        {
            var b = new bool[N]; //bool値の配列 iが2進数に変換された値が入る
            for(int j = 0; j < N; j++)
            {
                //boolの配列に値を格納する
                //1に対して0~N-1左シフトした2進数 = 0001 0010 0100 1000 ・・・　に対してiと論理積（同じ桁が1かつ1なら1それ以外は0）を取り、1の桁をtrueにしていく
                //するとiが二進数00000・・・（N個）、0000・・・1、0000・・・10、・・・に変換される。（配列bにtrue = 1 false = 0 として格納される。）
                //すなわち、00000・・・（N個）、0000・・・1、0000・・・10、・・・となり、0がオフ1がオンとすると、すべてのスイッチの状態が取得できる。

                b[j] = (i & (1 << j)) != 0;
            }
            for(int j = 0; j < M; j++) //すべての電球について
            {
                var c = 0;
                foreach(var item in s[j]) //この座標s[j]のうちonになっているスイッチは？
                {
                    if(b[item]) //座標itemのbがtrueならスイッチがon
                    {
                        c++;
                    }
                }

                if(c % 2 != p[j]) //on になっているスイッチの個数を2で割った余りがpiに等しい時に点灯
                {
                    count--;　//点灯しない場合はカウントマイナス
                    break;
                }

            }
            count++; //すべてついたとしてカウントする　（つかない場合はすでにマイナスされている）
        }

        Console.WriteLine(count);

    }
}


Measured memory_bytes: 13396
N = int(input())
X = input()

def e(x, y):
    t = [0] * len(x)
    if y <= 0: return (-1, t)
    if y == 1: return (0, t)
    res = 0
    z = 1
    for i in range(len(x) - 1, -1, -1):
        t[i] = z
        if x[i] == '1':
            res = (res + z) % y
        z = (z << 1) % y
    return (res, t)

def popcount(x):
    x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555)
    x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333)
    x = x + (x >> 4) & 0x0f0f0f0f0f0f0f0f
    x += x >> 8
    x += x >> 16
    x += x >> 32
    return x & 0x7f

fm = [-1] * (2 * (10 ** 5) + 1)
fm[0] = 0
def f(x):
    if fm[x] >= 0: return fm[x]
    fm[x] = 1 + f(x % popcount(x))
    return fm[x]


pc = X.count('1')
s0, t0 = e(X, pc + 1)
s1, t1 = e(X, pc - 1)

for i in range(N):
    t = 0
    if X[i] == '0':
        t = (s0 + t0[i]) % (pc + 1)
    else:
        if pc == 1:
            print(0)
            continue
        t = (s1 - t1[i]) % (pc - 1)
    print(1 + f(t))


Measured memory_bytes: 83016
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;
ll mod = 1000000007;

int main() {
    ll n;
    scanf("%lld",&n);
    ll ans = n * (n - 1) / 2;
    printf("%lld\n",ans);
    return 0;
}

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

int main(){
  int h,w,n;
  int x[100100],y[100100];
  int wx[200100],wy[200100];

  scanf("%d%d%d",&h,&w,&n);
  for(int i=0;i<n;i++){
    scanf("%d%d",&x[i],&y[i]);
    wx[2*i] = wx[2*i+1] = x[i];
    wy[2*i] = wy[2*i+1] = y[i];
  }

  sort(wx,wx+2*n); sort(wy,wy+2*n);
  ll sumx[2]={}, sumy[2]={};
  int med = n-1;

  for(int i=0;i<2*n;i++){
    sumx[0] += abs(wx[i]-wx[med]);
    sumy[0] += abs(wy[i]-wy[med]);
    sumx[1] += abs(wx[i]-wx[med+1]);
    sumy[1] += abs(wy[i]-wy[med+1]);
  }

  ll ans = 1e18;
  pair<int,int> cord(0,0);
  for(int i=0;i<n;i++){
    int dx = 0, dy = 0;
    if(x[i]<=wx[med])dx=1;
    if(y[i]<=wy[med])dy=1;

    int X = wx[med+dx], Y = wy[med+dy];
    ll cur = sumx[dx] + sumy[dy] - abs(X-x[i]) - abs(Y-y[i]);
    if(ans > cur){
      ans = cur; cord = make_pair(X,Y);
    }else if(ans == cur){
      cord = min(cord, make_pair(X,Y));
    }
  }

  printf("%lld\n", ans);
  printf("%d %d\n",cord.first, cord.second);
}

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


int A[100100],vis[100100];

int main(){
	int n,a=1,cnt=1;
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> A[i];
	}
	
	if(A[1]==2){
		cout << 1 << endl;
		return 0;
	}
	while(1){
		if(vis[a]){
			cout << -1 << endl;
			return 0;
		}
		
		vis[a]++;
		a=A[a];
		cnt++;
		if(A[a]==2)break;
	}
	
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <iomanip>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <time.h>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define X first
#define Y second

const LL MOD = 1000000007;
const int INF = 1000000007;
const LL LINF = 1LL * INF * INF;
const int MAXN = 51;
const LD EPS = 1e-6;
const LD PI = acos(-1.0);

int n, A[MAXN], B[MAXN];
bool g[MAXN][MAXN], used[MAXN];

void dfs(int v)
{
	used[v] = true;
	REP(i, MAXN)
	{
		if (g[v][i] && !used[i])
			dfs(i);
	}
}

bool ok(LL mask)
{
	REP(i, MAXN)
		memset(g[i], 0, MAXN);
	FOR(i, 1, MAXN)
	{
		if (!(mask & (1LL << i)))
			continue;
		REP(j, MAXN)
			g[j][j % i] = true;
	}
	REP(i, n)
	{
		memset(used, 0, MAXN);
		dfs(A[i]);
		if (!used[B[i]])
			return false;
	}
	return true;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	cin >> n;
	REP(i, n)
		cin >> A[i];
	REP(i, n)
		cin >> B[i];
	LL mask = 0;
	FOR(i, 1, MAXN)
		mask |= 1LL << i;
	if (!ok(mask))
	{
		cout << -1;
		return 0;
	}
	RFOR(i, MAXN, 1)
	{
		if (ok(mask ^ (1LL << i)))
			mask ^= 1LL << i;
	}
	cout << mask;
	return 0;
}

Measured memory_bytes: 384
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s: &str = iterator.next().unwrap();

    let n = s.len();

    for i in 0..n {
        for j in i..n {
            if &s[..i] == "keyence"
                || &s[j..] == "keyence"
                || &format!("{}{}", &s[..i], &s[j..]) == "keyence"
            {
                return String::from("YES");
            }
        }
    }

    return String::from("NO");
}


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

using vi = vector<long long>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;

int main() {
  const int MOD = 1000000007;
  int N; cin >> N;
  // dp[len][i][j][k] := 条件を満たし、末尾が ijk である長さ len の文字列の総数
  vvvvi dp(N+1, vvvi(4, vvi(4, vi(4, 0))));
  // A -> 0, G -> 1, C -> 2, T -> 3
  dp.at(0).at(3).at(3).at(3) = 1;  // 初期状態 TTT としておく
  for (int len = 0; len < N; len++) {
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 4; k++) {
          if (dp.at(len).at(i).at(j).at(k) == 0) continue;
          // 末尾に 0, 1, 2, 3 を追加
          for (int s = 0; s < 4; s++) {
            if (j == 0 && k == 2 && s == 1) continue;  // ACG
            if (j == 0 && k == 1 && s == 2) continue;  // AGC
            if (j == 1 && k == 0 && s == 2) continue;  // GAC
            if (i == 0 && j == 1 && s == 2) continue;  // AG?C
            if (i == 0 && k == 1 && s == 2) continue;  // A?GC
            dp.at(len+1).at(j).at(k).at(s) += dp.at(len).at(i).at(j).at(k);
            dp.at(len+1).at(j).at(k).at(s) %= MOD;
          }
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 4; k++) {
        ans += dp.at(N).at(i).at(j).at(k);
        ans %= MOD;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    int n,m; cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
using i64 = long long;

int main() {
    int a, b, k;
    std::cin >> k >> a >> b;
    while (a <= b) {
        if (a++ % k == 0) {
            std::cout << "OK" << std::endl;
            return 0;
        }
    }

    std::cout << "NG" << std::endl;

    return 0;
}


Measured memory_bytes: 3636
s=input().split()
p=[0,0,0]
for n in range(3):
    p[n]=int(s[n])
if p[0]+p[1]==p[2]:
    print("Yes")
elif p[1]+p[2]==p[0]:
    print("Yes")
elif p[2]+p[0]==p[1]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main() {
    cin>>N;
    vec a(N);
    ll ma = 0, mi = N;
    rep(i,N){
        cin>>a[i];
        ma = max(ma, a[i]);
        mi = min(mi, a[i]);
    }
    S = "Yes";
    if(ma - mi >= 2) {
        S = "No";
    }else if(ma - mi == 1){
        ll kind = ma, num = N;
        rep(i,N){
            if(a[i] == mi){
                --num; --kind;
            }
        }
        if(kind <= 0 || kind*2 > num) S = "No";
    }else {
        if(ma != N - 1 && ma * 2 > N) S = "No";
    }
    cout<<S<<endl;
}

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

using namespace std;

int main() {
	int a, b, c, d, flag = 0;
	cin >> a >> b >> c >> d;
	if(abs(c - a) <= d) flag = 1;
	else if(abs(a - b) <= d && abs(b - c) <= d) flag = 1;
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fr(x,i,n) for(int x = i; x < n; ++x)
#define fb(x,i,n) for(int x = i; x >= n; --x)
#define pr pair<int,int>
#define ll long long int
#define ull unsigned long long int
//const int mod=1e9+7;
const ll inf=1LL<<32;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    vector<ll> v;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            v.push_back(i);
            if(i!=n/i)
            v.push_back(n/i);
        }
    }
    v.push_back(n);
    // ans= elements in v which satisfy + no of divisors of n-1 except 1
    ll k,ans=0;
    //cout<<"v.size()="<<v.size()<<endl;
    ll m=n;
    fr(i,0,v.size())
    {
        n=m;
        k=v[i];
        while(n%k==0)
        n/=k;
        n%=k;
        if(n==1)
        ans++;
    }
    n=m;
    n--;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            ans++;
            if(i!=n/i)
            ans++;
        }
    }
    if(n-1>1)
    ans++;
    cout<<ans;


}


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

int main()
{
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for(int i=a; i<b+1; i++){
    if((i % 10000 / 1000) == (i % 100 / 10) && (i / 10000) == (i % 10)){
      ans += 1;
    }
  }
  
  cout << ans << endl;
}

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

int a[4007], D[4];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        char ch;
        cin >> ch;
        a[i] = (ch == 'R' ? 1 : (ch == 'G' ? 2 : 3));
    }

    long long ans = 0LL;
    for (int i = 3; i <= n; ++i)
    {
        D[1] = D[2] = D[3] = 0;
        for (int j = 1; j < i; ++j)
        {
            if (a[j] != a[i])
                for (int k = 1; k < 4; ++k)
                    if (k != a[i] && k != a[j])
                    {
                        ans += 1LL * D[k];
                        int x = i - j;
                        ans -= (j - x > 0 && a[j-x]==k);
                    }
            D[a[j]]++;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;

vector<long long> calc_combi(int n){
	vector<long long> v,b;

	for (size_t i = 0; i < n+1; i++) {
		v.push_back(1);
	}

	for (size_t i = 2; i < n+1; i++) {
		b = v;
		for (size_t j = 1; j < i; j++) {
			v[j] = b[j-1] + b[j];
		}
	}
	return v;
}

int main(int argc, char const *argv[]) {
	int n,p,temp;
	int zero,one;
	zero = one = 0;
	cin >> n >> p;
	for (size_t i = 0; i < n; i++) {
		cin >> temp;
		temp = temp % 2;
		switch (temp) {
			case 0:
				zero++;
				break;
			case 1:
				one++;
				break;
		}
	}
	long long sum = 0;
	vector<long long> v = calc_combi(one);
	for (size_t i = p; i <= one; i += 2) {
		sum += v[i];
	}
	sum = sum * pow(2,zero);
	cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s1, s2, s3;
    cin>>s1>>s2>>s3;
    char a, b, c;
    a = s1[0] - 32;
    b = s2[0] - 32;
    c = s3[0] - 32;
    cout<<a<<b<<c<<endl;
    return 0;
}


Measured memory_bytes: 3612
A, B = map(int, input().split())

white = [["#"] * 100 for i in range(50)]
black = [["."] * 100 for i in range(50)]
A, B = A-1, B-1

row = 0
line = 0

for i in range(A):
	white[line][row] = "."
	row += 2
	if row >=100:
		row = 0
		line += 2

row = 0
line = 1
for i in range(B):
	black[line][row] = "#"
	row += 2
	if row >= 100:
		row = 0
		line += 2

ans = white + black
print(100, 100)
for a in ans:
	print("".join(a))


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>

#define MY_SIZE_MAX 100001
#define MY_VALUE_MAX 100001

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	vector< vector<char> > tbl( h, vector<char>( w ) );
	for( int n = 0; n < h; ++n )
	{
		for( int m = 0; m < w; ++m )
		{
			cin >> tbl[n][m];
		}
	}

	const int dx[] = { -1, 0, 1, 0 };
	const int dy[] = { 0, -1, 0, 1 };
	for( int n = 0; n < h; ++n )
	{
		for( int m = 0; m < w; ++m )
		{
			if( tbl[n][m] != '#' ){ continue; }
			bool bAbleFill = false;
			for( int k = 0; k < 4; ++k )
			{
				const int y = min( max( n + dy[k], 0 ), h - 1 );
				const int x = min( max( m + dx[k], 0 ), w - 1 );
				if( (x == m) && (y == n) ){ continue; }
				if( tbl[y][x] != '#' ){ continue; }
				bAbleFill = true;
				break;
			}
			if( !bAbleFill )
			{
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String N = scan.next();
    N = "00" + N;
    scan.close();

    int total = 0;
    int kurikoshi = 0;
    for(int i=N.length()-1; i>=0; i--) {
      if(N.charAt(i) - '0' + kurikoshi < 5) {
        total += N.charAt(i) - '0' + kurikoshi;
        kurikoshi = 0;
      }
      else if(N.charAt(i) - '0' + kurikoshi == 5) {
        total += 5;
        if(N.charAt(i-1) - '0' >= 5) {
          kurikoshi = 1;
        }
        else {
          kurikoshi = 0;
        }
      }
      else {
        total += 10 - (N.charAt(i) - '0' + kurikoshi);
        kurikoshi = 1;
      }
    }
    System.out.println(total);
  }
}

Measured memory_bytes: 37764
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>

using namespace std;

int N, M;

int main() {
	cin >> N >> M;
	vector<pair<int, int> > job(N);//日数、報酬
	for (int i = 0; i < N; i++) {
		cin >> job[i].first >> job[i].second;
	}
	sort(job.begin(), job.end());
	//for (int i = 0; i < N; i++) {
	//	cout << job[i].first << " " << job[i].second << endl;
	//}

	priority_queue<int> que;//報酬
	long long ans = 0;
	int now = 0;//受けれる仕事の末尾
	for (int i = 1; i <= M; i++) {//受ける仕事を最終日から決めていく
		//cout << M - i << "日目の仕事候補追加" << endl;
		for (int j = now; j < N && job[j].first <= i; j++) {
			que.push(job[j].second);
			now++;
		}
		if (!que.empty()) {
			ans += que.top();
			que.pop();
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1660
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N;
    cin >> N;
    vl A(N);
    rep(i,N){
        cin >> A[i];
    }
    multiset<ll> st;
    st.insert(A[N-1]);
    st.insert(INF);
    per(i,N-2){
        ll k=*st.upper_bound(A[i]);
        if(k==INF){
            st.insert(A[i]);
        }
        else{
            st.erase(st.find(k));
            st.insert(A[i]);
        }
    }
    cout << st.size()-1 << endl;
}

Measured memory_bytes: 8584