akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    string s;
    ll N, K;
    cin >> s >> K;
    N = s.size();

    string ans = "";
    ll rest = K;
    rep(i,N-1){
        char c = s[i];
        if (c == 'a'){
            ans += 'a';
        }else if('z'-c+1<=rest){
            rest -= 'z' - c + 1;
            ans += 'a';
        }else{
            ans += c;
        }
    }
    //末尾はrest回だけ操作
    if(rest>0){
        ans += 'a' + (s[N - 1] - 'a' + rest) % 26;
    }else{
        ans += s[N - 1];
    }

    cout << ans << endl;
}

Measured memory_bytes: 720
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <numeric>
#include <type_traits>
#include <limits>
#include <random>
#include <iomanip>

using namespace std;

using ll = long long;

typedef pair<int, int> P;

#define rep(i,N) for(long long i = 0;i < (long long)N; ++i)

static int mod = 1000000007;
static int large = 1000000000;

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

int K;
int S;
int ans;

int main() {
	cin >> K >> S;
	rep(a, K + 1) {
		rep(b, K + 1) {
			if (S - a - b >= 0 && S - a - b <= K) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
struct revran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { --i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr revran(const i64 e) noexcept: b(0), e(e) {}
  constexpr revran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(e - 1); }
  constexpr iter end() const noexcept { return iter(b - 1); }
};

struct ran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { ++i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr ran(const i64 e) noexcept: b(0), e(e) {}
  constexpr ran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(b); }
  constexpr iter end() const noexcept { return iter(e); }
  constexpr revran rev() const noexcept { return revran(b, e); }
};

constexpr ran rin(const i64 e) noexcept { return ran(1, e + 1); }
constexpr ran rin(const i64 b, const i64 e) noexcept { return ran(b, e + 1); }

int main() {
  string s;
  cin >> s;
  if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
    cout << "Bad" << endl;
  }
  else {
    cout << "Good" << endl;
  }
}


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

using namespace std;


int main() {
    int n;
    cin >> n;
    int ans = 0;
    vector<int> a(n);
    for (auto &&i : a) cin >> i;
    sort(a.rbegin(), a.rend());
    int sgn = 1;
    for( auto i : a ){
        ans += i * sgn;
        sgn *= -1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007

int main(){
    int n,m;
    cin>>n>>m;
    ll x[n],y[n],z[n],ans=0;
    rep(i,0,n)scanf("%lld %lld %lld",&x[i],&y[i],&z[i]);
    //全部正
    ll f1[n],t1=0;
    rep(i,0,n)f1[i]=x[i]+y[i]+z[i];
    sort(f1,f1+n,greater<ll>());
    rep(i,0,m)t1+=f1[i];
    ans=max(ans,t1);
    ll f2[n],t2=0;
    rep(i,0,n)f2[i]=x[i]*-1+y[i]+z[i];
    sort(f2,f2+n,greater<ll>());
    rep(i,0,m)t2+=f2[i];
    ans=max(ans,t2);
    ll f3[n],t3=0;
    rep(i,0,n)f3[i]=x[i]+y[i]*-1+z[i];
    sort(f3,f3+n,greater<ll>());
    rep(i,0,m)t3+=f3[i];
    ans=max(ans,t3);
    ll f4[n],t4=0;
    rep(i,0,n)f4[i]=x[i]+y[i]+z[i]*-1;
    sort(f4,f4+n,greater<ll>());
    rep(i,0,m)t4+=f4[i];
    ans=max(ans,t4);
    ll f5[n],t5=0;
    rep(i,0,n)f5[i]=x[i]*-1+y[i]*-1+z[i];
    sort(f5,f5+n,greater<ll>());
    rep(i,0,m)t5+=f5[i];
    ans=max(ans,t1);
    ll f6[n],t6=0;
    rep(i,0,n)f6[i]=x[i]*-1+y[i]+z[i]*-1;
    sort(f6,f6+n,greater<ll>());
    rep(i,0,m)t6+=f6[i];
    ans=max(ans,t6);
    ll f7[n],t7=0;
    rep(i,0,n)f7[i]=x[i]+y[i]*-1+z[i]*-1;
    sort(f7,f7+n,greater<ll>());
    rep(i,0,m)t7+=f7[i];
    ans=max(ans,t7);
    ll f8[n],t8=0;
    rep(i,0,n)f8[i]=x[i]*-1+y[i]*-1+z[i]*-1;
    sort(f8,f8+n,greater<ll>());
    rep(i,0,m)t8+=f8[i];
    ans=max(ans,t8);
    cout<<ans<<"\n";
    
}

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

int main() {
	string s; cin >> s;
	int oppoP = 0;
	for (auto&& x : s)if (x == 'p')oppoP++;
	int n = (int)s.size();
	cout << n / 2 - oppoP << endl;

	return 0;
}

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

int main() {
    int h;
    cin >> h;
    int n;
    cin >> n;
    int arr[n];
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
        sum += arr[i];
    }
    if(sum >= h) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
    return 0;
}


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

//諸機能
#pragma region MACRO 
#define putans(x)  std::cerr << "[ answer ]: " ; cout << (x) << endl
#define dputans(x) std::cerr << "[ answer ]: "; cout << setprecision(40) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,n,a) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,n,0)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define equals(a,b) (fabs((a)-(b)) < EPS)
#ifdef _DEBUG //ファイルからテストデータを読み込む
std::ifstream ifs("data.txt");
#define put ifs >>
#else //ジャッジシステムでいい感じにやる
#define put cin >>
#endif
#pragma endregion
//デバッグなどの支援
#pragma region CODING_SUPPORT
#ifdef _DEBUG
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#else
#define dbg(var0) {}
#define dbg2(var0, var1) {}
#define dbg3(var0, var1, var2) {}
#define dbgArray(a,n) {}
#endif 
#pragma endregion 
//typedef（書き換える、書き足す可能性ある）
#pragma region TYPE_DEF
typedef long long ll;
//#define int ll //オーバーフローでWAのときコメントアウトする(非推奨)
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-10)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(2*1e15)
#pragma endregion

int main() {
	int n; put n;
	int sum = 0;
	int a[100];
	rep(i, n) {
		put a[i];
		sum += a[i];
	}
	sort(a, a + n);
	if (sum % 10 != 0) {
		putans(sum);
		return 0;
	}
	else{
		rep(i, n) {
			if ((sum- a[i]) % 10 != 0 ) {
				putans(sum - a[i]);
				return 0;
			}
		}
		putans(0);
		return 0;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 10000
#define NIL -1

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

void preParse(int u, Node tree[]) {
    if (u == NIL ) return;
    cout << " " << u;
    preParse(tree[u].left, tree);
    preParse(tree[u].right, tree);
}

void inParse(int u, Node tree[]) {
    if (u == NIL ) return;
    inParse(tree[u].left, tree);
    cout << " " << u;
    inParse(tree[u].right, tree);
}

void postParse(int u, Node tree[]) {
    if (u == NIL ) return;
    postParse(tree[u].left, tree);
    postParse(tree[u].right, tree);
    cout << " " << u;
}

int main() {
    Node tree[MAX];
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        tree[i].parent = NIL;
    }

    int v, l, r, root = 0;
    for (int i = 0; i < n; i++) {
        cin >> v >> l >> r;
        tree[v].left = l;
        tree[v].right = r;
        if (l != NIL) tree[l].parent = v;
        if (r != NIL) tree[r].parent = v;
    }

    for (int i = 0; i < n; i++) {
        if (tree[i].parent == NIL) {
            root = i;
            break;
        }
    }

    cout << "Preorder" << endl;
    preParse(root, tree);
    cout << endl;
    cout << "Inorder" << endl;
    inParse(root, tree);
    cout << endl;
    cout << "Postorder" << endl;
    postParse(root, tree);
    cout << endl;
}



Measured memory_bytes: 3088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		Integer a[] = new Integer[n];
		Integer b[] = new Integer[n];
		Integer c[] = new Integer[n];

		String str[] = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(str[i]);
		}

		str = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			b[i] = Integer.parseInt(str[i]);
		}

		str = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			c[i] = Integer.parseInt(str[i]);
		}

		Arrays.sort(a);
		Arrays.sort(b);
		Arrays.sort(c);

		long ans = 0;
		for (int i = 0; i < n; i++) {
			int aup = ~Arrays.binarySearch(a, b[i], (x, y) -> x.compareTo(y) >= 0 ? 1 : -1);
			int cup = ~Arrays.binarySearch(c, b[i], (x, y) -> x.compareTo(y) > 0 ? 1 : -1);

			ans += (long) aup * (n - cup);
		}

		System.out.println(ans);
	}
}


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

int N, M, Q;
vector<int> adj[100000];
int dp[100000][11];
int c_arr[100000];

void go(int now, int d, int q_cnt){
    for(int i = 0; i < d; i++){
        dp[now][i] = max(dp[now][i], q_cnt);
    }
    if(d == 0){
        return;
    }
    for(int i = 0; i < adj[now].size(); i++){
        int next = adj[now][i];
        dp[next][d-1] = max(dp[next][d-1], q_cnt);
        go(next, d-1, q_cnt);
    }
}

void visit(int now){
    int m = -1;
    for(int d = 10; d >= 0; d--){
        if(dp[now][d] > m){
            go(now, d, dp[now][d]);
            m = dp[now][d];
        }
    }
}

int main(){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= 10; j++){
            dp[i][j] = -1;
        }
    }
    cin >> Q;
    for(int i = 0; i < Q; i++){
        int v, d, c;
        cin >> v >> d >> c;
        v--;
        c_arr[i] = c;
        dp[v][d] = max(dp[v][d], i);
    }

    for(int d = 10; d > 0; d--){
        for(int i = 0; i < N; i++){
            dp[i][d-1] = max(dp[i][d-1], dp[i][d]);
            for(int j = 0; j < adj[i].size(); j++){
                int next = adj[i][j];
                dp[next][d-1] = max(dp[next][d-1], dp[i][d]);
            }
        }
    }

    

    for(int i = 0; i < N; i++){
        if(dp[i][0] == -1){
            cout << 0 << endl;
        }else{
            cout << c_arr[dp[i][0]] << endl;
        }
    }
}
    


Measured memory_bytes: 11128
#include <bits/stdc++.h>
#define LL long long
#define FOR(i,c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define F first
#define S second
using namespace std;

const LL mod = 1e9 + 7;

template<typename T> T gcd(T a, T b) { return b == 0?a: gcd(b, a % b); }
template<typename T> T LCM(T a, T b) { return a*(b/gcd(a, b)); }
template<typename T> T expo(T base, T e, T mod) { T res = 1;
  while(e > 0) { if(e&1) res = res * base % mod; base = base * base % mod; e >>= 1; }
  return res;
}
template<typename T, typename S> T expo(T b, S e){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b), e>>1): (b*expo((b*b), e>>1));}
template<typename T, typename S> T modinv(T a, S mod) { return expo(a, mod-2, mod); }
template<class T, class S> std::ostream& operator<<(std::ostream &os, const std::pair<T, S> &t) {
	os<<"("<<t.first<<", "<<t.second<<")";
	return os;
}
template<class T> std::ostream& operator<<(std::ostream &os, const std::vector<T> &t) {
	os<<"["; FOR(it,t) { if(it != t.begin()) os<<", "; os<<*it; } os<<"]";
	return os;
}
#define gc getchar_unlocked
template <typename T> void in(T &x) {
	T c = gc(); while(((c < 48) || (c > 57)) && (c!='-')) c = gc();
	bool neg = false; if(c == '-') neg = true; x = 0; for(;c < 48 || c > 57;c=gc());
	for(;c > 47 && c < 58;c=gc())	x = (x*10) + (c - 48); if(neg)	x = -x;
}

const int MAXN = 2e3 + 100;
string grid[MAXN];
char buf[MAXN];
int n, m, q;

int to_left[MAXN][MAXN], to_up[MAXN][MAXN];
int cf[MAXN][MAXN];

int edges_cut(int i1, int j1, int i2, int j2) {
	int res = to_up[i1][j2] - to_up[i1][j1-1];
	res += to_left[i2][j1] - to_left[i1-1][j1];
	return res;
}

int calc(int i1, int j1, int i2, int j2) {
	return cf[i2][j2] + cf[i1-1][j1-1] - cf[i2][j1-1] - cf[i1-1][j2];
}

int main() {
	in(n), in(m), in(q);
	for(int j = 0; j <= m; j++) {
		grid[0].push_back('0');
	}
	for(int i = 1; i <= n; i++) {
		scanf("%s", buf);
		grid[i] = "0" + string(buf);
		for(int j = 1; j <= m; j++) {
			if(grid[i][j] == '1' && grid[i][j-1] == '1') {
				to_left[i][j]++;
			}
			if(grid[i][j] == '1' && grid[i-1][j] == '1') {
				to_up[i][j]++;
			}
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			to_up[i][j] += to_up[i][j-1];
			to_left[i][j] += to_left[i-1][j];
		}
	}
	for(int i = 1; i <= n; i++) {
		int sum = 0;
		for(int j = 1; j <= m; j++) {
			if(grid[i][j] == '1') {
				if(grid[i-1][j] == '1' && grid[i][j-1] == '1') {
					sum--;
				} else if(grid[i-1][j] == '0' && grid[i][j-1] == '0') {
					sum++;
				}
			}
			cf[i][j] = cf[i-1][j] + sum;
		}
	}
	while(q--) {
		int i1, j1, i2, j2;
		in(i1), in(j1), in(i2), in(j2);
		int res = edges_cut(i1, j1, i2, j2) + calc(i1, j1, i2, j2);
		printf("%d\n", res);
	}
  return 0;
}


Measured memory_bytes: 60928
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int mod = 1e9 + 7;

int n, k;

int main()
{
  cin >> n >> k;
  double ans = 0;
  for(int i = 1 ; i <= n ; i++){
    double p = 1.0 / n;
    int v = i;
    while(v < k){
      p *= 0.5;
      v *= 2;
    }
    ans += p;
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  int ans = 0;
  int v[100];
  for (int i = 0 ; i < n; i ++){
    scanf("%d",&v[i]);
  }
  int c[100];
  for (int i =0; i < n ; i ++){
    scanf("%d",&c[i]);
  }
  for (int i = 0 ; i < n; i ++){
    if(v[i]-c[i] > 0){
      ans = ans + v[i] - c[i];
    }
  }
  printf("%d\n",ans);
  return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        // 入力
        long n = long.Parse(Console.ReadLine());
        long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();

        long ans = 9223372036854775807;
        for (int i = 1; i < 100; i++)
        {
            long sum = 0;
            for (int k = 0; k < x.Length; k++)
            {
                sum += (long)Math.Pow((x[k] - i),2);
            }
            ans = Math.Min(ans ,sum);
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  ll x;
  cin>>x;
  ll val=100;
  int i;
  for (i=0;val<x;i++)
    val=(ll)(val*1.01);
  cout<<i<<endl;
  return 0;
}

Measured memory_bytes: 3632
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    e = collections.defaultdict(set)
    for _ in range(n-1):
        a,b = LI()
        e[a].add(b)
        e[b].add(a)

    def f(i, p):
        w = 1
        b = 1
        for c in e[i]:
            if c == p:
                continue
            ww,bb = f(c, i)
            w *= (ww+bb)
            w %= mod
            b *= ww
            b %= mod
        return (w,b)

    r = f(1,-1)

    return sum(r) % mod


print(main())


Measured memory_bytes: 143292
import sys
input=sys.stdin.readline

s = []
for i in range(5):
    s.append(int(input()))

t = 0
ss = []
for i in s:
    if i%10 != 0:
        ss.append(i)
    else:
        t += i

if len(ss) > 0:
    mx = ss[0]
    m1 = ss[0]%10
    for i in ss:
        if i%10 < m1:
            m1 = i%10
            mx = i
    ss.remove(mx)
    for i in range(0,len(ss)):
        t += ss[i] + (10-ss[i]%10)
    t += mx

print(t)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int> pii;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}

int main(){
	string s;
	cin>>s;
	int tot=0;
	for(int i=0;i<SZ(s);i++)tot+=s[i]-'0';
	cout<<(tot%9==0?"Yes":"No")<<endl;
	return 0;
}


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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=1010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};
typedef struct it{
  ll weight,cost;
}Item;
ll knapsack(ll n,ll w,Item item[]){
  ll ret=-1;
  ll dp[n+10][w+10];
  for(int i=0;i<n+10;i++)
    for(int j=0;j<w+10;j++)
      dp[i][j]=-1;
  dp[0][0]=0;
  for(int i=1;i<=n;i++){
    //cout<<item[i-1].weight<<" "<<item[i-1].cost<<endl;
    for(int j=0;j<=w;j++){
      if(dp[i-1][j]!=-1){
	if(j+item[i-1].weight<=w){
	  dp[i][j+item[i-1].weight]=max(dp[i][j+item[i-1].weight],dp[i-1][j]+item[i-1].cost);
	}
	dp[i][j]=max(dp[i][j],dp[i-1][j]);
      }
    }
  }

  for(int i=0;i<=w;i++)
    ret=max(dp[n][i],ret);
  return ret;
}
int main(){
  ll n,w;cin>>n>>w;
  Item item[n+10]={};
  for(int i=0;i<n;i++){
    cin>>item[i].weight>>item[i].cost;
  }
  cout<<knapsack(n,w,item)<<endl;
  return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;

vector< string> kaun;

void func(string a, int l, int r){  
    if (l == r)  
        kaun.push_back(a);  
    else{  
        for (int i = l; i <= r; i++){  
            swap(a[l], a[i]);   
            func(a, l+1, r);  
            swap(a[l], a[i]);  
        }  
    }  
}  

int main() {
    fastio
    int n;
    cin >> n;
    
    int te;
    string fi = "", se = "", s = "";
    rng(i, 0, n){
		cin >> te;
		fi += to_string(te);
	}
	rng(i, 0, n){
		cin >> te;
		se += to_string(te);
		s += to_string(i+1);
	}
	kaun.clear();
	func(s, 0, n-1);
	int a, b;
	n = kaun.size();
	sort(kaun.begin(), kaun.end());
	
	rng(i, 0, n){
		
		if(kaun[i] == fi){
			a = i+1;
			
		}
		else if(kaun[i] == se)
			b = i+1;
	}
	if(fi == se){
		a = 0;
		b =0;
	}
	cout<<abs(a-b)<<endl;
	return 0;
}






Measured memory_bytes: 2424
from sys import stdin

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

N = int(stdin.readline())
A = list(map(int,stdin.readline().strip().split()))

ans = A[0]
for i in range(1,N):
    ans = gcd(ans,A[i])

print(ans)


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

int main(){
  int n; cin >> n;
  string s; cin >> s;
  int ans = 0;
  for(int i=0; i<n; i++){
    if(s.at(i)=='A'){
      if(s.substr(i,3)=="ABC"){
        ans++;
        i +=2;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a0,n) for(int i=a0; i<n; ++i)

using namespace std;
int main(){
	int n, m;
	string s;
	while(cin >> n  && n){
		cin >> m >> s;
		string findee = "I";
		REP(i,n) findee += "OI";
		int ans = 0;
		for(int pos=0; (pos=s.find(findee, pos)+1); ++ans);
		cout << ans << endl;
	}
}

Measured memory_bytes: 3888
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

bool par(vector<int>& a, vector<int>& b) {
	return (a[1]-a[0]) > (b[1]-b[0]);
}

bool cmpa(vector<int>& a, vector<int>& b) {
	if (a[0] == b[0]) return (a[1]-a[0]) > (b[1]-b[0]);
	return a[0] < b[0];
}

bool cmpb(vector<int>& a, vector<int>& b) {
	if (a[1] == b[1]) return (a[1]-a[0]) > (b[1]-b[0]);
	return a[1] > b[1];
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	string no = "No\n";
	string yes = "Yes\n";
	vector<vector<int>> a(n, vector<int>(2));
	for (int i=0; i<n; i++) {
		string s;
		cin >> s;
		// bal for minimum needed open bracket also open bracket that will be taken
		int bal = 0, add = 0;
		for (int j=0; j<(int)s.length(); j++) {
			if (s[j] == '(') bal++, add++;
			else bal--, add--;
			if (add<0) add = 0;
			a[i][0] = max(a[i][0], -bal);
		}
		a[i][1] = add;
	}
	sort(a.begin(), a.end(), par);
	int mid = 0;
	while (mid<n && a[mid][1] - a[mid][0] >= 0) mid++;
	sort(a.begin(), a.begin()+mid, cmpa);
	sort(a.begin()+mid, a.end(), cmpb);
//	for (int i=0; i<n; i++) cout << a[i][0] << ' ' << a[i][1] << '\n';
	int bal = 0;
	for (int i=0; i<n; i++) {
		if (bal < a[i][0]) {
			cout << no;
			return 0;
		}
		bal -= a[i][0];
		bal += a[i][1];
		if (bal < 0) {
			cout << no;
			return 0;
		}
	}
	if (bal) cout << no;
	else cout << yes;
}

Measured memory_bytes: 57788
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x,y,sizeof(x))
struct node
{
	int x,y;
}a[102];
node b[102];
int vis[102],cx[102],cy[102],e[102][102];
int n;
int dfs(int x)
{
	for(int y= 1;y<=n;y++)
	{
		if(e[x][y] && !vis[y])
		{
			vis[y] = 1;
			if(cy[y] == -1 || dfs(cy[y]) )
			{
				cx[x] = y;
				cy[y] = x;
				return 1;
			}
		}
	}
	return 0;
}
int main()
{
	ms(e,0);ms(cx,-1);ms(cy,-1);
	
	cin>>n;
	for(int i= 1;i<=n;i++)
	{
		cin>>a[i].x>>a[i].y;
	}
	for(int i = 1;i<=n;i++)
	{
		cin>>b[i].x>>b[i].y;
	}
	int ans = 0;
	for(int i = 1;i<=n;i++)
	{
		for(int j = 1;j<=n;j++)
		{
			if(a[i].x < b[j].x && a[i].y<b[j].y)
			{
				e[i][j] = 1;
			}
		}
	}
	for(int i = 1;i<=n;i++)
	{
		ms(vis,0);
		ans += dfs(i);
	}
	cout<<ans <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
using namespace std;

int main(){
    int n;cin>>n;
    vector<int> a(n);

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

    int ans = 0;

    for(int i = 0; i < n; ++i){
        if(a[i] < a[a[i]] && i == a[a[i]])
            ans++;
    }

    cout << ans <<endl;

    return EXIT_SUCCESS;
}


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

int main()
{
    string s;
    cin>>s;
    int k=0;
    if(s[0]=='R' && s[1]=='R' && s[2]=='R')
    {
        cout<<3;
    }
    else if(s[0]=='S' && s[1]=='S' && s[2]=='S')
    {
        cout<<0;
    }
    else if(s[0]=='R' && s[1]=='R' && s[2]=='S')
    {
        cout<<2;
    }
    else if(s[0]=='S' && s[1]=='R' && s[2]=='R')
    {
        cout<<2;
    }
    else
    {
        cout<<1;
    }
    return 0;
}


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

using namespace std;

int main()
{
    int n,m;
    int a[200000]={0};
    cin>>n>>m;
    for (int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        a[x-1]++;
    }
    int dem=0;
    for (int i=0;i<200000;i++)
    if (a[i]) dem++; else a[i]=200001;
    if (dem<=m) cout<<0; else
    {
        sort(a,a+200000);
        int sum=0;
        for (int i=0;i<(dem-m);i++) sum+=a[i];
        cout<<sum;
    }
}


Measured memory_bytes: 1024
#include <stdio.h>
#define X 36
 
typedef struct{
  char mark;
  int value;
  int order;
}trump;
 
int main()
{
  int N,i,minj,flag=1,j;
  trump C1[X],C2[X],temp;
 
  scanf("%d",&N);

  if(N>=1 && N<=36){
    for(i=0;i<=N-1;i++){
      while(1){
	scanf("%c",&C1[i].mark);
	if(C1[i].mark!='D' && C1[i].mark!='C' && C1[i].mark!='S' && C1[i].mark!='H'){
	  continue;
	}
	scanf("%d",&C1[i].value);
	break;
      }
      C1[i].order=i+1;
      C2[i]=C1[i];
    }
 
    for(i=0;i<=N-1;i++){
      for(j=N-1;j>=i+1;j--){
	if(C1[j].value < C1[j-1].value){
	  temp=C1[j];
	  C1[j]=C1[j-1];
	  C1[j-1]=temp;
	}
      }
    }
 
    for(i=0;i<N-1;i++){
      printf("%c%d ",C1[i].mark,C1[i].value);
    }
 
    printf("%c%d\n",C1[N-1].mark,C1[N-1].value);
 
    for(i=0;i<=N-1;i++){
      if(C1[i].value==C1[i-1].value && C1[i].order-C1[i-1].order<0){
	flag=0;
      }
    }
 
    if(flag==1){
      printf("Stable\n");
    }
    else{
      printf("Not stable\n");
    }
 
    flag=1;
 
    for(i=0;i<=N-1;i++){
      minj=i;
 
      for(j=i;j<=N-1;j++){
	if(C2[j].value < C2[minj].value){
	  minj=j;
	}
      }
      temp=C2[i];
      C2[i]=C2[minj];
      C2[minj]=temp;
    }
 
    for(i=0;i<N-1;i++){
      printf("%c%d ",C2[i].mark,C2[i].value);
    }
 
    printf("%c%d\n",C2[N-1].mark,C2[N-1].value);
 
    for(i=1;i<N;i++){
      if(C2[i].value==C2[i-1].value && C2[i].order-C2[i-1].order<0){
	flag=0;
      }
    }
 
    if(flag==1){
      printf("Stable\n");
    }
    else{
      printf("Not stable\n");
    }
  }

  return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    string s;
    string t;
    cin >> s >> t;
    long a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if (s.compare(u) == 0) {
        cout << (a-1) << " " << b;
    }
    else {
        cout << a << " " << (b-1);
    }

    return 0;
}


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

int main()
{
    string S;
    cin >> S;

    if(S == "Sunny")
    {
        cout << "Cloudy" << endl;
    }

    else if(S == "Cloudy")
    {
        cout << "Rainy" << endl;
    }

    else
    {
        cout << "Sunny" << endl;
    }
    

    return 0;
}

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

const long long MOD = 1e9+7;
const int MAX = 5000;
int N;
vector<int> edges[MAX];
int sz[MAX];
long long dp[MAX][MAX+1][2];
long long tmp[MAX+1][2];
long long g[5001];

void add(long long& a, long long b){
    a = (a+b+MOD) % MOD;
}

void rec(int i, int pre){
    int x, y, kx, ky;
    sz[i] = 1;
    dp[i][1][0] = 1;
    for(auto j : edges[i]){
        if(j == pre) continue;
        rec(j, i);

        for(x=1; x<=sz[i]; x++){
            for(kx=0; kx<2; kx++){
                tmp[x][kx] = dp[i][x][kx];
                dp[i][x][kx] = 0;
            }
        }

        for(x=1; x<=sz[i]; x++){
            for(y=1; y<=sz[j]; y++){
                for(kx=0; kx<2; kx++){
                    for(ky=0; ky<2; ky++){
                        int k = (kx+ky)%2;
                        long long prod = tmp[x][kx] * dp[j][y][ky] % MOD;
                        add(dp[i][x][!k], prod * g[y] % MOD);
                        add(dp[i][x+y][k], prod);
                    }
                }
            }
        }
        sz[i] += sz[j];
    }
}

int main(){
    long long i, j, k;
    cin >> N;
    for(i=0; i<N-1; i++){
        int x, y;
        cin >> x >> y;
        edges[x-1].push_back(y-1);
        edges[y-1].push_back(x-1);
    }
    g[2] = 1;
    for(i=4; i<=N; i+=2){
        g[i] = g[i-2] * (i-1) % MOD;
    }
    rec(0, -1);
    long long ans = 0;
    for(i=1; i<=N; i++){
        add(ans, (dp[0][i][0] - dp[0][i][1]) * g[i] % MOD);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 390016
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	ll x;
	cin >> x;
	ll maxdist = 0, t = 1;
	while (maxdist < x) {
		maxdist += t;
		t++;
	}
	cout << t - 1 << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
plist = list(input().split())
qlist = list(input().split())
p = int("".join(plist))
q = int("".join(qlist))

import itertools

nlis = itertools.permutations(range(1, n + 1), n)
nl = [map(str, i) for i in nlis]
nlit = ["".join(i) for i in nl]
nlist = [int(i) for i in nlit]
nlist.sort()

import bisect

pidx = bisect.bisect_left(nlist, p)
qidx = bisect.bisect_left(nlist, q)

print(abs(pidx - qidx))

Measured memory_bytes: 15556
m,k = map(int,input().split())

if 2**m <= k:
    print(-1)
elif m == 0:
    if k == 0:
        print(0,0)
    else:
        print(-1)
elif m == 1:
    if k == 0:
        print('0 0 1 1')
    else:
        print(-1)
else:
    ans = []
    append = ans.append
    for i in range(2**m):
        if i == k:
            continue
        else:
            append(i)
    append(k)
    for i in range(2**m-1,-1,-1):
        if i == k:
            continue
        else:
            append(i)
    append(k)

    for a in ans:
        print(a,end=' ')

Measured memory_bytes: 53056
mod = 10**9 + 7
k = 5


class Lagrange:
    def __init__(self, lst):
        self.lst = lst

    def prd(self, j, x):
        tmp = 1
        for i, (xi, yi) in enumerate(self.lst):
            if j != i:
                tmp *= (x - xi)
                tmp %= mod
        return tmp

    def pln(self, x):
        tmp = 0
        for i, (xi, yi) in enumerate(self.lst):
            tmp += yi * (self.prd(i, x) * pow(self.prd(i, xi), mod - 2, mod))
            tmp %= mod
        return tmp


def cmb(x, y):
    if x < y:
        return 0
    tmp = 1
    for i in range(y):
        tmp *= x - i
        tmp *= pow(y - i, mod - 2, mod)
        tmp %= mod
    return tmp


def pln(n):
    tmp = 0
    for x in range(n):
        tmp += cmb(x + k - 1, k - 1) * cmb(n - (2 * x) + k, 2 * k)
        tmp %= mod
    return tmp


lst_eve = [(i, pln(i)) for i in range(0, 6 * k + 1, 2)]
lst_odd = [(i, pln(i)) for i in range(1, 6 * k + 2, 2)]

lag_eve = Lagrange(lst_eve)
lag_odd = Lagrange(lst_odd)

t = int(input())
for _ in range(t):
    n = int(input())
    if n % 2 == 0:
        print(lag_eve.pln(n))
    else:
        print(lag_odd.pln(n))


Measured memory_bytes: 9324
import copy
from functools import reduce
alphabet = " abcdefghij"
def dfs(n, arr, cur):
  if cur == n:
    return print(reduce(lambda x, y:x+y, map(lambda x:alphabet[x], arr)))
  else:
    i = 1
    while i <= max(arr)+1:
      tmp = copy.copy(arr)
      tmp[cur] = i
      dfs(n, tmp, cur+1)
      i += 1

N = int(input())
dfs(N, [0]*N, 0)

Measured memory_bytes: 4972
#include <iostream>
#include <cmath>
using namespace std;
typedef long long int LLI;

LLI string_to_int(string tmp)
{
	LLI ans = 0;
	int save = tmp.size();
	for(int i = 0; i < save; i++)
	{
		ans *= 10;
		ans += tmp[i]-'0';
	}
	return ans;
}
int main()
{
	string a, b;
	cin >> a >> b;
	
	string tmp = a + b;
	int save = string_to_int(tmp);
	
	double check = sqrt( save );
	if( ceil( check ) == floor( check ) )
		cout << "Yes";
	else
		cout << "No";
}

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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   //最大値を求める
#define MIN(x) *min_element(ALL(x))   //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007      //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素

//for (auto& e : array)



signed main()
{
    string S;
    int K;

    cin >> K >> S;

    if(S.size() <= K){
        cout << S << endl;
    } else{
        cout << S.substr(0, K) << "..." << endl;
    }
}


Measured memory_bytes: 3628
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    int num = Integer.parseInt(s.replace("/", ""));
    
    System.out.println((num <= 20190430) ? "Heisei" : "TBD");
  }
}

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

ans = sum(B)
now = 99
for i in A:
  pre = now
  now = i
  if now == (pre+1):
    ans += C[pre-1]
print(ans)

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

int main(){
  long long N;
  cin >> N;

  long long max_sq_factor = 1;
  for(long long i = 1; i * i <= N; i++){
    if(N % i == 0){
      max_sq_factor = i;
    }
  }

  cout << (max_sq_factor - 1) + (N / max_sq_factor - 1) << endl;
}


Measured memory_bytes: 888
#include<iostream>
using namespace std;
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0016
int main(){
    int a,b;
    cin>>a>>b;
    if(a>b){
        cout<<"a > b"<<endl;
    }
    else if(a<b){
        cout<<"a < b"<<endl;
    }
    else{
        cout<<"a == b"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

set<ll> f(ll n){
  set<ll> res;
  for(ll i = 1; i*i<=n; ++i){
    if(n%i==0){
      res.insert(i);
      res.insert(n/i);
    }
  }
  return res;
}
int main() {
  ll n;
  cin >> n;
  ll ans = 0;

  for(ll k : f(n)){
    if(k==1)continue;
    ll m = n;
    while(m%k==0){
      m /= k;
    }
    if (m%k==1) ++ans;
  }

  ans += f(n-1).size()-1;
  cout << ans << endl;
}


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

int main() {
  string s; cin >> s;
  list<char> str;
  for (char c:s) str.push_back(c);
  
  bool rev = false;
  int q; cin >> q;
  while (q--) {
    int t; cin >> t;
    if (t == 1) rev = (rev ? false : true);
    else {
      int f; cin >> f;
      char c; cin >> c;
      if ((f == 1) && !rev || (f == 2) && rev) str.push_front(c);
      else str.push_back(c);
    }
  }
  
  if (rev)
    for (auto itr = str.rbegin(); itr != str.rend(); ++itr)
      cout << (*itr);
  else
    for (auto itr = str.begin(); itr != str.end(); ++itr)
      cout << (*itr);
  cout << endl;
}

Measured memory_bytes: 9984
#include <iostream>
#include <string>
#include <cctype>

using namespace std;




int main(){
	
	int n;
	string str1, str2;
	int c1 = 0, c2 = 0;
	
	cin >> n;
	
	for (int i = 0; i < n; i++){
		cin >> str1 >> str2;
		if (str1 > str2) c1 += 3;
		else if (str1 < str2) c2 +=3;
		else {c1++; c2++;}
		
	}	

		cout << c1 << " " << c2 << endl;
	
	return 0;
}

Measured memory_bytes: 1208
#include <cstdio>
#include <cctype>

template <int BUFFER_SIZE = 100000>
class fastIO {
private:
	char input_buffer[BUFFER_SIZE], output_buffer[BUFFER_SIZE];
	char *p1, *p2, *p;
	
public:
	explicit fastIO(void) : p1(input_buffer), p2(input_buffer), p(output_buffer)
	{}
	~fastIO();
	
	char getchar(void);
	void putchar(const char&);
	
	template <typename Type>
	void read(Type&);
	
	void read(char*);
	void read(char&);
	
	template <typename Type>
	void write(Type x, int SIZE = 35);
};

template <int BUFFER_SIZE>
fastIO<BUFFER_SIZE>::~fastIO() {
	std::fwrite(output_buffer, 1, p - output_buffer, stdout);
}

template <int BUFFER_SIZE>
char fastIO<BUFFER_SIZE>::getchar(void) {
	if (p1 == p2) {
		p1 = input_buffer;
		p2 = p1 + std::fread(input_buffer, 1, BUFFER_SIZE, stdin);
		return ' ';
	}
	else {
		return *p1++;
	}
}

template <int BUFFER_SIZE>
template <typename Type>
void fastIO<BUFFER_SIZE>::read(Type& a) {
	double temp = 1;
	bool flag = false;
	a = 0;
	char ch = this->getchar();
	
	while (!std::isdigit(ch)) {
		if (ch == '-') {
			flag = true;
		}
		ch = this->getchar();
	}
	while (std::isdigit(ch)) {
		a = a * 10 + (ch - '0');
		ch = this->getchar();
	}
	
	if (ch == '.') {
		ch = this->getchar();
		while (std::isdigit(ch)) {
			temp /= 10;
			a += temp * (ch - '0');
			ch = this->getchar();
		}
	}
	
	if (flag) {
		a = -a;
	}
	return;
}

template <int BUFFER_SIZE>
void fastIO<BUFFER_SIZE>::read(char* str) {
	char ch = this->getchar();
	while (std::isblank(ch)) {
		ch = this->getchar();
	}
	while (!std::isblank(ch)) {
		*str++ = ch;
		ch = this->getchar();
	}
	return;
}

template <int BUFFER_SIZE>
void fastIO<BUFFER_SIZE>::read(char& ch) {
	ch = this->getchar();
	while (std::isblank(ch)) {
		ch = this->getchar();
	}
	return;
}

template <int BUFFER_SIZE>
void fastIO<BUFFER_SIZE>::putchar(const char& ch) {
	if (p - output_buffer == BUFFER_SIZE) {
		std::fwrite(output_buffer, 1, BUFFER_SIZE, stdout);
		p = output_buffer;
	}
	*p++ = ch;
	return;
}

template <int BUFFER_SIZE>
template <typename Type>
void fastIO<BUFFER_SIZE>::write(Type x, int SIZE) {
	if (x < 0) {
		x = -x;
		this->putchar('-');
	}
	int stack[SIZE];
	int top = 0;
	
	do {
		stack[top++] = x % 10;
		x /= 10;
	}
	while (x);
	
	while (top) {
		this->putchar(stack[--top] + '0');
	}
	return;
}

fastIO<> io;

#include <unordered_map>

std::unordered_map<int, bool> umap;

int main(int argc, char** argv) {
	int n;
	std::scanf("%d", &n);
	bool flag = false;
	for (int i = 0; i < n; ++i) {
		int inp;
		std::scanf("%d", &inp);
		if (umap.count(inp)) {
			flag = true;
			std::puts("NO");
			break;
		}
		umap[inp] = true;
	}
	if (!flag) {
		std::puts("YES");
	}
	return 0;
}

Measured memory_bytes: 8520
// =====================================================================================
//
//       Filename:  atCoder.cpp
//
//    Description:  
//
//        Version:  1.0
//        Created:  13/04/20 06:17:26 PM IST
//       Revision:  none
//       Compiler:  g++
//
//         Author:  Kiran Bhanushali (), kiranbhanushali143.kb143@gmail.com
//   Organization:  
//
// =====================================================================================

#include<bits/stdc++.h>


using namespace std;

#define int long long 
#define pb push_back
//#define _SHOW_TIME

void solve(){
    //your code here;
    int n , m , x;
    cin>>n>>m>>x;
    vector<int> a(m);
    for(int i =0;i<m;i++) cin>>a[i];
    auto it = lower_bound(a.begin(),a.end(),x);
    cout<<min(it-a.begin(),a.end()-it)<<endl;
  }
int32_t main(){
 /////////////////////////////////////
    #ifdef _SHOW_TIME
	int tt = (int) clock();
    #endif
    /////////////////////////////////////
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /////////////////////////////////////
    solve();
    /////////////////////////////////////
    #ifdef _SHOW_TIME
        cerr << "TIME = " << (double)(clock() - tt) / CLOCKS_PER_SEC << endl;
    #endif
    /////////////////////////////////////
    return 0;

}



Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define SREP(s,i,m) for(unsigned int i = s; i < m; ++i)
#define REP(i,m) SREP(0,i,m)
using namespace std;
#ifdef _MSC_VER
using LONG = __int64;
using ULONG = unsigned __int64;
#else
using LONG = long long int;
using ULONG = unsigned long long int;
#endif

int N;
vector<int> a;
set<int> used;
map<int, int> pos;
ULONG result = 0;

// container の中から key より小さい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator less_than(T &container, typename T::key_type &key) {
  typename T::iterator prev = container.lower_bound(key);
  if (prev == container.begin()) prev = container.end();
  else prev--;
  return prev;
}

// container の中から key より大きい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator greater_than(T &container, typename T::key_type &key) {
  return container.upper_bound(key);
}

void calculate() {
  for (int num = 1; num <= N; num++) {
    auto prev = less_than(used, pos[num]);
    auto next = greater_than(used, pos[num]);
    int left, right;
    if (prev == used.end()) {
      left = pos[num];
    } else {
      left = pos[num] - *prev - 1;
    }
    if (next == used.end()) {
      right = N - pos[num] - 1;
    } else {
      right = *next - pos[num] - 1;
    }
    if (right < 0) throw runtime_error("bug 1");
    if (left < 0) throw runtime_error("bug 2");
    if (right >= N) throw runtime_error("bug 3");
    if (left >= N) throw runtime_error("bug 4");
    result += (ULONG)num * ((ULONG)right * (ULONG)left + (ULONG)right + (ULONG)left + 1);
    used.insert(pos[num]);
  }
}

int main(void) {
  cin >> N;
  a.resize(N);
  REP(i, N) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  calculate();
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 19840
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	sort(a,a+n);
	double temp = 1.0 * (a[0] + a[1])/2.0;
	for(int i = 2; i < n; i++){
		temp = (temp+a[i])/2.0;
	}
	cout << fixed << setprecision(10) << temp;

	return 0;
}



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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 5;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const ll N = 1e6+5;
string s;
vector<ll> v[N];
ll n,r;
ll a[N],b[N];

int main () {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  rep(i,n) {
    cin >> a[i];
    b[i] = a[i];
  }
  SORT(b,n);
  // reverse(b,b+n);
  rep(i,n) {
    // cout << b[i] << endl;
    if(a[i] != b[i]) r++;
  }
  if(r==2 || r==0) s = "YES";
  else s = "NO";
  cout << s << endl;
}


Measured memory_bytes: 27008
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
typedef long long ll;
using namespace std;

int main() {
	ll a,b,c,x,makichankawaiikakikukeko=0;
	cin>>a>>b>>c>>x;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				if(500*i+100*j+50*k==x){
					makichankawaiikakikukeko++;
				}
			}
		}
	}
	cout <<makichankawaiikakikukeko<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int d, g;
	cin >> d >> g;
	vector<P> p(d);
	rep(i, d) cin >> p[i].first >> p[i].second;
	int ans = inf;
	rep(bit, (1 << d)) {//全部解くやつ
		int tmp = 0;
		int cnt = 0;
		rep(i, d) {
			if (bit & (1 << i)) {
				tmp += p[i].first * (i + 1)*100 + p[i].second;
				cnt += p[i].first;
			}
		}
		if (tmp >= g) {
			ans = min(ans, cnt);
			continue;
		}
		for (int i = d - 1; i >= 0; --i) {
			if (!(bit & (1 << i))) {
				int now = p[i].first;
				while (tmp < g && now > 0) {
					tmp += (i + 1) * 100;
					now--;
					cnt++;
				}
				break;
			}
		}
		if (tmp >= g) ans = min(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void solve()
{
	long long n;
	cin>>n;
	long a[n];
	for(long long i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	if(a[0]==0)
	{
		cout<<0;
		return;
	}
	long long ans=1,tm=1e18;
	for(long long i=0;i<n;i++)
	{
		if((tm/ans)>=a[i]) 
			ans*=a[i];
		else
		{
			cout<<-1;
			return;
		}
	}
	cout<<ans<<endl;
}
int main()
{
 	solve();
}

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


int main()
{
	int cnt=0;	
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='2')cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    string s;
    cin >> s;
    int cnt = 0;
    for (auto ch : s)
        if (ch == '1')
            cnt++;
    cout << cnt << endl;
}


Measured memory_bytes: 3616