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

#define ll long long int

const ll sz=3010;
ll dp[sz][sz][3];
ll vis[sz][sz][3];

ll n, ara[sz];

ll cholo(ll l,ll r,ll mark)
{
    if(l>r) return 0ll;
    ll &ret=dp[l][r][mark];

    if(vis[l][r][mark] != -1) return ret;
    vis[l][r][mark]=1;

    if(mark==1){
        ll mx1=ara[l]+cholo(l+1,r,2);
        ll mx2=ara[r]+cholo(l,r-1,2);
        ret=max(mx1, mx2);
    }
    else{
        ll mx1=cholo(l+1,r,1)-ara[l];
        ll mx2=cholo(l,r-1,1)-ara[r];
        ret=min(mx1, mx2);
    }

    return ret;
}


int main()
{
    ll m,p,q,i,j,k,l;
    cin>>n;

    for(i=1;i<=n;i++) cin>>ara[i];
    memset(vis,-1,sizeof vis);
    ll ans=cholo(1,n,1);
    cout<<ans<<'\n';
}


Measured memory_bytes: 333252
import math
q=int(input())
for j in range(q):
	AB=[int(i) for i in input().split()]
	AB.sort()#4,11
	ab=AB[0]*AB[1] #44
	for i in range(int(math.sqrt(ab)),AB[1]+1):
		if i*i>=ab:
			x=i-1
			break
	if x==0:
		print(0)
		continue
	for i in range(int(ab/x),ab+1):
		if x*i>=ab:
			y=i-1
			break
	cnt1=2*x
	cnts=1 if x==y else 0
	cntdd=1 if x-AB[0]>=0 else 0
	cntdu=1 if AB[1]-y>=0 and (AB[1]+1)*(x-AB[1]+y)>=ab else 0 #x-i, y+i=c,b->c,b+1
	print(cnt1-cnts-cntdd-cntdu)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

const pii Dir[8] = { //?????????
	{ 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 },
	{ 1,1 },{ 1,-1 },{ -1,-1 },{ -1,1 }
};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}

signed main() {
	int w, h;

	while (scanf("%d %d", &h, &w)) {
		if (h == 0 & w == 0)
			break;
		vector<vector<int>> stat(h, vector<int>(w));
		vector<int> hsum(w);
		REP(i, h) {
			REP(j, w) {
				scanf("%d", &stat[i][j]);
				hsum[j] += 1 - stat[i][j];
			}
		}
		function<int(int, int)> func = [&](int cur, int st) {

			if (cur == h) {
				vector<int> buf(hsum);
				REP(i, h) {
					if (bitcheck(st, i)) {
						REP(j, w) {
							if (stat[i][j]) {
								buf[j] ++;
							}
							else {
								buf[j] --;
							}
						}
					}
				}
				int sum = 0;
				for (auto itr : buf) {
					sum += max(abs(h - itr), abs(itr));
				}
				return sum;
			}
			int buf = func(cur + 1, st);
			bitset(st, cur);
			return max(buf, func(cur + 1, st));
		};
		printf("%d\n", func(0, 0));
	}
	return 0;
}

Measured memory_bytes: 3552
#include <stdio.h>
#include <algorithm>
int n;
int a[100010];
int b[100010];
int c[100010];
long long psum_b[100010];
long long ans;
long long find_bc(int st,int ed,int x){
	int mid = (st+ed)/2;
	if(ed-st<=1){
		if(x<c[st]) return n-st;
		if(x>=c[ed]) return n-ed-1;
		return n-ed;
	}
	if(c[mid]<=x) return find_bc(mid,ed,x);
	return find_bc(st,mid,x);
}
long long find_ab(int st,int ed,int x){
	int mid = (st+ed)/2;
	if(ed-st<=1){
		if(x<b[st]) return psum_b[st];
		if(x>=b[ed]) return psum_b[ed+1];
		return psum_b[ed];
	}
	if(b[mid]<=x) return find_ab(mid,ed,x);
	return find_ab(st,mid,x);
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	std::sort(a,a+n);
	for(int i=0;i<n;i++){
		scanf("%d",&b[i]);
	}
	std::sort(b,b+n);
	for(int i=0;i<n;i++){
		scanf("%d",&c[i]);
	}
	std::sort(c,c+n);
	for(int i=n-1;i>=0;i--){
		psum_b[i]=psum_b[i+1]+find_bc(0,n-1,b[i]);
	}
	for(int i=0;i<n;i++){
		ans+=find_ab(0,n-1,a[i]);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    string s;
    cin >> s;
    if(s.at(s.size()-1) == 's') s += "es";
    else s += "s";
    cout << s << endl;
     
return 0;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  set<int> A;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    if (A.find(a) != A.end()) {
      A.erase(a);
    } else {
      A.insert(a);
    }
  }
  cout << A.size() << endl;
  return 0;
}



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

int main(){
    char c;
    cin >> c;
    if(c == 'A') cout << 'T' << endl;
    if(c == 'T') cout << 'A' << endl;
    if(c == 'C') cout << 'G' << endl;
    if(c == 'G') cout << 'C' << endl;
}

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

using namespace std;

typedef long long ll;

const int MAX_N = 5e3 + 10;
const ll MOD = 1e9 + 7;

int N, siz[MAX_N];
ll dp[MAX_N][MAX_N], fac2[MAX_N];
vector<int> edge[MAX_N];

void solve(int x, int y) {
    dp[x][siz[x] = 1] = 1;
    for (int i : edge[x]) {
        if (i == y) continue;
        solve(i, x);
        for (int j = siz[x] + siz[i]; j; j--) {
            ll t = 0;
            for (int k = max(0, j - siz[x]); k <= min(siz[i], j); k++) {
                (t += dp[i][k] * dp[x][j - k]) %= MOD;
            }
            dp[x][j] = t;
        }
        siz[x] += siz[i];
    }
    for (int i = 1; i <= siz[x]; i++) {
        (dp[x][0] += MOD - dp[x][i] * fac2[i - 1] % MOD) %= MOD;
    }
}

int main() {
    scanf("%d", &N);
    fac2[1] = 1;
    for (int i = 3; i <= N; i += 2) fac2[i] = fac2[i - 2] * i % MOD;
    for (int i = 1; i < N; i++) {
        int a, b; scanf("%d%d", &a, &b);
        edge[a].push_back(b); edge[b].push_back(a);
    }
    solve(1, 0);
    ll ans = (MOD - dp[1][0]) % MOD;
    printf("%lld\n", ans);
}


Measured memory_bytes: 195072
#!/usr/bin/env python3
"""def fac(n):
	ret = 1
	for i in range(2,n+1):
		ret = (ret*i) % (10**9+7)
    return ret"""
def fac(n):
    ret = 1
    for i in range(2,n+1):
        ret = ret*i % (10**9+7)
    return ret
a,b = map(int,input().split())
mod = 10**9+7
if abs(a-b) >= 2:
	print(0)
elif abs(a-b) == 1:
	print(fac(a)*fac(b)%mod)
else:
	print(2*fac(a)*fac(b)%mod)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <assert.h>
#include <map>
#include <set>
#include <bitset>
#include <iomanip>
#include <stack>
#include <unordered_map>
#include <cmath>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define INF 0x7f7f7f7f  //2139062143
#define INF1 0x3f3f3f3f //1061109567
#define INF2 2147483647
#define llINF 9223372036854775807
#define pi 3.14159265358979323846264338327950254
#define pb push_back
#define ll long long
#define debug cout << "debug\n";
#define STDIN                      \
    freopen("in.txt", "r", stdin); \
    freopen("out.txt", "w", stdout);
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);
#define scai(x) scanf("%d", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define scaf(x) scanf("%lf", &x)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define For(m, n) for (int i = m; i < n; i++)
#define PII pair<int, int>
#define PLL pair<long, long>
#define ft first
#define sd second
#define pb push_back
#define lson o << 1, l, mid
#define rson o << 1 | 1, mid + 1, r
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define ROF(i, a, b) for (int i = (a); i >= (b); i--)
#define MEM(x, v) memset(x, v, sizeof(x))
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
inline int read()
{
    char ch = getchar();
    int x = 0, f = 0;
    while (ch < '0' || ch > '9')
        f |= ch == '-', ch = getchar();
    while (ch >= '0' && ch <= '9')
        x = x * 10 + ch - '0', ch = getchar();
    return f ? -x : x;
}

int main() {
    // STDIN
    string s, t;
    cin >> s >> t;
    t.pop_back();
    if (s == t) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 3032
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    vector<ll> v[100010];
    cin>>n;
    bool can=false;
    for(int i=1;i*(i+1)<=200000;i++){
        if(i*(i+1)==n*2){
            can=true;
            k=i;
            break;
        }
    }
    if(!can){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
        cout<<k+1<<endl;
        ll R=k,L=1,now=0;
        while(R!=L){
            for(ll i=L;i<=R;i++){
                v[now].pb(i);
                v[now+(i-L+1)].pb(i);
            }
            L+=(k-now);
            R+=(k-now-1);
            now++;
        }
        v[k-1].pb(L);
        v[k].pb(L);
        rep(i,k+1){
            cout<<k<<" ";
            for(ll j=0;j<(ll)v[i].size()-1;j++){
                cout<<v[i][j]<<" ";
            }
            cout<<v[i][v[i].size()-1]<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5632
/**
 * @author yuzining
**/
#ifdef local
#include "D:\vscode\acm\local.hpp"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(...) do { } while(false)
void Main();
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
  return 0;
}
#endif

char s[7][7], t[7][7];

void Main() {
  int n, m, k; cin >> n >> m >> k;
  for(int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int ans = 0;
  for(int i = 0; i < (1 << n); i++) {
    for(int j = 0; j < (1 << m); j++) {
      memcpy(t, s, sizeof s);
      for(int k = 0; k < n; k++) {
        if((i >> k) & 1) {
          for(int l = 0; l < m; l++) {
            t[k][l] = '.';
          }
        }
      }
      for(int l = 0; l < m; l++) {
        if((j >> l) & 1) {
          for(int k = 0; k < n; k++) {
            t[k][l] = '.';
          }
        }
      }
      int cnt = 0;
      for(int k = 0; k < n; k++) {
        for(int l = 0; l < m; l++) {
          if(t[k][l] == '#') {
            cnt++;
          }
        }
      }
      if(cnt == k) {
        ans++;
      }
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <utility>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
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;}
using ll = long long;
constexpr long long INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int A,B,C;cin >> A >> B >> C;
    if((A >= C && C >= B) || (B >= C && C >= A)) cout << "Yes";
    else cout << "No";
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
static const int64_t mod=998244353;
int64_t f(int64_t x,int64_t y){
if(y==0)
  return 1;
  else if(y%2==0)
    return (f(x,y/2)*f(x,y/2))%mod;
  else
    return (x*((f(x,y/2)*f(x,y/2))%mod))%mod;
}
int main(){
  int64_t N,A,B,K;
  cin>>N>>A>>B>>K;
  vector<int64_t>Comb(N+1);
  Comb[0]=1;
  for(int64_t i=1;i<=N;i++)
    Comb[i]=((N+1-i)*((Comb[i-1]*f(i,mod-2))%mod))%mod;
  int64_t ans=0;
  for(int64_t i=0;i<=N;i++){
  if(K%B==(i*A)%B){
  int64_t c=(K-i*A)/B;
    if(0<=c && c<=N)
      ans=(ans+Comb[i]*Comb[c])%mod;
  }
   }cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5604
N=int(input())
lst=list(map(int,input().split()))
lst.sort()
freq={}
for i in lst:
    if i in freq:
        freq[i]+=1
    else:
        freq[i]=1
ans=0
for key,value in freq.items():
    if key>value:
        ans+=value
    elif key<value:
        ans+=abs(key-value)
print(ans)

Measured memory_bytes: 21768
#[allow(dead_code)]
fn main() {
    let mut nn = i::u();
    let mut mm = i::i();
    let mut hash = HashMap::new();
    for xx2 in 0..nn {
        let mut kk = i::u();
        for x1 in 0..kk {
            let mut kk = i::i();
            *hash.entry(kk).or_insert(0) +=1;
        }
    }

    let mut vec2: Vec<_> = hash.iter().collect();
    let mut count = 0;
    for xx1 in vec2 {
        if (*xx1.1==nn){
            count+=1;
        }
    }
    println!("{}",count);
}


#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }
    pub fn strv(n: usize) -> Vec<String> {
        (0..n).map(|_| str()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 2168
#include <iostream>
#include <complex>
#include <vector>
#include <stack>

using namespace std;

template<class T> bool operator<(const complex<T> &a, const complex<T> &b){
    return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();
}

typedef complex<double> P;
#define X real()
#define Y imag()

double dot(P a, P b){
    return (a * conj(b)).X;
}
double cross(P a, P b){
    return (a * conj(b)).Y;
}

vector<P> points;
deque<P> selected;
int max_count;

void search(int index) {
    if(index > points.size()) return;
    int selected_size = selected.size();

    bool is_all_overlap = true;
    if(selected_size >= 2 && selected_size > max_count) {
        // calc is all overlaps
        vector<P> copied_selected;
        copy(selected.begin(), selected.end(), back_inserter(copied_selected));

        for (int i = 0; i < selected_size ; ++i) {
            for (int j = 0; j < selected_size; ++j) {
                if(i == j) continue;
                // two point check
                double d12 = abs(copied_selected[i] - copied_selected[j]);
                if(d12 > 2.0 + 1e-10) {
                    is_all_overlap = false;
                    break;
                }

                for (int k = 0; k < selected_size; ++k) {
                    if(i == k || j == k) continue;
                    // three point check
                    P p1 = copied_selected[i];
                    P p2 = copied_selected[j];
                    P p3 = copied_selected[k];

                    P center12 = P((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2);
                    double allow_distance = 1 + sqrt(1 - ((d12 * d12) / 4));
                    if(abs(center12 - p3)  > allow_distance + 1e-10) {
                        is_all_overlap = false;
                        break;
                    }
                }

            }
            if(!is_all_overlap) {
                break;
            }
        }

        copied_selected.clear();
        copied_selected.shrink_to_fit();
    }

    if (is_all_overlap) {
        // update max count
        if(selected_size > max_count) {
            max_count = selected_size;
        }

        P p = points[index];
        // remove bad situation
        if(selected.empty() || abs(p - selected.front()) <= 2.0 + 1e-10) {
            // take
            selected.push_front(p);
            search(index + 1);
            selected.pop_front();
        }

        // for next dispatch
        // not take
        search(index + 1);
    }
}

int main() {
    int n;
    while (cin >> n) {
        if(n == 0) break;
        points.clear();
        points.shrink_to_fit();
        selected.clear();
        selected.shrink_to_fit();
        max_count = 0;

        // load points
        for (char i = 0; i < n; ++i) {
            double x;
            double y;
            scanf("%lf,%lf", &x, &y);
            P p = P(x, y);
            points.push_back(p);
        }

        search(0);
        cout << max_count << endl;
    }
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, k;
	cin >> n >> k;
	
	ll res = 0;
	while (n--) {
		ll h;
		cin >> h;
		res += h >= k;
	}
	cout << res << endl;

}



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

int main() {
  int N, l, r;
  int sum = 0;
  
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> l >> r;
    sum += r - l + 1;
    }      
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
N,M=list(map(int,input().split()))
H=list(map(int,input().split()))

bad=[]
for i in range(M):
	A,B=list(map(int,input().split()))
	if (H[A-1]<=H[B-1])and(A-1 not in bad): bad.append(A-1)
	if (H[A-1]>=H[B-1])and(B-1 not in bad): bad.append(B-1)

print(N-len(bad))

Measured memory_bytes: 84896
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> ac(n);
    ac[0] = 0;
    for (int i = 1; i < n; ++i) {
        if (s[i-1] == 'A' && s[i] == 'C') ac[i] = ac[i-1]+1;
        else ac[i] = ac[i-1];
    }

    while (q--) {
        int l, r;
        cin >> l >> r;
        cout << ac[r-1] - ac[l-1] << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		String b = sc.next();
		int c = sc.nextInt();

		if (b.equals("+")) {
			System.out.print(a + c);

		} else if (b.equals("-")) {

			System.out.print(a - c);
		}

	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) (((long long)mod_x)%modulo)


int main(){
	string S;
	cin>>S;
	
	vector<vector<int>> dp(S.size(),vector<int>(2,0));
	dp[0][0]=2;
	dp[0][1]=1;
	
	for(int i=1;i<S.size();i++){
		if(S[i]=='0'){
			dp[i][1]=mod(dp[i-1][1]*3);
			dp[i][0]=dp[i-1][0];
		}
		else{
			dp[i][1]=mod(mod(dp[i-1][1]*3)+dp[i-1][0]);
			dp[i][0]=mod(dp[i-1][0]*2);
		}
	}
	
	int ans = mod(dp[S.size()-1][0]+dp[S.size()-1][1]);
	
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 5760
n = input()
k = int(input())
digit = len(n)
dp0 = [[0 for i in range(k+1)] for j in range(digit+1)]
dp1 = [[0 for i in range(k+1)] for j in range(digit+1)]

dp1[1][1] = 1
dp0[1][1] = int(n[0])-1
for i in range(1, digit+1):
    dp0[i][0] = 1

for i in range(2, digit+1):
    for j in range(1, k+1):
        num = int(n[i-1])
        if num == 0:
            dp0[i][j] = dp0[i-1][j-1]*9 + dp0[i-1][j]
            dp1[i][j] = dp1[i-1][j] 
        else:
            dp0[i][j] = dp0[i-1][j-1]*9 + dp0[i-1][j] + dp1[i-1][j-1] * (num-1) + dp1[i-1][j]
            dp1[i][j] = dp1[i-1][j-1]

print(dp0[digit][k] + dp1[digit][k])

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

class Tree{
public:
  vector<vector<int>> adj;
  int size;
  Tree(int size): size(size) {
    adj = vector<vector<int>>(size);
  }
  friend istream& operator>>(istream& is, Tree& tree){
    for(int i = 0; i < tree.size - 1; i++){
      int a, b;
      is >> a >> b;
      a--; b--;
      tree.adj[a].push_back(b);
      tree.adj[b].push_back(a);
    }
    return is;
  }
  int diameter(){
    pair<int, int> farthest_from_0 = farthest_node(0);
    pair<int, int> diameter_node = farthest_node(farthest_from_0.first);
    return diameter_node.second;
  }
  pair<int, int> farthest_node(int from){
    // pair: node, distance
    vector<bool> visited(size, false);
    vector<int> distances(size);
    pair<int, int> ret = make_pair(from, 0);

    stack<int> st;
    st.push(from);
    visited[from] = true;
    distances[from] = 0;
    while(!st.empty()){
      int now = st.top();
      st.pop();
      if(distances[now] > ret.second){
        ret = make_pair(now, distances[now]);
      }
      for(auto next: adj[now]){
        if(!visited[next]){
          st.push(next);
          visited[next] = true;
          distances[next] = distances[now] + 1;
        }
      }
    }
    return ret;
  }
};


int main(){
  int N;
  cin >> N;
  auto tree = Tree(N);
  cin >> tree;

  int diam = tree.diameter();
  //cout << diam << endl;
  if(diam % 3 != 1){
    cout << "First" << endl;
  }else{
    cout << "Second" << endl;
  }
}


Measured memory_bytes: 13556
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  ldouble l;
  cin >> l;
  cout << fixed << setprecision(7) <<l*l*l/27 << endl;
  return 0;
}

Measured memory_bytes: 256
from operator import itemgetter
N = int(input())
rest = []

for i in range(N) :
  raw = list(input().split())
  raw[1] = int(raw[1]) 
  raw.append(int(i + 1))
  rest.append(raw)

rest.sort(key=itemgetter(1), reverse = True )
rest.sort(key=itemgetter(0))

for k in range(N) :
  print(rest[k][2])

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

int main()
{
	int n,m,ct = 0;
	cin >> n >> m;
	int a[n];
	for(int i = 1;i <= n;i++){
		cin >> a[i];
	}
	for(int i = 1;i <= n;i++){
		if(a[i] >= m)
			ct++;
	}
	cout << ct;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> a(N);
  for (int i = 0; i < N; ++i) cin >> a.at(i);
  
  bool judge = false; // 1 が存在するか判定
  for (int i : a) {
    if (i == 1) judge = true;
  }
  if (!(judge)) {
    cout << -1 << endl;
    return 0;
  }
  
  int count = 0;
  int MAX = 0;
  for (int i : a) {
    if (i == MAX + 1) ++MAX;
    else ++count;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 1024
#include"bits/stdc++.h"


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = (l);x<=(u);x++)
#define RREP(x,l,u) for(ll x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 800010;
const int mod = 924844033,g = 5;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,k;

int sz[maxn],has[maxn];

int fac[maxn],inv[maxn];

int A[maxn],B[maxn],Ans[maxn];

vector<int> G[maxn];

void NTT(int *a,int f,int k){
	for(int i=0,j=0;i<k;i++){
		if(i>j)swap(a[i],a[j]);
		for(int l=k>>1;(j^=l)<l;l>>=1);
	}
	
	for(int i=1;i<k;i<<=1){int w=fexp(g,(f*(mod-1)/(i<<1)+mod-1)%(mod-1));
		for(int j=0;j<k;j+=i<<1){int e=1;
			for(int k=0;k<i;k++,e=1LL*e*w%mod){int x,y;
				x=a[j+k];y=1LL*a[j+k+i]*e%mod;
				a[j+k]=(x+y)%mod;a[j+k+i]=(x-y+mod)%mod;
			}
		}
	}
	
	if(f==-1){
		int _inv=fexp(k,mod-2);
		for(int i=0;i<k;i++)a[i]=1LL*a[i]*_inv%mod;
	}
}

void dfs(int u,int f){
	for(auto v:G[u])if(v!=f){
		dfs(v,u);
		sz[u]+=sz[v];
	}
	has[++sz[u]]++;
}

void Work(){
	for(k=1;k<=n*2;k<<=1);
	REP(i,0,k-1)A[i]=B[i]=0;
	has[n]--;
	REP(i,0,n)A[i]=1LL*(has[n-i]+has[i])*fac[n-i]%mod;
	REP(i,0,n)B[i]=inv[i];
//	REP(i,0,n)cout<<A[i]<<' ';cout<<endl;
//	REP(i,0,n)cout<<B[i]<<' ';cout<<endl;
	NTT(A,1,k);NTT(B,1,k);
	REP(i,0,k-1)A[i]=1LL*A[i]*B[i]%mod;
	NTT(A,-1,k);
//	REP(i,0,n)cout<<A[i]<<' ';cout<<endl;
	REP(i,1,n)Ans[i]=1LL*A[n-i]*inv[i]%mod;
//	REP(i,1,n)cout<<Ans[i]<<' ';cout<<endl;
	REP(i,1,n)Ans[i]=(1LL*n*fac[n]%mod*inv[i]%mod*inv[n-i]%mod-Ans[i]+mod)%mod;
	REP(i,1,n)printf("%d\n",Ans[i]);
}

void Init(){
	read(n);
	REP(i,2,n){
		int u,v;
		read(u,v);
		G[u].PB(v);G[v].PB(u);
	}
	dfs(1,0);
	fac[0]=1;
	REP(i,1,n)fac[i]=1LL*fac[i-1]*i%mod;
	REP(i,0,n)inv[i]=fexp(fac[i],mod-2);
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 57984
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = read().decode().rstrip()

if S[0] == S[1] == S[2]:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
    if(x>=10)out(x/10);
    putchar(x%10+'0');
}
int n,m,ans=0;
pii a[101010];
prq<int> pq;
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n>>m;
	fo(i,0,n)cin>>a[i].fi>>a[i].se;
	sort(a,a+n);
	int k=0;
	for(int i=m;i>=0;i--){
		while(a[k].fi<=m-i&&k<n)pq.push(a[k++].se);
		if(!pq.empty()){
			ans+=pq.top();
			pq.pop();
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1660
// Try AtCoder
/// author: Leonardone @ NEETSDKASU
import std.stdio     : readln, writeln;
import std.string    : chomp;
import std.array     : split;
import std.conv      : to;

auto getVals(T)() { return readln.chomp.split.to!(T[]); }

void main() {
    bool[char] table;
    foreach (ch; readln.chomp) {
        table[ch] = true;
    }
    for (auto ch = 'a'; ch <= 'z'; ch++) {
        if (ch !in table) {
            writeln(ch);
            return;
        }
    }
    writeln("None");
}

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

for i in range(len(A)):
  C += A[i]
  
for i in range(len(A)):
  if A[i] >= C/(4*M):
    B += 1

if B >= M:
  print('Yes')
else:
  print('No')
    

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

int main(void)
{
  int abc[3];
  int k;
  cin >> abc[0] >> abc[1] >> abc[2] >> k;
  sort(abc, abc+3);
  for (int i = 0; i < k; i++){ abc[2] *= 2; }
  cout << accumulate(abc, abc+3, 0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

//k!
ll facctorialMethod(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum = (sum*i%MOD)%MOD;
    }
    return sum;
}

//nCr
ll permutationMethod(ll n,ll r){
    ll n_sum,r_sum;
    ll i;
	ll rr = n - r;
    n_sum = facctorialMethod(n);
    r_sum = (facctorialMethod(rr)*facctorialMethod(r))%MOD;
	print(n_sum);
	print(r_sum);
    return n_sum/r_sum;
}

int main(){
	int n,x; cin >> n >> x;
	vector<int> v(n);
	int ans = 0;
	int count = 0;
	rep(i,n){
		cin >> v[i];
	}
	rep(i,n+1){
		if (ans <= x){
			count++;
			ans = ans + v[i];
		}
	}
	cout << count << endl;
}

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

#define ALL(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0, __##i##_length = (n); i < __##i##_length; i++)
#define rep_reverse(i, n) for (ll i = (n)-1; 0 <= i; i--)
#define FOR(i, from, to) for (ll i = (from), __##i##_end = (to); i < __##i##_end; i++)
#define FOR_REVERSE(i, from, to) for (ll i = (to)-1, __##i##_end = (from); __##i##_end <= i; i--)
#define foreach(e, v) for (const auto e : (v))
#define vfree(v) std::vector<int>().swap(v)
#define DEBUG(x) cout << #x << " = " << (x) << endl

using namespace std;
typedef int64_t ll;
typedef vector<ll> llv;
typedef vector<llv> llvv;

ll gcd(ll a, ll b)
{
    return (a < b) ? gcd(b, a) : ((a % b) ? gcd(b, a % b) : b);
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
    ll n;
    cin >> n;
    llv d(n);
    rep(i, n)
    {
        cin >> d[i];
    }
    sort(ALL(d));
    // rep(i, n)
    // {
    //     cout << d[i] << " ";
    // }
    // cout << endl;
    ll a = d[n / 2 - 1];
    ll b = d[n / 2];
    cout << b - a << endl;
    return 0;
}


Measured memory_bytes: 1024
N=int(input())
A=list(map(int,input().split()))
a=[0]*(N+1)
for i in range(N):
    a[i+1]=a[i]+A[i]
from collections import Counter
c=Counter(a)
r=0
for n in c.values():
    r+=n*(n-1)//2
print(r)

Measured memory_bytes: 41784
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n;
    cin >> n;
    vi s(n);
    rep(i,n)cin >> s[i];
    int ans = 0;
    loop(c,1,n-1){//t = f(k,c)を求める
        int t = 0;
        int ma = -INF;
        map<int,int> mp;
        //cout << "c=" << c << endl;
        for(int k = 0; c*k < n-1; k++){
            if(mp[n-1-k*c] || mp[k*c] || n-1-k*c == k*c || n-1-k*c < c)break;
            //printf("(%lld, %lld) ",n-1-k*c,k*c);
            mp[n-1-k*c]++;
            mp[k*c]++;
            t += s[n-1-k*c] + s[k*c];
            ma = max(ma, t);
        }
        //cout << endl;
        //cout << "ma:" << ma << endl;
        ans = max(ans, ma);
    }
    cout << ans << endl;
}


Measured memory_bytes: 9344
#include <cstdio>
#include <string>
#include <iostream>

using namespace std;

int main(void){
    int n,k;
    string s;

    cin >> n;
    cin >> s;
    cin >> k;

    for (auto& c : s) {
        if (c != s[k-1]) c = '*';
    }
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
/*
Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}
*/
Node treeSearch(Node u, int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
    
  }
  return u;

}
/*
Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}
*/


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;

  if(y==NIL)root=z;
  else if(z->key<y->key)y->left=z;
  else y->right=z;

}

void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
     if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
     }  else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } /*else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
      }*/
  }

  return 0;
}



Measured memory_bytes: 20520
#include<stdio.h>
int main(){
  int N,i,j,minj,temp,cout=0;
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<N-1;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj])minj=j;
    }
    if(minj!=i){
      temp=A[i];
      A[i]=A[minj];
      A[minj]=temp;
      cout++;
    }
  }
  printf("%d",A[0]);
  for(i=1;i<N;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  printf("%d\n",cout);
  return 0;
}



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

int main() {
  long x;
  cin >> x;
  long result = 0;
  result += (x / 500) * 1000;
  long x2 = x % 500;
  result += (x2 / 5) * 5;
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
n,k=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
h=Hash.new(0)
a.each{|v|h[v]+=1}
sorted_num=h.values.sort
size=sorted_num.size
if size<=k
  puts 0
else
  puts sorted_num.take(size-k).inject(:+)
end

Measured memory_bytes: 32880
sheet = []
3.times do |i|
  sheet << gets.split.map(&:to_i)
end
N = gets.to_i
#=begin
N.times do |n|
  num = gets.to_i
  3.times do |i|
    pos = sheet[i].index(num)
    unless pos.nil?
      sheet[i][pos] = "*"
    end
  end
end

# 縦
bingo = false
3.times do |pos|
  if (sheet[pos][0] == "*") && (sheet[pos][1] == "*") && (sheet[pos][2] == "*")
    puts "Yes"
    exit
  end
  if (sheet[0][pos] == "*") && (sheet[1][pos] == "*") && (sheet[2][pos] == "*")
    puts "Yes"
    exit
  end
end

if (sheet[0][0] == "*") && (sheet[1][1] == "*") && (sheet[2][2] == "*")
  puts "Yes"
  exit
end
if (sheet[0][2] == "*") && (sheet[1][1] == "*") && (sheet[2][0] == "*")
  puts "Yes"
  exit
end

puts "No"
#=end

Measured memory_bytes: 1788
#include <stdio.h>

int main (void){

  int i, k;
  int m1 , m2 , m3;
  int height[10];

  for(i=0; i<10; i++){
    scanf("%d",&height[i]);
  } 

  m1=height[0];

  for(i=0; i<10; i++){

    if(m1<height[i]){

      m1=height[i];
      k=i;
    }
  }   height[k]=0;

  m2=height[0];
  for(i=0; i<10; i++){

    if(m2<height[i]){

      m2=height[i];
      k=i;
    }
  }   height[k]=0;

  m3=height[0];

  for(i=0; i<10; i++){

    if(m3<height[i]){

      m3=height[i];
      k=i;
    }
  }   height[k]=0;

  printf("%d\n%d\n%d\n",m1, m2, m3);

  return 0;

}

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

typedef long long int ll;


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

    ll ans = 0;
    for(ll i = 0;i < n - 1;i++){
        if((x[i + 1] - x[i]) * a < b){
            ans += (x[i + 1] - x[i]) * a;
        }
        else{
            ans += b;
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 1024
//abc092_d.cpp
//Sun Mar 25 21:58:00 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;

int main(){
	int a;
	int b;
	cin >> a;
	cin >> b;

	cout << 100 << " "<< 100 <<endl;

	int grid[100][100];
	int firstflag = 0;
	for (int h=0;h<50;h++){
		int w=0;
		string s;
		s = ".#";
		if (firstflag == 1){
			w=0;
			while (w<100){
				cout << "#";
				w++;
			}
			cout << "\n";
			w=0;
		}else{
			for (w=0;w<100;w=w+2){
				if (a>1){
					cout << s;
					a--;
				}else{
					while (w < 100){
						cout << "#";
						w++;
					}
					w=0;
					firstflag = 1;
					break;
				}
			}
			cout << "\n";
			w=0;
			while (w<100){
				cout << "#";
				w++;
			}
			h++;
			cout << "\n";
		}
	}

	int z = 0;
	while (z<100){
		cout << ".";
		z++;
	}
	cout << "\n";

	firstflag = 0;
	for (int h=0;h<49;h++){
		int w=0;
		string s;
		s = "#.";
		if (firstflag == 1){
			w=0;
			while (w<100){
				cout << ".";
				w++;
			}
			w=0;
			cout << "\n";
		}else{
			for (w=0;w<100;w=w+2){
				if (b>1){
					cout << s;
					b--;
				}else{
					while (w < 100){
						cout << ".";
						w++;
					}
					w=0;
					firstflag = 1;
					break;
				}
			}
			cout << "\n";
			w=0;
			while (w<100){
				cout << ".";
				w++;
			}
			h++;
			cout << "\n";
		}
	}
}

Measured memory_bytes: 256
#!/usr/bin/ruby

def exe_print(a, b, str)
  str[a..b]
end

def extract_pre(a, str)
  if a == 0
    ""
  else
    str[0..a-1]
  end
end

def extract_post(b, str)
  if b == str.length-1
    ""
  else
    str[b+1..str.length]
  end
end

def exe_reverse(a, b, str)
  pre = extract_pre(a, str)
  post = extract_post(b, str)
  pre + str[a..b].reverse + post
end

def exe_replace(a, b, p, str)
  pre = extract_pre(a, str)
  post = extract_post(b, str)
  pre + p + post
end

def execute_command(command, str)
  command_list = command.split(" ")
  if command_list[0] == "print"
    print_str = exe_print(command_list[1].to_i, command_list[2].to_i, str)
    puts print_str
    str
  elsif command_list[0] == "reverse"
    return exe_reverse(command_list[1].to_i, command_list[2].to_i, str)
  elsif command_list[0] == "replace"
    str = exe_replace(command_list[1].to_i, command_list[2].to_i, command_list[3], str)
    return str
  end
end


str = $stdin.gets.chomp
q = $stdin.gets.to_i

while q > 0 do
  command = $stdin.gets
  str = execute_command(command, str)
  q -= 1
end

Measured memory_bytes: 8860
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

#define DIV 1000000007
using namespace std;
using ll = long long;

typedef struct {
	int par = 0;
	int hei = 1;
	ll mem = 1;
}node_t;
vector<node_t> node;

int root(int a) {
	if (node[a].par == 0) return a;
	else {
		node[a].par = root(node[a].par);
		return node[a].par;
	}
}

void unite(int art, int brt) {
	int up, low;
	if (node[art].hei >= node[brt].hei) up = art, low = brt;
	else up = brt, low = art;
	node[low].par = up;
	node[up].hei = max(node[up].hei, node[low].hei + 1);
	node[up].mem += node[low].mem;
}

int main(void) {
	ll N, M;
	cin >> N >> M;

	vector<pair<int, int>> bri(M);
	for (int i = 0; i < M; i++) {
		cin >> bri[i].first >> bri[i].second;
	}

	node = vector<node_t>(N + 1);
	vector<ll> ans(M);
	ans[M - 1] = N * (N - 1) / 2;
	for (int i = M - 1; i >= 1; i--) {
		ans[i - 1] = ans[i];
		int a = bri[i].first, b = bri[i].second;
		int art = root(a), brt = root(b);
		if (art == brt) continue;
		ll temp = node[art].mem * node[brt].mem;
		ans[i - 1] -= temp;
		unite(art, brt);
	}

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

}


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

#define int long long

struct Dinic {
  const int INF = 1<<28;
  
  struct FlowEdge {    
    int to, cap, rev;
    FlowEdge() {}
    FlowEdge(int to, int cap, int rev) : to(to), cap(cap), rev(rev) {}
  };

  int n;
  vector<vector<FlowEdge> > G;
  vector<int> level, iter;

  Dinic() {}
  Dinic(int sz) : n(sz), G(n), level(n), iter(n) {}
  
  void add_edge(int from, int to, int cap) {
    G[from].push_back(FlowEdge(to, cap, G[to].size()));    
    // undirected
    //G[to].push_back(FlowEdge(from, cap, G[from].size()-1));
    // directed
    G[to].push_back(FlowEdge(from, 0, G[from].size()-1));    
  }
  
  void bfs(int s) {
    fill(level.begin(), level.end(), -1);
    queue<int> Q;
    level[s] = 0;
    Q.push(s);
    while ( !Q.empty() ) {
      int v = Q.front(); Q.pop();
      for ( int i = 0; i < (int)G[v].size(); i++ ) {
	FlowEdge &e = G[v][i];
	if ( e.cap > 0 && level[e.to] < 0 ) {
	  level[e.to] = level[v]+1;
	  Q.push(e.to);
	}
      }
    }
  }
  
  int dfs(int v, int t, int f) {
    if ( v == t ) return f;
    for ( int &i = iter[v]; i < (int)G[v].size(); i++ ) {
      FlowEdge &e = G[v][i];
      if ( e.cap > 0 && level[v] < level[e.to] ) {
	int d = dfs(e.to,t,min(f,e.cap));
	if ( d > 0 ) {
	  e.cap -= d;
	  G[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }
  
  int max_flow(int s, int t, int lim) {
    int flow = 0;
    while ( 1 ) {
      bfs(s);
      if ( level[t] < 0 || lim == 0 ) return flow;
      fill(iter.begin(), iter.end(), 0);
      int f;
      while ( (f=dfs(s, t, lim)) > 0 ) {
	flow += f;
	lim -= f;
      }
    }
  }

  int max_flow(int s, int t){
    return max_flow(s, t, INF);
  }
  
  vector<bool> get_cut(int s, int t) {
    vector<bool> res(n);
    for ( int i = 0; i < n; i++ ) {
      res[i] = (level[i] == -1);      
    }
    return res;  
  }
};

signed main(){
  int V,E;
  cin >> V >> E;
  Dinic dinic(V);
  for ( int i = 0; i < E; i++ ) {
    int u, v, c;
    cin >> u >> v >> c;
    dinic.add_edge(u, v, c);
  }
  cout << dinic.max_flow(0,V-1) << endl;
  return 0;
}



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

int main() {
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  double pi = 3.141592653589793;//πの定義
  cout << fixed << setprecision(15);//出力会
  double radA, radB, radX;//針の角度
  radA = 30 * H +  0.5 * M;
  radB = 6 * M;
  
  if(radA >= radB){
    radX = radA - radB;
  }
  else{
    radX = radB - radA;
  }//radX was defined!
  double rad;
  rad = pi * radX / 180;
  
  double ans, ans2;
  int A2 = pow(A, 2);
  int B2 = pow(B, 2);
  ans2 = A2 + B2 - 2*A*B*cos(rad);
  ans = pow(ans2, 0.5);
  cout << ans << endl;
  
  
}

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

typedef long long ll;
int main()
{
  int n,l;

  cin >> n >> l;
  vector<int> taste(n);
  //taste:L+i-1
  int sum=0;
  int flag=0;
  for(int i=0;i<n;i++){
    taste.at(i)=l+i+1-1;
    if(taste.at(i)==0)
    {
      flag=1;
    }
    sum+=taste.at(i);
  }
  //cout << sum;
  //sort(taste.begin(),taste.end());
  int ans=1000000;
  //int k=0;
  if(l<=0&&taste.at(n-1)<=0){
    ans=sum-taste.at(n-1);
  }
  else if(l<=0&&taste.at(n-1)>0){
    ans=sum;
  }
  else if(l>0){
    ans=sum-taste.at(0);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;


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

    int sheet_count = (N+999)/1000;
    int ans = sheet_count*1000 - N;

    cout << ans << endl;

}



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

using namespace std;

int main(void){
    // Your code here
    int N; string S;
    int i;
    long r=0,g=0,b=0;
    int x=0,y=0,z=0;

    cin >> N >> S;

    for(i=0;i<N;i++){
        if(S.at(i)=='R')r++;
        if(S.at(i)=='G')g++;
        if(S.at(i)=='B')b++;   
    }

    long long all = r*g*b;

    for(x=0;x<N-2;++x){
        for(y=x+1;y<N-1;++y){
            if(S.at(x)==S.at(y))continue;
            z=y*2-x;
            if(z>N-1||S.at(x)==S.at(z)||S.at(y)==S.at(z))continue;
            all--;
        }
    }


    cout << all << endl;
}


Measured memory_bytes: 3632