akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
    int w, h , n; cin >> w >> h >> n;
    int field[w + 1][h + 1] = {0};
    for (int i = 0; i < n; i++) {
        int x, y, a; cin >> x >> y >> a;

        if (a == 1) {
            for (int j = 0; j < x; j++) {
                for (int k = 0; k < h; k++) {
                    field[j][k] = 1;
                }
            }
        }

        else if (a == 2) {
            for (int j = x; j < w; j++) {
                for (int k = 0; k < h; k++) {
                    field[j][k] = 1;
                }
            }
        }

        else if (a == 3) {
            for (int j = 0; j < w; j++) {
                for (int k = 0; k < y; k++) {
                    field[j][k] = 1;
                }
            }
        }

        else {
            for (int j = 0; j < w; j++) {
                for (int k = y; k < w; k++) {
                    field[j][k] = 1;
                }
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < w; i++) {
        for (int j = 0; j < h; j++) {
            if (field[i][j] == 0) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    if S[-1] == "s":
        print(S + "es")
    else:
        print(S + "s")
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 61680
import sys

n = int(input())
x = [0]*n ; y = [0]*n
for i in range(n):
    x[i],y[i] = map(int, input().split())

if n == 1:
    print(1)
    sys.exit()

ans = []
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        p = x[i]-x[j]
        q = y[i]-y[j]
        count = 0
        for k in range(n):
            for l in range(n):
                if p == x[k]-x[l] and q == y[k]-y[l]:
                    count += 1
                ans.append(count)

print(n-max(ans))

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n;
  cin >> n;

  vii a(n);
  rep(i,0,n) {
    int k;
    cin >> k;
    a[i] = mp(k, i);
  }

  sort(all(a));
  reverse(all(a));

  vvl dp(n+1, vl(n+1));

  rep(i,0,n) {
    ll val = (ll)a[i].fst;
    int idx = a[i].snd;

    rep(j,0,i+1) {
      ckmax(dp[i+1][j+1], dp[i][j] + abs(j-idx)*val);
      ckmax(dp[i+1][j], dp[i][j] + abs(idx-(n-1-(i-j)))*val);
    }
  }

  cout << *max_element(all(dp[n])) << '\n';


}

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

int main(){
    string s,t;
    cin >> s >> t;
    int ans = 0;
    rep(i,s.size()){
        if(s.at(i) != t.at(i)) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3832
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String answer = "";

		for(int i=0; i<str.length(); i++){
			if(String.valueOf(str.charAt(i)).equals("B") && answer.length() != 0){
				answer = answer.substring(0, answer.length()-1);
			}else if(String.valueOf(str.charAt(i)).equals("0") || String.valueOf(str.charAt(i)).equals("1")){
				answer = answer + str.charAt(i);
			}
		}

		System.out.println(answer);
	}

}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

const int INF = 1001001001;

int main()
{   
    ll k;
    cin >> k;

    set<ll> s;
    ll mod = 7%k;
    int i = 1;
    while(s.count(mod) == 0) {
        if(mod == 0) {
            cout << i << endl;
            return 0;
        }
        s.insert(mod);
        mod = (mod*10+7)%k;
        i++;
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 50476
#include<bits/stdc++.h>
using namespace std;
long long a[405];
long long x[405][4];
long long c[405][10];
map<long long,int>m;
long long get(long long x,long long y,long long z,long long h){return (((((x<<10)+y)<<10)+z)<<10)+h;}
long long doit(long long x,long long y,long long z,long long h){return min(min(get(x,y,z,h),get(y,z,h,x)),min(get(z,h,x,y),get(h,x,y,z)));}
long long fac(long long x){long long ret=1;for(int i=1;i<=x;i++)ret*=i;return ret;}
long long rot(long long x)
{
    int k[4];
	for(int i=0;i<=3;i++,x>>=10)k[i]=x&((1<<10)-1);
    if(k[0]==k[1]&&k[1]==k[2]&&k[2]==k[3])return 4;
    if(k[0]==k[2]&&k[1]==k[3])return 2;
    return 1;
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)c[i][0]=c[i][i]=1;
    for(int i=1;i<=n;i++)for(int j=1;j<=min(4,i-1);j++)c[i][j]=c[i-1][j]+c[i-1][j-1];
    for(int i=1;i<=n;i++)
    {
    	for(int j=0;j<=3;j++)cin>>x[i][j];
    	a[i]=doit(x[i][0],x[i][1],x[i][2],x[i][3]);
    }
    long long ans=0;
    m.clear();
	for(int i=1;i<=n;i++)
	{
		for(int ii=1;ii<i;ii++)
		{
	        for(int j=0;j<=3;j++)
            {
                long long y[4];
            	y[0]=doit(x[ii][(j+1)%4],x[ii][(j+0)%4],x[i][1],x[i][0]);
                y[1]=doit(x[ii][(j+0)%4],x[ii][(j+3)%4],x[i][2],x[i][1]);
                y[2]=doit(x[ii][(j+3)%4],x[ii][(j+2)%4],x[i][3],x[i][2]);
                y[3]=doit(x[ii][(j+2)%4],x[ii][(j+1)%4],x[i][0],x[i][3]);
                sort(y,y+4);
                long long ret=1;
                for(int p=0;p<4;)
                {
                    int cnt=1;
                    for(int r=p+1;r<4&&y[r]==y[p];r++)cnt++;
                    int num=m[y[p]];
                    if(y[p]==a[ii])num--;
                    if(num<cnt){ret=0;break;}
                    ret*=c[num][cnt]*pow(rot(y[p]),cnt)*fac(cnt);
                    p+=cnt;
                }
                ans+=ret;
            }
        }
		m[a[i]]++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 20224
#include <stdio.h>

int main(void) {
	int sum;
	int d;
	int i;
	while(!feof(stdin)) {
		scanf("%d",&d);
		if(feof(stdin))break;
		for(i=0,sum=0;i<600;i+=d)sum+=i*i*d;
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 0
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int H, W; cin >> H >> W;
    vs S(H); REP(i, H) cin >> S[i];

    int black = 0;
    REP(i,H) {
        REP(j,W) {
            if (S[i][j] == '#') black++;
        }
    }

    queue<pii> que;
    que.push(pii(0, 0));
    int dx[4] = { 0,0,1,-1 };
    int dy[4] = { 1,-1,0,0 };
    vvb vis(H, vb(W, false));
    vvi dist(H, vi(W, INF));
    dist[0][0] = 0;
    while(!que.empty()) {
        pii p = que.front(); que.pop();
        int x = p.first;
        int y = p.second;
        vis[x][y] = true;
        
        if (vis[H - 1][W - 1]) break;

        REP(i,4) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (nx<0 || H<=nx || ny<0 || W<=ny ||
                S[nx][ny]=='#' || vis[nx][ny]) continue;

            if (dist[nx][ny] > dist[x][y] + 1) {
                dist[nx][ny] = dist[x][y] + 1;
                que.push(pii(nx,ny));
            }
        }
    }

    int ans = 0;
    if (dist[H-1][W-1] == INF) {
        ans = -1;
    } else {
        ans = H * W - black - (dist[H - 1][W - 1] + 1);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
import bisect

pre = defaultdict(list)
ori = []
n, m = map(int, input().split())
for _ in range(m):
    x, y = map(int, input().split())
    pre[x].append(y)
    ori.append([x, y])

for key, val in pre.items():
    val.sort()

for i in range(m):
    l = pre[ori[i][0]]
    idx = bisect.bisect(l, ori[i][1])
    print(f'{ori[i][0]:06}{idx:06}')



Measured memory_bytes: 38708
//
// Created by watemus on 04.07.2020.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define FF first
#define SS second

using ll = long long;
using ld = long double;

template<typename T>
using vec = std::vector<T>;

template<typename T>
using uset = std::unordered_set<T>;
template<typename T1, typename T2>
using umap = std::unordered_map<T1, T2>;

constexpr ll INFL = 1'000'000'000'000'000'228;
constexpr int INFI = 1'000'000'228;
const ld PI = acos(-1);
std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());

vec<pair<int, int>> DD = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

#ifdef LOCAL
#else
#endif

void run() {
  int n, q;
  cin >> n;
  ll sum = 0;
  map<ll, ll> cnt;
  for (ll i = 0; i < n; i++) {
    int el;
    cin >> el;
    cnt[el]++;
    sum += el;
  }
  cin >> q;
  for (int it = 0; it < q; it++) {
    ll b, c;
    cin >> b >> c;
    sum -= cnt[b] * b;
    sum += cnt[b] * c;
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << sum << '\n';
  }
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

signed main() {
#ifdef LOCAL
  std::freopen("input.txt", "r", stdin);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
#endif
  int t = 1;
  //cin >> t;
  while (t--) {
    run();
  }
  return 0;
}



Measured memory_bytes: 9476
import sys
sys.setrecursionlimit(10 ** 9)

x = int(input())

def per(year):
  if year == 0:
    return 100
  else:
    return int(per(year-1) * 1.01)
  
year = 0
while True:
  if per(year) >= x:
    print(year)
    break
  else:
    year += 1

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

int main(){
  int a,b;
  cin >>a >>b;
  if(a==1) a = 14;
  if(b==1) b = 14;
  if(a>b) cout << "Alice" << endl;
  if(a==b) cout << "Draw" << endl;
  if(a<b) cout << "Bob" << endl;
  return 0;
}


Measured memory_bytes: 256
MOD = 1000000007
ii = lambda :  int(input())
si = lambda :  input()
dgl = lambda : list(map(int, input()))
f = lambda :   map(int, input().split())
il = lambda :  list(map(int, input().split()))
ls = lambda :  list(input())
n,m=f()
a=il()
l=n-sum(a)
if(l>=0):
    print(l)
else:
    print(-1)

Measured memory_bytes: 9884
use std::collections::HashMap;

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()
}

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

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let i : Vec<i64> = read_vec();
    let ac = vec![i[0],i[2]];
    let bd = vec![i[1],i[3]];
    let ans = if ac.iter().max().unwrap() <= bd.iter().min().unwrap() {
         bd.iter().min().unwrap() - ac.iter().max().unwrap()
    } else{
        0
    };
    println!("{}",ans);
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
string a;
long long ans;
int main()
{
    cin>>a;
    if(a[0]!='C') ans++;
    if(a[1]!='O') ans++;
    if(a[2]!='D') ans++;
    if(a[3]!='E') ans++;
    if(a[4]!='F') ans++;
    if(a[5]!='E') ans++;
    if(a[6]!='S') ans++;
    if(a[7]!='T') ans++;
    if(a[8]!='I') ans++;
    if(a[9]!='V') ans++;
    if(a[10]!='A') ans++;
    if(a[11]!='L') ans++;
    if(a[12]!='2') ans++;
    if(a[13]!='0') ans++;
    if(a[14]!='1') ans++;
    if(a[15]!='6') ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
main :: IO ()
main = do
  mn <- getLine
  if mn == "0 0"
    then return ()
    else do
      let [m,n] = map read . words $ mn
          taniL = ["","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"]
      putStrLn $ solve (m `pow` n) taniL
      main
pow :: Integer -> Integer -> Integer
pow m n = pow' m n 1
  where
    pow' :: Integer -> Integer -> Integer -> Integer
    pow' m 0 a = a
    pow' m n a = pow' m (n-1) (a*m)
solve :: Integer -> [String] -> String
solve 0 _ = ""
solve x (y:ys) = (solve (x `div` 10000) ys) ++ if (x `mod` 10000 == 0) then "" else ((show (x `mod` 10000)) ++ y)

Measured memory_bytes: 4316
import java.util.*;

class Main{
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int W = sc.nextInt();
		int w[] = new int[N+1];
		int v[] = new int[N+1];

		for(int n=1;n<N+1;n++){
			w[n] = sc.nextInt();
			v[n] = sc.nextInt();
		}

		long dp[][] = new long[N+1][W+1];
		Arrays.fill(dp[0],0);
		for(int n=1;n<N+1;n++){
			for(int i=1;i<W+1;i++){
				if(w[n] > i) dp[n][i] = dp[n-1][i];
				else dp[n][i] = Math.max(dp[n-1][i],dp[n-1][i-w[n]]+v[n]);
			}
		}

		System.out.println(dp[N][W]);
	}
}

Measured memory_bytes: 126932
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    int n;
    double x1, y1, x2, y2, x3, y3, x4, y4;
    cin >> n;
    for(int i=0; i<n; i++){
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        if(fabs(x2-x1)<0.0000000001 && fabs(x4-x3)<0.0000000001)   cout << "YES" <<endl;
        else{
            if(fabs((y2-y1)/(x2-x1) - (y4-y3)/(x4-x3))<0.0000000001)  cout << "YES" << endl;
            else cout << "NO" << endl;
        }

    }
    return 0;
}


Measured memory_bytes: 3184
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
const char bn = '\n';
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T,typename S,typename U>
ostream& operator<<(ostream& os, tuple<T,S,U> const& P){
    os << "(";
    os << get<0>(P);
    os << ", ";
    os << get<1>(P);
    os << ", ";
    os << get<2>(P);
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
    os<<endl;
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, map<T,S> const&M){
    for(auto e:M){
        os<<e;
    }
    os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;

vector<int64> calc_score(int D, vector<int64> const& C, vector<vector<int64>> const& S, vector<int> T){
    int64 score = 0;
    vector<int> last(26);
    vector<int64> res(D);
    REP(i,D){
        last[T[i]] = i+1;
        score += S[i][T[i]];
        REP(j,26){
            score -= C[j] * (i+1-last[j]);
        }
        res[i] = score;
    }
    return res;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int D; cin >> D;

    vector<int64> C(26);
    REP(i,26) cin >> C[i];

    vector<vector<int64>> S(D, vector<int64>(26));
    REP(i,D) REP(j,26) cin >> S[i][j];

    vector<int> T(D);
    REP(i,D) cin >> T[i], T[i]--;


    auto ans=calc_score(D, C, S, T);

    for(auto a:ans) cout << a << endl;

}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


#include <bits/stdc++.h>
using namespace std;
signed main(){
    int N;
    cin>>N;
    vector<int> a(N); 
    REP(i,N) cin>>a[i];
    Sort(a);
    Reverse(a);
    int Alice =0;
    int Bob =0;
    for(int i=0; i<N; i+=2){
        Alice += a[i];
    }
    for(int i=1; i<N; i+=2){
        Bob += a[i];
    }
    cout<<Alice-Bob<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define mod 1000000007
#define MOD 998244353
#define INF 10000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
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;
}
int N, K, C;
string S;
vector<int> compute(string s) {
    vector<int> dp(N, 0);
    rep(i, N) {
        if(i <= C)
            dp[i] = 1;
        else {
            if(s[i] == 'x')
                dp[i] = dp[i - 1];
            else
                dp[i] = dp[i - C - 1] + 1;
            if(dp[i - 1] > dp[i]) dp[i] = dp[i - 1];
        }
    }
    return dp;
}
signed main() {
    cin >> N >> K >> C >> S;
    vector<int> dp1 = compute(S);
    reverse(all(S));
    vector<int> dp2 = compute(S);
    reverse(all(dp2));
    rep(i, N) {
        int before = 0;
        if(i > 0) before = dp1[i - 1];
        int after = 0;
        if(i < N - 1) after = dp2[i + 1];
        if(before + after < K) cout << i + 1 << endl;
    }
}


Measured memory_bytes: 5056
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#define N 200010
#define inf 2147483647
using namespace std;

struct tt{int l, r, p[2], f;}t[N*2];
int n, w[N], l, x, L, R, y;
set<int>q;
set<int>::iterator it;

inline void update(int i){
	for(int j=0; j<=1; j++)t[i].p[j]=w[t[t[i].l].p[j]]<=w[t[t[i].r].p[j]]?t[t[i].l].p[j]:t[t[i].r].p[j];
}
inline void maketree(int L, int R){
	t[l].l=t[l].r=t[l].f=t[l].p[0]=t[l].p[1]=0;
	if(L<R){
		int mid=(L+R)>>1, l1=l;
		l++; t[l1].l=l; maketree(L, mid);
		l++; t[l1].r=l; maketree(mid+1, R);
		update(l1);
	}else t[l].p[L&1]=L;
}
inline void pushdown(int i){
	if(t[i].f){
		t[t[i].l].f^=1; swap(t[t[i].l].p[0], t[t[i].l].p[1]);
		t[t[i].r].f^=1; swap(t[t[i].r].p[0], t[t[i].r].p[1]);
		t[i].f=0;
	}
}
inline void ins(int i, int x, int L, int R){
	if(L==R){w[L]=inf; t[i].p[0]=t[i].p[1]=0; return;}
	pushdown(i);
	int mid=(L+R)>>1;
	if(x<=mid)ins(t[i].l, x, L, mid); else ins(t[i].r, x, mid+1, R);
	update(i);
}
inline void insf(int i, int a, int b, int L, int R){
	if(a<=L&&R<=b){t[i].f^=1; swap(t[i].p[0], t[i].p[1]); return;}
	pushdown(i);
	int mid=(L+R)>>1;
	if(a<=mid)insf(t[i].l, a, b, L, mid);
	if(mid<b)insf(t[i].r, a, b, mid+1, R);
	update(i);
}
inline int check(int i, int a, int b, int L, int R){
	if(a==L&&R==b)return t[i].p[0];
	pushdown(i);
	int mid=(L+R)>>1, x1, x2;
	if(b<=mid)return check(t[i].l, a, b, L, mid);
	if(a>mid)return check(t[i].r, a, b, mid+1, R);
	x1=check(t[i].l, a, mid, L, mid); x2=check(t[i].r, mid+1, b, mid+1, R);
	return w[x1]<=w[x2]?x1:x2;
}

int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; i++)scanf("%d", &w[i]); w[0]=inf;
	l=1; maketree(1, n);
	q.clear(); q.insert(0); q.insert(n+1);
	for(int i=1; i<=n/2; i++){
		x=t[1].p[1]; printf("%d ", w[x]);
		it=q.lower_bound(x); L=x+1; R=(*it)-1;
		y=check(1, L, R, 1, n); printf("%d", w[y]); if(i<n/2)printf(" ");
		q.insert(x); q.insert(y);
		ins(1, x, 1, n); ins(1, y, 1, n);
		if(x+1<=y-1)insf(1, x+1, y-1, 1, n);
	}
	return 0;
}

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

int main() {
  string S; cin >> S;
  int N = S.size();
  int total =0;
  for (int i =0; i<N; i++) {
    total += (int)(S[i] - '0');
  }
  if (total % 9 ==0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3692
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}



int main(){
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n)
	{
		cin >> a[i];
	}
	sort(all(a));
	int s = 0;
	rep(i, k) s += a[i];
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 3584
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())
sv = sum(v)
dp = [[int(1e10)] * (sv+1) for i in range(N + 1)]
dp[0][0] = 0
for i in range(1, N + 1):
    for j in range(sv + 1):
        if j - v[i-1] >= 0:
            dp[i][j] = min(dp[i-1][j], dp[i-1][j - v[i-1]] + w[i-1])
        else:
            dp[i][j] = dp[i-1][j]
#print(dp)
ans = sv
while(dp[N][ans] > W):
    ans -= 1
print(ans)


Measured memory_bytes: 120556
fun main(args: Array<String>) {

    val (A, B) = readInts()
    val n = B - A

    val height = n * (n + 1) / 2
    println(height - B)
}

fun readInts(): List<Int> = readStrings().map { it.toInt() }
fun readStrings(): List<String> = readLine()!!.split(" ")

Measured memory_bytes: 36036
from heapq import heappop, heappush
N,M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A = sorted(A,reverse = True)
hq = []
ans = 0
for i in range(N):
  heappush(hq,-A[i])
for i in range(M):
  heappush(hq,int(heappop(hq)/2))
print(-sum(hq))

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=2019;

int main(){
    int N; cin >> N;
    vector<ll> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    ll cnt=0, sum=1000;
    for(int i=0; i<N-1; i++){
        if(A[i+1] > A[i]){
            ll tmp=sum/A[i];
            cnt+=tmp;
            sum=sum-A[i]*tmp;
        }
        else{
            sum=sum+cnt*A[i];
            cnt=0;
        }
    }
    if(cnt > 0) sum=sum+cnt*A[N-1];
    cout << sum << endl;
    return 0;
}

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

int main(void) {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (p[i] == i + 1) {
      i++;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
n = gets.to_i
$pre = gets.split.map(&:to_i)
$in = gets.split.map(&:to_i)
$post = []

$pos = 0

def reconstruction(l, r)
  if l >= r
    return
  end

  c = $pre[$pos]
  $pos += 1

  m = $in.index(c)

  reconstruction(l, m)
  reconstruction(m+1, r)

  $post << c
end

reconstruction(0, n)

puts $post.join(" ")


Measured memory_bytes: 6864
n, x = map(int, input().split())
x_list = [int(i) for i in input().split()]

diff_list = [max(x, x_list[i])-min(x, x_list[i]) for i in range(n)]

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    while y > 0:
        x, y = y, x%y
    return x

def multi_gcd(a):
    z = 0
    for i in a:
        z = gcd(i, z)
    return z
  
if __name__ == "__main__":
  ans = multi_gcd(diff_list)
  print(ans)

Measured memory_bytes: 14252
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1];}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const objvs =(a)=>{const b=[];for(const v in a){b.push(a[v])}return b};
const main=()=>{
  let [n,a,b]=tnn(3),ans=0
  for(let i=1;i<=n;i++){
    let s=('00000'+i).slice(-5)
    let l=Number(s[0])+Number(s[1])+Number(s[2])+Number(s[3])+Number(s[4])
    if(l>=a&&l<=b)ans+=i
  }
  to(ans)
}
main()


Measured memory_bytes: 8248
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n, cnt, a[13][9], l[13], x[11], used[11], zero[11], power[9]; char c[11];
int solve(int depth, int value) {
	if (depth == cnt) return value ? 0 : 1;
	int ret = 0;
	for (int i = 0; i < 10; i++) {
		if (!used[i]) {
			used[i] = 1;
			if(i || zero[depth]) ret += solve(depth + 1, value + x[depth] * i);
			used[i] = 0;
		}
	}
	return ret;
}
int main() {
	string s; power[0] = 1;
	for (int i = 1; i < 9; i++) power[i] = power[i - 1] * 10;
	while (cin >> n, n) {
		cnt = 0;
		for (int i = 0; i < 10; i++) zero[i] = 1, x[i] = c[i] = 0;
		for (int i = 0; i < n; i++) {
			cin >> s; l[i] = s.size();
			reverse(s.begin(), s.end());
			for (int j = 0; j < s.size(); j++) {
				int flag = 0;
				for (int k = 0; k < cnt; k++) {
					if (s[j] == c[k]) {
						a[i][j] = k, flag = 1;
						break;
					}
				}
				if (!flag) a[i][j] = cnt, c[cnt++] = s[j];
			}
			if(l[i] > 1) zero[a[i][l[i] - 1]] = 0;
			for (int j = 0; j < l[i]; j++) x[a[i][j]] += power[j] * (i + 1 == n ? -1 : 1);
		}
		cout << solve(0, 0) << endl;
	}
}

Measured memory_bytes: 3112
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000
int L[MAX/2+2],R[MAX/2+2];
int cnt;
void merge(int A[],int n, int left, int mid, int right){
    int n1=mid-left;
    int n2=right-mid;
    for(int i=0;i<n1;i++) L[i]=A[left+i];
    for(int i=0;i<n2;i++) R[i]=A[mid+i];
    L[n1]=R[n2]=SENTINEL;
    int i=0,j=0;
    for(int k=left;k<right;k++){
        cnt++;
        if(L[i]<=R[j]){
            A[k]=L[i++];
        }else{
            A[k]=R[j++];
        }
    }
}
void mergeSort(int A[],int n,int left,int right){
    if(left+1<right){
        int mid=(left+right)/2;
        mergeSort(A,n,left,mid);
        mergeSort(A,n,mid,right);
        merge(A,n,left,mid,right);
    }
}
int main(){
    int A[MAX],n,i;
    cnt=0;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>A[i];
    }
    mergeSort(A,n,0,n);
    for(i=0;i<n;i++){
        if(i) cout<<" ";
        cout<<A[i];
    }
    cout<<endl;
    cout<<cnt<<endl;
}


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

#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end()

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

ll sum(int n){
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}
using namespace std;


int disl[10] = {1,1,1,1,1,1,1,1,1,1};//1's like 0's dislike
bool verify(int n){
   while(n > 0){
      if(disl[n%10] == 0) return false;
      n/=10;
   }
   return true;
}

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

   int n; cin >> n;
   int k; cin >> k;
   while(k--){
      int dint; cin >> dint;
      disl[dint] = 0;  
   }
   
   for(int i = n; ; i++){
      if(verify(i)){
         cout << i; break;
      }
   }
   return 0;
}


Measured memory_bytes: 256
n, x, y = map(int, input().split())
r = (y-x+1)//2
dist = [0] * n
for i in range(1, n+1):
  for j in range(i+1, n+1):
    if i <= x:
      if j <= x:
        dist[j-i] += 1
      elif j <= y:
        dist[min(j-i, y-j+1+ x-i)] += 1
      else:
        dist[j-i-(y-x)+1] += 1
    elif i < y:
      if j <= y:
        dist[min(j-i, y-j+i-x+1)] += 1
      else:
        dist[min(j-i, i-x + 1 + j-y)] += 1
    else:
      dist[j-i] += 1
for i in range(1, n):
  print(dist[i])


Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
int main(){
  int kazu = 0;
  cin >> kazu;
  vector<ll> num(kazu);
  vector<ll> copy(kazu);
  for(int i = 0;i <= kazu - 1;i++){
    cin >> num[i];
    copy[i] = num[i];
  }
  sort(copy.begin(),copy.end());
  int a,b;
  a = copy[kazu / 2 - 1];
  b = copy[kazu / 2];
  for(int i = 0;i <= kazu - 1;i++){
    if(num[i] <= a){
      cout << b << endl;
    }
    else{
      cout << a << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 5376
H, W = gets.split.map(&:to_i)

field = []

H.times do
  field << gets.chomp.chars
end

loop do
  update = false

  temp = []

  field.each do |row|
    if !row.all? { |a| a == '.' }
      temp << row
    else
      update = true
    end
  end

  remove_list = []

  temp.transpose.each_with_index do |col, index|
    if col.all? { |a| a ==  '.' }
      remove_list << index
      update = true
    end
  end

  field = temp.map do |row|
    r = []

    row.each_with_index do |a, i|
      next if remove_list.include?(i)

      r << a
    end

    r
  end

  break unless update
end

puts field.map(&:join)


Measured memory_bytes: 2684
n, m = map(int, input().split())
a = []
for i in range(n):
  a.append(list(map(int, input().split())))
  del a[i][0]
  
count = []
result = 0

for _ in range(m):
  count.append(0)

for i in range(n):
  for j in range(1, m+1):
      if j in a[i]:
        count[j-1] += 1
      
for _ in range(m):
  if n in count:
    count.remove(n)
    result += 1
      
print(result)

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

int main(){
  bool is_prime[1000000];

  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<1000000;i++){
    is_prime[i]=true;
  }

  for(int i=2;i*i<1000000;i++){
    if(is_prime[i]){
      for(int j=i*i;j<1000000;j+=i){
          is_prime[j]=false;
        }
    }
  }
  int n;
  while(true){
    cin>>n;
    if(n==0){
      break;
  }
  int a=0,b=0,cnt=0;
  while(a<=n/2){
  while(is_prime[a]==false){
      a++;
  }
  if(a>n/2){
    break;
  }
  b=n-a;
  if(is_prime[b]==true){
    cnt++;
  }
  a++;
}
cout<<cnt<<endl;
}
}



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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);

    int n, a;
    cin >> n >> a;
    cout << n*n - a << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}


int main(){
	string S;
	cin >> S;
	string F = "FESTIVAL";
	rep(i, F.size()) S.pop_back();

	Cout(S);
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 14 21:14:26 2020

@author: NEC-PCuser
"""

N = int(input())
A = list(map(int, input().split()))

a = [0] * (10 ** 6)

for i in A:
    first_flg = True
    for j in range(i, 10 ** 6 + 1, i):
        if first_flg == True and a[j - 1] != 0:
            a[j - 1] += 1
            break
        a[j - 1] += 1
        first_flg = False


count = 0
for i in A:
    if a[i - 1] == 1:
        count+=1

print(count)

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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

typedef long long ll;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
	int x(0), sgn(1); char ch(getchar());
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
	return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("D.in", "r", stdin);
	freopen ("D.out", "w", stdout);
#endif
}

const int N = 3e5 + 1e3;

int n, a[N];

ll pre[N], suf[N];

priority_queue<int> Max;
priority_queue<int, vector<int>, greater<int>> Min;

int main () {

	File();

	n = read();
	For (i, 1, n * 3) a[i] = read();

	For (i, 1, n)
		Min.push(a[i]), pre[i] = pre[i - 1] + a[i];

	For (i, n + 1, 2 * n) {
		pre[i] = pre[i - 1];
		if (a[i] > Min.top())
			pre[i] += a[i] - Min.top(), Min.pop(), Min.push(a[i]);
	}

	Fordown (i, n * 3, n * 2 + 1)
		Max.push(a[i]), suf[i] = suf[i + 1] + a[i];

	Fordown (i, n * 2, n + 1) {
		suf[i] = suf[i + 1];
		if (a[i] < Max.top())
			suf[i] += a[i] - Max.top(), Max.pop(), Max.push(a[i]);
	}

	ll ans = pre[n] - suf[n + 1];
	For (i, n, 2 * n)
		chkmax(ans, pre[i] - suf[i + 1]);
	printf ("%lld\n", ans);

	return 0;

}

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

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int total,x,res;
	res=0;
	for(int i=1;i<=N;i++){
		total = 0;
		x = i;
		while(true) {
			total += x%10;
			if(x/10 < 1) break;
			else x/= 10;
		}
		if(total >= A && total <= B) res+=i;
	}
	cout << res << endl;
}

Measured memory_bytes: 3488
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

int ans[105];

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    int a, b, k;
    scanf("%d%d%d", &a, &b, &k);

    int cnt = 0;
    for(int i = 1; i <= 100; i++)
    {
        if((a % i == 0) && (b % i == 0))    ans[++cnt] = i;
    }
    printf("%d\n", ans[cnt - k + 1]);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


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

int main() {
	int N, K, board = 1;
	cin >> N >> K;
	
	for(int i = 0; i < N; i++){
		if(board * 2 >= board + K){
			board += K;
		}else if(board * 2 < board + K){
			board *= 2;
		}
	}
	
	cout << board << endl;
}

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

using namespace std;

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

	vector < int >d(K);
	vector < vector < int >>A(K);
	for (int i = 0; i < K; i++) {
		cin >> d[i];
		vector < int >tmp(d[i]);
		for (int j = 0; j < d[i]; j++) {
			cin >> tmp[j];
		}
		A[i] = tmp;
	}

	set < int >st;
	for (int i = 1; i <= N; i++) {
		st.insert(i);
	}

	set < int >al;
	for (int i = 0; i < K; i++) {
		set < int >confectionery(A[i].begin(), A[i].end());
		set_union(al.begin(), al.end(),
			  confectionery.begin(), confectionery.end(),
			  inserter(al, al.end()));
	}

	set < int >ans;
	set_difference(st.begin(), st.end(),
		       al.begin(), al.end(), inserter(ans, ans.end())
	    );

	cout << ans.size() << endl;

	return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <numeric>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define ALL(x) (x).begin(),(x).end()
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

int main(){
	string s; cin >> s;
	int n = s.size();
	int ans = 0;
	for(int i=n-2; i>0; i-=2){
		string t = s.substr(0, i/2);
		string u = s.substr(i/2, i/2);
		if(t==u){
			ans = max(ans, i);

			// cout << t << ' ' << u << endl;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())
s=[[i for i in input()] for j in range(n)]
s_set=[list(set([i for i in s[j]])) for j in range(n)]
text=s_set[0]
for i in range(len(s_set)):
    text=text and s_set[i]
num=[0]*len(text)
for i in range(len(text)):
    mini=100000000000
    for j in range(len(s)):
        if s[j].count(text[i])<mini:
            mini=s[j].count(text[i])
    num[i]=mini
sorted_text=sorted(text)
ans=""
for i in sorted_text:
    for j in range(num[text.index(i)]):
        ans+=i
print(ans)

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

int main() {
	int n;
	cin >> n;
	if (n % 10 == 7) {
		cout << "Yes" << endl;
		return 0;
	}
	n /= 10;
	if (n % 10 == 7) {
		cout << "Yes" << endl;
		return 0;
	}
	n /= 10;
	if (n  == 7) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;//昇順
//N*longN
vector<bool> prime_table(int n) {
  vector<bool> prime(n+1,true);
  if(n>=0) prime[0]=false;
  if(n>=1) prime[1]=false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
int main(){
  auto t=prime_table(55555);
  int N;cin>>N;
  int count=0;
  for(int i=0;i<=55555;i++){
    if(t[i]==true&&i%5==1){
      cout<<i<<" ";
      count++;
      if(count==N){
        break;
      }
    }
  }
  cout<<endl;
}


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

using namespace std;

typedef long long ll;

const int unit[5] = {20 * 20 * 18 * 20, 20 * 18 * 20, 18 * 20, 20, 1};
const int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool is_leap(int y)
{
    if (y % 400 == 0) return 1;
    if (y % 100 == 0) return 0;
    if (y % 4 == 0) return 1;
    return 0;
}

ll fairfield(ll y, ll m, ll d)
{
    if (m <= 2) y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + 153 * (m + 1) / 5 + d - 428;
}
 
void a2m(vector<int> &v)
{
    ll y = v[0], m = v[1], d = v[2];

    ll day = (fairfield(y, m, d) - fairfield(2012, 12, 21)) % 1872000LL;    
    for (int i = 0; i < 5; i++) {
        if (i > 0) cout << ".";
        cout << day / unit[i];
        day %= unit[i];
    }
    cout << endl;
}

void m2a(vector<int> &v)
{
    int day = 0;
    for (int i = 0; i < 5; i++) {
        day += v[i] * unit[i];
    }

    int y = 2012, m = 12, d = 21;
    for (int i = 0; i < 11; i++) {
        if (day == 0) break;
        day--; d++;
    }
    
    if (d == 32) y++, d = 1, m = 1;
    
    bool update = 1;
    while (update) {
        update = 0;
        if (is_leap(y)) {
            if (day >= 366) {
                day -= 366;
                y++;
                update = 1;
            } 
        } else {
            if (day >= 365) {
                day -= 365;
                y++;
                update = 1;
            }            
        }
    }
    
    for (int i = 1; i <= 12; i++, m++) {
        int md = month[i];
        if (is_leap(y) && i == 2) md++;
        if (day >= md) {
            day -= md;
        } else {
            break;
        }
    }
    
    cout << y << "." << m << "." << d + day << endl;
}

int s2i(string &s)
{
    stringstream ss(s);
    int num;
    ss >> num;
    return num;
}

int main()
{
    string s;
    while (cin >> s, s != "#") {
        stringstream ss(s);
        vector<int> v;
        while (getline(ss, s, '.')) {
            v.push_back(s2i(s));
        }
        (v.size() == 3 ? a2m(v) : m2a(v));
    }
    return 0;
}

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

#define rep(i,n) for(int i=0; i < (int)n; i++)

 int main(){ 

 string s;
 cin >> s;

 string ans = "Bad";

 if((s[0] != s[1]) && (s[1] != s[2]) && (s[2] != s[3])) ans = "Good";

 cout << ans << endl;


 return 0;
}

Measured memory_bytes: 256