akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;


int main () {
    int d, g;
    cin >> d >> g;
    vector<int> p(11);
    vector<int> c(11);
    rep(i, d) {
        cin >> p[i] >> c[i]; 
    }

    int ans = INF;
    for(int mask = 0; mask < (1 << d); mask++) {
        int s = 0; int num = 0; int rest_mask = -1;
        rep(i, d) {
            if(mask >> i & 1) {
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            } else {
                rest_mask = i;
            }
        }
        if (s < g) {
            int s1 = 100 * (rest_mask + 1);
            int need = (g - s + s1 - 1) / s1;
            if(need >= p[rest_mask]){
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
local n = io.read("*n")
local a = {}
for i = 1, n do a[i] = io.read("*n") end
table.sort(a)

if n % 2 == 0 then
  local sum = 0
  local half = n / 2
  for i = 1, half do
    sum = sum - a[i] + a[half + i]
  end
  sum = sum * 2 - a[half + 1] + a[half]
  print(sum)
else
  local sum = 0
  local half = (n - 1) / 2
  for i = 1, half do
    sum = sum - a[i]
  end
  for i = half + 1, n do
    sum = sum + a[i]
  end
  sum = sum * 2 - a[half + 1] - a[half + 2]
  local cand = sum
  sum = 0
  half = (n + 1) / 2
  for i = 1, half do
    sum = sum - a[i]
  end
  for i = half + 1, n do
    sum = sum + a[i]
  end
  sum = sum * 2 + a[half - 1] + a[half]
  print(math.max(cand, sum))
end


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int ans;
int main(){
	std::ios::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	int d[10001];
	for(int i=1;i<=a;++i){
	cin>>d[i];
	if(d[i]<b||d[i]>=c){
		ans++;
	}
}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
icase=0
if icase==0:
    s=dict()
    n=int(input())
    for i in range(n):
        si=input()
        if si in s:
            s[si]=s[si]+1
        else:
            s[si]=1
    t=dict()
    m=int(input())
    for i in range(m):
        ti=input()
        if ti in t:
            t[ti]=t[ti]+1
        else:
            t[ti]=1
    smax=0
    for ss in s.items():
        if ss[0] in t:
            st=ss[1]-t[ss[0]]
        else:
            st=ss[1]
        smax=max(smax,st)
    print(smax)
    

Measured memory_bytes: 3064
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
string S;
int main(){
    cin>>N;
    cin>>S;
    ll cnt=0;
    for(ll i=0;i<S.length();i++){
        if(S[i]=='('){
            cnt++;
        }else{
            cnt--;
            if(cnt<0)cnt=0;
        }
    }
    string ans=S;
    for(;cnt>0;cnt--){
        ans+=')';
    }
    for(ll i=S.length()-1;i>=0;i--){
        if(S[i]==')'){
            cnt++;
        }else{
            cnt--;
            if(cnt<0)cnt=0;
        }
    }
    string tmp;
    for(;cnt>0;cnt--){
        tmp+='(';
    }
    cout<<tmp+ans<<endl;

    return 0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    int a[N];
    int b[N];
    for(int i = 0; i < N; i++) {
        cin >> a[i] >> b[i];
    }
    int c[M];
    int d[M];
    for(int i = 0; i < M; i++) {
        cin >> c[i] >> d[i];
    }
    int e[N][M];
    int ans[N];

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

        for(int j = 0; j < M; j++) {
            e[i][j] = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        }

        int min = e[i][0];
        for(int j = 1; j < M; j++) {

            if(e[i][j] < min) {
                min = e[i][j];
            }
        }

        int k;
        for(k = 0; k < M; k++) {
            if(e[i][k] == min) {
                break;
            }
        }

        ans[i] = k+1;
    }

    for(int i = 0; i < N; i++) {
        cout << ans[i] << "\n";
    }

    cout << endl;
    return 0;
}

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

typedef long long ll;
int main(){
  int N;
  ll B;
  cin>>N;
  vector<ll> A(N);
  for(int i = 0;i<N;i++){
  	cin>>A[i];
  }for(int i = 0;i<N;i++){
  	cin>>B;
  	A[i]-=B;
  }
  sort(A.begin(),A.end());
/*  cout<<A[0]<<endl;
  cout<<A[1]<<endl;*/
  ll sum = 0;
  int minus = 0;
  while(minus<N&&A[minus]<0){
  	sum -= A[minus];
  	minus++;
  }
  int i = N-1;
  while(i>=0&&A[i]>0&&sum>0){
  	sum -= A[i];
  	i--;
  }
  if(sum>0){
  	cout<<-1<<endl;
  }else{
  	cout<<minus+(N-1)-i<<endl;
  }

  return 0;
}


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

using namespace std;

const int maxn=1e5+5;

vector < vector < int > > l(maxn);
map < int, bool > root;
int dp[maxn];

int dfs(int pos){
	if(dp[pos]){
		return dp[pos]+1;
	}
	for(int i=0; i<l[pos].size(); i++){
		dp[pos]=max(dp[pos], dfs(l[pos][i]));
	}
	return dp[pos]+1;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, m;
	cin >> n >> m;
	int a, b;
	for(int i=0; i<m; i++){
		cin >> a >> b;
		a--;
		b--;
		l[a].push_back(b);
		root[b]=1;
	}
	int maksi=0;
	for(int i=0; i<n; i++){
		if(!root[i]){
			maksi=max(dfs(i)-1, maksi);
		}
	}
	cout << maksi << '\n';
	return 0;
}

Measured memory_bytes: 13952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll s; cin >> s;
    ll a = s;
    ll count = 2;
    map<ll, ll> m;
    m[s] = 1;
    while (true) {
        if (a % 2 == 1) {
            a = 3 * a + 1;
        }
        else {
            a /= 2;
        }
        if (m.count(a)) break;
        else m[a] = 1;
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

struct BBag {
    v: Vec<i32>,
}

impl BBag {
    fn new() -> BBag {
        BBag {
            v: vec![-1, 1000000001],
        }
    }

    fn push_back(&mut self, a: i32) {
        self.v.pop();
        self.v.push(a);
        self.v.push(1000000001);
    }

    fn min_gt_id(&self, a: i32, l: usize, r: usize) -> Option<usize> {
        if l + 1 == r {
            if r == self.v.len() - 1 {
                None
            } else {
                Some(r)
            }
        } else {
            let m = (l + r) / 2;
            if self.v[m] <= a {
                self.min_gt_id(a, m, r)
            } else {
                self.min_gt_id(a, l, m)
            }
        }
    }

    fn insert(&mut self, a: i32) {
        match self.min_gt_id(a, 0, self.v.len() - 1) {
            None => {
                self.push_back(a);
            }
            Some(i) => {
                self.v[i] = a;
            }
        }
    }

    fn mlen(&self) -> usize {
        self.v.len() - 2
    }
}

fn main() {
    let n: usize = read();
    let a: Vec<i32> = read_col(n);
    let mut bag = BBag::new();

    for i in (0..n).rev() {
        bag.insert(a[i]);
    }

    println!("{:?}", bag.mlen());
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using Long = long long;
//BEGIN CUT HERE
struct UnionFind {
    int n;
    vector<int> sz,par;
    UnionFind(){}
    UnionFind(int sz):n(sz),sz(sz,1),par(sz,0){ iota(par.begin(),par.end(),0); }
    int find(int x){
        return (x==par[x]?x:par[x]=find(par[x]));
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y) return;
        if(sz[x]<sz[y]) swap(x,y);
        sz[x]+=sz[y];
        par[y]=x;
    }
    int size(int x){
        return sz[find(x)];
    }
};

int main(void) {
    int n,q;
    cin >> n >> q;
    UnionFind uf(n);
    for(int i = 0 ; i < q ; i++){
        int c,x,y;
        cin >> c >> x >>y;
        if(c) cout<<uf.same(x,y)<<"\n";
        else uf.unite(x,y);
    }
    cout<<flush;
    return 0;
}


Measured memory_bytes: 3168
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.stream.Collectors;

@SuppressWarnings("unused")
public class Main {
	String fileName = "input.txt";
	final boolean isDebug = false;
	//final boolean isDebug = true;
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	final int MOD = (int)1e9+7;
	final long INF = Long.MAX_VALUE / 2;
	//final int INF = Integer.MAX_VALUE / 2;
	
	//System.out.println();はつかわない！！
	void solve() throws Exception{
		int N = in.nextInt();
		int X = in.nextInt();
		long now = 0;
		int cnt = 1;
		for(int i = 0; i < N; i++){
			now += in.nextInt();
			if(now <= X) cnt++;
		}
		out.println(cnt);
	}
	
	/* end solve */
	
	/* main */
	public static void main(String[] args) throws Exception {
		new Main().m();
	}
	
	void m() throws Exception {
		if(isDebug) in = new FastScanner(new FileInputStream(fileName));
		solve();
		out.flush();
	}
	/* end main */
}
/* end Main */

class FastScanner {
	Reader input;

	FastScanner() {this(System.in);}
	FastScanner(InputStream stream) {this.input = new BufferedReader(new InputStreamReader(stream));}
	
	int nextInt() {return (int) nextLong();}

	long nextLong() {
		try {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			long ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		} catch (IOException e) {
			e.printStackTrace();
			return -1;
		}
	}

	double nextDouble() {
		try {
			double sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			double ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) break;
				ret *= 10;
				ret += b - '0';
			}
			if (b != '.') return sign * ret;
			double div = 1;
			b = input.read();
			while ('0' <= b && b <= '9') {
				ret *= 10;
				ret += b - '0';
				div *= 10;
				b = input.read();
			}
			return sign * ret / div;
		} catch (IOException e) {
			e.printStackTrace();
			return Double.NaN;
		}
	}

	char nextChar() {
		try {
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			return (char) b;
		} catch (IOException e) {
			e.printStackTrace();
			return 0;
		}
	}

	String nextStr() {
		try {
			StringBuilder sb = new StringBuilder();
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			while (b != -1 && !Character.isWhitespace(b)) {
				sb.append((char) b);
				b = input.read();
			}
			return sb.toString();
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}
}

Measured memory_bytes: 23124
/******************************\
*  Everyone has a different way of thinking, so God Created us
Hope You Respect My Way..,Thank You ):  *
*                            *
*   Created by : Murad   *
\******************************/
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
#include<iostream>
using namespace std;
#include<string>
#include<sstream>
#include<algorithm>
#include<functional>
#include<set>
#include<math.h>
#include<map>
#include<vector>
#include<list>
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define MP make_pair
#define fi first
#define se second
#define INF 2147483647
#define _INF -2147483647
#define pq priority_queue
#define MM multimap
#define PB push_back
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
LL MMIN(LL a, LL b)
{
	if (a <= b)
		return a;
	else
		return b;
}
LL MMAX(LL a, LL b) {
	if (a >= b)
		return a;
	else
		return b;
}
int main()
{
	int n,ans=1;
	cin >> n;
	vector<int>a(n);
	forn(i, 0, n)cin >> a[i];
	int ma = a[0];
	for (int i = 1; i < n; i++) {
		if (a[i] >= ma)ans++, ma = a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>


using namespace std;

int main() {
    int X, max = 1;

    cin >> X;


    if (X > 1) {
        for (int i = 2; i <= 31; i++) {
            for (int j = 2; pow(i, j) <= X; j++) {
                if (pow(i, j) > max) {
                    max = pow(i, j);
                }
            }
        }
    }
    cout << max;

}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lef(x) (x<<1)
#define rig(x) (lef(x)+1)
#define int long long
pair<string,int> a[60];
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
    	cin>>a[i].first>>a[i].second;
    }
    int x=0,t=0;
    string sx;
    cin>>sx;
    for (int i = 0; i < n; ++i)
    {
    	if(t)
    		x+=a[i].second;
    	if(a[i].first==sx)
    		t=1;
    }
    cout<<x<<"\n";
    return 0;   
}

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

int r = 0;
char *str;
string n;

void C(char x, int ps){
	char y;
	if(ps == n.length()) return;
	if(x - '0') y = '0';
	else y = '1';
	if(x == str[ps]) r++;
	C(y, ps + 1);
}

int main() {

	cin >> n;
	str = new char[n.length()];
	for(int i = 0; i < n.length(); i++) str[i] = n[i];
	C(str[0], 1);
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 512
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long X, Y, Z;
    scan(X, Y, Z);
    writefln("%s %s %s", Z, X, Y);
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <vector>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for(auto i = (c).begin(); i != (c).end(); ++i)
#define BIT(n, m) (((n) >> (m)) & 1)

typedef long long ll;
typedef pair<int, int> PI;

const ll inf = 1e15;
const ll mod = 1000 * 1000 * 1000 + 7;
const double eps = 1e-9;

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

template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  REP(i, v.size()){
    if (i > 0) out << ", ";
    out << v[i];
  }
  out << "]";
  return out;
}

bool check(const vector<int> &V, ll W, ll L){
  vector<ll> sum1(V.size() + 1);
  vector<ll> sumL(V.size() + 1);
  REP(i, V.size()){
    sum1[i + 1] = sum1[i] + V[i] + 1;
    sumL[i + 1] = sumL[i] + V[i] + L;
  }
  
  vector<int> dp(V.size() + 1); // dp[i] = V[0..i)???valid?????????
  dp[0] = 0;
  dp[1] = 1;
  dp[2] = 1;
  
  REP2(i, 2, V.size()){
    // int llb = -1;
    // int lub =
    // find max x s.t. sum of V[i - x, i) + (x - 1) <= W
    int left  = i - 2;
    int right = i - 1;
    {
      int  lb = -1;
      int &ub = left;
      while (ub - lb > 1){
        int mb = (ub + lb) >> 1;
        ll  sum = sum1[i] - sum1[mb] - 1;
        // cout << sum << endl;
        if (sum <= W) ub = mb;
        else lb = mb;
      }
    }

    {
      int  lb = 0;
      int &ub = right;
      while (ub - lb > 1){
        int mb = (lb + ub) >> 1;
        ll  sum = sumL[i] - sumL[mb] - L;
        if (sum < W) ub = mb;
        else lb = mb;
      }
    }
    // find min x s.t. sum of V[i - x, i) + L * (x - 1) < W
    // cout << i << " " <<  L << "  " << left << " " << right << endl;
    if (right > left && dp[right] > dp[left] && sumL[i] - L >= W){
      dp[i + 1] = dp[i] + 1;
    } else {
      dp[i + 1] = dp[i];
    }
  } 

  bool res = false;
  REP(i, V.size()){
    ll sum = sum1[V.size()] - sum1[i] - 1;
    if (sum <= W) res = res || dp[i + 1] > dp[i];
  }
  return res;
}

int main(){
  int W, N;
  while (cin >> W >> N && W){
    vector<int> V(N);
    REP(i, N) cin >> V[i];

    int ub = W;
    int lb = 0;
    // cout << check(V, W, 1) << endl;
    while (ub - lb > 1){
      int mb = (ub + lb) >> 1;
      if (check(V, W, mb)) ub = mb;
      else lb = mb;
    }
    cout << ub << endl;
  }
  return 0;
}

Measured memory_bytes: 2316
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] d = new long[n];
    for(int i = 0; i < n; i++) {
      d[i] = sc.nextLong();
    }
    long ans = 0;
    for(int i = 0; i < n; i++) {
      for(int j = i + 1; j < n; j++) {
        ans += (d[i] * d[j]);
      }
    }
    System.out.println(ans);
  }
}

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

constexpr int MAX = 200000;

int main()
{
   int n;
   cin >> n;
   int R[MAX];
   for(int i=0; i<n; i++) cin >> R[i];
   
   int maxv = -2000000000; //十分小さい値
   int minv = R[0];

   for(int i=1; i<n; i++){
      maxv = max(maxv,R[i] - minv);
      minv = min(minv, R[i]);
   }
   
   cout << maxv << endl;
}


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

using namespace std;

int main() {
  int n;cin>>n;
  vector<int> d(n);
  rep(i,n)cin>>d[i];
  int cnt=0;
  sort(d.begin(),d.end());
  reverse(d.begin(),d.end());
  rep(i,n){
    if(d[i]==d[i+1])continue;
       cnt++;
       }
       cout<<cnt<<endl;
}

Measured memory_bytes: 3612
using System;
using static System.Console;
using static System.Math;

class Program {
  static void Main(string[] args) {
    int x = int.Parse(ReadLine());
    int ans = 0;
    for (int i = 1; i <= 40; i++) {
      for (int j = 2; j <= 10; j++) {
        if (Pow(i, j) <= x) ans = Max(ans,(int)Pow(i, j));
      }
    }
    WriteLine(ans);
  }
}


Measured memory_bytes: 11348
#include <stdio.h>

int main(void) {
    int X, Y, x, y, r;
    scanf("%d %d %d %d %d", &X, &Y, &x, &y, &r);
    if(x + r > X || x - r < 0) {
        puts("No");
    } else if(y + r > Y || y - r < 0) {
        puts("No");
    } else {
        puts("Yes");
    }
}


Measured memory_bytes: 2140
// 17D8104010B 宮本拓輝 1_E c++14

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
  int n=1;
  int result[n];
  for(int s=0;s<n;s++){
    string x,y;
    cin>>x;
    cin>>y;
    int x_size=x.size();
    int y_size=y.size();
    int score[x_size+1][y_size+1];

    for(int i=0;i<x_size+1;i++){
      score[i][0]=i;
    }
    for(int j=0;j<y_size+1;j++){
      score[0][j]=j;
    }

    for(int i=1;i<x_size+1;i++){
      for(int j=1;j<y_size+1;j++){
        int a=1;
        if(x[i-1]==y[j-1]){
          a=0;
        }
        score[i][j]=min(score[i-1][j]+1,score[i][j-1]+1);
        score[i][j]=min(score[i-1][j-1]+a,score[i][j]);
      }
    }
    /*
    for(int i=0;i<x_size+1;i++){
      for(int j=0;j<y_size+1;j++){
        cout<<score[i][j]<<' ';
      }
      cout<<"\n";
    }
    */
    cout<<score[x_size][y_size]<<"\n";

  }

  return 0;
}

/* 実行結果
Miyamoto:~ miyamotohiroki$ ./a.out
apple
player
5
Miyamoto:~ miyamotohiroki$ ./a.out
acac
acm
2
Miyamoto:~ miyamotohiroki$ ./a.out
icpc
icpc
0
*/


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

#define fr(i,a,b) for(ll i=a;i<b;i++)
#define ffr(i,a,b) for(ll i=a;i>=b;i--)
#include<bits/stdc++.h>
#include<vector>
#define vl vector<ll>
#define pb push_back
//const ll N=1e5+5;




// int solve(){
    
// }


int main(){
    ll n,k,s=0;
    cin>>n>>k;
    ll p[n];
    fr(i,0,n) cin>>p[i];
    sort(p,p+n);
    fr(i,0,k) s+=p[i];
    cout<<s;
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define int long long int
#define gif(a,b) (a/b +(a%b?1:0))
#define pi 3.14159265358
#define watch(x) cout<<(#x)<<" is "<<(x)<<"\n";
#define float long double
using namespace std;

int32_t main()
{   
    cin.tie(NULL);
    std::ios::sync_with_stdio(false);
  	int a , b , c;
  	cin >> a >> b >> c;
  	if( a + b + c >= 22)
  	cout << "bust";
  else 
  	cout << "win";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 int main(){
   int N; 	
   cin >> N; 
      vector<int64_t> A(N+1), B(N);
      for (int i = 0; i < N+1; i++) {
        cin >> A.at(i);
      }
   
      for (int i = 0; i < N; i++) {
        cin >> B.at(i);
      } 
   
    int64_t S=0; 
   	for ( int i=0; i< N; i++){
      if( B.at(i) < A.at(i) ){
        S += B.at(i); 
      }else if( A.at(i+1) + A.at(i) > B.at(i) ){
          S += B.at(i); 
          A.at(i+1)= A.at(i+1) - ( B.at(i) - A.at(i) );
      }else{
          S += A.at(i) + A.at(i+1);
          A.at(i+1)=0; 
      }
    } // for 終わり
   cout << S << endl;
 }

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef __int128_t i128;
typedef long long i64;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define FPEN2 freopen("out.txt", "w", stdout);
#else
#define FPEN
#define FPEN2
#endif
#define Sz(a) ((int)(a).size())
const int maxn = 200009;
const int MOD = 1e9 + 7;
int main(){
  FPEN;
  ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
  int n;cin>>n;
  i64 a=1;
  for(int i=0;i<n;++i){
    i64 t;cin>>t;
    if(a==-1){
      if(t!=0)continue;
      else {
        a=0;break;
      }
    }
    if((long double)a*t>1e18){
      a=-1;
    }else{
      a=a*t;
    }
  }
  cout<<a<<"\n";
  
  return 0;
}
//2020.05.31 20:01:38


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int vector_finder(std::vector<int> 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 x;
  std::cin >> x;
  std::vector<int> a;
  a.pb(1);
  rrep(i,2,1000){
    rrep(j,2,1000){
      int d=pow(i,j);
      if(d<=x)a.pb(d);
      else break;
    }
  }
  sort(all(a),greater<int>());
  std::cout << a[0] << std::endl;
  
}


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

using namespace std;

int main(){
    long M, K;

    cin>>M>>K;
    if(pow(2, M) <= K){
        cout<<-1<<endl;
        return 0;
    }
    
    if(K==0){
        cout<<0<<" "<<0;
        long range = pow(2, M);
        for(int i=1; i<range; ++i){
            cout<<" "<<i<<" "<<i;
        }
        cout<<endl;
        return 0;
    }

    if(M>1){
        long range = pow(2, M);
        vector<int> a;
        for(int i=0; i<range; ++i){
            if(i != K){
                a.push_back(i);
            }
        }
        a.push_back(K);
        for(int i=range-1; i>=0; --i){
            if(i != K){
                a.push_back(i);
            }
        }
        a.push_back(K);

        cout<<a[0];
        for(int i=1; i<a.size(); ++i){
            cout<<" "<<a[i];
        }
        cout<<endl;
        return 0;
    }

    cout<<-1<<endl;

    return 0;
}


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

using namespace std;

int main()
{
  int n, q;
  vector<int> v_a;
  
  cin >> n >> q;

  while (n--) {
    int a;
    cin >> a;
    v_a.push_back(a);
  }

  sort(v_a.begin(), v_a.end());
  
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << upper_bound(v_a.begin(), v_a.end(), r)
      - lower_bound(v_a.begin(), v_a.end(), l) << endl;
  }
}



Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
typedef long long int llint;

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  u64 &value() noexcept { return a; }
  const u64 &value() const noexcept { return a; }
  modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
	*this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

struct UnionFind {
  std::vector<int> par;

  UnionFind(int N) : par(N) {
    for(int i = 0; i < N; i++) par[i] = i;
  }

  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    int rx = root(x); 
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
  }

  bool same(int x, int y) { 
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main(void){

  int n, m, k;
  std::cin >> n >> m >> k;

  std::vector<std::set<int> > friends(n);
  std::vector<std::set<int> > blocks(n);

  UnionFind uf(n);
  for(int i=0; i<m; i++){
    int a, b;
    std::cin >> a >> b;
    a--;
    b--;
    uf.unite(a,b);
    friends[a].insert(b);
    friends[b].insert(a);
  }

  for(int i=0; i<k; i++){
    int c,d;
    std::cin >> c >> d;
    c--;
    d--;
    blocks[c].insert(d);
    blocks[d].insert(c);
  }

  std::map<int, int> group_sizes;
  for(int i=0; i<n; i++){
    int r = uf.root(i);
    if(group_sizes.find(r) == group_sizes.end()) group_sizes[r] = 0;
    group_sizes[r]++;
  }

  for(int i=0; i<n; i++){
    int r = uf.root(i);
    int possible = group_sizes[r] - 1; // remove himself
    for(const auto& elem: friends[i]){
      if(uf.root(elem) == r) possible--;
    }
    for(const auto& elem: blocks[i]){
      if(uf.root(elem) == r) possible--;
    }
    std::cout << possible << " ";
  }

  std::cout << std::endl;
  
  return 0;
}


Measured memory_bytes: 33664
import numpy as np

n = int(input())

dp = np.zeros(n + 1)
dp[0] = 1.

for p in map(float, input().split()):
  tmp = (1. - p) * dp
  tmp[1:] += p * dp[:-1]
  dp = tmp

print(dp[n // 2 + 1:].sum())

Measured memory_bytes: 12468
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<stack>
#include<set>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int,int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout<<"debug"<<endl;
#define PLL pair<ll,ll>
#define PDD pair<double,double>
#define ULL unsigned long long
#define fo(i,a,b) for (int i=a;i<=b;++i)
#define fd(i,a,b) for (int i=a;i>=b;--i)
#define mem(x,a) memset(x,a,sizeof(x))
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int main(){
	int a , b , c , d;cin >> a >> b >> c >> d;
	int cnt = a / d + (a%d==0?0:1), cct = c / b + (c%b == 0?0:1);
	puts(cnt >= cct?"Yes":"No");
	return 0;
}

Measured memory_bytes: 3596
#include<iostream>
using namespace std;
int main (){
    int a,b;
    cin>>a>>b;
    if (a<b){
        cout<<"a < b"<<endl;
    }
    if (a==b){
        cout<<"a == b" <<endl;
    }
    if(a>b){
        cout<<"a > b"<<endl;
        
    }
    return 0;
}


Measured memory_bytes: 3092
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        s:chars,
    }
    let odds = vec!['R','U','D'];
    let evens = vec!['L','U','D'];
    let mut flag = true;
    for i in 0..s.len() {
        if !flag {break;} 
        if i % 2 == 0 {
            flag = odds.contains(&s[i]);
        } else {
            flag = evens.contains(&s[i]);
        }
    }
    println!("{}",if flag {"Yes"} else {"No"});
}


fn is_prime(x:i64) -> bool {
    if x == 2 {return true;}
    if x < 2 || x % 2 == 0 {return false;}
    let mut j = 3;
    while j <= (x as f64).sqrt() as i64 {
        if x % j == 0 {
            return false;
        }
        j += 2;
    }
    true
}


Measured memory_bytes: 4352
N = int(input())
D, X = map(int, input().split())
a_list = list(map(int, [input() for i in range(N)]))
counter = 0
for a in a_list:
  counter += 1
  base = 1
  for i in range(1, D):
    base = (i * a + 1)
    if base <= D:
      counter += 1
    else: 
      break
counter += X
print(counter)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"regexp"
	"strconv"
)

func solve() {
	s := next()
	// phrases := []string{"dream", "dreamer", "erase", "eraser"}
	r := regexp.MustCompile(`^(dream(er)?|eraser?)*$`)

	if r.MatchString(s) {
		println("YES")
	} else {
		println("NO")
	}
	return
}

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, scBufSize), scBufSize)

	solve()
}

// --- template ---

const scBufSize = 1 * 1024 * 1024 // 1MB

var (
	in  = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func println(a ...interface{}) {
	fmt.Fprintln(out, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(out, format, a...)
}

func next() string {
	in.Scan()
	return in.Text()
}

func nextInt() int {
	s := next()
	i, e := strconv.Atoi(s)
	if e != nil {
		fmt.Println(e)
	}
	return i
}

func nextInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = nextInt()
	}
	return res
}

func unique(list []int) []int {
	m := make(map[int]bool)
	uniq := make([]int, 0)
	for _, e := range list {
		if !m[e] {
			m[e] = true
			uniq = append(uniq, e)
		}
	}
	return uniq
}


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

struct DATA{
  string ans;
  int i;
  DATA(string s,int n){ans=s;i=n;}
};

string equation(string s);
DATA formula(string s, int i);

string equation(string s){
  DATA res=formula(s,0);
  return res.ans;
}

DATA formula(string s, int i)
{
  if(s[i]=='T')return DATA("T",i+1);
  if(s[i]=='F')return DATA("F",i+1);
  if(s[i]=='-'){
    DATA res=formula(s,i+1);
    if(res.ans=="T")return DATA("F",res.i);
    else return DATA("T",res.i);
  }
  if(s[i]=='('){
    string res,op;
    DATA res1 = formula(s,i+1);
    i=res1.i;
    op=s[i];
    if(op=="-")i++;
    DATA res2 = formula(s,i+1);
    i=res2.i;

    if(op=="*"){
      if( (res1.ans=="T") & (res2.ans=="T") ) res="T";
      else res="F";
    }
    if(op=="+"){
      if( (res1.ans=="T") | (res2.ans=="T") ) res="T";
      else res="F";
    }
    if(op=="-"){
      if( (res1.ans=="T") && (res2.ans=="F") ) res="F";
      else res="T";
    }
    return DATA(res,i+1);
  }
}

int main()
{
  bool ok;
  string in,s1,s2;
  while(cin>>in,in!="#"){
    ok=true;
    for(int i=0;i<(1<<11);i++){
      s1=in;
      for(int j=0;j<11;j++){
	if(i>>j&1){
	  while(s1.find('a'+j,0)!=string::npos){
	    s1.replace(s1.find('a'+j,0),1,"T");
	  }
	}else{
	  while(s1.find('a'+j,0)!=string::npos){
	    s1.replace(s1.find('a'+j,0),1,"F");
	  }
	}
      }
      s2=s1.substr(s1.find("=",0)+1);
      s1=s1.substr(0,s1.find("=",0));
      if(equation(s1)!=equation(s2))ok=false;
    }
    if(ok)puts("YES");
    else puts("NO");
  }
}

Measured memory_bytes: 2020
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
  for(i=0;i<=VMAX;i++) C[i]=0;
  for(i=0;i<n;i++){
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
  }
  for(i=1;i<=VMAX;i++) C[i]=C[i]+C[i-1];

  for(j=1;j<=n;j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

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



Measured memory_bytes: 9580
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;

    vector<int> ans(N);
    for(int i=1; i<=200; i++) {
        for(int j=1; j<=200; j++) {
            for(int k=1; k<=200; k++) {
                int f = i*i + j*j + k*k + i*j + j*k + k*i;
                if(f > N) continue;
                ans[f-1]++;
            }
        }
    }

    for(int i=0; i<N; i++) cout << ans[i] << endl;
    return 0;
}


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

int main(){
	int m, d, count = 0;
	cin >> m >> d;
	if(m >= 4){
		for (int j = 1; j <= m; j++){
			for (int i = 1; i <= d; i++){
				int a, b;
				a = (i % 10);
				b = (i / 10);
				if((a >= 2) && (b >= 2)){
					if((a * b) == j){
						count++;
					}
					else
						continue;
				}
				else{
					continue;
				}
			}
		}
		cout << count << endl;
	}
	else{
		cout << "0" << endl;
	}
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <utility>
using namespace std;
 
int main()
{
    int H, W;
    cin>>H>>W;
    vector<int> A(H), B(H);
    for (int y=0; y<H; y++)
    {
        cin>>A[y]>>B[y];
        A[y]--;
    }
 
    set<pair<int, int>> S;
    multiset<int> T;
    for (int x=0; x<W; x++)
    {
        S.insert({x, 0});
        T.insert(0);
    }
 
    for (int y=0; y<H; y++)
    {
        auto s = S.lower_bound({A[y], 0});
        if (s!=S.end())
        {
            int t = 999999;
            while (s!=S.end() && s->first<B[y])
            {
                T.erase(T.find(s->second));
 
                t = min(t, s->second+(B[y]-s->first));
                s = S.erase(s);                
            }
            if (B[y]<W && t<999999)
            {
                S.insert({B[y], t});
                T.insert(t);
            }
        }
 
        if (T.empty())
            cout<<-1<<endl;
        else
            cout<<*T.begin()+y+1<<endl;
    }
}


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

int main() {
  int n;
  cin >> n;
  ll m = 0,a = 0,r = 0,c = 0,h = 0;
  rep(i,0,n){
    string s;
    cin >> s;
    if(s[0] == 'M') m++;
    if(s[0] == 'A') a++;
    if(s[0] == 'R') r++;
    if(s[0] == 'C') c++;
    if(s[0] == 'H') h++;
  }
  ll ans = 0;
  ans += m*a*r;
  ans += m*a*c;
  ans += m*a*h;
  ans += m*r*c;
  ans += m*r*h;
  ans += m*c*h;
  ans += a*r*c;
  ans += a*r*h;
  ans += a*c*h;
  ans += r*c*h;
  cout << ans << endl;
}

Measured memory_bytes: 3564
while True:
    n,m=map(int,input().split())
    A=[]
    a=[]
    V=0
    if n==0 and m==0:
        break
    A=list(map(int,input().split()))
    for i in range(n-1):
        for j in range(n-i-1):
            B=0
            B=A[i]+A[i+j+1]
            if B<=m:
                a.append(B)
                V=1
    if V==0:
        print('NONE')
    else:
        print(max(a))


Measured memory_bytes: 27504
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll n; cin >> n;
	set<string> se;
	rep(i,n){
		string s; cin >> s;
		se.insert(s);
	}
	ll m; cin >> m;
	ll open = 0;
	rep(i,m){
		string s; cin >> s;
		if(se.find(s) == se.end()) print2("Unknown",s);
		else{
			if(open) print2("Closed by",s);
			else print2("Opened by",s);
			open = !open;
		}
	}
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N;
  cin >> N;
  vector<int> T(N);
  ll sum = 0ll;
  REP(i, N){
    cin >> T.at(i);
    sum += T.at(i);
  }
  int M;
  cin >> M;
  int p, x;
  REP(i, M){
    cin >> p >> x;
    --p;
    cout << sum - T.at(p) + x << endl;
  }
  
  return 0;
}

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

int main() {
    int N; cin >> N;
    vector<int> C;
    rep(i, N){
        int a; cin >> a;
        int x = upper_bound(C.begin(), C.end(), -a) - C.begin();
        if(x == C.size()){
            C.push_back(-a);
        } else {
            C[x] = -a;
        }
    }

    int ans = C.size();
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3908
from __future__ import print_function

import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# import math
# import string
# import fractions
# from fractions import Fraction
# from fractions import gcd

# def lcm(n,m):
#     return int(n*m/gcd(n,m))

# import re
# import array
# import copy
# import functools
# import operator

# import collections
# import itertools
# import bisect
# import heapq


# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace

# from queue import PriorityQueue as pq

# def reduce(p, q):
#     common = fractions.gcd(p, q)
#     return (p//common , q//common )
# # from itertools import accumulate
# # from collections import deque

# from operator import mul
# from functools import reduce

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

# import random

def main():
    # n, *l = map(int, open(0).read().strip().split())
    # n = int(input().strip())
    # a = list(map(int, input().strip().split()))
    n = int(input().strip())
    max0=0;max1=0;i0=sys.maxsize;i1=sys.maxsize               # assure that max1<=max0
    for i in range(n):
        n_temp=int(input())
        if n_temp >= max0 :
            max1=max0;i1=i0 
            max0=n_temp;i0=i
        elif max0>n_temp and n_temp>max1:
            max1=n_temp;i1=i
        else: #  n_tem@ <= max1
            pass
    for i in range(n):
        if i==i0:
            print(max1)
        else:
            print(max0)
    return

if __name__ == '__main__':
    main()

    '''
    


    '''


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

ll a[32][200010];
ll b[32][200010];
ll c[32];
int n;
/*
int f(int k, ll upper, ll lower) {
  ll up = -1;
  for (ll i = 30; i >= 0; i--) {
    if (up + c[i] >= n) continue;
    if (b[k][up+c[i]] < upper) {
      up += c[i];
    }
  }
  ll low = -1;
  for (ll i = 30; i >= 0; i--) {
    if (low + c[i] >= n) continue;
    if (b[k][low+c[i]] < lower)
      low += c[i];
  }
  return up - low;
}
*/

int f(int k, ll upper, ll lower) {
  return upper_bound(b[k],b[k]+n,upper)-lower_bound(b[k],b[k]+n,lower);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i <= 31; i++) {
    c[i] = (1LL << i);
  }
  for (int i = 0; i < n; i++) cin >> a[0][i];
  for (int i = 0; i < n; i++) cin >> b[0][i];
  for (int i = 1; i < 31; i++) {
    for (int j = 0; j < n; j++) {
      a[i][j] = a[0][j] % c[i];
      b[i][j] = b[0][j] % c[i];
    }
    sort(b[i],b[i]+n);
  }

  ll ans = 0;
  for (ll i = 1; i < 31; i++) {
    ll cnt = 0;
    for (int j = 0; j < n; j++) {
      cnt += f(i, c[i]-a[i][j]-1, c[i-1]-a[i][j])
          + f(i, c[i+1]-a[i][j]-1, c[i-1]*3-a[i][j]);
    }
    if (cnt%2)
    ans |= c[i-1];
  }

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


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

#define PB push_back
#define MP make_pair
#define F first
#define S second

using namespace std;

typedef long long ll;

const int max_d = 12, max_n = 1011, inf = 1000111222;

int dp[max_d][max_n];
int cnt[max_d];
int sc[max_d];

int main() {
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    //cout.tie(0);
    ll d, g;
    cin >> d >> g;
    for (int i = 0; i < d; ++i) {
        cin >> cnt[i] >> sc[i];
    }
    for (int i = 0; i <= d; ++i) {
        for (int j = 0; j < max_n; ++j) {
            dp[i][j] = -inf;
        }
    }
    dp[0][0] = 0;

    for (int i = 0; i < d; ++i) {
        for (int j = 0; j < max_n; ++j) {
            dp[i + 1][j + cnt[i]] = max(dp[i + 1][j + cnt[i]], dp[i][j] + sc[i] + cnt[i] * 100 * (i + 1));
            for (int k = 0; k < cnt[i]; ++k) {
                dp[i + 1][j + k] = max(dp[i + 1][j + k], dp[i][j] + k * 100 * (i + 1));
            }
        }
    }
    //cout << dp[2][7] << endl;
    for (int j = 0; j < max_n; ++j) {
        if (dp[d][j] >= g) {
            cout << j;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256