akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef unsigned long ul;
#define REP(i, n) for (int i = 0; i < n; i++)

priority_queue<pair<ul, pair<int, int>>> q, q1;
const int maxn = 1e3 + 10;
ul X, Y, Z, K;
ul ans[maxn * 3];
inline bool cmp(int x, int y) { return x > y; }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> X >> Y >> Z >> K;
  vector<ul> A(X, 0);
  vector<ul> B(Y, 0);
  vector<ul> C(Z, 0);
  REP(i, X) cin >> A[i];
  REP(i, Y) cin >> B[i];
  REP(i, Z) cin >> C[i];
  int len = min(K, X * Y);

  vector<ul> AB(len, 0);

  sort(A.rbegin(), A.rend());
  sort(B.rbegin(), B.rend());
  sort(C.rbegin(), C.rend());
  vector<vector<bool>> visitedAB(1010, vector<bool>(1010, true));
  vector<vector<bool>> visitedABC(3010, vector<bool>(3010, true));

  q.push(make_pair(A.front() + B.front(), make_pair(0, 0)));
  visitedAB[0][0] = false;
  REP(cas, len) {
    int i = q.top().second.first, j = q.top().second.second;
    AB[cas] = q.top().first;
    q.pop();
    if (visitedAB[i][j + 1] && j+1 < Y) {
      q.push(make_pair(A[i] + B[j + 1], make_pair(i, j + 1)));
      visitedAB[i][j + 1] = false;
    }
    if (visitedAB[i + 1][j] && i+1 < X) {
      q.push(make_pair(A[i + 1] + B[j], make_pair(i + 1, j)));
      visitedAB[i + 1][j] = false;
    }
  }
  // REP(ii, K) { cout << AB[ii] << endl; }

  // while (!q.empty()) q.pop();
  q.swap(q1);
  q.push(make_pair(C.front() + AB.front(), make_pair(0, 0)));
  REP(cas, K) {
    int i = q.top().second.first, j = q.top().second.second;
    ans[cas] = q.top().first;
    q.pop();
    if (visitedABC[i][j + 1] && j+1 < len) {
      q.push(make_pair(C[i] + AB[j + 1], make_pair(i, j + 1)));
      visitedABC[i][j + 1] = false;
    }
    if (visitedABC[i + 1][j] && i+1 < Z) {
      q.push(make_pair(C[i + 1] + AB[j], make_pair(i + 1, j)));
      visitedABC[i + 1][j] = false;
    }
  }
  REP(ii, K) { cout << ans[ii] << endl; }

  return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <stack>

typedef std::stack<int> Tray;

bool moveNtoN(Tray tr[], int src, int dst){
    if((tr[src]).empty() ||
        !(tr[dst]).empty() && (tr[src]).top() < (tr[dst]).top()){
        return false;
    }
    (tr[dst]).push((tr[src]).top());
    (tr[src]).pop();
    return true;
}

bool ifSorted(Tray tr[]){
    return ((tr[1]).empty() && ((tr[0]).empty() || (tr[2].empty())));
}

int solveCenter(Tray tr[], int m, int lastMove){
    for(int i = 1; i <= m; i++){
        if(lastMove != 1 && moveNtoN(tr, 0, 1)){
            lastMove = 0;
        }
        else if(lastMove != 0  && moveNtoN(tr, 1, 0)){
            lastMove = 1;
        }
        else if(lastMove != 3 && moveNtoN(tr, 1, 2)){
            lastMove = 2;
        }
        else if(lastMove != 2 && moveNtoN(tr, 2, 1)){
            lastMove = 3;
        }
        if(ifSorted(tr)){
            return i;
        }
    }
}

int solveLeft(Tray tr[], int m){
    if(moveNtoN(tr, 0, 1)){
        if(ifSorted(tr)){
            return 1;
        }
        int ret = solveCenter(tr, m - 1, 0) + 1;
        return ret ? ret : -1;
    }
    else if(moveNtoN(tr, 1, 0)){
        if(ifSorted(tr)){
            return 1;
        }
        int ret = solveCenter(tr, m - 1, 1) + 1;
        return ret ? ret : -1;
    }
}

int solveRight(Tray tr[], int m){
    if(moveNtoN(tr, 1, 2)){
        if(ifSorted(tr)){
            return 1;
        }
        int ret = solveCenter(tr, m - 1, 2) + 1;
        return ret ? ret : -1;
    }
    else if(moveNtoN(tr, 2, 1)){
        if(ifSorted(tr)){
            return 1;
        }
        int ret = solveCenter(tr, m - 1, 3) + 1;
        return ret ? ret : -1;
    }
}

int solve(Tray argTr[], int m){
    if(ifSorted(argTr)){
        return 0;
    }
    Tray tr[3];
    tr[0] = argTr[0];
    tr[1] = argTr[1];
    tr[2] = argTr[2];
    int ansl = solveLeft(tr, m);
    tr[0] = argTr[0];
    tr[1] = argTr[1];
    tr[2] = argTr[2];
    int ansr = solveRight(tr, m);
    if(ansl == -1 && ansr == -1){
        return -1;
    }
    else if(ansl == -1 || ansr == -1){
        return ansl > 0 ? ansl : ansr;
    }
    else{
        return ansl < ansr ? ansl : ansr;
    }
}

int main(){
    int n, m;
    while(1){
        std::cin >> n >> m;
        if(!(n || m)){
            break;
        }
        Tray trays[3];
        for(int col = 0; col < 3; col++){
            int nCups;                     // #cups on the line
            std::cin >> nCups;
            while(nCups--){
                int cup;
                std::cin >> cup;
                (trays[col]).push(cup);
            }
        }
        std::cout << solve(trays, m) << std::endl;
    }
    return 0;
}

Measured memory_bytes: 1232
#include <cstdio>
#include <cstdint>

int main() {
  int N;
  scanf("%d", &N);

  intmax_t a = 2;
  intmax_t b = 1;
  for (int i = 0; i < N; ++i) {
    intmax_t c = a+b;
    a = b;
    b = c;
  }
  printf("%jd\n", a);
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;
typedef stringstream SS;

struct Edge{int to,from,cost;};

#ifdef DEBUG
#define debug cout
#else
SS ss;
#define debug ss
#endif

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n)-1;i>=(m);--i)
#define repc(i,n) for(int i=0;i<=(n);++i)
#define repcn(i,m,n) for(int i=(m);i<=(n);++i)
#define repcd(i,n) for(int i=(n);i>=0;--i)
#define repcnd(i,m,n) for(int i=(n);i>=(m);--i)
#define repc0(i,n) for(i=0;i<=(n);++i)
#define repcn0(i,m,n) for(i=(m);i<=(n);++i)
#define repcd0(i,n) for(i=(n);i>=0;--i)
#define repcnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define X second
#define Y first
#define p_queue(n) priority_queue<n,vector<n>,greater<n> >
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

vint a,b,c;
int m;

int f(vint a,vint b,vint c,int now){
	repc(i,m){
		if(now==0){
			if(sz(a)==0){
				if(sz(b)==0){
					return i;
				}else{
					a.PB(b[sz(b)-1]);
					b.pop_back();
				}
			}else{
				if(sz(b)==0||a[sz(a)-1]>b[sz(b)-1]){
					b.PB(a[sz(a)-1]);
					a.pop_back();
				}else{
					a.PB(b[sz(b)-1]);
					b.pop_back();
				}
			}
		}else{
			if(sz(b)==0){
				if(sz(c)==0){
					return i;
				}else{
					b.PB(c[sz(c)-1]);
					c.pop_back();
				}
			}else{
				if(sz(c)==0||b[sz(b)-1]>c[sz(c)-1]){
					c.PB(b[sz(b)-1]);
					b.pop_back();
				}else{
					b.PB(c[sz(c)-1]);
					c.pop_back();
				}
			}
		}
		now^=1;
	}
	return INF;
}

int main() {
	int n,k;
	IL{
		cin>>n>>m;
		if(n==0&&m==0)break;
		a.clear();
		cin>>k;
		rep(i,k)a.PB(in());
		b.clear();
		cin>>k;
		rep(i,k)b.PB(in());
		c.clear();
		cin>>k;
		rep(i,k)c.PB(in());
		int res=min(f(a,b,c,0),f(a,b,c,1));
		if(res<=m)cout<<res<<endl;
		else cout<<-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 952
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int a[n];
  	for(int i = 0 ; i < n ; i++ )
    {
      cin >> a[i];
    }
    sort(a,a+n);
  	float sum = a[0];
  	for(int i = 1 ; i < n ; i++)
    {
      sum=(sum+a[i])/2;
    }
  	cout<<sum;
}
/*
First of all precompute hashes of all substrings and store it in some kind of set where, hash[x][len] stores all the starting indices of all substrings having hash = x and length = len.

Binary search on the length len and for all i from 1 to n - len + 1, find the hash value x.

Check in the corresponding set hash[x][len] if there is any index greater than i + len which can be done by lower_bound in C++ and higherKey() function of TreeSet in Java.
And you are done.

Complexity : O(n^2) because of n^2 hashes precomputation.
*/

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority queue
#include<deque>//double_ended queue
using namespace std;
int main()
{ 
    int a,b;
    cin>>a>>b;
    if(a<10){
        if(b<10){
            cout<<a*b<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
<?php
// B
fscanf(STDIN, '%d', $n);
$ans = 'Yes';
for ($i  = 0; $i < $n; $i++) {
    fscanf(STDIN, '%s', $w);
    if (isset($x[$w])) {
        $ans = 'No';
    } else {
        $x[$w] = $w;
    }
    if ($i !== 0) {
        if (substr($w, 0, 1) !== $pl) {
            $ans = 'No';
        }
    }
    $pl = substr($w, -1, 1);
}
echo $ans;

Measured memory_bytes: 4728
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    ll x;
    cin >> x;
    ll p = x/11*2;
    if(x%11 > 6) {
        p+=2;
    }else if(x%11 >= 1){
        p+=1;
    }
    cout << p << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			String s = "";
			String t = "";
			String[][] map90 = new String[8][8];
			String[][] map180 = new String[8][8];
			String[][] map270 = new String[8][8];
			
			for(int i=0;i<8;i++){
				s = sc.next();
				for(int j=0;j<8;j++){
					t = s.substring(j,j+1);
					map90[j][7-i] = t;
					map180[7-i][7-j] = t;
					map270[7-j][i] = t;
				}
			}
			System.out.println("90");
			for(int i=0;i<8;i++){
				for(int j=0;j<8;j++){
					System.out.print(map90[i][j]);
				}
				System.out.println();
			}
			System.out.println("180");
			for(int i=0;i<8;i++){
				for(int j=0;j<8;j++){
					System.out.print(map180[i][j]);
				}
				System.out.println();
			}
			
			System.out.println("270");
			for(int i=0;i<8;i++){
				for(int j=0;j<8;j++){
					System.out.print(map270[i][j]);
				}
				System.out.println();
			}
	
		}
	}	
}

Measured memory_bytes: 17136
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  int n;
  cin>>n;
  ll l[n + 1];
  l[0] = 2;
  l[1] = 1;
  FOR(i, 2, n + 1) {
    l[i] = l[i-1] + l[i - 2];
  }
  cout << l[n] << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int sum = 0;
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            sum += a[i];
        }
        float v = (float)sum / (4 * m);
        int count = 0;
        for (int i = 0; i < n; i++) {
            if(a[i] >= v){
                count++;
            }
        }
        if(count < m){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 23764
from collections import defaultdict, Counter

N = int(input())
D = list(map(int, input().split()))
c = Counter(D)
M = max(c.keys())

if D[0] != 0 or c[0] != 1:
    print(0)
    exit()

mod = 998244353
depth = 1
ans = 1
while depth <= M:
    ans *= pow(c[depth - 1], c[depth], mod)
    ans %= mod
    depth += 1
print(ans)

Measured memory_bytes: 62004
#include <iostream>

using namespace std;

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

	int min = l;
	int max = l + n-1;
	int ans;

	if(max < 0){
		ans = (min+max-1) * (n-1) / 2;
	}else{
		if(min <= 0){
			ans = (min+max) * n / 2;
		}else{
			ans = (min+1+max) * (n-1) / 2;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
int pa[maxn];
int f(int x) {
    return x == pa[x] ? x : (pa[x] = f(pa[x]));
}
void un(int x, int y) {
    int px = f(x);
    int py = f(y);
    if (px != py) {
        pa[px] = py;
    }
}
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> nums(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> nums[i];
    }
    for (int i = 0; i < maxn; i++) {
        pa[i] = i;
    }
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        un(x, y);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (f(nums[i]) == f(i)) {
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main{
  public static void main(String args[]){
    
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    int sum = 0;
    
    sum = (c/a)*b;
    
    System.out.println(sum);
  }
}

Measured memory_bytes: 21844
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {//階乗、その逆元も存在する。
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n,int k){
  return fact[n]*ifact[n-k];
  }
}comb(1000005);//100005まで計算（どこまで必要かで変更）

int main(){
int n;
ll k;
cin>>n>>k;
if(n<=k){
    cout<<comb(2*n-1,n)<<endl;
}
else{
    mint ans=0;
    rep(i,k+1){
        ans+=comb(n,i)*(comb(n-1,i));
    }
    cout<<ans<<endl;
}
}

Measured memory_bytes: 18596
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#define FOR(x,y) for(int i=x; i<y; ++i)
#define FORR(x,y) for(int i=y-1; i>=x; i--)

typedef long long ll;

using namespace std;

int main() {
     string S;
     cin >> S;
    
     int ans = 0;
    
     FOR(0,4){
       S.at(i) == '+' ? ans++ : ans--;
     }
    
     cout << ans << endl;
     return 0;
}


Measured memory_bytes: 3544
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 1 << 21;
using pii = std::pair<int, int>;
#define SORT(v) std::sort(v.begin(), v.end())
int F[100][15];
int main(void) {
	int N, g=0,p=0,win=0,drow=0,lose=0;
	std::string s;
	std::cin >> s;
	for (size_t i = 0; i < s.size(); i++) {
		if (p == g && s[i] == 'g') {
			drow++;
			g++;
		}
		else if (p < g && s[i] == 'g') {
			win++;
			p++;
		}
		else if (p == g && s[i] == 'p') {
			lose++;
			g++;
		}
		else if (p < g && s[i] == 'p') {
			drow++;
			p++;
		}
	}
	std::cout << win - lose << std::endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n,r;
int main()
{
	cin >>n;
	for (ll i=1;i*i<=n;i++) if (n%i==0) r=i;
	cout <<r+(n/r)-2;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int binarySearch(int,int [],int);

int A[1000001],n;

int main(){
  int i,q,key,sum = 0;

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

  return 0;
}

int binarySearch(int n,int A[],int key){
  int left = 0;
  int right = n;
  int mid;

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



Measured memory_bytes: 2244
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 998244353;
const int IMAX = 1000000;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
class unko {
public:
	int fac[IMAX + 1], ifac[IMAX + 1], inv[IMAX + 1];
	unko() : fac(), ifac(), inv() {
		fac[0] = 1;
		rep1(i, IMAX) fac[i] = ll(fac[i - 1]) * i % mod;
		ifac[IMAX] = modpow(fac[IMAX], mod - 2);
		for (int i = IMAX; i > 0; i--) ifac[i - 1] = ll(ifac[i]) * i % mod;
		inv[0] = 1;
		rep1(i, IMAX) inv[i] = ll(ifac[i]) * fac[i - 1] % mod;
	}
	int comb(int A, int B) {
		return ll(fac[A]) * ifac[B] % mod * ifac[A - B] % mod;
	}
} f;

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


	int N;
	cin >> N;

	int A[1000001] = {};
	rep(i, N) {
		int a;
		cin >> a;
		A[a]++;
	}
	ll B[1000001] = {};
	ll kotae = 0;
	for (int i = 1000000; i >= 1; i--) {

		ll tmp = (ll(A[i] - 1) * A[i] >> 1) * i % mod * i % mod * f.inv[i];
		ll a = A[i] * i;
		for (int j = i + i; j <= 1000000; j += i) {
			tmp += a * A[j] % mod * j % mod * f.inv[i];
			tmp += (ll(A[j] - 1) * A[j] >> 1) * j % mod * j % mod * f.inv[i];
			tmp -= B[j] * j / i;

			tmp %= mod;
			a += A[j] * j;
		}
		tmp %= mod;
		B[i] = tmp;
		kotae += tmp;
		kotae %= mod;

	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 23680
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    boolean t = false;
    for(int i=1;i<10;i++){
      for(int j=1;j<10;j++){
        if(i*j == n){
          t = true;
          break;
        }
      }
    }
    if(t == true){
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

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

int main() {
  // ここにプログラムを追記
  string s;
  cin >> s;
  int count = 0;
  if(s[0] == '1') count++;
  if(s[1] == '1') count++;
  if(s[2] == '1') count++;
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        uf.unite(a,b);
    }
    set<int> s;
    rep(i,n) {
        s.insert(uf.find(i));
    }
    int ans = int(s.size()-1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7480
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
#define int ll
using pii = pair <int, int>;

string s, t;
int32_t main()
{
	usecppio
	int n;
	cin >> n;
	cin >> s >> t;
	for (int i = 0; i<n; i++)
	{
		cout << s[i] << t[i];
	}
}

Measured memory_bytes: 256
/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */

#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <list>
#include <cstring>
#include <stdio.h>
using namespace std;


int main(){

	int x, y;

	cin >> x >> y;

	for(int i=0; i<=x; ++i){
		if (i*2+(x-i)*4 == y){
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;

}


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

using namespace std;

using ll = int_fast64_t;
constexpr ll llmax = INT_FAST64_MAX; // std::numeric_limits<int_fast64_t>::max()
constexpr ll llmin = INT_FAST64_MIN; // std::numeric_limits<int_fast64_t>::min()
using ull = uint_fast64_t;
constexpr ull ullmax = UINT_FAST64_MAX; // std::numeric_limits<uint_fast64_t>::max()

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define RFOR(i, b, e) for (int i = ((e) - 1); (b) <= i; --i)
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define RREP(i, N) for (int i = ((N) - 1); 0 <= i; --i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    scanLLInt(K);
    scanVecInt(A, N);
    for(auto& a : A) --a;
    unordered_map<int, int> reached;
    reached.emplace(0, 0);
    int now = 0;
    int old = 0;
    vector<int> order; order.reserve(N);
    REP(i, N + 1){
        old = now;
        order.emplace_back(old);
        reached.emplace(old, i);
        now = A[old];
        if (reached.count(now)){
            break;
        }
    }
    /*for(auto& e : order) cout << e << " "; cout << endl;
    for(auto& e : reached) cout << "(" << e.first << "," << e.second << ") "; cout << endl;
    cout << "now:" << now << endl;
    cout << "old:" << old << endl;*/
    if (K <= reached[old]){
        cout << 1 + order[K] << endl;
        return 0;
    }
    cout << 1 + order[(K - reached[now]) % (reached[old] - reached[now] + 1) + reached[now]] << endl;
}


Measured memory_bytes: 12904
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long int 
const int64_t N=1e18+1;
int64_t ans=1;
int main() {
   long double a,b;
   cin>>a>>b;
   b*=1000;
   long long int ans=(a*b)/1000;
   cout<<ans;
   return 0;
   
   
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

ll N, K;
int main() {
    cin >> N >> K;
    ll ans = 0;
    if (K == 0) ans = N*N;
    else {
        for (int b=K+1; b<=N; ++b) {
            ans += (N / b) * (b - K);
            ans += max(0LL, (N%b)-K+1);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

long long SOD(long long n){
    long long sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

signed main(){
    int n;
    cin >> n;
    int cnt[10][10] = {};
    for(int i = 1; i <= n; i++){
        int t = 1;
        while(i >= t){
            t *= 10;
        }
        t /= 10;
        cnt[i / t][i % 10]++;
    }
    ll ans = 0;
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            ans += cnt[i][j] * cnt[j][i];
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int W;
    int H;
    int x;
    int y;
    int r;
    
    cin >> W >> H >> x >> y >> r ;
    
    if (((((x-r)>=0)&&((y-r)>=0)))&&(((x+r)<=W)&&((y+r)<=H))){
        cout <<"Yes"<<endl;
    }
    else {
        cout <<"No" <<endl;
    }
    return 0;
}


Measured memory_bytes: 3092
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int input,s1,s2,s3,output = 0;
    cin >> input;
    s1 = input%10;
    input /= 10;
    s2 = input%10;
    input /= 10;
    s3 = input%10;
    input /= 10;
    if (s1 == 1) output++;
    if (s2 == 1) output++;
    if (s3 == 1) output++;
    cout << output << endl;
}

// vim: set fileencoding=utf-8


Measured memory_bytes: 3624
#include <iostream>
#define MAX 100000
using namespace std;

int n, k;
long long T[MAX];

int check(long long P) {
  int i=0;
  for (int j=0; j<k; j++) {
    long long s = 0;
    while (s+T[i] <= P) {
      s += T[i];
      i++;
      if (i==n) {
        return n;
      }
    }
  }
  return i;
}
int solve() {
    long long left=0;
    long long right=100000*10000;
    long long mid;
    while (right-left>1) {
        mid = (left+right)/2;
        int v = check(mid);
        if (v>=n) {
            right=mid;
        }
        else left = mid;
    }
    return right;
}
int main() {
    cin>>n>>k;
    for (int i=0; i<n; i++) {
        cin>>T[i];
    }
    long long ans = solve();
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3880
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int32_t main(){
	ll n; cin>>n;
	string ans="";
	for(;n>0;n/=26){ n--;
		ans+=n%26+'a';
	}
	reverse(ans.begin(), ans.end());
	cout<<ans<<endl;
	return 0;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    int x, t;
    cin >> x >> t;

    cout << (x > t ? x - t : 0) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
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 (b<a) { a=b; return 1; } return 0; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    LL A,B,K; cin >>A>>B>>K;
    LL rA = max(0LL,A-K);
    LL rB = max(0LL,B-max(0LL,K-A));
    cout << rA << " " << rB << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

// 常にX1>Y1とする。無限回出会う場合は-1を返す
const LLONG Compute(
    const LLONG X1, const LLONG X2, const LLONG Y1, const LLONG Y2)
{
    // X1+X2>Y1+Y2のとき，常に前者が先に行く→０回
    if (X1 + X2 > Y1 + Y2)
    {
        return 0;
    }
    // X1+X2=Y1+Y2のとき，T1+T2ごとに出会う→無限回
    else if (X1 + X2 == Y1 + Y2)
    {
        return -1;
    }
    // X1+X2<Y1+Y2のとき，T1+T2ごとに後者がDだけ先に行く
    const LLONG D = Y1 + Y2 - (X1 + X2);
    const LLONG n = (X1 - Y1) / D;
    // もしX1-Y1=n*Dならば，n(T1+T2)～(n+1)(T1+T2)の間に１度交差して終わり
    if ((X1 - Y1) % D == 0)
    {
        return 2 * n;       // (n-1)回だけ２回交差し，最初と最後に１回ずつ交差→2n回
    }
    // もしn*D<(X1-Y1)<(n+1)*Dならば，n(T1+T2)までで交差は終了
    else
    {
        return 2 * (n + 1) - 1;   // スタートは交差しないので１を引く
    }
}

int main()
{
    LLONG T1, T2, A1, A2, B1, B2;
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
    LLONG X1 = A1 * T1, X2 = A2 * T2;
    LLONG Y1 = B1 * T1, Y2 = B2 * T2;
    LLONG ans = X1 > Y1 ? Compute(X1, X2, Y1, Y2) : Compute(Y1, Y2, X1, X2);
    if (ans < 0)
    {
        cout << "infinity" << endl;
    }
    else
    {
        cout << ans << endl;
    }
}


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

int main(void){
  while(true){
    int m, nmin, nmax = 0;
    cin >> m >> nmin >> nmax;
    if(m == 0 && nmin == 0 && nmax == 0){ break; }

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

    int maxgap = 0, ans = 0;
    for(int i = nmin; i <= nmax; i++){
      int gap = p[i - 1] - p[i];
      if(maxgap <= gap){
        maxgap = gap;
        ans = i;
      }
    }
    
    cout << ans << endl;
  }




  return 0;
}

Measured memory_bytes: 2884
//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <limits>
#include <map>
#include <vector>
#include <queue> 
#define LL long long
#define ft first
#define sd second
#define mp(x,y) make_pair(x,y)
#define db double
//#define int LL
using namespace std;
const int N   = 2e5+233;
//const int mod = ;
const int INF =numeric_limits<int >::max();

#define rep(i,x,y) for (int i=x;i<=y;++i)
void read(int &x)
{
	x=0;
	char ch=getchar();
	int f=1;
	while (!isdigit(ch)) (ch=='-'?f=-1:0),ch=getchar();
	while ( isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	x*=f;
}

void write(int x)
{
	if (x<0) putchar('-'),x=-x;
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int n,p[N],nxt[N],vis[N],head[N];
int ans;
signed main()
{
	read(n);
	rep(i,1,n) read(p[i]);
	rep(i,1,n)
	{
		vis[p[i]]=i;head[i]=1;
		if (vis[p[i]-1]) nxt[i]=vis[p[i]-1],head[vis[p[i]-1]]=0;
	}
	rep(i,1,n) if (head[i])
	{
		int tmp=i,cnt=1;
		while (nxt[tmp]) tmp=nxt[tmp],++cnt;
		ans=max(ans,cnt);
	}
	return printf("%d",n-ans),0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<complex>
#include<vector>
#include<algorithm>
#include<functional>
#include<array>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;


int main() {
	ll a, b, c;
	ull k;
	cin >> a >> b >> c >> k;
	if (k % 2 == 0) {//Kが偶数
		if (abs(a - b) > pow(10, 18)) cout << "Unfair" << endl;
		else cout << a - b << endl;
	}
	else {//Kが偶数
		if (abs(b-a) > pow(10, 18)) cout << "Unfair" << endl;
		else cout << b-a << endl;
	}


	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	//B - Chocolate
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		int N = scanner.nextInt();
	    int D = scanner.nextInt();
	    int X = scanner.nextInt();
	    
	    for(int i =1; i<=N; i++){
	      int ai = scanner.nextInt();
	      for(int d = 1; d<=D; d+=ai){
	         X++;
	      }
	    }
	    System.out.println(X);

	}

}


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

using namespace std;

double p(double b,int e)
{
    double res=1.0;
    for(int i=0;i<e;i++) res*=b;
    return res;
}

int main()
{
    int n,k;
    cin >> n >> k;
    double res=0;
    for(int i=1;i<=n;i++)
    {
        int cnt=0,temp=i;
        while(temp<k)
        {
            temp*=2;
            cnt++;
        }
        res+=(1/(double)n)*(p(0.5,cnt));
    }
    cout << fixed << setprecision(14) << res << endl;
    return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if 500 * i + 100 * j + 50 * k == x:
                count += 1

print(count)


Measured memory_bytes: 3060
def resolve():
    '''
    code here

    '''
    import math

    N, M = [int(item) for item in input().split()]

    deff = N - M

    if deff == -1:
        N, M = M, N

    if deff == 0:
        res = (math.factorial(N)**2 * 2) % (10**9+7)

    elif abs(deff) == 1:
        res = (math.factorial(N) **2 // N ) % (10**9+7)

    else:
        res = 0
    
    print(res)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 4740
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main(){

    int N;
    cin >> N;

    int ab[2 * N][2 * N];

    for (int i = 0; i < N; i++){
        int a, b;
        cin >> a >> b;
        ab[a][b] = 1;
    }

    vector < pair<int, int> > cd(N);
    for (int i = 0; i < N; i++){
        cin >> cd[i].first >> cd[i].second;
    }

    sort(cd.begin(), cd.end());

    int ans = 0;
    for (int i = 0; i < N; i++){
        int c = cd[i].first;
        int d = cd[i].second;

        bool f = true;

        for (int j = d - 1; j >= 0; j--){
            for (int k = c - 1; k >= 0; k--){
                if (ab[k][j] == 1){
                    ab[k][j] = 0;
                    f = false;
                    ans++;
                }
                if (f == false){
                    break;
                }
            }
            if (f == false){
                break;
            }
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <cmath>
 
using namespace std;
 
const int len = 200010;
int a[len],n,k;
 
int main() {
	cin >> n;
	long long sum = 0;
	for (int i=1;i<=n;i++) {
		cin >> a[i];
		sum += a[i];
	}
	long long mn = 1e18;
	long long s = 0;
    if  (n == 2) {
    	cout << abs(a[1]-a[2]) << endl;
	}
	else {
		for (int i=1;i<n;i++) {
			s += a[i];
			sum -= a[i];
			mn = min(mn,abs(s-sum));
		}
		cout << mn << endl;
    }
	return 0;
} 

Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AACOrWA solver = new AACOrWA();
        solver.solve(1, in, out);
        out.close();
    }

    static class AACOrWA {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            w.println(s.nextInt() == s.nextInt() ? "Yes" : "No");
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    LL N,x; cin >> N >> x;
    vector<LL> a(N);
    vector<LL> ni(N-1);
    vector<bool> ok(N-1);
    REP(i,N)
    {
        cin >> a[i];
    }
    LL ans = 0;
    REP(i,N-1)
    {
        int sum = a[i] + a[i+1];
        if(sum > x)
        {
            if(a[i] > x)
            {
                ans += sum - x;
                a[i+1] = 0;
            }
            else
            {
                ans += sum - x;
                a[i+1] = x - a[i];
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long int
#define MOD 1000000007
#define oo 1000000000000000000
#define forr(i,n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define pb push_back
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
using namespace __gnu_pbds; 
using namespace std;

ll valueOfIndex(ordered_set&s , ll i){ return *(s.find_by_order(i)); }
ll indexOfValue(ordered_set&s , ll x){ return s.order_of_key(x); }
ll add(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a+b + p)%p;}
ll mul(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a*b + p)%p;} // __int128
ll power(ll x,ll n,ll p=MOD){ if(x==0) return 0; if(n==0 || x==1) return 1LL;
    ll r = (power(x,n/2,p))%p; if(n&1) return mul(mul(r,r,p) , x,p); else return mul(r,r,p);
}
ll inv(ll x){return power(x,MOD-2);}


void __sol(){
    
    string s; cin >> s;
    if(s[1]=='R') cout << "ABC";
    else cout << "ARC";
    
}


int main(){
    fastio
    ll tc=1; //cin >> tc;
    while(tc--) __sol();
    return 0;
}

Measured memory_bytes: 3616
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
deque<int> deq;
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

int main(){
    int a,b,c;
    cin >> a>>b>>c;
    if(a+b+c>21){
        cout<<"bust"<<endl;
    }else{
        cout<<"win"<<endl;
    }
    return 0;
}

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

using namespace std;
const int N = 1e5 + 10;
int cnt[N];
int main()
{
    int n; cin >> n;
    for (int i = 0; i < n; i ++) {
        int x; cin >> x;
        if (x <= n) cnt[x]++;
    }
    int Cnt = 0;
    for (int i = 1; i <= n; i ++) {
        if (cnt[i] >= i) Cnt += i;
    }
    cout << n - Cnt << "\n";
}


Measured memory_bytes: 256
n = input()
op = [bin(i)[2:].zfill(3) for i in range(8)]
for i in range(8):
    cnt = int(n[0])
    ans = [n[0]]
    for j in range(3):
        if op[i][j] == "0":
            cnt += int(n[j+1])
            ans.append("+")
        else:
            cnt -= int(n[j+1])
            ans.append("-")
        ans.append(n[j+1])
    if cnt == 7:
        ans += ["=", "7"]
        print("".join(ans))
        exit()



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

#define LL long long

const int noun = 3;
const LL p1[3] = {127, 769, 1009};
const LL p2[3] = {11618141, 11618107, 11618143};

string S;
int N;
LL P[500010][3], H[500010][3];
bool Hash[11620000][3];

bool check(int m){
	bool flag = false;
	for (int i = m + 1; i + m - 1 <= N; i++){
		LL x;
		for (int j = 0; j < noun; j++){
			x = (P[i - 1][j] - P[i - m - 1][j] * H[m][j] % p2[j] + p2[j]) % p2[j];
			Hash[x][j] = true;
		}
		bool ff = true;
		for (int j = 0; j < noun; j++){
			x = (P[i + m - 1][j] - P[i - 1][j] * H[m][j] % p2[j] + p2[j]) % p2[j];
			if (!Hash[x][j])
				ff = false;
		}
		if (ff){
			flag = true;
			break;
		}
	}
	for (int i = 1; i + m - 1 <= N; i++){
		LL x;
		for (int j = 0; j < noun; j++){
			x = (P[i + m - 1][j] - P[i - 1][j] * H[m][j] % p2[j] + p2[j]) % p2[j];
			Hash[x][j] = 0;
		}
	}
	return flag;
}

int main(){
	cin >> N >> S;
	int l = 0, r = N;
	P[0][0] = P[0][1] = P[0][2] = 0;
	H[0][0] = H[0][1] = H[0][2] = 1;
	for (int i = 1; i <= N; i++)
		for (int j = 0; j < noun; j++){
			P[i][j] = (P[i - 1][j] * p1[j] % p2[j] + S[i - 1] - 'a') % p2[j];
			H[i][j] = H[i - 1][j] * p1[j] % p2[j];
		}
	while (l < r){
		int mid = (l + r + 1) >> 1;
		if (check(mid)) l = mid;
		else r = mid - 1;
	}
	cout << l << endl;
}

Measured memory_bytes: 37120
a,b,c,d=gets.split("")

a=a.to_i
b=b.to_i
c=c.to_i
d=d.to_i

array=[]
array2=

array<<a+b+c+d
array<<a+b+c-d
array<<a+b-c+d
array<<a+b-c-d
array<<a-b+c+d
array<<a-b+c-d
array<<a-b-c+d
array<<a-b-c-d


if array[0]==7
    puts "#{a}+#{b}+#{c}+#{d}=7"
    
elsif array[1]==7  
    
     puts "#{a}+#{b}+#{c}-#{d}=7"
    
 elsif array[2]==7  
    
     puts "#{a}+#{b}-#{c}+#{d}=7"  
    
  elsif array[3]==7  
    
     puts "#{a}+#{b}-#{c}-#{d}=7"  
    
  elsif array[4]==7  
    
     puts "#{a}-#{b}+#{c}+#{d}=7"
     elsif array[5]==7  
    
     puts "#{a}-#{b}+#{c}-#{d}=7"
     elsif array[6]==7  
    
     puts "#{a}-#{b}-#{c}+#{d}=7"
     elsif array[7]==7  
    
     puts "#{a}-#{b}-#{c}-#{d}=7"
    
    
end
    


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    bool f[10000];fill_n(f,10000,true);
    f[0]=f[1]=false;
    vector<int>P;
    for(int i=2;i<10000;i++){
        if(!f[i])continue;
        for(int j=i+i;j<10000;j+=i)f[j]=false;
        P.push_back(i);
    }

    int n;
    while(cin>>n,n){
        int cnt=0;
        for(int i=0;i<P.size();i++){
            int sum=0;
            int idx=i;
            while(idx<P.size()&&sum<n)sum+=P[idx++];
            if(n==sum)cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 1240