akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n, m;
vector <int> can;//今ある分銅で測れる重さ

//今ある分銅で測れる重さを、総当たりで求める再帰関数。
void make_can(int depth, int sum, vector<int> w){
	if(depth >= m){
		can.push_back(sum);
		return;
	}
	make_can(depth+1, sum, w);//置かない
	make_can(depth+1, sum+w[depth], w);//薬品じゃない方に置く(足す)
	make_can(depth+1, abs(sum-w[depth]), w); //薬品の方に置く(引く)
}

int main(void){
	while(1){
		cin >> n >> m;
		if(!n && !m) break;

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

		//前半(今ある分銅で、全ての薬品を測れるか)
		can.clear();
		make_can(0, 0, w); 
		sort(can.begin(), can.end());
		for(int i=0; i<can.size(); i++){
			for(int j=0; j<a.size(); j++){
				if(can[i] == a[j]) a.erase(a.begin()+j); //今ある分銅で測れる薬品を消す
			}
		}

		if(a.size() == 0){
			cout << 0 << endl; //全ての薬品は今ある分銅で測れる
			continue;
		}

		//後半(どの重さの分銅を追加すればいいか)
		vector <vector<int> > cand(n); //各薬品に対して追加が必要な分銅の候補
		for(int i=0; i<a.size(); i++){
			for(int j=0; j<can.size(); j++){
				cand[i].push_back(can[j]+a[i]);
				cand[i].push_back((abs(can[j]-a[i])));
			}
			sort(cand[i].begin(), cand[i].end());
		}

		vector <int> need = cand[0]; //v1とv2の積集合。答えの候補。
		for(int s=1; s<a.size(); s++){
			vector <int> v1 = need;
			vector <int> v2 = cand[s];
			need.clear();
			int i=0, j=0; // iはv1に jはv2に対応。v1[i], v2[j]
			while(i<v1.size() && j<v2.size()){
				if(v1[i] < v2[j]) i++;
				else if(v1[i] > v2[j]) j++;
				else{
					//重複を省くための条件式
					if(need.size() == 0) need.push_back(v1[i]);
					else if(need[need.size()-1] != v1[i]){
						need.push_back(v1[i]);
					}
					i++; j++;
				}
			}
		}

		if(need.empty()) cout << -1 << endl; //候補が残っていない -> 1つ追加しても無理
		else cout << need[0] << endl; //候補の中で一番軽いやつが答え
	}
	return 0;
}


Measured memory_bytes: 43192
//---------- Begin IO utilities ----------
// Thanks to https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:tt : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! p {
    ($v:ident) => {
        println!("{}", $v);
    };
    ($v:ident, $($t:ident),*) => {
        print!("{}", $v);
        ($(print!(" {}", $t)),*);
        println!();
    }
}
#[allow(unused_macros)]
macro_rules! ps {
    ($v:ident) => {
        println!("{}", $v.iter().collect::<String>());
    };
    ($v:ident, $($t:ident),*) => {
        print!("{}", $v.iter().collect::<String>());
        ($(print!(" {}", $t.iter().collect::<String>())),*);
        println!();
    }
}
#[allow(dead_code)]
fn pv<T: std::string::ToString>(v: &[T], sep: &str) {
    let s = v.iter().map(|e| e.to_string()).collect::<Vec<String>>().join(sep);
    println!("{}", s);
}
#[allow(dead_code)]
fn pvs(v: &[Vec<char>], sep:&str) {
    let s = v.iter().map(|e| e.iter().collect::<String>()).collect::<Vec<String>>().join(sep);
    println!("{}", s);
}
//---------- End IO utilities ----------

fn main() {
    input!{
        n: usize,
        s: [String; n],
    }
    let mut  r = s.clone();
    r.sort();
    r.dedup();
    println!("{}", r.len());
}


Measured memory_bytes: 28040
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    ll n,m;
    cin >> n >> m;
    if(m < 2*n) cout << m/2 << endl;
    else cout << n + (m-2*n)/4 << endl;
}

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

signed main() {
	int a, b, k;
	cin >> a >> b >> k;

	int cnt = 0;

	for (int i = min(a, b); ; --i) {
		if (a % i == 0 and b % i == 0) {
			cnt++;
		}
		if (cnt == k) {
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
//{{{
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
#ifdef LOCAL
#include "prettyprint.hpp"
#endif
// clang-format off
void _print() { cerr << "]\033[0m\n"; }
template <typename T> void __print(T x) { cerr << x; }
template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#ifdef LOCAL
#define debug(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m["; _print(x)
#define debug_arr(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m" << (x) << "\033[0m\n"
#else
#define debug(x...)
#define debug_arr(x...)
#endif
// clang-format on
//}}}

const int N = 2e5 + 10;
const int mod = 1e9 + 7;

int n;
LL a[N];

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif

    while (cin >> n)
    {
        for (int i = 1; i <= n; ++i)
        {
            cin >> a[i];
        }
        LL ans = 0;
        for (int i = 2; i <= n; i++)
        {
            if (a[i] < a[i - 1])
            {
                ans += a[i - 1] - a[i];
                a[i] = a[i - 1];
            }
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 5148
/*ITS FUCKING O(N) now
GET ACCEPTED FOR FUCK'S SAKE*/
#define _USE_MATH_DEFINES
 
#include <cmath>

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

long long powerexp(long long base, long long exp, int mod) {
   long long res = 1;
   while (exp > 0) {
      if (exp % 2 == 1)
         res= (res * base) % mod;
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}
int gcd(int a, int b)
{
    int c = a % b;
    while(c != 0)
    {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}
void PrintVector(vector<long long int> v,long long int n)
{
 
    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void Takevector(vector<long long int> &v,long long int n)
{
  for(long long int i=0;i <n;i++)
  { long long int number;
    cin>>number;
    v.push_back(number);
  }
}
typedef long long int ll;
typedef vector<long long int> vi;

#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define scl(x)         ll x;       scanf("%lld", &x);
#define scll(x, y)     ll x, y;    scanf("%lld %lld", &x, &y);
#define sclll(x, y, z) ll x, y, z; scanf("%lld %lld %lld", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define rep(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
#define repi(i, x, y)  for (__typeof(x) i = x; i >= y; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
#define nl cout<<"\n";
int min(int x, int y)  
{  
    return (x < y)? x: y;  
      
}  
  
int main()
{
 	int flag=0;
 	ll sum=0;
 	int flag1=1;
 	ll tot=0;
 	int ans=0;
 	map<int,int>m;
 	vi v;
 	set<ll>st;
 	string s;
  ll c=0;
  ll d=0;
  while(st.size()<=100000)
  {
    d=c*c*c*c*c;
    
    { st.insert(d);
      st.insert(-d);}
      c++;
  }
  scl(x);

  for(long long int i=0;i<=100000;i++)
  {
    ll xy=x;
    xy+=i*i*i*i*i;
    if(st.count(xy)>0)
    {
      cout<<pow(xy,0.2)<<" "<<i;
      break;
    }
    xy=x;
    xy-=i*i*i*i*i;
    if(st.count(xy)>0)
    {
      cout<<pow(xy,0.2)<<" "<<-i;
      break;
    }


  }
 	 
    return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 2e3 + 3;

struct edge {
    int to;
    int len;
};

vector <edge> g[N];
vector <int> min_dist(N, INF);

void dijkstra(int source) {
    min_dist[source] = 0;
    set <pii> S;            // S is set of active vertices (min_dist, vertex)
    S.insert({0, source});

    while (!S.empty()) {
        int curr = S.begin() -> se;
        S.erase(S.begin());

        for (auto e: g[curr]) {
            if (min_dist[e.to] > min_dist[curr] + e.len) {
                S.erase({min_dist[e.to], e.to});
                min_dist[e.to] = min_dist[curr] + e.len;
                S.insert({min_dist[e.to], e.to});
            }
        }
    }
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, x, y;
    cin >> n >> x >> y;

    g[x].pb({y, 1});
    g[y].pb({x, 1});
    for (int i = 1; i < n; i++) {
        g[i].pb({i+1, 1});
        g[i+1].pb({i, 1});
    }

    vector<int> cnt(N, 0);
    for (int i = 1; i <= n; i++) {
        fill(all(min_dist), INF);
        dijkstra(i);
        for (int i = 1; i <= n; i++) {
            cnt[min_dist[i]]++;
        }
    }

    for (int i = 1; i < n; i++) {
        cout << cnt[i] / 2 << "\n";
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < n; i++)
#define rep2(i,start,end) for(ll i = start; i < end; i++)
#define dwn(i,n) for(int i = n; i >= 0; i--)
#define dwn2(i,start,end) for(ll i = start; i >= end; i--)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int main(){
	ll n;
	cin>>n;
	ll k = (ll)sqrt(n);
//	cout<<k<<endl;
	ll ans = n;
	int flag = 0;
	for(int i = 1; i <= k; i++){
		ll tmp = n/i;
		if(tmp * i == n && ( i+ tmp) <= ans){
			ans = i+tmp;
			flag = 1;
//			cout<<ans<<" "<<i<<" "<<tmp<<endl;
		}
	}
	if(flag)
	cout<<ans-2<<endl;
	else cout<<ans-1<<endl;

	return 0;
}






Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

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

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

int c[110], t[110];

int main() {
    int n, T;
    cin>>n>>T;
    for (int i = 0; i < n; i++) {
        cin>>c[i]>>t[i];
    }
    int res=100000000;
    for (int i = 0; i < n; i++) {
        if(t[i]<=T){
            if(c[i]<res){
                res=c[i];
            }
        }
    }
    if(res==100000000){
        cout<<"TLE"<<endl;
        return 0;
    }

    cout<<res<<endl;   
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
int divr[maxn];
/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}*/
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 
 














int main()
{
     int n,k;
     cin>>n>>k;
     ll ct=0;
     if(k==0){cout<<1LL*n*n;return 0;}
     for(int i=k+1;i<=n;i++)
     {
          int t=n/i;
          ct+=1LL*t*(i-k);
          ct+=max(0,n%i-k+1);
          
                
     }
     cout<<ct;
}



















 
 
 
 
 

















Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 500010, P = 1000000007, M = 1 << 20;

int n;
int a[N];
int cc[M], sa[M], s0[M];

int norm(int x) { return x >= P ? x - P : x; }

int mpow(int x, int k, int p = P) {
  int ret = 1;
  while (k) {
    if (k & 1)
      ret = ret * (ll)x % p;
    x = x * (ll)x % p;
    k >>= 1;
  }
  return ret;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i)
    a[i] ^= a[i - 1];
  if (a[n]) {
    int s0 = 1, sa = 0, dp = 1;
    for (int i = 1; i <= n; ++i)
      if (a[i] == a[n]) {
        dp = s0;
        sa = norm(sa + dp);
      } else if (a[i] == 0) {
        dp = sa;
        s0 = norm(s0 + dp);
      }
    printf("%d\n", dp);
  } else {
    int cnt = 0;
    fill(s0, s0 + M, 1);
    for (int i = 1; i < n; ++i) {
      if (a[i]) {
        s0[a[i]] = (s0[a[i]] + sa[a[i]] * (ll)(cnt - cc[a[i]])) % P;
        sa[a[i]] = norm(sa[a[i]] + s0[a[i]]);
        cc[a[i]] = cnt;
      } else
        ++cnt;
    }
    int cnt0 = count(a + 1, a + n, 0);
    int ans = (accumulate(sa + 1, sa + M, 0LL) + mpow(2, cnt0)) % P;
    printf("%d\n", ans);
  }

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


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

const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    long long res = 0;
    for (int i = 0; i < 60; i++) {
        long long x = 0;
        for (int j = 0; j < N; j++) {
            if ((A[j] >> i) & 1) x++;
        }
        long long temp = x * (N - x) % MOD;
        for (int j = 0; j < i; j++) {
            temp = temp * 2 % MOD;
        }
        res += temp;
        res %= MOD;
    }
    cout << res << endl;
    return 0;
}

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

int dp[41][401][401];

int main(){
    int N,Ma,Mb;
    cin>>N>>Ma>>Mb;
    vector<int>A,B,C;
    for(int i=0;i<N;i++){
        int a,b,c;
        cin>>a>>b>>c;
        A.push_back(a);B.push_back(b);C.push_back(c);
    }
    for(int i=0;i<41;i++){
        for(int j=0;j<401;j++){
            for(int k=0;k<401;k++)dp[i][j][k]=1145141919;
        }
    }
    dp[0][A[0]][B[0]]=C[0];
    dp[0][0][0]=0;
    for(int i=1;i<N;i++){
        for(int ma=0;ma<=400;ma++){
            for(int mb=0;mb<=400;mb++){
                dp[i][ma][mb]=dp[i-1][ma][mb];
                if (ma-A[i]>=0&&mb-B[i]>=0) dp[i][ma][mb]=min(dp[i][ma][mb],dp[i-1][ma-A[i]][mb-B[i]]+C[i]);
            }
        }
    }
    int ans=114514;
    for(int ma=1;ma<=400;ma++)
    for(int mb=1;mb<=400;mb++){
        if(ma*Mb!=mb*Ma)continue;
        ans=min(ans,dp[N-1][ma][mb]);
    }
    cout<<((ans>=114514)?-1:ans)<<endl;
  
    return 0;
}

Measured memory_bytes: 26112
#include <bits/stdc++.h>
#define rep0(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define mREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int a[10000000];
int main(){
  int n;
  cin >> n;
  rep0(i,n)cin >> a[i];
  int ans  = 0;
  int nowright = a[0];
  while(1){
    if(nowright == 2)break;
    nowright = a[nowright - 1];
    ans++;
    if(ans >= 200000000){
      cout << -1 << endl;
      return 0;
    }
    
  }
  cout << ans + 1 << endl;
  return 0;
}

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

int N;
long long ans;
long long m, a, r, c, h;
string tmp;

int main() {
	ans = 1;
	m = 0, a = 0, r = 0, c = 0, h = 0;

	cin >> N;

	for (int i = 0; i<N; i++) {
		cin >> tmp;
		if (tmp[0] == 'M') {
			m++;
		}else if (tmp[0] == 'A') {
			a++;
		}
		else if (tmp[0] == 'R') {
			r++;
		}
		else if (tmp[0] == 'C') {
			c++;
		}
		else if (tmp[0] == 'H') {
			h++;
		}
	}

	ans = m * a*r + m * a*c + m * a*h + m * r*c + m * r*h + m * c*h + a * r*c + a * r*h + a * c*h + r * c*h;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())

if N == 1 or N == 2:
    print(0)
    exit()


ans = 0

i = 2
while i * i <= N:
    if N % i == 0:
        q = N // i
        if q-1 >= 2 and N % (q-1) == i:

            ans += q-1
    i += 1

ans += N-1
print(ans)

Measured memory_bytes: 3060
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define per(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define enter cout << endl
#define siz(x) ((int)x.size())
typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef pair <ll, ll> pll ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 100010 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }

string s ;
int ans ;

int main() {
	cin >> s ;
	for (int i = 0; i < siz(s); i++) if (s[i] == '2') ans++ ;
	printf("%d\n", ans) ;
}

/*
写代码时请注意：
	1.ll？数组大小，边界？数据范围？
	2.精度？
	3.特判？
	4.至少做一些
思考提醒：
	1.最大值最小->二分？
	2.可以贪心么？不行dp可以么
	3.可以优化么
	4.维护区间用什么数据结构？
	5.统计方案是用dp？模了么？
*/


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

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> A(N+1),B(N+1);
    
    for ( int64_t i = 0; i < N+1; ++i){
        cin >> A.at(i);
    }
    B.at(0) = 0;
    for ( int64_t i = 1; i <= N; ++i){
        cin >> B.at(i);
    }
    
    int64_t ans = 0;
    for ( int64_t i = 0; i < N; ++i){
        if ( A.at(i) >= B.at(i) ){
            A.at(i) = A.at(i) - B.at(i);
            ans += B.at(i);
            if ( A.at(i) >= B.at(i+1) ){
                ans += B.at(i+1);
                B.at(i+1) = 0;
            } else {
                ans += A.at(i);
                B.at(i+1) = B.at(i+1) - A.at(i);
            }
        } else {
            ans += A.at(i);
        }
    }
    if ( A.at(N) >= B.at(N) ){
        ans += B.at(N);
    } else {
        ans += A.at(N);
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<queue>
#include<tuple>

using namespace std;
typedef long long ll;
typedef tuple<ll, int, int> T3;

int N, M, S, T;
vector<vector<int>> E;

ll d[100000][3];

void djk(int start) {
	priority_queue<T3, vector<T3>, greater<T3>> pq;
	d[start][0] = 0;
	pq.push(make_tuple(0, start, 0));

	while (pq.size()) {
		auto now = pq.top(); pq.pop();
		int nowp = get<1>(now), amari = get<2>(now);
		if (get<0>(now) > d[nowp][amari])continue;
		for (int i = 0; i < E[nowp].size(); i++) {
			int next = E[nowp][i];
			if (d[next][(amari + 1) % 3] > d[nowp][amari] + 1) {
				d[next][(amari + 1) % 3] = d[nowp][amari] + 1;
				pq.push(make_tuple(d[next][(amari + 1) % 3], next, (amari + 1) % 3));
			}
		}
	}

}

int main() {
	cin >> N >> M;
	E.resize(N);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		E[a].push_back(b);
	}

	cin >> S >> T, S--, T--;

	for (int i = 0; i < 100000; i++)for (int j = 0; j < 3; j++)d[i][j] = 1145141919810;

	djk(S);
	if (d[T][0] == 1145141919810)cout << -1 << endl;
	else cout << d[T][0] / 3 << endl;

	return 0;
}

Measured memory_bytes: 8064
from collections import deque
from operator import itemgetter
import heapq

N, M = map(int, input().split())
jobs = [tuple(map(int, input().split())) for _ in range(N)]
jobs.sort()

q = deque(jobs)
r = []

heapq.heapify(r)

res = 0
for i in range(M):
    while q:
        job = q.popleft()
        if job[0] > i + 1:
            q.appendleft(job)
            break
        else:
            heapq.heappush(r, -job[1])

    if len(r) >= 1:
        res -= heapq.heappop(r)

print(res)

Measured memory_bytes: 93556
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

typedef long long i64;

const i64 MOD = 1e9 + 7;

vector <int> vec;

template<class T>
T modularExp(T base, i64 exp)
{
	T answer(1);

	while (exp)
	{
		if (exp & 1)
			answer = answer * base % MOD;
		base = base * base % MOD;
		exp = exp >> 1;
	}
	return answer;
}

struct Matrix
{
	i64 data[4][4];

	Matrix(i64 x)	// Load a filled matrix
	{
		memset(data, 0x00, sizeof data);
		for (int i = 0; i < 4; i++)
			data[i][i] = x;
	}

	i64 * operator [](unsigned index)
	{
		return this->data[index];
	}

	const i64 * operator [](unsigned index) const
	{
		return this->data[index];
	}


	Matrix operator *(const Matrix & rhs) const
	{
		Matrix result(0);

		for (int k = 0; k < 3; k++)
			for (int i = 0; i < 3; i++)
				for (int j = 0; j < 3; j++)
					result[i][j] = (result[i][j]
							+ data[i][k] * rhs.data[k][j] % MOD) % MOD;
		return result;
	}

	Matrix operator %(i64 modular)
	{
		return (*this);
	}
};

char mp[1005][1005];
i64 N, M, K;
i64 blkCnt, adjCnt;
i64 upDown, leftRight;

int solve()
{
	if (K <= 1)
		return 1;
	if (upDown && leftRight)
		return 1;
	if (!upDown && !leftRight)
		return modularExp(blkCnt, K - 1);
	if (!upDown)
		swap(upDown, leftRight);

	Matrix x(0);
	x[0][0] = x[1][1] = blkCnt;
	x[1][2] = 1;
	x[2][2] = upDown;

	x = modularExp(x, K - 2);

	i64 V(0), E(0);
	int tmp[3] =
	{ blkCnt, adjCnt, adjCnt * upDown };

	for (int i = 0; i < 3; i++)
		V = (V + x[0][i] * tmp[i] % MOD) % MOD;
	for (int i = 0; i < 3; i++)
		E = (E + x[1][i] * tmp[i] % MOD) % MOD;

	return (V - E + MOD) % MOD;
}

void countAdj()
{
	// Count adjacent blocks
	for (int i = 0; i < N; i++)
		leftRight += (mp[i][0] == '#' && mp[i][M - 1] == '#');
	for (int i = 0; i < M; i++)
		upDown += (mp[0][i] == '#' && mp[N - 1][i] == '#');
	// Count total blocks
	for (int i = 0; i < N; i++)
		for (int j = 0; j < M; j++)
			blkCnt += (mp[i][j] == '#');

	if (upDown)
		for (int i = 0; i < N - 1; i++)
			for (int j = 0; j < M; j++)
				adjCnt += (mp[i][j] == '#' && mp[i + 1][j] == '#');
	else
		for (int i = 0; i < N; i++)
			for (int j = 0; j < M - 1; j++)
				adjCnt += (mp[i][j] == '#' && mp[i][j + 1] == '#');
}

int main()
{
	cin >> N >> M >> K;
	for (int i = 0; i < N; i++)
		cin >> mp[i];
	cerr << "Input Finished !" << endl ;
	countAdj();
	cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 1280
while True:
    (n, x) = [int(i) for i in input().split()]
    if n == x == 0:
        break

    count = 0
    for a in range(1, n + 1):
        if a >= x:
            break
        for b in range(a + 1, n + 1):
            if sum([a,b]) >= x:
                break
            for c in range(b + 1, n + 1):
                if sum([a,b,c]) == x:
                    count += 1

    print(count)

Measured memory_bytes: 6724
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll K,A,B;
    cin >> K >> A>>B;
    ll top = (B / K) * K;
    if(A <= top){
        cout << "OK" << endl;
    }
    else cout << "NG" << endl;
}

Measured memory_bytes: 3536
#include <stdio.h>

int     main(void)
{
    int rect_w;
    int rect_h;
    int x;
    int y;
    int r;
    
    scanf("%d %d %d %d %d",&rect_w,&rect_h,&x,&y,&r);
    if (x >= r && x + r <= rect_w && y >= r && y + r <= rect_h)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return (0);
}


Measured memory_bytes: 2088
#include <bits/stdc++.h>
using namespace std;
using PP = pair<long, long>;
const int INF = 1e9;
template <class T> T Next() { T buf; cin >> buf; return buf; }

int n;
long p[100000];
vector<int> g[100000];
vector<long> f[100000];

long rec(int from, int prev) {
  if (prev != -1 && g[from].size() == 1) {
    f[from].push_back(p[from]);
    return p[from];
  }
  
  long ret = 2 * p[from];
  for (int to : g[from]) {
    if (to == prev) continue;
    long res = rec(to, from);
    f[from].push_back(res);
    ret -= res;
  }
  
  if (prev != -1) {
    f[from].push_back(ret);
  }
  return ret;
}

bool sub() {
  const int start = 0;
  long res = rec(start, -1);
  if (g[start].size() == 1) {
    if (res != p[start]) return false;
  } else {
    if (res != 0) return false;
  }
  
  for (int i = 0; i < n; ++i) {
    if (f[i].size() == 1) continue;
    sort(f[i].rbegin(), f[i].rend());
    if (f[i].back() < 0) return false;
    long sum = accumulate(f[i].begin() + 1, f[i].end(), 0ll);
    if (f[i].front() > sum) return false;
  }
  return true;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> p[i];
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  cout << (sub() ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 18688
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>

using namespace std;


int main(void) {
	long long n;
	cin >> n;
	int ans = 100000;
	for (int a = 1; a <= sqrt(n); a++) {
		if (n%a == 0) {
			long long b = n / a;
			ans = min(ans, (int)max(log10(a) + 1, log10(b) + 1));
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 640
'use strict';

function Main(input) {
    const tmp = input.trim().split('\n');
    const [H, W, K] = tmp[0].split(' ').map((v) => Number(v));
    let [_, ...C] = tmp;
    C = C.reduce((str, v) => (str += v), '')
        .split('')
        .map((v) => (v === '#' ? 0 : 1));

    const masks = createMasks(H, W);

    let answer = 0;
    for (const mask of masks) {
        const maskedArray = C.map((v, i) => mask[i] | v);
        if (K === maskedArray.filter((v) => v === 0).length) {
            answer += 1;
        }
    }

    console.log(String(answer));
    return;
}

function createMasks(height, width) {
    const masks = [];
    for (let y = 0; y < 2 ** height - 1; y++) {
        const row = y.toString(2).padStart(height, 0);
        for (let x = 0; x < 2 ** width - 1; x++) {
            const col = x.toString(2).padStart(width, 0);
            masks.push(correctMask(row, col));
        }
    }
    return masks;
}

function correctMask(row, col) {
    const mask = [];
    for (let y = 0; y < row.length; y++) {
        for (let x = 0; x < col.length; x++) {
            mask.push(Number(row[y]) | Number(col[x]));
        }
    }
    return mask;
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m = M) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

int exp(int n, int k) {
  if (k == 0) return 1;
  if (k == 1) return n;
  int ax = exp(n, k / 2);
  ax = mod(ax * ax);
  if (k % 2) ax = mod(ax * n);
  return ax;
}

int gcd(int a, int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
//#define MULTIPLE_TEST_CASE
void solution() {
  string s;
  string t;
  cin >> s >> t;
  int n = s.size();
  int ans = 0;
  for (int i = 0; i < n; i++) ans += (s[i] != t[i]);
  cout << ans << endl;
}

int32_t main() {
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--) solution();
}


Measured memory_bytes: 3824
#include <stdio.h>
int main(void){
   int  a,b,c,x,y=0;
    scanf("%d %d %d",&a,&b,&c);
    for( x=a; x <=b;x++){
       
       if(c%x==0){
        y++;
        }
     
   }
    printf("%d\n",y);// Your code here!
    return(0);
}



Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;


int main()
{
    ll n;
    cin >> n;
    ll ans = INF;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            if(ans >= i + n/i -2){
                ans = i + n/i -2;
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int main()
{
    int n;  ll a[200010];
    cin>>n;
    for(int i=0;i<n;i++)
        scanf("%lld",&a[i]);
    sort(a,a+n);
    int flag=1;
    for(int i=0;i<n;i++)
    {
        if(a[i]==a[i+1])
        {
            flag=0;
            break;
        }
    }
    if(flag)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int M=1e9+7;

int power(int a,int b){
    int ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%M;}
                a=(a*a)%M;
                b>>=1;
        }
    return(ans);
        
}
int fact[200005],fact_inv[200005];
void pre(){
    fact[0]=1;
    fact_inv[0]=1;
    for(int i=1;i<200005;i++){
        fact[i]=fact[i-1]*i;
        fact[i]%=M;
        fact_inv[i]=power(fact[i],M-2);
    }
}
int ncr(int n,int r){
    if(n<r){return 0;}
    if(n==r||r==0){return 1;}
    return (((fact[n]*fact_inv[n-r])%M)*fact_inv[r])%M;
}


int32_t main(){
	IOS;
	pre();
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	int ans=0;
	for(int i=0;i<n;i++){
		ans=(ans+M-(a[i]*ncr(n-i-1,k-1))%M)%M;
		ans=(ans+(a[i]*ncr(i,k-1))%M)%M;
	}
	cout<<ans<<endl;
}

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

int a[101][101]={{}}, b, c;

int main(){
    cin >> b >> c;
    int i, j;
    for(i = 0; i < b; i++){
        for( j = 0; j < c; j++){
            cin >> a[i][j];
            a[i][c] += a[i][j];
        }
    }
    for(j = 0; j <= c; j++){
        for( i = 0; i < b; i++){
            a[b][j] += a[i][j];
        }
    }
    for( i = 0; i <= b; i++){
        for( j = 0; j <= c; j++){
            if(j) cout << " ";
            cout << a[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3084
/*
    YES PAIN YES GAIN
*/

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
template<class T> using rbTree=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long int
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define unmap unordered_map
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define mem(u,v) memset(u,v,sizeof(u))
#define all(x) x.begin(),x.end()
#define r_all(x) x.rbegin(),x.rend()
#define vvi vector<vector<int>>
#define bug1 cout<<"hi1"<<endl
#define bug2 cout<<"hi2"<<endl
#define bug3 cout<<"hi3"<<endl

const int N=1e5;
const int M=2e5;
const int mod=1e9+7;

void solve()
{
    int n,ans=0;
    cin>>n;

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                ans+=__gcd(__gcd(i,j),k);
            }
        }
    }

    cout<<ans;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    int t=1;
    //cin>>t;

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

    #ifndef ONLINE_JUDGE
    cout << "\n\ntime: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms";
    #endif

    return 0;
}

Measured memory_bytes: 3664
#                         author:  kagemeka 
#                         created: 2019-11-08 18:39:24(JST)
### modules
## from standard library
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## from external libraries
# import scipy.special   # if use comb function on AtCoder, 
# import scipy.misc      # select scipy.misc.comb (old version)  
# imort numpy as np 

def main():
    r = int(sys.stdin.readline().rstrip())
    if r < 1200:
        ans = 'ABC'
    elif r < 2800:
        ans = 'ARC'
    else:
        ans = 'AGC'

    print(ans)


if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
dish = []
for i in range(5):
    dish.append(int(input()))
ichi = 0
for i in range(1,5):
    if dish[i]%10 > 0 and dish[ichi] % 10 > dish[i] % 10:
        ichi = i
for i in range(5):
    if i != ichi and dish[i]%10 > 0:
        dish[i] += 10 - dish[i]%10
print(sum(dish))

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long MOD = 998244353;

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

	ll s;
	cin >> s;
	ll x, y, t = 1e9;
	x = (t - s % t) % t;
	y = (s + x) / t;
	char space = ' ';
	cout << 0 << space << 0 << space << t << space << 1 << space << x << space << y << "\n";

	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H.at(i);
  reverse(H.begin(), H.end());
  int ans = 0;
  for (int i = 1, cnt = 0; i < N; i++) {
    if (H.at(i) >= H.at(i - 1)) cnt++;
    else cnt = 0;
    ans = max(ans, cnt);
  }
  cout << ans << "\n";
}

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

int main() {
	long long a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;
    if (abs(a - b) <= (v - w) * t) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793
#define INF 1000000007
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2)*pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int jo(int n) {
	int ans = 1;
	rep(i, n) {
		ans *= 2;
	}
	return ans;
}
int d[26] = {};
signed main() {
	int n,ans=1;
	string s;
	cin >> n >> s;
	rep(i, n) {
		d[s[i]-97]++;
	}
	rep(i, 26) {
		ans *= d[i] + 1;
		ans %= INF;
	}
	if (ans == 0)cout << 1000000006 << endl;
	else cout << ans - 1 << endl;
}

Measured memory_bytes: 512
// ref: https://qiita.com/tubo28/items/e6076e9040da57368845
use std::io::{stdin, Read};
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: i64 = read();
    let b: i64 = read();
    let x: i64 = read();

    let ans = if a > 0 {
        b / x - (a - 1) / x
    } else {
        b / x + 1
    };
    println!("{}", ans);
}

Measured memory_bytes: 4352
// Zigzag

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

constexpr int MAXN = 20;
constexpr int MOD = 1e9 + 7;

int answer;
int N, M, K;
int constrain[MAXN + 5][MAXN];

int upperBnd;
int dp1[(1 << MAXN) + 5], dp2[(1 << MAXN) + 5];
int *dpOld, *dpNew;

inline int loBit(int x)
{
    return x & (-x);
}

int main(int argc, char const *argv[]) {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    memset(constrain, 0xFF, sizeof constrain);
    //cin >> N >> M >> K ;
    scanf("%d%d%d",&N, &M, &K);
    for(int i = 1; i <= K; i++)
    {
        int x, y;
        //cin >> x >> y >> constrain[x][y - 1] ;
        scanf("%d%d", &x, &y);
        scanf("%d", &constrain[x][y-1]);
    }

    upperBnd = 1 << (-- N);
    dpNew = dp2, dpOld = dp1;
    dpOld[0] = 1;

    for(int i = 1; i <= M; i++)
    {
        for(int j = 0; j < N; j++)
        {
            memset(dpNew, 0x00, (sizeof (int)) * upperBnd);
            for(int k = upperBnd - 1; k >= 0; k--)
            {
                if(dpOld[k])
                {
                    dpNew[k] = (dpNew[k] + dpOld[k]) % MOD;
                    int & ref = dpNew[k - loBit(k & (upperBnd - (1 << (j + 1)))) + (1 << j)];
                    if(!((k >> j) & 1))
                        ref = (ref + dpOld[k]) % MOD;
                }
            }
            swap(dpNew, dpOld);
        }

        int flag = 0, last = 0;
        for(int j = 0; j < N; j++)
            if(constrain[i][j] != -1)
                flag |= constrain[i][j] << j;
            else
                last |= 1 << j ;

        for(int j = 0; j < upperBnd; j++)
            if(((j ^ flag) | last) != last)
                dpOld[j] = 0;
    }

    for(int i = 0; i < upperBnd; i++)
        answer = (answer + dpOld[i]) % MOD;

    cout << answer << endl ;

    return 0;
}


Measured memory_bytes: 8448
#include <stdio.h>
#include <assert.h>
int main(void){
  int h, a;
  scanf("%d %d", &h, &a);
  assert((1 <= h)&&(h <= 10000));
  assert((1 <= a)&&(a <= 10000));
  int n;
  for(n = 0; h > 0; h -= a, n++);
  printf("%d", n);
}

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

typedef long long LL;
typedef pair<int, int> II;

const int N = (int) 5e3 + 10;
const int M = (int) 2e2 + 10;
int n, m, a[N][M], L[N], R[N];
LL d[N], val[N][N];

void Update(int x1, int y1, int x2, int y2, int v) {
    val[x1][y1] += v;
    val[x1][y2 + 1] -= v;
    val[x2 + 1][y1] -= v;
    val[x2 + 1][y2 + 1] += v;
}

int main() {
    #ifdef LOCAL
        freopen("Data.inp", "r", stdin);
        freopen("Data.out", "w", stdout);
    #endif

    scanf("%d%d", &n, &m);
    for (int i = 2; i <= n; ++i) scanf("%lld", &d[i]), d[i] += d[i - 1];
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            scanf("%d", &a[i][j]);

    for (int j = 1; j <= m; ++j) {
        for (int i = 1; i <= n; ++i) {
            L[i] = i;
            while (1 < L[i] && a[L[i] - 1][j] <= a[i][j]) L[i] = L[L[i] - 1];
        }
        for (int i = n; i >= 1; --i) {
            R[i] = i;
            while (R[i] < n && a[R[i] + 1][j] <  a[i][j]) R[i] = R[R[i] + 1];
        }
        for (int i = 1; i <= n; ++i) Update(L[i], i, i, R[i], a[i][j]);
    }
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            val[i][j] = val[i - 1][j] + val[i][j - 1] - val[i - 1][j - 1] + val[i][j];

    LL ans = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = i; j <= n; ++j)
            ans = max(ans, val[i][j] - (d[j] - d[i]));
    cout << ans;
    return 0;
}


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

int main(void) {
    // initialize
    int n, a, m = 0;
    cin >> n >> a;
    vector<int> x(n+1);
    for(int i = 1; i <= n; ++i) {
        cin >> x[i];
        m = max(m, x[i]);
    }
    vector<vector<vector<long long>>> dp(n+1);
    for(int j = 0; j <= n; ++j) {
        dp[j].resize(n+1);
        for(int k = 0; k <= n; ++k) {
            dp[j][k].assign(n*m+1, 0LL);
        }
    }
    for(int j = 1; j <= n; ++j) dp[j][0][0] = 1;
    dp[1][1][x[1]] = 1;
    // solve
    for(int j = 2; j <= n; ++j) {
        for(int k = 1; k <= j; ++k) {
            for(int s = 1; s <= n*m; ++s) {
                dp[j][k][s] = dp[j-1][k][s] + (s-x[j] >= 0 ? dp[j-1][k-1][s-x[j]] : 0);
            }
        }
    }
    long long ans = 0LL;
    for(int k = 1; k <= n; ++k) {
        ans += dp[n][k][a*k];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 51200
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> a >> b >> c >> d;
	cout << max(a * c, max(a * d, max(b * c, b * d))) << "\n";
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    vector<int> P(N), Q(N), X(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];

    rep(i, N) {
        X[i] = i + 1;
    }

    int a = 0;
    int b = 0;
    int cnt = 1;
    do {
        bool ok_a = true;
        rep(i, N) {
            if (X[i] != P[i]) {
                ok_a = false;
            }
        }
        if (ok_a) {
            a = cnt;
        }
        bool ok_b = true;
        rep(i, N) {
            if (X[i] != Q[i]) {
                ok_b = false;
            }
        }
        if (ok_b) {
            b = cnt;
        }
        cnt++;
    } while (next_permutation(X.begin(), X.end()));
    cout << abs(b-a) << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll k, a, b; cin >> k >> a >> b;
    ll ans = 1;
    if(a >= b || (a<b && (b-a <= 2))){
        ans += k;
    }else{
        ll a_dis = a - 1;
        ans += a_dis; k-= a_dis; // 所持数をA枚まで持っていく
        if(k%2==0){
            ans += (b-a) *(k/2);
        }else{
            ans += (b-a) *(k/2) + 1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int sum_test_pnt(int n)
{
	int test;
	int sum = 0;
	int min_pnt = 100;
	
	while(n--) {
		cin >> test;
		
		sum += test;
		if(min_pnt > test) {
			min_pnt = test;
		}
	}
	
	return sum - min_pnt;
}

int main()
{
	int ans = sum_test_pnt(4);
	ans += sum_test_pnt(2);
	
	cout << ans << endl ;
	
	return 0;
}

Measured memory_bytes: 1160