akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

int main(void)
{
    ll n;
    cin >> n;
    priority_queue<ll, vector<ll>, greater<ll>> a;
    priority_queue<ll> b;
    vector<ll> vec(3 * n), left(n + 1), right(n + 1);
    rep(i, 0, 3 * n) cin >> vec[i];
    ll ans = INT64_MIN;
    rep(i, 0, n) a.push(vec[i]), b.push(vec[i + 2 * n]), left[0] += vec[i], right[0] += vec[i + 2 * n];
    rep(i, 0, n)
    {
        a.push(vec[i + n]);
        auto A = a.top();
        a.pop();
        left[i + 1] = left[i] + vec[i + n] - A;
        b.push(vec[2 * n - i - 1]);
        A = b.top();
        b.pop();
        right[i + 1] = right[i] + vec[2 * n - i - 1] - A;
    }
    rep(i, 0, n + 1) ans = max(ans, left[i] - right[n - i]);
    cout << ans << endl;
}

Measured memory_bytes: 9012
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define debug(x)  cerr << #x << " = " << x << endl
#define pb push_back
#define F first
#define S second
#define OK order_of_key
#define FO find_by_order
#define PI 3.14159265
#define nmax 100100
const ll inf = std::numeric_limits<ll>::max();
const int infint = std::numeric_limits<int>::max();
const ll mod = 1e9+7;
using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    string a,b,c;
    cin >> a >> b >> c;
    int ans = 0;
    fo(i,0,n){
        set<char> s;
        s.insert(a[i]);
        s.insert(b[i]);
        s.insert(c[i]);
        if(s.size() == 1) continue;
        if(s.size() == 2) ans++;
        else ans += 2;
    }
    cout << ans;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
# define MOD 1000000007
int dp[101][100001];
int util(int arr[], int n, int k, int i){
    if(i == n and k == 0) return 1;
    else if(k < 0 or i == n) return 0;
    if(dp[i][k] != -1) return dp[i][k]%MOD;
    dp[i][k] = (MOD + (util(arr, n, k, i+1) + util(arr, n, k-1, i))%MOD - util(arr, n, k-1-arr[i], i+1))%MOD;
    return dp[i][k];
}
int main() {
	int n, k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++){
	    cin>>arr[i];
	}
	memset(dp, -1, sizeof(dp));
	int res = util(arr, n, k, 0);
	cout<<res;
	return 0;
}

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

int main(){
  int N, K;
  string S;
  cin >> N >> K >> S;
  
  if(S[K-1] == 'A') S[K-1] = 'a';
  if(S[K-1] == 'B') S[K-1] = 'b';
  if(S[K-1] == 'C') S[K-1] = 'c';
  
  cout << S << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
typedef long long ll;
const ll N=100000000;
using namespace std;
ll x[N];
int main()
{
	ll ans=0;
	ll n,a,b;
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i];
		if(i!=1)
		{
			int d=x[i]-x[i-1];
			if(d*a<b)
				ans+=d*a;
			else ans+=b;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
d[5000],c;main(w,n,i,C,W,b){for(;scanf("%d%d",&w,&n),w;printf("Case %d:\n%d\n%d\n",++c,d[w],b))for(bzero(d,w*5);n--;)for(i=w+scanf("%d,%d",&C,&W);i-->W;b=d[i]-d[w]?b:i)d[i]=fmax(d[i],d[i-W]+C);}

Measured memory_bytes: 0
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 610000
ll n,m,k;
ll mem[N];
int a[N];
int calc(int x){
    bool flag=false;
    rep(i,n){
        if(x>=a[i]){
            if(mem[x-a[i]]!=-1){
                flag|=1-mem[x-a[i]];
            }
            else{
                flag|=(1-calc(x-a[i]));
            }
        }
    }
    return mem[x]=flag;
}
int main(){
    n=in();
    k=in();
    rep(i,n)a[i]=in();
    fill(mem,mem+k,-1);
    mem[0]=0;
    cout<<(calc(k)?"First":"Second");
}

Measured memory_bytes: 7040
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
m = {}
a.each do |x|
  if m[x]
    m[x] += 1
  else
    m[x] = 1
  end
end

m = m.sort_by { |_, v| v }


ret = 0

[0, m.size - k].max.times { |i|
  ret += m[i][1]
}

puts ret


Measured memory_bytes: 40960
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{

    int a, p;
    cin >> a >> p;
    cout << (a * 3 + p) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;

int main(){
    int N;
    cin >> N;
    if(N == 1){
        cout << "Hello World" << endl;
        return 0;
    }
    else{
        int a, b;
        cin >> a;
        cin >> b;
        cout << a+b << endl;
    }
    return 0;
}

Measured memory_bytes: 768
from sys import stdin

INF = int(1e10)
MOD = int(1e9 + 7)

def input():
    return stdin.readline()[:-1]

def main():
    from builtins import int, map
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A = [0] + A
    la = []
    now = 1
    visited = [False] * (N + 1)
    last = None
    while True:
        if visited[now]:
            last = now
            break
        la.append(now)
        visited[now] = True
        now = A[now]

    ans = None
    if len(la) > K:
        ans = la[K]
    else:
        period = len(la) - la.index(last)
        lai = la.index(last)
        if lai > 0:
            K -= lai
        rem = K % period
        ans = la[lai + rem]
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 96752
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> t(N+1);
  t[0] = 0;
  vector<int> x(N+1);
  vector<int> y(N+1);
  x[0] = 0;
  y[0] = 0;
  for(int i = 1; i <= N; i++){
    cin >> t[i] >> x[i] >> y[i];
  }
  int dt, dl;
  for(int i = 1; i <= N; i++){
    dt = t[i] - t[i-1];
    dl = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]);
    if(dl > dt) {
      cout << "No" << endl;
      return 0;
    }else if((dt-dl) % 2 == 0){
      continue;
    }else{
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>

#include <unordered_map>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <sstream>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll pow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = pow(N, P/2);
        return t*t;
    }
    return N * pow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    n=abs(n);
    m=abs(m);
    if(n*m==0)return max(n,m);
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
int main(){
    int n;cin>>n;
    set<string> memo;
    rep(i,n){
        string s;cin>>s;
        memo.insert(s);
    }
    cout<<memo.size()<<endl;

}

Measured memory_bytes: 19176
#include<bits/stdc++.h>
using namespace std;
int main(){
  int ans = 0, N, M, a, b;
  cin >> N >> M;
  vector<bool> view(N, 1);
  vector<int> H(N);
  vector<set<int>> road(N); 
  
  for(int i=0; i<N; i++) cin >> H.at(i);
  
  for(int i=0; i<M; i++){
    cin >> a >> b;
    if(!road.at(a-1).count(b)) road.at(a-1).insert(b);
    if(!road.at(b-1).count(a)) road.at(b-1).insert(a);
  }
  
  for(int i=0; i<N; i++){
    int h;
    h = H.at(i);
    for(auto j: road.at(i)){
      if(h > H.at(j-1)){
        view.at(i) = 1;
      }else{
        view.at(i) = 0;
        break;
      }
    }
  }
    
  for(int i=0; i<N; i++){
    if(view.at(i)){
      ans++;
    }
  }
  
  cout << ans << endl;
}

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

#define INF INT_MAX
#define ll long long

using namespace std;

int main(){
	ll n,x;
	cin >> n >> x;
	vector<ll> a(n,0);
	vector<ll> b(n,0);
	ll ans = 0;
	cin >> a[0];
	if(a[0] > x){
		ans += a[0] - x;
		a[0] = x;
	}
	for(int i = 1;i < n;i++){
		cin >> a[i];
		if(a[i] > x){
			ans += a[i] - x;
			a[i] = x;			
		}
		b[i-1] = a[i-1]+a[i];
	}
	for(int i = 0;i < n-1;i++){
		if(a[i] + a[i+1] > x){
			ans += a[i+1]+a[i] - x;
			a[i+1] = x - a[i];
		}
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define mod 1000000007
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);cout.tie(NULL);
	int n;
  	cin>>n;
  	int arr[n];
  	for(int i=0;i<n;i++)
  		  cin>>arr[i];
	int dp[n];
  dp[n-1]=arr[n-1];
  for(int i=n-2;i>=0;i--)
    dp[i]=dp[i+1]+arr[i];
  	int ans=0;
  	for(int i=0;i<n-1;i++)
    	ans+=(arr[i]*dp[i+1]);
  	cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    ll a; cin >> a;
    string s; cin >> s;
    ll b = (s[0]-'0');
    b = b*10 + (s[2]-'0');
    b = b*10 + (s[3]-'0');
    cout << a*b/100 << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    int T;
    // cin >> T;
    T = 1;

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

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> acc(n + 2);
  rep(i, m) {
    int l, r;
    cin >> l >> r;
    acc[l]++;
    acc[r + 1]--;
  }
  rep3(i, 1, n + 2) acc[i] += acc[i - 1];
  // cout << acc << endl;
  int ans = 0;
  rep(i, n + 2) if (acc[i] == m) ans++;
  cout << ans << endl;
}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	int n,k,i,j;
	scanf("%d %d",&n,&k);
	k--;
	string s;
	cin>>s;
	s[k] -= 'A';
	s[k] += 'a';
	cout<<s<<endl;
	return 0;
};

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

// THINGS TO REMEMBER
// ENDL is slow, '\n' is fast
// Clear everything (including graphs) between test cases
// use anti-anti-hash: https://codeforces.com/blog/entry/62393
// pb-ds: https://codeforces.com/blog/entry/11080
// check when to use LLONG_MAX/LLONG_MIN vs INT_MAX or INT_MIN
// You frequently suffer from confirmation bias - you trust your initial solution and miss simple things. 
// When you hit a roadblock, remember to rethink the solution ground up, not just try hacky fixes

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

    ll n;
    cin>>n;

    ll arr[n+1];
    for(int i=0;i<n+1;i++){
    	cin>>arr[i];
    }

    ll leftLeaves[n+1];
    leftLeaves[n]=arr[n];
    for(int i=n-1;i>=0;i--){
    	leftLeaves[i]=leftLeaves[i+1]+arr[i];
    }

    ll ans=0;
    ll curr=1;

    for(int i=0;i<=n;i++){
    	if(arr[i]>curr){
    		cout<<-1<<endl;
    		return 0;
    	}

    	ans+=curr;

    	curr-=arr[i];

    	if(i<n && curr<leftLeaves[i+1]){
    		curr=min(curr*2,leftLeaves[i+1]);
    	}

    }

    cout<<ans<<endl;

}

Measured memory_bytes: 5216
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();

        Set<String> hash_set = new HashSet<String>();
        
        for(int i=0;i<A;i++) {
        	String s = sc.next();
        	hash_set.add(s);
        }
        System.out.println(hash_set.size());
        

	}
}


Measured memory_bytes: 76876
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

bool p[101];
int main() {
  int X, N;
  cin >> X >> N;
  int a = 0;
  int res = 0;
  for (int i = 0; i < N; i++) {
    cin >> a;
    p[a] = true;
  }

  int low = X, h = X;
  for (; low >=0 && p[low]; low--);
  for (; h >=0 && p[h]; h++);
    
  if (h-X >= X-low) cout << low << endl;
  else cout << h << endl;
  return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define ll 				long long
#define ld 				long double
#define fastio 			ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) 		cerr<<#x<<" "<<x<<endl
#define cina(a,n) 		for(ll i = 0;i<n;i++)	cin>>a[i];
#define couta(a,n) 		for(ll i = 0;i<n;i++) cout<<a[i]<<" ";
#define fauto(ar)		for(auto x : ar)	cout<<x<<" ";
#define mod 			1000000007
#define siz 			105
#define f 				first
#define s 				second
#define pb 				push_back
#define endl 			"\n"
#define ci 				cin.ignore()
using namespace std;
struct nodes
{
	ll x,h;
};
bool cmp(nodes a,nodes b)
{
	return a.x < b.x;
}
ll getpos(nodes *node,ll n,ll start,ll value)
{
	ll end = n,mid,pos = start;
	while(start <= end)
	{
		mid = start + end >> 1;
		
		if(node[mid].x <= value)
		{
			pos = mid;
			start  = mid+1;
		}
		else
		end = mid-1;	
	}
	return pos;
	
}
void update(ll *bit,ll n,ll ind,ll value)
{
	for(;ind <= n;ind += ind&-ind)
	bit[ind] += value;
}
ll query(ll *bit,ll ind)
{
	ll res = 0;
	for(;ind >= 1;ind -= ind&-ind)
	res += bit[ind];
	return res;
}
int main()
{
	ll n,d,a,i,j,right;
	cin>>n>>d>>a;
	
	nodes node[n];
	for(i = 0;i<n;i++)
	cin>>node[i].x>>node[i].h;
	
	sort(node,node+n,cmp);
	
	ll bit[n+4];
	memset(bit,0,sizeof(bit));
	
	ll ans = 0,curr;
	for(i = 0;i<n;i++)
	{
		update(bit,n,i+1,node[i].h);
		update(bit,n,i+2,node[i].h*-1);
//		cout<<i+1<<" "<<query(bit,i+1)<<endl;
	}
	for(i = 0;i<n;i++)
	{
		right = getpos(node,n,i,node[i].x+2*d);
		
		curr = query(bit,i+1);
		if(curr < 0)
		curr = 0;
		// get the ans;
		
		
		if(curr%a)
		{
			curr = curr/a;
			curr++;	
		}	
		else
		curr /= a;
		
		ans += curr;
		
		update(bit,n,i+1,curr*-a);
		update(bit,n,right+2,curr*a);
		
//		cerr<<"\n"<<i+1<<" -> ";
//		
//		for(j = 0;j<n;j++)
//		cerr<<query(bit,j+1)<<" ";		
		
	}
	
	cout<<ans;
	
	
	
	
	
}

Measured memory_bytes: 4992
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
A = get_ints
B = get_ints
C = get_ints

sum = 0
last = nil
A.each do |a|
  i = a - 1
  sum += B[i]
  sum += C[last-1] if a - 1 == last

  last = a
end

puts sum


Measured memory_bytes: 14500
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール
// Union-Find モジュール
struct union_find {
    vector<ull> par;
    vector<ull> num;
    union_find(ull n) : par(n, 0), num(n, 1) { iota(ALL_OF(par), 0); }
    ull root(ull i) { return par[i] == i ? i : (par[i] = root(par[i])); }
    bool same(ull i, ull j) { return root(i) == root(j); }
    void unite(ull i, ull j) {
        ull ri = root(i);
        ull rj = root(j);
        if (ri != rj) {
            if (num[ri] > num[rj]) swap(ri, rj);
            par[ri] = rj;
            num[rj] += num[ri];
        }
    }
};

// 処理内容
int main() {
    
    ll n; cin >> n;
    vector<ll> x(n), y(n);
    REP(i, n) {
        cin >> x[i] >> y[i];
        --x[i];
        --y[i];
    }

    constexpr ll m = 100000;
    union_find uf(m * 2);
    REP(i, n) {
        ll u = x[i];
        ll v = y[i] + m;
        uf.unite(u, v);
    }
    REP(i, m*2) uf.root(i); // 根につなぎなおす

    vector<ull> unquf = uf.par;
    UNIQUE(unquf);
    ll unqsz = unquf.size();
    map<ll, ll> sahzuf;
    REP(i, unquf.size()) sahzuf[unquf[i]] = i;

    vector<ll> en(unqsz, 0);
    vector<ll> xn(unqsz, 0);
    vector<ll> yn(unqsz, 0);
    REP(i, n) {
        ll p = sahzuf[uf.par[x[i]]];
        ++en[p];
    }
    REP(i, m) {
        ++xn[sahzuf[uf.par[i]]];
        ++yn[sahzuf[uf.par[i+m]]];
    }

    ll ans = 0;
    REP(i, unqsz) {
        ll cplt = xn[i] * yn[i];
        ll curr = en[i];
        ans += cplt - curr;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 23680
import java.util.Scanner;
 public class Main {
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
       int N = scanner.nextInt();
       int D = scanner.nextInt();
      
      int a =N/(D*2+1);
      
      if(N>D && N%(D*2+1)!=0){
       System.out.println(a+1);
      }
      else if(N>D && N%(D*2+1)==0){
      System.out.println(a);
    }
      else if(N<=D){
      System.out.println("1");
      }
      else if(a<=0){
       System.out.println("1");
      }
 }
}

Measured memory_bytes: 21972
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{ min, max };

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let m: usize = sc.cin();
    let xs: Vec<usize> = (0..n).map(|_| sc.cin()).collect();
    let ys: Vec<usize> = (0..m).map(|_| sc.cin()).collect();

    let mut memo: Vec<Vec<usize>> = vec![vec![0; m]; n];
    let mut acc: Vec<Vec<usize>> = vec![vec![0; m]; n];

    for i in 0..n {
        for j in 0..m {
            if i == 0 || j == 0 {
                memo[i][j] = if xs[i] == ys[j] { 1 } else { 0 };
                if i == 0 && j == 0 {
                    acc[0][0] = memo[0][0];
                } else if i == 0 {
                    acc[0][j] = (acc[0][j-1] + memo[0][j]) % M;
                } else {
                    acc[i][0] = (acc[i-1][0] + memo[i][0]) % M;
                }
            } else {
                if xs[i] == ys[j] {
                    memo[i][j] = (acc[i-1][j-1] + 1) % M;
                    acc[i][j] =
                        (((acc[i-1][j] + acc[i][j-1]) % M + M - acc[i-1][j-1]) % M + memo[i][j]) % M;
                } else {
                    memo[i][j] = 0;
                    acc[i][j] = ((acc[i-1][j] + acc[i][j-1]) % M + M - acc[i-1][j-1]) % M;
                }
            }
        }
        // trace!(&memo[i]);
    }
    put!(acc[n-1][m-1] + 1);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 86268
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

#include <bits/stdc++.h>

using namespace std;

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

	int n, k;
	cin >> n >> k;
	int ans = 0;
	while (n--) {
		int h;
		cin >> h;
		if (h >= k) ans++;
	}
	cout << ans << endl;
}

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



namespace CSharpSample01
{

    
    class Program
    {

        
        static void Main(string[] args)
        {
            //入力1(N, K)
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int K = int.Parse(input[1]);

            //入力2(V)
            long[] V = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

            long ans = 0;

            //操作A:a回
            //操作B:b回
            //a+b <= min(K, N) を満たす回数行い、
            //残った操作回数 K-(a+b) 回まで捨てる操作を行う(行わなくてもいい)
            for(int a = 0; a <= Math.Min(K, N); a++)
            {
                for(int b = 0; a + b <= Math.Min(N, K); b++)
                {
                    long sum = 0;
                    List<long> bag = new List<long>();

                    //a回右から取る(右端0からi個目)
                    for (int i = 0; i < a; i++)
                    {
                        sum += V[i];
                        bag.Add(V[i]);
                    }
                    //b回左から取る(左端N-1からi個目)
                    for (int i = 0; i < b; i++)
                    {
                        sum += V[N - 1 - i];
                        bag.Add(V[N - 1 - i]);
                    }

                    //負の価値を捨てるために昇順ソート
                    bag = bag.OrderBy(x => x).ToList();

                    // K - (a + b) 回までbagから負の価値を捨てる操作を行う
                    //リストの範囲を超えない回数まで
                    for(int i = 0; i < Math.Min(K - (a + b), bag.Count); i++)
                    {
                        if (bag[i] < 0) sum -= bag[i];
                    }

                    //ansの更新
                    ans = Math.Max(ans, sum);
                }
            }

            Console.WriteLine(ans);

        }
    }

}

Measured memory_bytes: 15444
#include<bits/stdc++.h>
using namespace std;
long long int sum(long long int k)
{
  int sums=0;
  while(k!=0)
  {
	sums+=(k%10);
    k/=10;
  }
  return sums;
}
int main()
{
  long long int n;
  cin>>n;
  if(n%sum(n)==0)
    cout<<"Yes";
  else
    cout<<"No";
}

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

int dp[1000][8];//??\??°???????????¶???(?????????J,O,I)
char a[1000];//??¬??????(0=J,1=O,2=I)
int main(){
	memset(dp, 0, sizeof(dp));
	int n;
	scanf("%d%s", &n, a);
	for (int i = 0; i < n; i++){
		switch (a[i]){
		case 'J':
			a[i] = 0;
			break;
		case 'O':
			a[i] = 1;
			break;
		case 'I':
			a[i] = 2;
			break;
		}
	}
	for (int i = 0; i < 8; i++){
		if (i & 1 && i >> a[0] & 1)dp[0][i] = 1;
	}
	for (int i = 1; i < n; i++){
		for (int j = 0; j < 8; j++){//?????\
			for (int t = 0; t < 8; t++){//?????\
				if (j&t&&t >> a[i] & 1){
					dp[i][t] += dp[i - 1][j] %= 10007;
				}
			}
		}
	}
	int sum = 0;
	for (int i = 0; i < 8; i++){
		sum += dp[n - 1][i] %= 10007;
	}
	sum %= 10007;
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 1068
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc149/tasks/abc149_e
//ポイント：A[i]+A[j]を降順に並べた時、M番目にくる数は選んだ数の最小値

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,M;
LL A[100000];
 
LL ans = 0;

void solve(){
    sort(A,A+N,greater<LL>());//降順にソート

    //二部探索
    //A[s]+A[t]を全部列挙して降順に並べる場合を考える。
    //この時上からM個とっていくことになるが、
    //M番目の数をXとした時、X未満の数は絶対取られない
    //すなわちXはとった数の最小値となる。これをまず求める

    LL left = 0;//ギリギリOKなやつ
    LL right = INF;//ギリギリダメなやつ
    while(left+1<right){
        LL x = (left+right)/2;//このxがOKなやつなのかを判定する
 
        bool ok = [&]{//xより大きい(A[s]+A[t])がM個未満なのかどうかを返す
            LL total = 0;//xより大きい数がいくつあるかを格納
            for(int i=0;i<N;i++){//Aを順に一個ずつ見ていく
                int l = -1;//条件を満たす数が一個もなければ-1、全部条件を満たすならN-1になる
                int r = N;
                //二部探索
                while(l+1<r){
                    int c = (l+r)/2;
                    if(A[c]+A[i]>x) l = c;
                    else r = c;
                }
                //A[i]となんかを足した時、x以上となるペアはr組ある
                total += r;//結局、考えられるペアはr通り
            }
            return total<M;
        }();
 
        if(ok) right = x;//xより大きい数がM個未満
        else left = x;//xより大きい数がM個以上
    }
    //この時点でleft = X(A[s]+A[t]を全部列挙して降順に並べた時、上からM番目の数)となる
 
    LL sum_A[100000];//A[0] ~ A[i]の和をsum_A[i]とおく
    int ind[100000];//A[i]とペアを作る数値の数をind[i]とおく
    sum_A[0] = A[0];
    for(int i=1;i<N;i++){
        sum_A[i] = sum_A[i-1] + A[i];
    }
 
    LL okline = left+1;//okline未満の数は候補外 (A[s]+A[t]を降順に並べた時、そのM番目がleftに格納されている数と同じ値を持つ)
    for(int i=0;i<N;i++){//Aを順に一個ずつ見ていく
        int l = -1;//条件を満たす数が一個もなければ-1、全部条件を満たすならN-1になる
        int r = N;
        //二部探索
        while(l+1<r){
            int c = (l+r)/2;
            if(A[c]+A[i]>okline) l = c;
            else r = c;
        }
        //結局、考えられるペアはr通り
        ind[i] = r;
        if(r>0){
            ans += r*A[i]+sum_A[r-1];
        }
    }
 
    LL sum_of_ind = 0;
    for(int i=0;i<N;i++){
        sum_of_ind += ind[i];
    }
    for(LL i=0;i<(M-sum_of_ind);i++){
        ans += okline;
    }
}
 
int main(){
    cin >> N >> M;
    for(int i=0;i<N;i++) cin >> A[i];
 
    solve();
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int N, A, B;
    cin >> N >> A >> B;

    bool f = true;
    while (f == true){
        if (A != B - 1){
            A ++;
        }else{
            A --;
            if (A == 0){
                cout << "Borys" << endl;
                break;
            }
        }

        if (B != A + 1){
            B --;
        }else{
            B++;
            if (B == N + 1){
                cout << "Alice" << endl;
                break;
            }    
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 100005

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

void make()
{
	fac[0] = fac[1] = 1;
	inv[1] = 1;
	finv[1] = finv[0] = 1;
	for(int i = 2; i < N; ++i)
	{
		fac[i] = i * fac[i - 1] % MOD;
		inv[i] = MOD - MOD/i * inv[MOD % i] % MOD;
		finv[i] = inv[i] * finv[i - 1] % MOD;
	}
}

ll C(ll n, ll k)
{
	if(n < k || n < 0) return 0;
	return fac[n] * finv[n - k] % MOD* finv[k] % MOD;
}

ll gcd(ll a, ll b)
{
	if(b == 0)
		return a;
	return gcd(b, a % b);
}
#define N 100005
int n, k;
int a[N][3];
int dp[N][3];
int dpf(int i, int j)
{
	if(i == n)
		return 0;
	if(dp[i][j] >= 0)
		return dp[i][j];
	for (int h = 0; h < 3; ++h)
	{
		if(h != j)
		dp[i][j] = max(dp[i][j], a[i][h] + dpf(i + 1, h));
	}
	return dp[i][j];
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i][0] >> a[i][1] >> a[i][2];
		for (int j = 0; j < 3; ++j)
		{
			dp[i][j] = -1;
		}
	}
	for (int i = 0; i < 3; ++i)
	{
		dp[0][i] = a[0][i];
	}
	for(int i = 1; i < n; ++i)
	{
		// dp[i][0] = max(a[i][1] + dp[i-1][0], a[i][2] + dp[i - 1][0]);
		// dp[i][1] = max(a[i][0] + dp[i-1][1], a[i][2] + dp[i - 1][1]);
		// dp[i][2] = max(a[i][1] + dp[i-1][2], a[i][0] + dp[i - 1][2]);

		dp[i][0] = a[i][0] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = a[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = a[i][2] + max(dp[i-1][0], dp[i-1][1]);
	}
	int ans = *max_element(dp[n-1], dp[n-1] + 3);
	cout << ans << "\n";	
	return 0;
}

Measured memory_bytes: 4352
# vim: ft=ruby

class Solver
  def prepare
    @d = gets.to_i
    @cs = gets.split(" ").map(&:to_i)
    @mans = []  # mans[date][contest]

    @last = [0] * 26

    @d.times do
      @mans << gets.split(" ").map(&:to_i)
    end
  end

  # ----------- #

  def score(contest_id, date)
    @mans[date][contest_id]
  end

  def decrease_per_contest(contest_id, date)
    @cs[contest_id] * (date - @last[contest_id])
  end

  def decrease_all(date)
    (0..25).map do |contest_id|
      decrease_per_contest(contest_id, date)
    end.sum
  end


  # TOOLS

  def evaluate(ts)
    res = 0
    ts.each.with_index do |t, d|  # d = date
      t -= 1
      res += score(t, d)
      @last[t] = d+1
      res -= decrease_all(d+1)
    end
    res
  end

  def random_contest
    (0..25).to_a.sample
  end

  def random_pattern
    @d.times.map { random_contest }
  end

  def uniform_pattern
    ((0..25).to_a * 20)[0, @d]
  end

  def pretty_good_pattern
    @d.times.map do |d|
      @mans[d].each_with_index.max[1]
    end
  end

  def print_result(pattern)
    pattern.each do |p|
      puts p+1
    end
  end

  def elapsed_time
    # time_now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
    time_now = Time.now
    time_now - $time_start
  end

  ALPHA = 0.6
  MAX_TIME = 2
  def temperature(elapsed_time)
    r = elapsed_time / MAX_TIME
    ALPHA ** r
  end

  def probability(e_prev, e_next, elapsed_time)
    # t = temperature

    if e_next > e_prev
      # if e_next is better, always move
      1
    else
      # temperature
      remaining_time = MAX_TIME - elapsed_time
      (remaining_time / MAX_TIME) ** 2
      # Math.exp((e_prev - e_next) / t)
    end
  end

  # TOOLS END

  def change_randomly(pattern)
    pattern = pattern.dup
    pos = random_contest
    pattern[pos] = random_contest
    pattern
  end

  def swap_randomly(pattern)
    pattern = pattern.dup
    pos = rand(@d-1)
    c = pattern[pos]
    pattern[pos] = pattern[pos+1]
    pattern[pos+1] = c
    pattern
  end

  def solve
    pattern = pretty_good_pattern
    e = evaluate(pattern)

    count = 0
    movecount = 0
    et = elapsed_time

    # namasu
    # loop do
    #   if count % 10 == 0
    #     et = elapsed_time
    #   end
    #   count += 1

    #   break if et > 1.87
    #   new_pattern = swap_randomly(pattern)
    #   e_next = evaluate(new_pattern)

    #   r = rand
    #   if r < probability(e, e_next, et)
    #     movecount += 1
    #     pattern = new_pattern
    #     e = e_next
    #   end
    # end

    # end namasu

    if ENV['DEBUG']
      STDERR.puts movecount
      STDERR.puts count
    end

    print_result(pattern)
  end

end

# $time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
$time_start = Time.now
solver = Solver.new
solver.prepare
solver.solve


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

int main()
{
    int a, b;
    double aa, bb;
    cin >> a >> b;
    aa = static_cast<double>(a);
    bb = static_cast<double>(b);

    int ans1 = a / b;
    int ans2 = a % b;
    double ans3 = aa / bb;

    cout << ans1 << " " << ans2 << " " << std::fixed << std::setprecision(5) << ans3 << endl;
}



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


void solve()
{
	
	int h,w,k;
	cin>>h>>w>>k;

	//cout<<h<<" "<<w<<" "<<k<<endl;

	int ans = 0;

	char mat[h][w];

	for(int i = 0;i<h;i++)
	{
		for(int j = 0;j<w;j++)
		{
			cin>>mat[i][j];
		}
	}

	// for(int i = 0;i<h;i++)
	// {
	// 	for(int j = 0;i<w;j++)
	// 	{
	// 		cout<<mat[i][j]<<" ";
	// 	}

	// 	cout<<endl;
	// }

	for(int maskr = 0;maskr <= (1<<h) - 1;maskr++)
	{
		for(int maskc = 0;maskc <= (1<<w) - 1;maskc++)
		{
			int black = 0;

			for(int i = 0;i<h;i++)
			{
				for(int j = 0;j<w;j++)
				{
					if((((maskr >> i) & 1) == 0) && (((maskc >> j) & 1) == 0) && mat[i][j] == '#')
					{
						black++;
					}
				}
			}

			if(black == k)
			{
				ans++;
			}
		}
	}

	cout<<ans<<endl;

}

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

	solve();

	return 0;
} 

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	string n;
	int a[8];
	cin >> n;
	int t = 0;
	int b = 0;
	rep(i, n.size()) {
		a[i] = (int)(n[i] - '0');
		b += a[i] * (int)pow(10, n.size() - i-1);
		t += a[i];
	}
	int ans = b % t;
	if (!ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod 1000000007
#define pb emplace_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#ifndef ONLINE_JUDGE
#define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";}
template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);}
#else
#define pr(...){}
#define debarr(a,n){}
#define debmat(mat,row,col){}
#endif
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
bitset < 4000005 > bit;
signed main()
{
    fast;
    ll n,x;
    cin>>n;
    ll s = 1;
    bit.set(0);
    fr(i,n)cin>>x,s+=x,bit|=bit<<x;
    s/=2;
    rep(i,s,s*2+5){
        if(bit[i]){
            cout<<i;
            return 0;
        }
    }
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
int main()
{
	long i,n,s=0,a[334334];
	cin>>n;
	n*=3;
	for(i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	n/=3;
	for(i=0;i<n;i++)s+=a[n*3-2-i*2];
	cout<<s<<endl;
}

Measured memory_bytes: 2560
# -*- coding: utf-8 -*-
"""
Set - Set: Delete
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_7_B&lang=jp

"""
s = set()
for _ in range(int(input())):
    q, x = input().split()
    if q == '0':
        s.add(x)
        print(len(s))
    elif q == '1':
        print(int(x in s))
    else:
        s.discard(x)
        


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

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

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

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

    vector<int> a(n);
    REP(i, n) cin >> a[i];
    ll ans = 1;

    REP(i, n) ans *= 3;
    ll tmp = 1;
    REP(i, n) {
        if(a[i] % 2 == 0) {
            tmp *= 2;
        } else {

        }
    }

    cout << ans - tmp << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const int vx[]={1,0,-1,0}, vy[]={0,1,0,-1};
const int sqrtN = 512;
const int logN = 32;
const ll LINF=1e18;
const ld PI=abs(acos(-1));

int main(){
	int n, k; cin >> n >> k; k /= 1000;
	
	REP(i, 0, 2001){
		REP(j, 0, 2001){
			int pos = k - 10 * i - 5 * j;
			if(pos < 0) continue;
			if(i + j + pos != n) continue;
			cout << i << " " << j << " " << pos << endl;
			return 0;
		}
	}
	
	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N; cin >> N;
  vector<ll> A(N); REP(i, N) cin >> A[i];
  ll mon = 1000; ll kabu = 0;
  REP(i, N - 1) {
    if(A[i] < A[i + 1] && mon >= A[i]) {
      kabu = mon / A[i];
      mon = mon % A[i];
    } else if(A[i] > A[i + 1] && kabu != 0) {
      mon = mon + (kabu * A[i]);
      kabu = 0;
    }

    if(i == N - 2) {
      if(A[i] <= A[N - 1]) {
        if(kabu == 0) continue;
        mon = mon + (kabu * A[N - 1]);
      } else if(A[i] > A[N - 1]) {
        if(kabu == 0) continue;
        mon = mon + (kabu * A[i]);
      }
    }
  }
  cout << mon << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N],b[N],c[N*3],nex[N*3];
int main() {
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    for(int i=0;i<n;i++) scanf("%d",&b[i]);
    for(int i=0;i<n;i++) {
        c[i]=a[i]^a[(i+1)%n];
        c[i+n]=c[i+2*n]=b[i]^b[(i+1)%n];
    }
    nex[0]=c[n]=-1;
    int j=-1;
    for(int i=0;i<3*n;i++) {
        while(j>=0&&c[i]!=c[j]) j=nex[j];
        nex[i+1]=++j;
    }
    for(int i=0;i<n;i++) {
        if(nex[3*n-i]==n) {
            printf("%d %d\n",i,a[i]^b[0]);
        }
    }
    return 0;
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;

ll ans[100009];
int main()
{

   ll n,k,q;
   cin>>n>>k>>q;
   ll Q = q;
   while(q--)
   {
       ll a;
       cin>>a;
       ans[a]++;
   }


   for(int i=1;i<=n;i++)
   {
       ll temp = Q-ans[i];

       if(k-temp>0)
          cout<<"Yes"<<endl;
       else
          cout<<"No"<<endl;
   }



    return 0;
}


Measured memory_bytes: 4380