akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int a, b; cin>>a>>b;
    int sum = 1;
    for(int i=0; ; i++){
        if(b <= sum){
            //cout << sum << endl;
            cout << i << endl;
            return 0;
        }
        sum += a - 1;
    }
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] x = new int[N];
		int[] y = new int[N];
		int maxc = 0;
		int c = 0;
		for (int i = 0; i < N; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			if (x[i] == y[i]) {
				c++;
			} else {
				if (c > maxc)
					maxc = c;
				c = 0;
			}
		}
		if (maxc >= 3 || c >= 3)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 36000
# -*- coding: utf-8 -*-
x, y = map(int, input().split())

a = (4*x-y)/2
b = (y-2*x)/2

if a<0 or b<0:
    print('No')
else:
    if (a-int(a)) != 0 or (b-int(b)) != 0:
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 9204
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n,m; cin >> n >> m;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];
    bitset<n_max> ok = 0;
    ok = ~ok;
    rep(i,m){
        ll a,b; cin >> a >> b;
        a--;b--;
        if(h[a] > h[b])ok[b] = 0;
        if(h[a] < h[b])ok[a] = 0;
        if(h[a] == h[b]){
            ok[a] = ok[b] = 0;
        }
    }

    ll ans = 0;
    rep(i,n)if(ok[i])ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3992
#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 sp(x) fixed << setprecision(x)
#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;
	}
 
}

void out(vector<int> &v){
	for(int x : v) cout << x << " ";
}
void solve()
{
	int h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	int a[n];
	int x = 0, y = 0;
	int ans[h][w];
	bool rv = 0;
	rep(i, n) {
		cin >> a[i];
		while(a[i]--){
			ans[x][y] = i + 1;
			y += (!rv ? 1 : -1);
			if(y == w) y--, rv ^= 1, x++;
			if(y == -1) y++, rv ^= 1, x++;
		}
	}
	rep(i, h) rep(j, w) cout << ans[i][j] << " \n"[j == w - 1];

}

 
int main()
{
	// freopen("crosses.in", "r", stdin);
	// freopen("crosses.out", "w", stdout);
    Red;
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl "\n"

int32_t main(){
	boost;
	int n;
	cin >> n;
	vector<int>v[n+1];
	int s[n+1][n+1];
	memset(s,0,sizeof s);
	bool okk = true;
	for(int i = 1; i <= n; i++){
		for(int j = 1, x; j < n; j++) {
			cin >> x;
			v[i].push_back(x);
		}
		okk &= is_sorted(v[i].begin(),v[i].end());
		reverse(v[i].begin(),v[i].end());
		s[i][v[i].back()] = 1;
	}	
	if(okk){
		cout << 2*(n - 1) - 1  << endl;
		return 0;
	}
	int day = 0;
	int cnt = 0;
	while(true) {
		vector<pi>ve;
		for(int i = 1; i <= n; i++) {
			if(v[i].empty())
				continue;
			if(s[v[i].back()][i]) 
				ve.push_back({i,v[i].back()});
		}
		if(ve.empty())
			break;
		cnt += ve.size()/2;
		for(auto p : ve) {
			s[p.ff][p.ss] = 0;
			v[p.ff].pop_back();
			if(!v[p.ff].empty())
				s[p.ff][v[p.ff].back()] = 1;
		}
		day++;
	}
	if(2*cnt == n*(n - 1))
		cout << day << endl;
	else
		cout << -1 << endl;
}



Measured memory_bytes: 19260
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int INF=1<<29;

int main(){
	ios::sync_with_stdio(false);
	int N;
	string s;
	vector<string> arr={"SS","SW","WS","WW"};
	cin>>N>>s;
	for(int j=0;j<4;j++){
		for(int i=2;i<N;i++){
			if(arr[j][i-1]=='S'){
				if(s[i-1]=='o') arr[j]+=arr[j][i-2];
				else{
					if(arr[j][i-2]=='S') arr[j]+='W';
					else arr[j]+='S';
				}
			}else{
				if(s[i-1]=='x') arr[j]+=arr[j][i-2];
				else{
					if(arr[j][i-2]=='S') arr[j]+='W';
					else arr[j]+='S';
				}
			}
		}
		//cout<<arr[j]<<" ";
		bool check=true;
		for(int i=0;i<N;i++){
			if(i==0){
				if(arr[j][i]=='S'){
					if(s[i]=='o'){
						if(arr[j][N-1]!=arr[j][i+1]) check=false;
					}else{
						if(arr[j][N-1]==arr[j][i+1]) check=false;
					}
				}else{
					if(s[i]=='x'){
						if(arr[j][N-1]!=arr[j][i+1]) check=false;
					}else{
						if(arr[j][N-1]==arr[j][i+1]) check=false;
					}
				}
				continue;
			}
			if(i==N-1){
				if(arr[j][i]=='S'){
					if(s[i]=='o'){
						if(arr[j][i-1]!=arr[j][0]) check=false;
					}else{
						if(arr[j][i-1]==arr[j][0]) check=false;
					}
				}else{
					if(s[i]=='x'){
						if(arr[j][i-1]!=arr[j][0]) check=false;
					}else{
						if(arr[j][i-1]==arr[j][0]) check=false;
					}
				}
				continue;
			}
			if(arr[j][i]=='S'){
				if(s[i]=='o'){
					if(arr[j][i-1]!=arr[j][i+1]) check=false;
				}else{
					if(arr[j][i-1]==arr[j][i+1]) check=false;
				}
			}else{
				if(s[i]=='x'){
					if(arr[j][i-1]!=arr[j][i+1]) check=false;
				}else{
					if(arr[j][i-1]==arr[j][i+1]) check=false;
				}
			}
		}
		if(check){
			cout<<arr[j]<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef vector<pair<ll, ll>> vpll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(20);
    ll x, k, d;
    cin >> x >> k >> d;
    if (x > 0) {
        ll cnt = x / d;
        if (cnt >= k) x -= k * d, k = 0;
        else {
            x -= cnt * d, k -= cnt;
            while (k > 0 && abs(x - d) < abs(x)) k--, x -= d;
        }
    } else {
        ll cnt = abs(x) / d;
        if (cnt >= k) x += k * d, k = 0;
        else {
            x += cnt * d, k -= cnt;
            while (k > 0 && abs(x + d) < abs(x)) k--, x += d;
        }
    }
    if (k % 2 == 0) cout << abs(x) << "\n";
    else {
        if (abs(x - d) < abs(x + d)) cout << abs(x - d) << "\n";
        else cout << abs(x + d) << "\n";
    }
    return 0;
}

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

int main()
{
    int a, b, res = INT_MAX;
    cin >> a >> b;

    for(int i = 1; i <= 10000; ++i)
    {
        int x = i * 0.08;
        int y = i * 0.1;

        if(x == a && y == b)
            res = min(res, i);
    }

    cout << (res == INT_MAX ? -1 : res) << "\n";
    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n,greater<int>());
  int count=0;
  for(int i=0;i<n;i++){
    if(i%2==0){
      count+=a[i];
    }else{
      count-=a[i];
    }
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define WHITE 1
#define GRAY 2
#define BRACK 3

int n,color[101],time,d[101],f[101],G[101][101];

void visit(int u)
{
  int v;
  color[u] = GRAY;
  d[u] = ++time;
  for(v = 1;v <= n;v++)
    {
      if(G[u][v] == 1 && color[v] == WHITE)
	{
	  visit(v);
	}
    }
  color[u] = BRACK;
  f[u] = ++time;
  
}

void dfs()
{
  int u;
  for(u = 1;u <= n;u++)
    {
      color[u] = WHITE;
    }
  time = 0;
  for(u = 1;u <= n;u++)
    {
      if(color[u] == WHITE)
	{
	  visit(u);
	}
    }
}



int main()
{
  int i,u,k,j,v;
  
  scanf("%d",&n);

  for(i = 1;i <= n;i++)
    {
      scanf("%d %d",&u,&k);
      for(j = 1;j <= k;j++)
	{
	  scanf("%d",&v);
	  G[u][v] = 1;
	}     
    }
  dfs();

  for(i = 1;i <= n;i++)
    {
      printf("%d %d %d\n",i,d[i],f[i]);
    }

  return 0;  
  
}


Measured memory_bytes: 2100
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class CMaximalValue {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<int> b(n-1);
      rep(i, n-1) {
        cin >> b[i];
      }
      ll ans = 0;
      rep(i, n-2) {
        ans += min(b[i], b[i+1]);
      }
      ans += b[0];
      ans += b[n-2];
      cout << ans << endl;
    }
};

signed main() {
  CMaximalValue solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 100005
#define NIL -1

typedef struct node Node;
struct node{
  int parent;
  int left;
  int right;
};
Node T[MAX];
int Dep[MAX];

void print(int u){
  int i, child;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].parent, Dep[u]);

  if(T[u].parent == NIL) printf("root, ");
  else if(T[u].left == NIL) printf("leaf, ");
  else printf("internal node, ");
  
  printf("[");
  for (i=0, child = T[u].left; child != NIL; i++, child = T[child].right){
    if(i != 0) printf(", ");
    printf("%d", child);
  }
  printf("]\n");
  
}

void calcDepth(int u, int p){
  Dep[u] = p;
  if(T[u].right != NIL) calcDepth(T[u].right, p);
  if(T[u].left != NIL) calcDepth(T[u].left, p+1);
}

int main(){
  int i, j, k, n;
  int id, sib, child;
  int root = NIL;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    T[i].parent = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
   }
  for(i=0; i<n; i++){
    scanf("%d%d",&id,&k);
    for(j=0, sib=NIL; j<k; j++){
      scanf("%d",&child);
      T[child].parent = id;
      if(j == 0) T[id].left = child;
      else T[sib].right = child;
      sib = child;
    }
  }

  for(i=0; i<n; i++){
    if(T[i].parent == -1) root = i;
    }

  calcDepth(root, 0);

  for(i=0; i<n; i++) print(i);
  return 0;
}



Measured memory_bytes: 6412
// 答えを見て実装
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define int ll
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

#define fst first
#define pb push_back

const int MOD = (int)1e9 + 7;

signed main() {
    int N;

    cin >> N;

    int ans = 0;
    int biggest_digit = 0;

    // 下から数えてnビット目の1が立っている個数
    // zeros[d]はn - ones[d]で求められる
    // zeros[d]は無いものを数える必要があるから、直接数えるのはちょっと難しい。
    // 最大の桁数を持って教えないと、スルーしてしまう

    vector<int> ones(64);
    REP(i, N) {
        int a;
        cin >> a;

        int digit = (int)log2(a) + 1;
        if (digit > biggest_digit) {
            biggest_digit = digit;
        }

        REP(d, digit) {
            int shift = (1LL << d);
            int flag = (a & shift);
            if (flag) {
                ones.at(d) += 1;
            }
        }
    }

    // bitごとに見て、0グループと1グループから1つずつ選んだものだけが生き残る
    // だから、各bitごとに、#{0の数} * #{1の数} を計算すればよい

    // 桁数
    FORE(d, 0, biggest_digit-1) {
        int c = ((N - ones.at(d)) * ones.at(d)) % MOD;
        REP(i, d) {
            c = (c * 2) % MOD;
        }
        ans = (ans + c) % MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
/* Ajay Jadhav */
#include <bits/stdc++.h>
 
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve()
{
    int n,k;
    cin>>n>>k;
    vi a(n);
    rep(i,0,n) cin>>a[i];
    vi dp(n,1e9);
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    rep(i,2,n)
    {
        int jumps=0;
        for(int j=i-1;j>=0 and jumps<k ;j--,jumps++)
        {
            dp[i]=min(dp[i],dp[j]+abs(a[j]-a[i]));
        }
    }
    cout<<dp[n-1];
}
 
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		Nodes mynodes = new Nodes(n+1);

		int[] pre = new int[n];
		int[] in = new int[n];

		for(int i = 0; i < n; i++)
			pre[i] = scan.nextInt();
		for(int i = 0; i < n; i++)
			in[i] = scan.nextInt();

		for(int i = 1; i < n; i++){
			for(int j = 0; j < n; j++){
				if(in[j] == pre[i-1]){
					break;
				}else if(in[j] == pre[i]){
					mynodes.setLeft(pre[i-1], pre[i]);
					break;
				}
			}
		}

		for(int i = 1; i < n; i++){
			for(int j = 0; j < n; j++){
				if(pre[j] == in[i-1]){
					mynodes.setRight(in[i-1], mynodes.getRoot(in[i]));
					break;
				}else if(pre[j] == in[i]){
					break;
				}
			}
		}

		int root = mynodes.getRoot(pre[0]);
		mynodes.printPost(root);
		System.out.println();
	}
}

class Node{
	int parent = -1;
	int left = -1;
	int right = -1;
}

class Nodes{

	Node[] nodes;

	public Nodes(int n){
		nodes = new Node[n];
		for(int i = 0; i < n; i++){
			nodes[i] = new Node();
		}
	}

	public int getRoot(int id){
		if(nodes[id].parent == -1)
			return id;
		return getRoot(nodes[id].parent);
	}

	boolean first = true;

	public void printPost(int id){
		if(id == -1)
			return;
		printPost(nodes[id].left);
		printPost(nodes[id].right);
		if(first){
			System.out.print(id);
			first = false;
		}else{
			System.out.print(" " + id);
		}
	}

	public void setLeft(int id, int left){
		nodes[id].left = left;
		nodes[left].parent = id;
	}

	public void setRight(int id, int right){
		nodes[id].right = right;
		nodes[right].parent = id;
	}
}

Measured memory_bytes: 26484
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int n;(n=s.nextInt())>0;){String r=s.next();for(;n-->0;)r=f(r+" ");System.out.println(r);}}static String f(String s){StringBuilder r=new StringBuilder();char[]a=s.toCharArray();for(int c=1,i=1;i<a.length;++i)if(a[i]!=a[i-1]){r.append(c);r.append(a[i-1]);c=1;}else++c;return r.toString();}}

Measured memory_bytes: 12000
#include<iostream>
#include<string>
using namespace std;
int main() {
	string S;
	cin >> S;
	string last = "AC";
	if (S[0] != 'A') {
		last = "WA";
	}
	int i;
	int count = 0;
	for (int i = 2; i < S.size() - 1; ++i) {
		if (S[i] == 'C')
			count++;
	}
	if (count != 1) {
		last = "WA";
	}
	int count2 = 0;
	for (i = 0; i < S.size(); ++i) {
		if (isupper(S[i]))
			count2++;
	}
	if (count2 != 2) {
		last = "WA";
	}
	cout << last << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		if(n%2==0) {
			System.out.println(n);
		}else {
			System.out.println(2*n);
		}
		in.close();
	}

}


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

bool ip(ll n){
  for(ll i=2; i*i<=n; i++){
    //cout << i << endl;
    if(n%i==0)return false;
  }
  return n != 1;
}

int main(){
  ll x;cin >> x;
  for(ll i=0; x+i<=100003; i++){
    if(ip(x+i)){cout << x+i << endl;return 0;}
  }
}

Measured memory_bytes: 256
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

// #include <bits/extc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp> // tree
// #include <ext/pb_ds/hash_policy.hpp> // hash
// #include <ext/pb_ds/trie_policy.hpp> // trie
// #include <ext/pb_ds/priority_queue.hpp> // priority_queue
// using namespace __gnu_pbds;

#include <bits/stdc++.h>
using namespace std;

#define IOS() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define X first
#define Y second
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define Push push_back

using lli = long long;
using pii = pair<int, int>;
using pll = pair<lli, lli>;
using Double = long double;
template<typename T>
using Vector = vector<vector<T>>;
template<typename T>
using Prior = priority_queue<T>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;

const lli mod = 1E9 + 7;
const Double PI = 3.1415926535846;
const Double eps = 1e-8;

lli fastPow(lli base, lli exp, lli module = mod) {
	lli ans = 1;
	base %= module;
	while (exp) {
		if (exp & 1) ans = ans * base % module;
		base = base * base % module;
		exp >>= 1;
	}
	return ans;
}

bool millerRabin(lli n, lli a) {
	/*
	 * n < 4,759,123,141		3 : {2, 7, 61}
	 * n < 1,122,004,669,633	4 : {2, 13, 23, 1662803}
	 * n < 3,474,749,660,383	6 : {p in [2, 13]}
	 * n < 2^64					7 : 
	 * {2, 325, 9375, 28178, 450775, 9780504, 1795265022}
	 *
	 * else, random everytime gives a 75% of correction
	 */
	
	if (n < 2) return 0;
	if ((a = a%n) == 0) return 1;
	if (n & 1 ^ 1) return n == 2;
	
	lli lowb = (n - 1) & -(n - 1);
	lli tmp = (n - 1) / lowb; // lowbit of (n-1)
	lli t = __lg(lowb);
	lli x = 1;
	
	for (; tmp; tmp /= 2, a = a*a%n) {
		if (tmp & 1) x = x * a % n;
	}
	
	if (x == 1 or x == n - 1) return 1;
	
	while (--t) {
		if ((x = x*x%n) == n - 1) return 1;
	}
	
	return 0;
}

bool MR_PrimeFilter(lli n) {
	vector<lli> v[4];
	v[0] = {2, 7, 61};
	v[1] = {2, 13, 23, 1662803};
	v[2] = {2, 3, 5, 7, 11, 13};
	v[3] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
	
	if (n < 4759123141LL) {
		for (lli x : v[0]) {
			if (!millerRabin(n, x)) return false;
		}
		return true;
	}
	if (n < 1122004669633LL) {
		for (lli x : v[1]) {
			if (!millerRabin(n, x)) return false;
		}
		return true;
	}
	if (n < 3474749660383LL) {
		for (lli x : v[2]) {
			if (!millerRabin(n, x)) return false;
		}
		return true;
	}
	for (lli x : v[3]) {
		if (!millerRabin(n, x)) return false;
	}
	return true;
}

void solve() {
	lli n, tmp, ans = 1;
	cin >> n;
	
	vector<lli> app(n + 1, 0);
	app[n] = 3;
	for (int i = 0; i < n; ++i) {
		cin >> tmp;
		if (tmp == 0) ans *= app[n]--;
		else ans *= app[tmp - 1]--;
		ans %= mod;
		++app[tmp];
	}
	
	cout << ans << "\n";
}

int main() {
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdlib.h> //malloc
using namespace std;

#define M_MAX 500001

struct Node {
    int key;
    Node *right, *left, *parent;
};

void insert(int v);
void preorder(Node *u);
void inorder(Node *u);

Node *root = NULL;

int main(){
    int m, x;
    string command;

    cin >> m;

    while (m > 0) {
        cin >> command;

        if (command == "insert") {
            cin >> x;
            insert(x);
        } else if (command == "print"){
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        } else {
            cout << "Unknown command" << endl;
        }

        m--;
    }

    //dumpPreorder(root);
    return 0;
}

void insert(int v) {
    Node *n, *x, *p;
    n = (Node *)malloc(sizeof(Node));
    n->key = v;
    n->parent = n->left = n->right = NULL;

    x = root;
    p = NULL;
    while (x != NULL) {
        p = x;
        if (v < x->key)
            x = x->left;
        else
            x = x->right;
    }

    if (p == NULL) {
        root = n;
        return;
    }

    x = n;
    n->parent = p;

    if (n->key < p->key)
        p->left = n;
    else
        p->right = n;
}

void preorder(Node *u){
    if (u == NULL) return;

    cout << " " << u->key;
    preorder(u->left);
    preorder(u->right);
}

void inorder(Node *u){
    if (u == NULL) return;

    inorder(u->left);
    cout << " " << u->key;
    inorder(u->right);
}

Measured memory_bytes: 26624
from bisect import bisect_left
from collections import defaultdict
N, K, *A = map(int, open(0).read().split())
dic = defaultdict(list)
for i, a in enumerate(A):
  dic[a] += [i]
ls = []
ps = 0
m = A[0]
cycle = 0
while True:
  ls.append(ps+N*cycle+1)
  i = bisect_left(dic[m],ps+1)
  ps = dic[m][i%len(dic[m])]
  if i>=len(dic[m]):
    cycle += 1
  ps += 1
  ps %= N
  m = A[ps]
  if ps==0:
    cycle += 1
    break
k = K%cycle
j = bisect_left(ls,k*N)
if ls[j]==k*N:
  c = (ls[j]-1)%N
  print(A[c])
elif ls[j]==k*N+1:
  pass
else:
  c = (ls[j-1]-1)%N
  M = k*N-ls[j-1]
  ans = [A[c]]
  log = set(ans)
  ind = {}
  ind[A[c]] = 0
  cnt = 0
  while M:
    c += 1
    c %= N
    cnt += 1
    cnt %= N
    M -= 1
    if not A[c] in log:
      log.add(A[c])
      ind[A[c]] = cnt
      ans += [A[c]]
    else:
      log.remove(A[c])
      ans = ans[:ind[A[c]]]
      log = set(ans)
      cnt = ind[A[c]]-1
  print(*ans)

Measured memory_bytes: 128640
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

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

    std::vector<int> U;
    int sum = 0;
    for (decltype(N) i = 0; i < N; ++i) {
        int t;
        std::cin >> t;
        sum += t;
        U.push_back(sum);
    }

    std::vector<int> D;
    for (decltype(N) i = 0; i < N; ++i) {
        int t;
        std::cin >> t;
        D.push_back(t);
    }

    sum = 0;
    for (auto ri = D.rbegin(); ri != D.rend(); ++ri) {
        *ri = *ri + sum;
        sum = *ri;
    }

    int max = 0;

    for (int i = 0; i < N; ++i) {
        max = std::max(max, U[i] + D[i]);
    }

    std::cout << max << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
#define range(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) range(i,0,n)
#define INF 10000000000 //10^10
#define PI 3.141592
#define pb push_back

int main(){
    ll n;
    cin >> n;
    vll cnt(5);
    rep(i,n){
        string S;
        cin >> S;
        switch(S[0]){
            case 'M':
                ++cnt[0];
                break;
            case 'A':
                ++cnt[1];
                break;
            case 'R':
                ++cnt[2];
                break;
            case 'C':
                ++cnt[3];
                break;
            case 'H':
                ++cnt[4];
        }
    }

    ll ans=0;
    rep(i,5) range(j,i+1,5) range(k,j+1,5) ans+=cnt[i]*cnt[j]*cnt[k];
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXN=105;
int l;
int n,m;
struct edge
{
	int v,c;
	edge(){};
	edge(int vv,int cc)
	{
		v=vv,c=cc;
	}
};
vector<edge>w[MAXN];
int dfs(int now)
{
	if(now==0)
		return 1;
	int last=0;
	if((now&1)==0)
	{
		last=dfs(now/2-1);
		w[last].push_back(edge(last+1,0));
		m++;
		w[last].push_back(edge(last+1,now/2));
		m++;
		w[1].push_back(edge(last+1,now));
		m++;
	}
	else
	{
		last=dfs(now/2);
		w[last].push_back(edge(last+1,0));
		m++;
		w[last].push_back(edge(last+1,now/2+1));
		m++;
	}
	return last+1;
}
int main()
{
	scanf("%d",&l);
	l--;
	m=0;
	n=dfs(l);
	printf("%d %d\n",n,m);
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<int(w[i].size());j++)
		{
			printf("%d %d %d\n",i,w[i][j].v,w[i][j].c);
		}
	}
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n,input[10000],count=0,i,j,count1=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&input[i]);
    //if(input[i]==4)count1=1;
    for(j=2;j*j<=input[i];j++){
      if(input[i]%j==0){
	count1=1;
	break;
    }
    }  
    if(count1==0){
      count++;
      //printf("[%d]",input[i]);
    }
    count1=0;
  }
  printf("%d\n",count);
  return 0;
}



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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

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

int main(void){
    int n, m;
    cin >> n >> m;
    vector<int> s(m), c(m);
    for(int i = 0; i < m; i++){
        cin >> s.at(i) >> c.at(i);
    }
    int base;
    bool pass;
    if(n == 1){
        base = 0;
        while(base < 10){
            pass = true;
            for(int i = 0; i < m; i++){
                if(base != c.at(i)) pass = false;
            }
            if(pass == false){
                base++;
                continue;
            }
            else{
                cout << base << endl;
                return 0;
            }
            base++;
        }
    }else if(n == 2){
        base = 10;
        while(base < 100){
            pass = true;
            vector<int> bsd(2);
            bsd.at(0) = base%10;
            bsd.at(1) = base/10;
            for(int i = 0; i < m; i++){
                if(bsd.at(2-s.at(i)) != c.at(i)) pass = false;
            }
            if(pass == false){
                base++;
                continue;
            }
            else{
                cout << base << endl;
                return 0;
            }
        }
    }else{
        base = 100;
        while(base < 1000){
            pass = true;
            vector<int> bsd(3);
            bsd.at(0) = base%10;
            bsd.at(1) = (base%100)/10;
            bsd.at(2) = base/100;
            for(int i = 0; i < m; i++){
                if(bsd.at(3-s.at(i)) != c.at(i)) pass = false;
            }
            if(pass == false){
                base++;
                continue;
            }
            else{
                cout << base << endl;
                return 0;
            }
        }
    }

    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 764
#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>;

int main(){
    ll n;
    cin >> n;
    int k,k2,ans;
    ans=0;
    rep(i,1000000){
        k=0;
        while(n%(i+2)==0){
            ++k;
            n/=(i+2);
            
        }
        k2=0;
        if(k!=0){
        while(k2*(k2+1)<=2*k){
            ++k2;
            
            
        }
        --k2;
        ans+=k2;
        

    }
    }

    if(n!=1){
        ++ans;
    }

    cout << ans << endl;
    

    return 0;
}

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

int main()
{
	int n, c = 0;
	string s;
	cin >> n >> s;
	for(int i = 0; i < n - 2; i++)
		if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') c++;
	cout << c;
}



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

#define rep(i, n) for (int i = 0; i < n; i++)

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

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

    long long int cnt = 0;
    rep(i, n - 1) {
        if ((a[i] + a[i + 1]) > x) {
            int t = (a[i] + a[i + 1]) - x;

            cnt += t;

            if (a[i + 1] > t) {
                a[i + 1] -= t;
                t = 0;
            } else {
                a[i + 1] = 0;
                t -= a[i + 1];
            }
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

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

//START OF CODE ->->->->->->->

void solve()
{
    int n;
    cin>>n;
    vector<int> a(n+1,0);
    vector<int> b(n+1,0);
    vector<int> c(n,0);
    int ans = 0;
    rep(i,1,a.size()){
        cin>>a[i];
    }    
    rep(i,1,b.size()){
        cin>>b[i];
        ans += b[i];
    }
    rep(i,1,c.size()){
        cin>>c[i];
    }
    rep(i,2,a.size()){
        if ( a[i] == a[i-1] + 1 ){
            ans += c[a[i-1]];
        } 
    }
    cout<<ans<<endl;
    
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <math.h>
using namespace std;
int main()
{
  int a=0,b=0,c=0,d=0,e=0,f=0,i=0,j=0;
  int sum=0,num=0,count=0,ans=0,min=0,max=0;
  double d1=0,d2=0,d3=0,d4=0,d5=0,d6=0;
  int a1[999999],a2[999999],a3[999999];
  string s1,s2,s3;
  
  cin>>a>>b;
  
  cout<<a*b<<endl;
}
  


Measured memory_bytes: 3628
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <unordered_map>
#define Debug 0
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

vector<pair<double, double>> vans;
void solve(double *a, double *b) {
    double a2[3];
    double b2[3];
    a2[0] = a[0] * b[1];
    a2[2] = a[2] * b[1];
    b2[0] = b[0] * a[1];
    b2[2] = b[2] * a[1];
    double ans[2];
    if (a[1] && b[1]) {
        ans[0] = (a2[2]-b2[2])/(a2[0]-b2[0]); 
        ans[1] = ((a[2] - ans[0]*a[0]) / a[1]);
    } else {
        if (!a[1]) {
            ans[0] = a[2] / a[0];
            ans[1] = (b[2] - ans[0]*b[0]) / b[1];
        } else {
            ans[0] = b[2] / b[0];
            ans[1] = (a[2] - ans[0]*a[0]) / a[1];
        }
    }
    if (ans[0] == -0) ans[0] = 0;
    if (ans[1] == -0) ans[1] = 0;
    vans.push_back({ans[0], ans[1]});
}

int main(){
    double a[3], b[3];
    while (cin >> a[0]) {
        cin >> a[1];
        cin >> a[2];
        cin >> b[0];
        cin >> b[1];
        cin >> b[2];
        solve(a, b);
    }
    for (auto i: vans) {
        printf("%.3f %.3f\n", i.first, i.second);
    }
}





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


int main() {
    int A,B,X;
    cin>>A>>B>>X;
    if(X<A)cout<<"NO"<<endl;
    else if(A+B<X)cout<<"NO"<<endl;
    else cout << "YES"<<endl;
}

Measured memory_bytes: 256
import itertools

data = [0, 1]

h, w, k = map(int, input().split())
countA = 0
gyoL = [0]*h  # 1gyo, 2gyo...
retuL = [0]*w  # 1retu, 2retu...
cL = []
for i in range(h):
    inputL = list(input())
    countSum = 0
    for l in range(w):
        if inputL[l] == "#":
            countA+=1
            countSum += 1
            retuL[l] += 1
    gyoL[i] = countSum
    cL.append(inputL)

gyo = list(itertools.product(data, repeat=h))
retu = list(itertools.product(data, repeat=w))

ansC = 0
for tG in gyo:
    for tR in retu:
        count = countA
        gOneL = []
        rOneL = []
        for index1 in range(len(tG)):
            if tG[index1] == 1:
                count-=gyoL[index1]
                gOneL.append(index1)
        for index2 in range(len(tR)):
            if tR[index2] == 1:
                count-=retuL[index2]
                rOneL.append(index2)
        for g in gOneL:
            for r in rOneL:
                if cL[g][r] == "#":
                    count += 1
        if count == k:
            ansC+=1
print(ansC)

Measured memory_bytes: 9272
n,k = io.read("*n","*n", "*l")
t = {}
for i = 1, n do
    t[i] = io.read("*n")
end
table.sort( t )
a = 0
i = 1
while i <= n-k do
    a = a + t[i]
    i = i + 1
end
io.write(string.format("%d\n", a))

Measured memory_bytes: 4976
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n;
    in>>n;
    ll A{},B{};
    vector<pair<ll,int>> a(n),b(n),c;
    c.reserve(2*n);
    fr(i,n){
        in>>a[i].first>>b[i].first;
        A+=a[i].first;
        B+=b[i].first;
        a[i].second=b[i].second=i;
        c.emplace_back(a[i]);
        c.emplace_back(b[i]);
    }
    ll ans=min(A,B),ns{};
    vector<bool> v(n);
    sort(c.begin(),c.end());
    bool f{};
    fr(i,n){
        ns+=c[i].first;
        if(v[c[i].second]) f=true;
        v[c[i].second]=true;
    }
    if(f) return cout<<min(ans,ns)<<'\n',0;
    fr(i,n){
        f=c[i].second==c[n].second;
        ans=min(ans,ns-c[i].first+c[f?n+1:n].first);
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  ll ans=INF;

  for(ll i=1;i*i<=n;i++){
    if(n%i==0) {
      string s=to_string(n/i);
      ll m=s.size();
      chmin(ans,m);
    }
  }

  cout << ans << endl;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    map<int, int> st;
    int n;
    cin >> n;
    vector<int> d(n);
    REP(i, n) cin >> d[i];
    int m;
    cin >> m;
    vector<int> t(m);
    REP(i, m) cin >> t[i];

    REP(i, n) {
        st[d[i]]++;
    }

    REP(i, m) {
        if(st[t[i]] > 0) {
            st[t[i]]--;
        } else {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 11136
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long

int main(){
  int n;
  
  cin>>n;
  vector<int> p(n,0);
  int z=0;
  ll ans=0;
  for(int i=0;i<n;i++){
    cin>>p[i];
    ans+=p[i];
    if(z<p[i]){
      z=p[i];
    }
  }
  ans-=z/2;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

class UnionFind:
    __slots__ = ["data"]
    
    def __init__(self, n=0):
        self.data = [-1]*(n+1)
    
    def root(self, x):
        if self.data[x] < 0:
            return x
        self.data[x] = self.root(self.data[x])
        return self.data[x]
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.data[x] < self.data[y]:
                self.data[x] += self.data[y]
                self.data[y] = x
            else:
                self.data[y] += self.data[x]
                self.data[x] = y
    
    def same(self, x, y):
        return self.root(x) == self.root(y)
    
    def size(self, x):
        return -self.data[self.root(x)]
                


def main():
    n, m, k = map(int, input().split())
    friends = [set() for _ in range(n+1)]
    blocks = [set() for _ in range(n+1)]
    uf = UnionFind(n)
    for _ in range(m):
        a, b = map(int, input().split())
        friends[a] |= {b}
        friends[b] |= {a}
        uf.unite(a, b)
    for _ in range(k):
        c, d = map(int, input().split())
        blocks[c] |= {d}
        blocks[d] |= {c}
    for i in range(1, n+1):
        nf = len(friends[i])
        nb = sum([uf.same(i, b) for b in blocks[i]])
        ans = uf.size(i) - 1 - nf - nb
        print(ans)


if __name__ == "__main__":
    main()

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

int n,a[10005];

int main()
{
    while (scanf("%d",&n)==1)
    {
        if (n==0) break;
        int sum=0;
        for (int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        int ans=0;
        for (int i=1;i<=n;i++)
        {
            if (a[i]*n<=sum) ans++;
        }
        printf("%d\n",ans);
    }
}



Measured memory_bytes: 3228
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int sweet = N;
        if(N % 7 == 0){
            System.out.println("Yes");
        }else{
            while(sweet > 0){
            sweet =sweet - 4;
            if(sweet  % 7 == 0){
                System.out.println("Yes");
                break;
            }else{
                
            }
        }
        if(sweet < 0){
            System.out.println("No");
        }
        
        
        }
        
    }
}


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

using namespace std;

struct I{I(){ios::sync_with_stdio(false);cin.tie(0);}}init;
typedef long long LL;
typedef vector<LL> V;

int main(){
    int N;LL P,Q;
    cin>>N>>P>>Q;
    V C(N);for(auto &it:C)cin>>it;
    reverse(C.begin(),C.end());
    
    LL sum=0;
    for(int i=0;i<N;i++){
        C[i]-=i*P;
        sum+=P*(Q++);
    }
    Q--;
    LL res=sum;
    sort(C.begin(),C.end());
    reverse(C.begin(),C.end());
    for(int i=0;i<N;i++,Q-=2){
        sum+=C[i]-P*(Q);
        res=max(res,sum);
    }
    cout<<res<<endl;
    
    return 0;
}

Measured memory_bytes: 6812
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	string s;
	cin >> s;
	if (s.at(s.length() - 1) == 's')
		cout << s << "es" << endl;
	else
		cout << s << 's' << endl;
	
}

Measured memory_bytes: 3624
from itertools import product

x, y, z, k = list(map(int, input().split()))
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)

ab = [ai + bi for (ai, bi) in product(a[:k], b[:k])]
ab.sort(reverse=True)
abc = [abi + ci for (abi, ci) in product(ab[: min(k, x * y * z)], c[:k])]
abc.sort(reverse=True)

for abci in abc[: min(k, x * y * z)]:
    print(abci)


Measured memory_bytes: 206816
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N];
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextLong();
		}
		Arrays.sort(A);
		int left = -1;// γ
		int right = N;
		while (right - left > 1) {
			int middle = (right + left) / 2;
			if (check(A, middle)) {
				right = middle;
			} else {
				left = middle;
			}
		}
		System.out.println(N - 1 - left);
	}

	boolean check(long[] A, int idx) {
		long curSize = A[idx];
		for (int i = 0; i < A.length; ++i) {
			if (i == idx)
				continue;
			if (curSize * 2 >= A[i]) {
				curSize += A[i];
			} else {
				return false;
			}
		}
		return true;
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


Measured memory_bytes: 54820
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

/*==================================================*/

/*==================================================*/

long long N;

int main() {
    cin>>N;
    for(long long h = 1; h <= 3501; h++){
        for(long long n = 1; n <= 3501; n++){
            if(4*h*n - N*n - N*h <= 0) continue;
            if(N*h*n % (4*h*n - N*n - N*h) == 0){
                int w = N*h*n / (4*h*n - N*n - N*h);
                if(h<=0 || n<=0 || w<=0) continue;
                cout<<h<<" "<<n<<" "<<N*h*n / (4*h*n - N*n - N*h)<<endl;

                //test
                //cout<<4*h*n*w <<" == "<< N*n*w + N*h*w + N*h*n <<endl;

                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256