akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> book[12];
  for(int i=0;i<n;i++){
    int a,b; cin >> a >> b;
    book[b-1].push_back(a);
  }
  int dp[2010];
  memset(dp,-1,sizeof(dp));
  dp[0] = 0;
  for(int i=0;i<10;i++){
    sort(book[i].begin(),book[i].end(),greater<int>() );
    for(int j=k-1;j>=0;j--){
      if(dp[j] == -1) continue;
      int sum = 0;
      for(int l=0;l<book[i].size() && j + l + 1 <= k;l++){
	sum += book[i][l];
	dp[j+l+1] = max(dp[j+l+1],dp[j] + sum + (l + 1) * l);
      }
    }
  }
  cout << dp[k] << endl;
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  ll a, b, c; cin >> a >> b >> c;
  fin(b-a==c-b?"YES":"NO")
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()] 
b = [int(i) for i in input().split()] 
c = [int(i) for i in input().split()] 

satify = 0

for i in range(len(a)):
    if i == 0 or a[i-1] == n or a[i]-1 != a[i-1]:
        satify += b[a[i]-1]
    else:
        satify += b[a[i]-1] + c[a[i-1]-1]
        
print(satify)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

const int TR = 200002;
int sm[TR], tt[TR];

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

  int N, TC; cin >> N >> TC;
  int S[N], T[N], C[N];
  rep(i, N) {
    cin >> S[i] >> T[i] >> C[i];
  }

  rep1(c, TC) {
    rep(i, TR) tt[i] = 0;
    rep(i, N) {
      if(C[i] == c) {
        tt[S[i] * 2 - 1]++;
        tt[T[i] * 2]--;
      }
    }
    rep1(i, TR-1) {
      tt[i] += tt[i - 1];
    }
    rep(i, TR) {
      if(tt[i] > 0) sm[i]++;
    }
  }

  int ans = 0;
  rep(i, TR) {
    ans = max(ans, sm[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 2944
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    long x = sc.nextLong();
    long tmp = 100;
    long ans = 0;

    while(tmp < x){
      tmp *= 1.01;
      ans += 1;
    }

    System.out.println(ans);
  }
}


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

string s, t, bf="";
int ans;
int main() {
	cin >> s;
	for(int i=0; i<s.size(); ) {
		t = s[i];
		if(t != bf) {
			ans++;
			i++;
		} else if(s[i+1]) {
			t += s[i+1];
			ans++;
			i += 2;
		} else break;
		bf = t;
	}
	cout << ans;
	return 0;
}


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

    vector<vector<char>> vvcd(h+2, vector<char>(w+2));
 
    rep(i,h){
        rep(j,w){
            cin >> vvcd.at(i+1).at(j+1);
        } 
    }



    rep(i,h+2){
        rep(j,w+2){
            if(vvcd.at(i).at(j) == '#'){
                
                bool jd = false;
                if(vvcd.at(i  ).at(j-1) == '#') jd = true;
                if(vvcd.at(i-1).at(j  ) == '#') jd = true;
                if(vvcd.at(i+1).at(j  ) == '#') jd = true;
                if(vvcd.at(i  ).at(j+1) == '#') jd = true;
                                
                if(jd == false){
                    cout << "No" << endl;
                    return 0;
                }else{
                    //cout << i << " " << j << " " << endl;
                }
            }
        } 
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  int sum = 0;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  sort(vec.rbegin(),vec.rend());
  bool flag = true;
  for(int i=0; i<M; i++){
    if(vec.at(i)*4*M < sum){
      flag = false;
    }
  }
  
  if(flag){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int R,G,B,N;
  cin >>R>>G>>B>>N;
  int ans=0;
  
 for(int i=0;i<=N;i+=R){
 for(int j=0;i+j<=N;j+=G){
   int a=N-(i+j);
   
   if(a%B==0){if(a>=0){ans++;}} 
 }
 }
  
  cout <<ans<<endl;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long a, long long b, long long c, long long d){
    if(abs(a-c)<=d) {
        cout << YES << endl;
        return;
    }
    if(abs(a-b)<=d && abs(c-b)<= d){
        cout << YES << endl;
        return;
    }
    cout << NO << endl;
}

int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long c;
    scanf("%lld",&c);
    long long d;
    scanf("%lld",&d);
    solve(a, b, c, d);
    return 0;
}


Measured memory_bytes: 256
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    a = ni()
    b = ni()
    c = ni()
    d = ni()

    print(min(a, b) + min(c, d))


if __name__ == '__main__':
    main()

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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n, q;
    cin >> n >> q;
    Graph g(n);
    REP(i, n - 1) {
        ll a, b;
        cin >> a >> b;
        add_edge(g, --a, --b, 1, true, 1);
    }

    Array a(n, 0);
    REP(_, q) {
        ll p, x;
        cin >> p >> x;
        p--;
        a[p] += x;
    }

    auto dfs = [&](auto &&self, int v, int p) -> void {
        for(auto e : g[v]) {
            if(e.to == p)
                continue;
            a[e.to] += a[v];
            self(self, e.to, v);
        }
    };

    dfs(dfs, 0, -1);

    for(auto i : a)
        cout << i << " ";
    cout << en;
}

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

    solve();

    /*
    ll t;
    cin >> t;
    REP(i, t) { solve();}
    */

    return 0;
}


Measured memory_bytes: 42244
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e10
#define Length 80000
using namespace std;
typedef pair<ll, ll> P;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

bool used[110];

bool cmp(const pair<int,int> &a,const pair<int,int> &b) {
	return a.first * a.first + a.second * a.second > b.first*b.first + b.second * b.second;
}

void solve(int n) {
	vector<pair<int, int>>p(n), q(n);
	for (int i = 0;i < n;i++) {
		cin >> p[i].first >> p[i].second;
	}
	for (int i = 0;i < n;i++) {
		cin >> q[i].first >> q[i].second;
	}
	int dist = Length, flag = 0;
	int ans = 0;
	sort(p.begin(), p.end());
	for (int i = 0;i < n;i++) {
		dist = Length;
		flag = 0;
		for (int j = 0;j < n;j++) {
			if (!used[j]) {
				int x = q[j].first - p[i].first;
				int y = q[j].second - p[i].second;
				if ((x > 0) && (y > 0) && y < dist) {
					dist = y;
					flag = j;
				}
			}
		}
		if (dist < Length) {
			ans++;
			used[flag] = true;
		}
	}
	cout << ans << endl;
}

ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

ll Q[110];
	
int main(void){
	ll a, b, c, x, y, ans = 1000000000000000;
	cin >> a >> b >> c >> x >> y;
	for (ll i = 0;i <= 100000;i++) {
		ll A = max(a*(x - i), (ll)0);
		ll B = max(b*(y - i), (ll)0);
		ll C = 2 * c*i;
		ans = min(ans, A + B + C);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    private static int n1(char ch){
        if (ch > 'a')
            return 'z' - ch + 1;
        else
            return 0;
    }

    private static char n2(char ch, int offset){
        if (ch + offset > 'z')
            return (char)(ch + offset - 26);
        else
            return (char)(ch + offset);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        StringBuffer sb=new StringBuffer(str);
        int n = sc.nextInt();
        int i;
        for (i = 0; i < str.length() -1; i++){
            if (n >= n1(str.charAt(i))){
                n -= n1(str.charAt(i));
                sb.setCharAt(i, 'a');
            } else {
                continue;
            }
        }
        int tmp = n % 26;
        char last = str.charAt(str.length()-1);
        sb.setCharAt(str.length()-1, n2(last, tmp));


        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 14028
#include<iostream>
#include<string>
#include<queue>
#include<utility>
using namespace std;

typedef pair<int,int> P;
const int INF=100000000;

int H,W;
int s[50][50];
int d[50][50];
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};


int bfs(){
    for(int i=0;i<H;i++)
        for(int j=0;j<W;j++) d[i][j]=INF;
    queue<P> que;
    que.push(P(0,0));
    d[0][0]=0;

    while(que.size()){
        P p=que.front();que.pop();
        if(p.first==H-1&&p.second==W-1) return d[H-1][W-1];

        for(int i=0;i<4;i++){
            int nx=p.first+dx[i],ny=p.second+dy[i];
            if(0<=nx&&nx<H&&0<=ny&&ny<W&&d[nx][ny]==INF&&s[nx][ny]!='#'){
                d[nx][ny]=d[p.first][p.second]+1;
                que.push(P(nx,ny));
            }
        }
    }
    return false;
}



int main(){
    
    cin>>H>>W;
    int bcnt=0;
    
    for(int i=0;i<H;i++){
        string S;
        cin>>S;
        for(int j=0;j<W;j++){
            s[i][j]=S[j];
            if(s[i][j]=='#') bcnt++;
        }
    }
    int BFS=bfs();
    if(BFS==0) cout<<-1<<endl;
    else cout<<W*H-bcnt-BFS-1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n, q;
	cin >> n >> q;
	vector<vector<ll>> nx(n, vector<ll>(0));
	for (ll i = 0; i < n - 1; i++) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		nx[a].push_back(b);
		nx[b].push_back(a);
	}
	vector<ll> p(q), x(q), cnt(n, 0);
	for (ll i = 0; i < q; i++) {
		cin >> p[i] >> x[i];
		p[i]--;
		cnt[p[i]] += x[i];
	}

	queue<ll> task;
	task.push(0);
	vector<bool> seen(n, false);
	seen[0] = true;
	while (task.size()) {
		ll x = task.front();
		task.pop();
		for (ll i = 0; i < nx[x].size(); i++) {
			if (!seen[nx[x][i]]) {
				cnt[nx[x][i]] += cnt[x];
				task.push(nx[x][i]);
				seen[nx[x][i]] = true;
			}
		}
	}

	for (ll i = 0; i < n - 1; i++) cout << cnt[i] << " ";
	cout << cnt.back() << endl;
}


Measured memory_bytes: 21104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (isPrime(scanner.nextInt())) {
				count++;
			}
		}
		System.out.println(count);
	}

	static boolean isPrime(int x) {
		if (x == 2) {
			return true;
		}
		if ((x < 2) || (x % 2 == 0)) {
			return false;
		}
		for (int i = 3; i <= Math.sqrt(x); i+=2) {
			if (x % i == 0) {
				return false;
			}
		}
		return true;
	}

}



Measured memory_bytes: 43288
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF = 0x3f3f3f3f
#define mod  1e9 +7
#define maxn  1000005
ll n,k;
ll a[maxn];
ll check(ll x){
    ll res=0;
    for(int i=0;i<n;i++){
        if(a[i]<0){
            ll l=i,r=n;
            while(r-l>1){
                ll mid=(l+r)>>1;
                if(a[i]*a[mid]<=x){
                    r=mid;
                }else{
                    l=mid;
                }
            }
            res+=n-r;
        }else{
            ll l=i,r=n;
            while(r-l>1){
                ll mid=(l+r)>>1;
                if(a[i]*a[mid]<=x){
                    l=mid;
                }else{
                    r=mid;
                }
            }
            res+=l-i;
        }
    }
    return res;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    ll l=-1e18,r=1e18;
    while(r-l>1){
        ll mid=(l+r)>>1;
        if(check(mid)<k){
            l=mid;
        }else{
            r=mid;
        }
    }
    cout<<r;
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	int n;
	string s;
	cin >> n >> s;

	string sub = s.substr(s.length() / 2);
	cout << (s == sub + sub ? "Yes" : "No");
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define printP(x) "(" << (x).first << ", " << (x).second << ")"
#define mod 998244353
using namespace std;
typedef pair<llint, llint> P;
typedef pair<llint, P> E;

llint n;
llint a[200005];
llint b[1000005];
bool prime[1000005];
vector<llint> pvec;

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		b[a[i]] += a[i], b[a[i]] %= mod;
	}
	
	for(int i = 2; i < 1005; i++){
		if(prime[i]) continue;
		for(int j = 2*i; j < 1000005; j+=i) prime[j] = true;
	}
	for(int i = 2; i < 1000005; i++){
		if(!prime[i]) pvec.push_back(i);
	}
	
	for(int i = 0; i < pvec.size(); i++){
		llint p = pvec[i];
		for(int i = 1000004/p; i >= 1; i--){
			b[i] += b[i*p], b[i] %= mod;
		}
	}
	
	for(int i = 1; i < 1000005; i++) b[i] *= b[i], b[i] %= mod;
	
	for(int i = 0; i < pvec.size(); i++){
		llint p = pvec[i];
		for(int i = 1; i <= 1000004/p; i++) {
			b[i] += mod-b[i*p], b[i] %= mod;
		}
	}
	
	llint ans = 0;
	for(int i = 1; i < 1000005; i++) ans += b[i] * modpow(i, mod-2) % mod, ans %= mod;
	for(int i = 1; i <= n; i++) ans += mod - a[i], ans %= mod;
	ans *= modpow(2, mod-2), ans %= mod;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 11768
//
#include <atcoder/fenwicktree>
#include <atcoder/segtree>
#include <atcoder/lazysegtree>
#include <atcoder/string>
#include <atcoder/math>
#include <atcoder/convolution>
#include <atcoder/modint>
#include <atcoder/dsu>
#include <atcoder/maxflow>
#include <atcoder/mincostflow>
#include <atcoder/scc>
#include <atcoder/twosat>
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline void reverse(Type& arr) { reverse(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1000000007L;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
using P = pair<ll, ll>;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    atcoder::dsu d(N);
    rep(i, M)
    {
        ll A, B;
        cin >> A >> B;
        --A;
        --B;
        d.merge(A, B);
    }
    cout << d.groups().size() - 1;
    return 0;
}

Measured memory_bytes: 8608
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n;
  set<string> st;
  rep(i, n) {
    cin >> s;
    st.insert(s);
  }
  Cout(Size(st));
  return 0;
}

Measured memory_bytes: 19180
#include<iostream>
#include<string>
#define ll long long
using namespace std;

bool isprime(int n)
{
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0) return 0;
    }
    return 1;
}

int main()
{
    int n;
    cin>>n;
    for(int i=n;;i++)
    {
        if(isprime(i))
        {
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define FOR(i, s, n) for(int i = s; i <= (int)n; ++i)
#define per(i, n) for(int i = n; i > 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define MP make_pair
#define PB push_back
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define int long long
static const int dx[] = { -1, 0, 1, 0 };
static const int dy[] = { 0, -1, 0, 1 };

char feld[10][10];
int n;

void boms(int x,int y){
     if(feld[y][x]=='0')return;
     feld[y][x]='0';
     for(int i=1;i<=3;++i){
        rep(j,4){
            int nx=x+(dx[j]*i);
            int ny=y+(dy[j]*i);
            if(nx>8||nx<=0||ny>8||ny<=0)continue;
            boms(nx,ny);
        }
     }
}

signed main(){
    cin>>n;
    for(int i=1;i<=n;++i){
        for(int y=1;y<=8;++y){
            for(int x=1;x<=8;++x){
                cin>>feld[y][x];
            }
        }
        int a,b;
        cin>>a>>b;
        boms(a,b);
        cout<<"Data "<<i<<":"<<endl;
        for(int y=1;y<=8;++y){
            for(int x=1;x<=8;++x)cout<<feld[y][x];
            cout<<"\n";
        }
    }
}

Measured memory_bytes: 1156
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    int i, diff;
    string O, E, ans;
    cin >> O >> E;
    diff = O.size() - E.size();
    ans = "";
    for(i = 0; i < E.size(); i++) {
        ans.push_back(O[i]);
        ans.push_back(E[i]);
    }
    if(diff == 1) {
        ans.push_back(O.back());
    }
    cout << ans << endl;
    return 0;
}





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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll n;
ll dp[301][301];

int main(){
	while(cin >> n && n){
		vector<ll> v(n);
		rep(i,n)cin >> v[i];
		rep(i,301)rep(j,301)dp[i][j] = 0;
		for(ll b = 2;b <= n;b++){
			for(ll i = 0;i + b <= n;i++){
				if(abs(v[i] - v[i+b-1]) <= 1 && (dp[i+1][i+b-2] == b-2 || b == 2)){
					dp[i][i+b-1] = max(dp[i][i+b-1],dp[i+1][i+b-2] + 2);
				}
				for(ll j = i+1;j < i+b-1;j++){
					dp[i][i+b-1] = max(dp[i][i+b-1],dp[i][j] + dp[j+1][i+b-1]);
				}
			}
		}
		ll ans = 0;
		rep(i,n){
			rep(j,n){
				// cout << dp[i][j] << " ";
				ans = max(ans,dp[i][j]);
			}
			// cout << endl;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3784
n,m = map(int,input().split())
a = []
b = []
c = []
d = []
for i in range(n):
    ai, bi = map(int,input().split())
    a.append(ai)
    b.append(bi)

for i in range(m):
    ci, di = map(int,input().split())
    c.append(ci)
    d.append(di)

for i in range(n):
    ans = 0
    for j in range(m):
        if abs(a[i]-c[j])+abs(b[i]-d[j])<abs(a[i]-c[ans])+abs(b[i]-d[ans]):
            ans = j
    print(ans+1)

Measured memory_bytes: 39536
#include<iostream>
#include<algorithm>
#include<deque>
using namespace std;
typedef long long ll;
int n, m;
deque<int>d, t;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int k; cin >> k;
		d.push_back(k);
	}
	sort(d.begin(), d.end());
	cin >> m;
	for (int i = 0; i < m; i++) {
		int k; cin >> k;
		t.push_back(k);
	}
	sort(t.begin(), t.end());
	while (d.size() && t.size()) {
		if (d.front() == t.front()) {
			d.pop_front();
			t.pop_front();
		}
		else d.pop_front();
	}
	if (t.size() == 0)cout << "YES\n";
	else cout << "NO\n";
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
//mod kでx(>0)となるようなn以下の正の数を返す
int temp(int x,int k,int n){
    bool flag = true;
    int p = 0;
    int q = x;
    while(flag){
        if(q > n){
            flag = false;
        }
        p++;
        q = q + k;
    }
    return p - 1;
};
int main(){
    int n,k;
    cin >> n >> k;
    long long ans;
    if(k % 2 == 0){
        ans = pow(max(0,temp(0,k,n)-1),3) + pow(temp(k/2,k,n),3);
    }
    else{
        ans = pow(max(0,temp(0,k,n)-1),3);
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main() {
    int m, f, b;
    cin >> m >> f >> b;

    if (m >= b) {
        cout << 0 << endl;
    } else if (m + f >= b) {
        cout << b - m << endl;
    } else {
        cout << "NA" << endl;
    }
}


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


typedef long long ll;
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;

const ll MX = 2e5 + 5;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

#define F0R(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define re(x) cin >> x
#define ps(x) cout << x << "\n";
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (ll)x.size()
#define len(x) (ll)x.length()
#define rall(x) (x).rbegin(), (x).rend() 
#define rsz resize
#define ins insert 

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {	
		ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
		// cin.exceptions(cin.failbit); 
		// throws exception when do smth illegal2
		// ex. try to read letter llo ll
		if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
} 

ll N;
ll dp[MX][2];
vi adj[MX];

void dfs(ll at, ll par) {
	dp[at][0] = dp[at][1] = 1;
	for (auto x: adj[at]) if (x != par) {
		dfs(x, at);
		dp[at][1] = (dp[at][1] * ((dp[x][1] + dp[x][0]) % MOD)) % MOD; 
		dp[at][0] = (dp[at][0] * dp[x][1]) % MOD;
	}
}

int main() {
	cin >> N;
	F0R(i, N - 1) {
		ll u, v; cin >> u >> v;
		adj[u].pb(v); adj[v].pb(u);
	}
	dfs(1, 0);
	ps((dp[1][0] + dp[1][1]) % MOD);
}	








Measured memory_bytes: 19816
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <queue>


/**
 * @Author MaxHeap
 **/

using namespace std;
	

int main(){
  string s; cin >> s;
  s[3] = '8';
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>


// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
  return modpow(a, mod - 2, mod);
}

// nCk @mod を計算する
long long nCk(long long n, long k, long long mod){
  long long retval = 1;
  for (int i=0; i<k; i++){
    retval *= (n-i);
    retval %= mod;
  }
  for (int i=1; i<=k; i++){
    retval *= modinv(i, mod);
    retval %= mod;
  }
  return retval;
}

// nPk @mod を計算する
long long nPk(long long n, long k, long long mod){
  long long retval = 1;
  for (int i=0; i<k; i++){
    retval *= (n-i);
    retval %= mod;
  }
  return retval;
}

int main(){
  int N, M, K;
  scanf("%d", &N);
  scanf("%d", &M);
  scanf("%d", &K);
  std::vector<long long > A(N), B(M);
  for (int i=0; i<N; i++){
    scanf("%lld", &A[i]);
  }
  long long sum = 0;
  for (int i=0; i<M; i++){
    scanf("%lld", &B[i]);
    sum += B[i];
  }
  int b = M-1;
  int ans = 0;
  for(int a=0; a<=N; a++){
    while(sum>(long long)K && b>=0){
      //printf("b=%d\n", b);
      sum-=B[b];
      b--;
    }
    //printf("a=%d, b=%d, sum=%lld\n", a, b, sum);
    if (sum<=K){
      ans = std::max(ans, a+b+1);
    }
    if (a==N) break;
    sum += A[a];
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 6056
#include<iostream>
using namespace std;
int main(){
  int i,n,k;
  char s[100];
  cin >> n >> k;
  for(i=0;i<n;i++){
    cin >> s[i];
  }
  s[k-1]=tolower(s[k-1]);
  for(i=0;i<n;i++){
    cout << s[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3596
from collections import Counter

M = 998244353
N = int(input())
D = list(map(int, input().split()))
assert len(D) == N
dcnt = Counter(D)

def solve():
    if D[0] != 0:
        return 0
    D.sort()
    if N > 1 and D[1] != 1:
        return 0
    i = 1
    res = 1
    leaf = 1
    k = 0
    while i < N:
        if D[i] != k + 1:
            return 0
        k += 1
        c = dcnt[k]
        res *= pow(leaf, c, M)
        leaf = c
        i += c
    return res % M

if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 62260
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

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

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  ll A,B,C,D;
  cin>>A>>B>>C>>D;
  cout<<min(A,B)+min(C,D)<<endl;
  return 0;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <set>
#include <queue>
#include <cstdio>
#include <stack>
#include <list>
#include <iomanip>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define lrep(i, n) for(long long i=0;i<n;i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;
template <class T> T gcd(T n, T m){return m ? gcd(m, n%m):n;}

int main(){
    string s;cin>>s;
    if(s == "SUN")cout<<'7'<<endl;
    else if(s == "MON")cout<<'6'<<endl;
    else if(s == "TUE")cout<<'5'<<endl;
    else if(s == "WED")cout<<'4'<<endl;
    else if(s == "THU")cout<<'3'<<endl;
    else if(s == "FRI")cout<<'2'<<endl;
    else if(s == "SAT")cout<<'1'<<endl;
}

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

using namespace std;

void doc() {
    freopen("OB.inp", "r", stdin);
    freopen("OB.out", "w", stdout);
}

const   int MaxN = 1e5 + 5;

void solve(){
    int n;
    cin >> n;
    double a[n + 1], f[n + 1][n + 1][2];
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    memset(f, 0, sizeof(f));
        f[1][0][0] = 1 - a[1];
        f[1][1][1] = a[1];
    for(int i = 2; i <= n ; i++)
        f[i][0][0] = f[i - 1][0][0] * (1 - a[i]);
    for(int i = 2; i <= n; i++)
    for(int j = 1; j <= i; j++){
            f[i][j][0] = (f[i - 1][j][0] + f[i - 1][j][1]) * (1 - a[i]);
            f[i][j][1] = (f[i - 1][j - 1][0] + f[i - 1][j - 1][1]) * a[i];
    }
//    cout << f[2][0][0] << " " << f[3][1][1] << '\n';
//    cout << f[5][3][1] << '\n';
//    double sum[n + 1];
//    double temp = 0;
//    memset(sum, 0, sizeof(sum));
//    for(int i = 0; i <= 32; i++){
//        bool check = false;
//        int cnt = 0;
//        for(int j = 0; j < 5; j++)
//            if ((i >> j) & 1) cnt++;
//        if (cnt >= n / 2 + 1) check = true;
//        //if (!check) continue;
//        double t = (double)1;
//        for(int j = 1; j <= 5; j++)
//            t *= ((i >> (j-1))&1) ? (a[j]) : (1 - a[j]);
////            if ((i >> j)&1)
////                t *= a[i];
////            else t *= (1 - a[i]);
//    //    cout << i << " " << t << '\n';
////        if (cnt == 1 && (i >> 2)&1) {
////            temp += t;
////            //cout << i << endl;
////        }
//        sum[cnt] += t;
//    }
////    cout << "*" << temp << '\n';
//    for(int i = n / 2 + 1; i <= n; i++)
//        cout << sum[i] << '\n';
    double res = 0;
    for(int i = n / 2 + 1; i <= n; i++)
    {
        res += f[n][i][0] + f[n][i][1];
       // cout << i << " " << f[n][i][0] + f[n][i][1] << '\n';
      //  cout << i << endl;
    }
    cout << fixed << setprecision(10) << res << '\n';
}

int main()
{
//    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    //doc();
    solve();
}



Measured memory_bytes: 140928
d, n = [int(c) for c in input().split()]

if d == 0:
    if n == 100:
        print(101)
    else:
        print(n)
elif d == 1:
    if n == 100:
        print(101 * 100)
    else:
        print(n * 100)
else:
    if n == 100:
        print(101 * 10000)
    else:
        print(n * 10000)


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

int dp[5005][5005];

int main() {
  int n;
  string s;
  cin >> n >> s;
  for (int i = n-1; i >= 0; --i) {
    for (int j = n-1; j >= 0; --j) {
      if (s[i] != s[j]) dp[i][j] = 0;
      else dp[i][j] = dp[i+1][j+1]+1;
    }
  }
  int ans = 0;
  rep(i,n)rep(j,n) {
    if (i >= j) continue; // i < j;
    int now = min(dp[i][j], j-i);
    ans = max(ans, now);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 98048
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
using namespace std;
int main()
{
    long long A,B,X,C,Y;
    cin >> A >> B >> C >> X >> Y;
    int flag=1;
    if(2*C>A+B)
        flag=0;
    long long jiage=0;
    long long jia;
    if(flag==1)
    {
        long long temp;
        temp=min(X,Y);
        jiage=temp*2*C;
        if(X>Y)
        {
            temp=X-Y;
            jia=A;
        }
        else
        {
            temp=Y-X;
            jia=B;
        }
        if(2*C<jia)
            jiage=jiage+temp*2*C;
        else
            jiage=jiage+temp*jia;
    }
    else
    {
        jiage=A*X+Y*B;
    }
    printf("%lld\n",jiage);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll A[53];

int main(){
    ll K;
    cin >> K;
    if(K==0){
        cout << 4 << endl;
        cout << "3 3 3 3" << endl;
        return 0;
    }
    cout << 50 << endl;
    if(K<=50){
        rep(i,K){
            A[i]=50-i;
        }
    }
    else{
        rep(i,50){
            A[i]=50-i;
            if(K%50>=i+1){
                A[i]+=(K-1)/50;
            }
            else{
                if(K%50==0){
                    A[i]+=(K-1)/50;
                }
                else{
                    A[i]+=(K-51)/50;
                }
            }
        }
    }
    rep(i,50){
        cout << A[i];
        if(i<49){
            cout << " ";
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N; cin >> N;
    vector<bool> flag(1000001,true);

    int sol = 0;

    if(N == 1){
        cout << 1 << endl;
        return 0;
    }

    vector<int> A(N);
    for(auto &it:A){
        cin >> it;
    }
    sort(A.begin(), A.end());


    for(int i=0; i<N; i++){

        if(flag.at(A.at(i)) == true){
            if(i!=N-1 && A.at(i) == A.at(i+1)){
                flag.at(A.at(i)) = false;
                for(int j=A.at(i); j<=1000000; j+=A.at(i)){
                    flag.at(j) = false;
                }

                continue;
            }
            sol++;
            for(int j=A.at(i); j<=1000000; j+=A.at(i)){
                flag.at(j) = false;
            }
        }
    }

    cout << sol << endl;

}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

constexpr ll LLINF = 1LL<<60-1;

int main() {
  ll N; cin >> N;
  ll X[N], Y[N], P[N]; rep(i,N) cin >> X[i] >> Y[i] >> P[i];
  ll xmin[1<<N][N], ymin[1<<N][N];
  rep(i,1<<N) rep(j,N) {
    xmin[i][j] = abs(X[j]); rep(k,N) if (i&1<<k) xmin[i][j] = min(xmin[i][j], abs(X[k]-X[j]));
    ymin[i][j] = abs(Y[j]); rep(k,N) if (i&1<<k) ymin[i][j] = min(ymin[i][j], abs(Y[k]-Y[j]));
  }
  // rep(i,N) debug(xmin[i],xmin[i]+(1<<N));

  ll result[N+1]; rep(i,N+1) result[i] = LLINF;
  const int pw=pow(3,N);
  rep(i,pw) {
    ll ti = i, dx = 0, dy = 0, cnt = N;
    rep(j,N) {
      const int rem = ti%3;
      if (rem==2) { dx += 1<<j; }
      else if (rem==1) { dy += 1<<j; }
      else cnt--;
      ti /= 3;
    }
    ll sum = 0; rep(j,N) sum += min(xmin[dx][j], ymin[dy][j]) * P[j];
    result[cnt] = min(result[cnt], sum);
  }
  rep(i,N+1) cout << result[i] << endl;
  return 0;
}


Measured memory_bytes: 11704
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPEACH(i, k) for (auto &i : k)
#define all(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

signed main()
{
	int n,k;
	string s;
	cin >> n >> k >> s;
	vector<int> a(n);
	int now=0;
	bool is_one=false;
	int max=0;
	REP(i,n){
		if(i==0&&s[i]=='0'){
			is_one=false;
			now++;
			a[0]=i;
		}
		else if(s[i]=='1'&&!is_one){
			a[now]=i;
			is_one=true;
		}
		else if(s[i]=='1'){
			continue;
		}
		else if(s[i]=='0'&&is_one){
			if(k<=now){
				if(i-a[now-k]>max){
					max=i-a[now-k];
				}
			}
			now++;
			is_one=false;
		}
	}
	if(now<=k){
		cout << s.size() << endl;
		return 0;
	}
	if(s.size()-a[now-k]>max){
		max=s.size()-a[now-k];
	}
	cout << max << endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    rep (i,N) cin >> P.at(i);
    sort(begin(P), end(P), greater<int>());
    P[0] /= 2;
    cout << accumulate(begin(P), end(P), 0) << endl; 
}


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

int main(){
	int a, b, x; cin >> a >> b >> x;
	if (a <= x && a + b >= x) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int d[5000];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int k, q;
    cin >> k >> q;
    for (int i=0; i<k; i++)
        cin >> d[i];
    while (q--) {
        int n, x, m;
        cin >> n >> x >> m;

        int ret = n - 1;
        long long tot = x;
        for (int i=0; i<min(n-1, k); i++) {
            int dm = d[i] % m;
            if (dm == 0)
                ret -= (n - i - 2) / k + 1;
            tot += (long long) ((n - i - 2) / k + 1) * dm;
        }
        ret -= tot / m - x / m;

        cout << ret << "\n";
    }

    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int n, a[100000], max_a = 0, center = 0;
    cin >> n;
    REP(i, n) {
        cin >> a[i];
        max_a = max(max_a, a[i]);
    }
    REP(i, n) {
        if (abs(max_a / 2 - a[i]) < abs(max_a / 2 - center))
            center = a[i];
    }
    cout << max_a << " " << center << endl;
    
    return 0;
}

Measured memory_bytes: 640
/**
*    created: 23.05.2020 01:50:10
**/
#include <bits/stdc++.h>
#define int long long
#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++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n; cin >> n;
    double sum = 0;
    rep(i,n) {
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY") sum += x;
        else sum += x * 380000;
    }
    cout << fixed << setprecision(8);
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256