akhauriyash/Code-Regression huggingface dataset:
/*
https://atcoder.jp/contests/agc043/submissions/11062955
勉強させていただいた提出
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1};
const int dy[]={1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

int H,W;

bool isIn(int y,int x){
    return (0<=x&&x<W&&0<=y&&y<H);
}

int main(){
    cin>>H>>W;
    vector<string> s(H);
    vii dist(H+10,vi(W,INF));
    dist[0][0]=0;
    rep(i,H)cin>>s[i];
    if(s[0][0]=='#')dist[0][0]=1;
    queue<pair<int,int>> que;

    que.push({0,0});

    while(!que.empty()){
        int y=que.front().first,x=que.front().second;

        que.pop();

        rep(i,2){
            int nx=x+dx[i],ny=y+dy[i];
            if(isIn(ny,nx)&&(s[ny][nx]=='#'&&s[y][x]=='.')&&dist[ny][nx]>dist[y][x]+1){
                dist[ny][nx]=dist[y][x]+1;
                que.push({ny,nx});
            }else if(isIn(ny,nx)&&!(s[ny][nx]=='#'&&s[y][x]=='.')&&dist[ny][nx]>dist[y][x]){
                dist[ny][nx]=dist[y][x];
                que.push({ny,nx});
            }
            
        }
    }

    cout<<dist[H-1][W-1]<<endl;

    return 0;
}

//a=97,z=122


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

ll N, T[100005], X[100005], Y[100005];

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

	cin >> N;
	for (ll i = 1; i <= N; i++) {
		cin >> T[i] >> X[i] >> Y[i];
	}

	for (ll i = 1; i <= N; i++) {
		ll dist = abs(X[i]-X[i-1]) + abs(Y[i]-Y[i-1]);
		if (T[i] - T[i-1] < dist) {
			cout << "No\n";
			return 0;
		}
		if ((T[i] - T[i-1]) % 2 != dist % 2) {
			cout << "No\n";
			return 0;
		}
	}

	cout << "Yes\n";
	
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define MOD 998244353

using namespace std;
 
typedef long long ll;
typedef pair<int,int> ii;

ll fpow(ll x, ll p) {
    if (p == 0)
        return 1;
    return ((p & 1) ? x : 1) * fpow(x * x % MOD, p >> 1) % MOD;
}

ll subs(ll x, ll d) {
    return ((x - d) % MOD + MOD) % MOD;
}

ll comb(ll n) {
    if (n & 1)
        return (n - 1) / 2 * n % MOD;
    return n / 2 * (n - 1) % MOD;
}

class Fnwick {
    int *ar;
    int size;
  public:
    Fnwick(int n) {
        size = n + 1;
        ar = new int[size];
        memset(ar, 0, sizeof(int) * size);
    }
    ~Fnwick() {
        delete ar;
    }
    int add(int x, int v) {
        for (int ctr1 = x + 1; ctr1 <= size; ctr1 += (ctr1 & -ctr1))
            ar[ctr1] += v;
    }
    int get(int x) {
        int rez = 0;
        for (int ctr1 = x + 1; ctr1 > 0; ctr1 -= (ctr1 & -ctr1))
            rez += ar[ctr1];
        return rez;
    }
};

ll count(vector<ii> &p, unordered_map<int, int> &rc, int n) {
    ll rez = 0;
    Fnwick bit(2 * n);
    for (int ctr1 = 0; ctr1 < n; ++ctr1) {
        rez = subs(rez, fpow(2, ctr1));
        rez = subs(rez, fpow(2, n - 1 - ctr1));
        int y = rc.find(p[ctr1].second)->second;
        int lower = bit.get(y);
        int higher = ctr1 - lower;
        rez = (rez + fpow(2, lower)) % MOD;
        rez = (rez + fpow(2, higher)) % MOD;
        bit.add(y, 1);
    }
    return rez;
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;

    int x, y;
    vector<ii> points;
    vector<int> compressed;
    unordered_map<int, int> rev;
    for (int ctr1 = 0; ctr1 < n; ++ctr1)
        cin >> x >> y, points.push_back(make_pair(x, y)), compressed.push_back(y);
    
    sort(points.begin(), points.end());
    sort(compressed.begin(), compressed.end());
    for (int ctr1 = 0; ctr1 < n; ++ctr1)
        rev.emplace(compressed[ctr1], ctr1);
    
    ll rez = subs(fpow(2, n), 1) * n % MOD;
    rez = (rez + count(points, rev, n)) % MOD;
    reverse(points.begin(), points.end());
    rez = (rez + count(points, rev, n)) % MOD;
    
    cout << rez << "\n";

    return 0;
}

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

std::vector<int> A, M;

bool solve(int i, int m, int n) {
    if (m == 0) return true;
    if (i >= n) return false;
    bool res = solve(i+1, m, n) || solve(i+1, m-A[i], n);
    return res;
}

int main() {
    int n, q, temp;
    std::cin >> n;
    for (int i=0; i<n; ++i) {
        std::cin >> temp;
        A.push_back(temp);
    }
    std::cin >> q;
    for (int i=0; i<q; ++i) {
        std::cin >> temp;
        M.push_back(temp);
    }
    
    for (auto&& m : M) {
        if (solve(0, m, n)) {
            std::cout << "yes" << std::endl;
        } else {
            std::cout << "no" << std::endl; 
        }
    }
    
    return 0;
}


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

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

	int ans = 0;
	for( int i = a; i <= b; i++ ) {
		if( c % i == 0 ) {
			ans++;
		}
	}

	cout << ans << endl;
}



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

int main(){
    int a, b, h;
    cin >> a >> b >> h;
    cout << ( a + b ) * h / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int i, n, m[100], flag = 1, tmp, c = 0;

  scanf("%d",&n);

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

  while(flag){
    flag = 0;
      for( i = n-1; i >= 1; i--){
	if( m[i] < m[i-1]){
	  tmp = m[i];
	  m[i] = m[i-1];
	  m[i-1] = tmp;
	  flag = 1;
	  c++;
	}
      }
  }
  for(i = 0; i < n; i++){
    printf("%d",m[i]);
    if(i < n-1)
      printf(" ");
  }
  printf("\n%d\n",c);
  return 0;
}

Measured memory_bytes: 604
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}


//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let s:Vec<char> = read::<String>().chars().collect();

    let mut ans:i32 = 0;
    for i in 0..s.len() {
        for j in i..s.len() {
            let mut cnt:i32 = 0;
            for k in i..j+1 {
                let f = match s[k as usize] {
                    'A' => true,
                    'C' => true,
                    'G' => true,
                    'T' => true,
                    _ => false,
                };
                //debug!(i,j,k,s[k as usize]);
                //print!("{}",s[k as usize]);
                if !f {break}
                cnt += 1;
            }
            //println!("");
            ans = max(ans, cnt);
        }
    }

    println!("{}", ans);
}


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

int main()
{
	int n;
	cin>>n;
	
	string a[n+1];
	for(int i=1;i<=n;i++) cin>>a[i];	
	
	map<string, int> mp;
	 
	for(int i=1;i<=n;i++)
	{
		if(mp.count(a[i])==0) mp[a[i]]=1;
		else mp[a[i]]++;
	}
	
	int maxv=0;
	string s[n+1];
	
	for(int i=1;i<=n;i++)
	{
		if(mp[a[i]]>maxv){
			maxv=mp[a[i]];
		}
	}
	
	int j=0;
	for(int i=1;i<=n;i++){
		if(mp[a[i]]==maxv)
		{
			s[j++]=a[i];	
		}
	}
	
	sort(s,s+j);
	
	for(int i=0;i<j;i++)
	{
		if(s[i]==s[i+1]) continue;
		cout<<s[i]<<endl;
	}
		
	
	return 0;
	 
} 

Measured memory_bytes: 28416
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, AB):
    
    t = []
    for a, b in AB:
        t.append((a+b, a, b))
    
    t.sort(reverse=True)
    A = 0
    B = 0
    for i, (_, a, b) in enumerate(t):
        if i % 2 == 0:
            A += a
        else:
            B += b
    return A- B


def main():
    N = read_int()
    AB = [read_int_n() for _ in range(N)]
    print(slv(N, AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 41452
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

vector<bool> is_prime(1001000,true);
vector<long> cnt_prime(1001000,0);

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

void InitP(){
    is_prime.at(1) = false;
    for(int i=2;i<1001000;i++){
        if(is_prime.at(i)){
            for(int j=2;i*j<1001000;j++){
                is_prime.at(i*j) = false;
            }
        }
    }
}

const int MAX = 1001000;

long long inv[MAX];

// テーブルを作る前処理
void COMinit() {
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    }
}

int main(){
    InitP();
    COMinit();
    long n;
    cin >> n;
    vector<long> a(n);
    rep(i,n) cin >> a.at(i);
    sort(all(a));
    long ans = 0;
    rep(i,n){
        ans += inv[a.at(i)];
        ans %= MOD;
    }


    

    rep(i,n){
        map<long,long> mp;
        long tmp = a.at(i);
        for(int i=2;i<=1000;i++){
            while(tmp % i == 0){
                tmp /= i;
                if(mp.count(i)) mp.at(i)++;
                else mp[i] = 1;                
            }
        }
        if(is_prime.at(tmp)) mp[tmp] = 1;
        for(auto x : mp){
            long num = x.first;
            long cnt = x.second;
            cnt_prime.at(num) = max(cnt_prime.at(num),cnt);
        }
    }

    for(int i=2;i<=1000000;i++){
        ans *= pow(i,cnt_prime.at(i));
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 16128
#include<stdio.h>

int main(void){
    int n,t;
    scanf("%d %d",&n,&t);
    
    int cost[100],tim[100];
    int i,ans,tmp1,tmp2=1001;
    
    for(i=0;i<n;i++){
        scanf("%d %d",&cost[i],&tim[i]);
    }
    
    for(i=0;i<n;i++){
        if(tim[i]<=t){
            tmp1=cost[i];
            if(tmp1<tmp2){
                tmp2=tmp1;
                ans=i;
            }
        }
    }
    
    if(tmp2!=1001){
        printf("%d",cost[ans]);
    }else{
        printf("TLE\n");
    }
    
    return 0;
}

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

using namespace std;

int main() {
    int D,T,S;
    cin >> D >> T >>S;
    double passed_time;
    passed_time = (double)D / S;
    if(passed_time <= T){
        cout << "Yes" << endl;
        return 0;
    }
    else{
        cout << "No" << endl;
        return 0;
    }
}

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

int main()
{
    int N, M;
    cin >> N>>M;
    
    vector<int> a;
    
    int total = 0;
    for(int i=0;i<N;i++)
    {
        int t;
        cin >>t;
        a.push_back(t);
        total += t;
    }
    
    sort(a.begin(),a.end(),greater<int>());
    
    if(a[M-1] < (double)total / (4 * M))
    {
        cout << "No" <<endl;
    }
    else
    {
        cout << "Yes" <<endl;
    }
    
    
    return 0;
}

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

int main(){
    string s; cin >> s;
    int z = 0, o = 0;
    for(int i = 0; i < s.size(); i++){
        if(s.at(i) == '0') z++;
        else o++;
    }
    cout << min(o, z)*2 << endl;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

const int MAX_N = 2e3 + 5;

int arr [MAX_N][MAX_N];
int deds [MAX_N][MAX_N];
int reds [MAX_N][MAX_N];

int get_arr (int x1, int y1, int x2, int y2) {
  x1--;
  y1--;
  return arr[x2][y2] - arr[x1][y2] - arr[x2][y1] + arr[x1][y1];
}

int get_deds (int x1, int y1, int x2, int y2) {
  x1--;
  y1--;
  return deds[x2][y2] - deds[x1][y2] - deds[x2][y1] + deds[x1][y1];
}

int get_reds (int x1, int y1, int x2, int y2) {
  x1--;
  y1--;
  return reds[x2][y2] - reds[x1][y2] - reds[x2][y1] + reds[x1][y1];
}

int query (int x1, int y1, int x2, int y2) {
  int vc = get_arr(x1, y1, x2, y2);
  int dc = get_deds(x1, y1, x2 - 1, y2);
  int rc = get_reds(x1, y1, x2, y2 - 1);
  return vc - (dc + rc);
}

int main () {
  ios::sync_with_stdio(false);

  int n, m, q;
  cin >> n >> m >> q;

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      char c;
      cin >> c;
      arr[i][j] = c - '0';
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (arr[i][j] && arr[i + 1][j]) deds[i][j]++;
      if (arr[i][j] && arr[i][j + 1]) reds[i][j]++;
    }
  }

  // cumulativize
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      arr[i][j] += arr[i - 1][j] + arr[i][j - 1] - arr[i - 1][j - 1];
      reds[i][j] += reds[i - 1][j] + reds[i][j - 1] - reds[i - 1][j - 1];
      deds[i][j] += deds[i - 1][j] + deds[i][j - 1] - deds[i - 1][j - 1];
    }
  }

  for (int i = 0; i < q; i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    cout << query(x1, y1, x2, y2) << '\n';
  }
}


Measured memory_bytes: 48896
h,w=gets.chomp.split(" ").map { |e| e.to_i  }
a=h.times.map { gets.chomp.split("")  }


x=Array.new(w,".")

a.delete(x)

newh = a.length

xx=Array.new(newh,".")

newa = Array.new(w).map { Array.new(newh)}

w.times do |i|
  newh.times do |j|
    newa[i][j] = a[j][i]
  end
end
newa.delete(xx)

neww = newa.length

aa = Array.new(newh).map { Array.new(neww)}



neww.times do |i|
  newh.times do |j|
    aa[j][i] = newa[i][j]
  end
end



newh.times do |i|
  print aa[i].join
  puts
end

Measured memory_bytes: 2428
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n; //データ数
    int room[4][3][10]={}; //[棟番号][階数][部屋番号]
    int b, f, r, v;
    int i;
    scanf("%d", &n);
    
    for (i=0; i<n; i++) {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        room[b-1][f-1][r-1] += v;
    }
    for (int k=0; k<4; k++) {
        for (int j=0; j<3; j++) {
            for (int i=0; i<10; i++) {
                printf(" %d", room[k][j][i]);
            }
            printf("\n");
        }
        if (k!=3) {
            printf("####################\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2040
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <set>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> ii;

int main() {
  unordered_map<ll, ll> cc;
  ll h, w, n;
  scanf("%lld%lld%lld", &h, &w, &n);
  ll count[10]; memset(count, 0, sizeof count);
  ll sum = 0;
  ll x = 1e9;
  for (int i = 0; i < n; i++) {
    ll a, b;
    scanf("%lld%lld", &a, &b);
    a--; b--;
    for (int j = -2; j <= 0; j++) {
      for (int k = -2; k <= 0; k++) {
        if (a+j >= 0 && b+k >= 0 && a+j+2 < h && b+k+2 < w) {
          int d = ++cc[(a+j)*x+(b+k)];
          if (d-1 == 0) {
            sum++;
          } else {
            --count[d-1];
          }
          ++count[d];
        }
      }
    }
  }
  count[0] = (h-3+1)*(w-3+1)-sum;
  for (int i = 0; i < 10; i++) {
    printf("%lld\n", count[i]);
  }
}


Measured memory_bytes: 36624
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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 main() {
    int aa, bb, ab, x, y;
    cin >> aa >> bb >> ab >> x >> y;
    x *= 2; y *= 2;
    //cout << "aa:" << aa << " bb:" << bb << " ab:" << ab << ln;
    //cout << "x:" << x << " y:" << y << ln;

    int res = 0;
    if(2 * ab < aa + bb){
        res += min(x, y) * ab;
        //cout << "res:" << res << ln;
        int value;
        if(x > y) value = aa; else value = bb;
        //cout << "value:" << value << " 2ab:" << ab * 2 << ln;
        if(value < 2 * ab)
            res += value * abs(x-y) / 2;
        else
            res += ab * abs(x-y);
    } else{
        res += aa * x / 2 + bb * y / 2;
    }
    cout << res << ln;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#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(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

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

    if(suma<sumb){
        cout<<-1<<endl;
        return 0;
    }

    vector<ll> c(n),over;
    ll sumc=suma,v=0;
    REP(i,n){
        if(a[i]<b[i]){
            c[i]=b[i];
            sumc-=b[i];
            v++;
        }else{
            c[i]=a[i];
            sumc-=a[i];
            over.push_back(a[i]-b[i]);
        }
    }
    sort(ALL(over),greater<int>());
    for(int i=0;sumc<0;i++){
        sumc+=over[i];
        v++;
    }
    cout<<v<<endl;

	return 0; 
}

Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include<string>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	

	string str;
	cin>>str;
	bool flag = true;	
	
	int N = str.size() ;
	
	int s_num = 0;
	int t_num = 0;
	for(int i = 0; i < N; i++){
		
		if(str[i] == 'S'){

			s_num += 1;
		}
		else if(str[i] == 'T'){

			if(t_num < s_num){
				t_num += 1; 
			}
		}
	}

	int ans = N - t_num * 2;
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
long long r;
int i,n,k,a[200001];
int main()
{
	scanf("%d%d",&n,&k);
	for(;++i<=n;)scanf("%d",a+i);
	std::sort(a+1,a+n+1);
	for(i=1;i<=n-k;++i)r+=a[i];
	printf("%lld",r);
}

Measured memory_bytes: 896
using System;
using System.Text;

namespace ConsoleApplication{
    public class Program{
        public static void Main(string[] args){
            int count = 0;
            StringBuilder buffer = new StringBuilder();

            while(true){
                string temp = Console.ReadLine();
                if("0".CompareTo(temp) == 0){
                    break;
                }
                count++;
                buffer.AppendLine("Case "+ count +": "+ temp);
            }
            Console.Write(buffer.ToString());
        }
    }
}

Measured memory_bytes: 11148
n=int(input())
T,H=0,0
for i in range(n):
    t_card,h_card=input().split()
    if t_card>h_card:
        T+=3
    elif t_card<h_card:
        H+=3
    else:
        T+=1
        H+=1
print(str(T)+" "+str(H))

Measured memory_bytes: 7656
from queue import Queue
k = int(input())
q = Queue()
for i in range(9):
    q.put(i + 1)
for i in range(k):
    x = q.get()
    y = x % 10
    if x % 10 != 0:
        q.put(10 * x + y - 1)
    q.put(10 * x + y)
    if x % 10 != 9:
        q.put(10 * x + y + 1)
print(x)


Measured memory_bytes: 12476
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

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

    int n,Q;
    string s;
    cin >>n >>s >>Q;
    vector<int> x(Q);
    rep(i,Q) cin >>x[i];

    for(int k:x){
        ll ans = 0;

        ll num_m = 0;
        ll num_c = 0;

        ll c = 0;
        rep(i,k){
            if(s[i]=='M'){
                ++num_m;
            }
            else if(s[i]=='C'){
                ++num_c;
                c += num_m;
            }
        }

        rep(i,n){
            if(s[i]=='D'){
                ans += c;
            }

            if(s[i]=='M'){
                c -= num_c;
                --num_m;
            }
            else if(s[i]=='C'){
                --num_c;
            }

            if(i+k<n){
                if(s[i+k]=='M'){
                    ++num_m;
                }
                else if(s[i+k]=='C'){
                    ++num_c;
                    c += num_m;
                }
            }
        }

        cout << ans << '\n';
    }

    return 0;
}


Measured memory_bytes: 1948
N,M,X = map(int, input().split())
C = [0]*N
A = []
for i in range(N):
    P = list(map(int, input().split()))
    C[i] = P[0]
    A.append(P[1:])

ans = float('inf')
exist = False
for bit in range(1 << N):
    flag = True
    S = [0]*M
    sumnum = 0
    for i in range(N):
        if bit & (1 << i):
            sumnum += C[i]
            for j in range(M):
                S[j] += A[i][j]

    for k in range(M):
        if S[k] < X:
            flag = False
            break
    if flag:
        ans = min(ans, sumnum)
    
if ans != float('inf'):
    print(ans)
else:
    print(-1)

Measured memory_bytes: 9248
#include <stdio.h>

int main(void)
{
  int min = 100, max = 1;
  for(int i = 0; i < 3; i++){
    int A;
    scanf("%d", &A);
    if(max < A){
      max = A;
    } 
    if(A < min){
      min = A;
    }
  }
  printf("%d\n", max-min);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#define MAX 100000
#define SENTI 2000000000

struct Card{
  char pic;
  int num;
};

struct Card L[MAX / 2 + 2];
struct Card R[MAX/ 2 + 2];

void Merge(struct Card *, int, int, int, int);
void mergeSort(struct Card *, int, int, int);
int Prtition(struct Card *, int, int, int);
void QuickSort(struct Card *, int, int, int);

int main(){
  int n, i, value;
  int stable = 1;
  char P[10];
  struct Card A[MAX], B[MAX];

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    scanf("%s %d",P,&value);
    A[i].pic = B[i].pic = P[0];
    A[i].num = B[i].num = value;
  }

  mergeSort(A,n,0,n);
  QuickSort(B,n,0,n-1);

  for(i = 0 ; i < n ; i++){
    if(A[i].pic != B[i].pic) stable = 0;
  }

  if(stable == 1) printf("Stable\n");
  else printf("Not stable\n");

  for(i = 0 ; i < n ; i++){
    printf("%c %d\n",B[i].pic,B[i].num);
  }

  return 0;
}

void Merge(struct Card A[], int n, int l, int m, int r){
  int n1, n2, i, j, k;

  n1 = m - l;
  n2 = r - m;
  for(i = 0 ; i < n1 ; i++) L[i] = A[l + i];
  for(i = 0 ; i < n2 ; i++) R[i] = A[m + i];
  L[n1].num = R[n2].num = SENTI;

  i = 0;
  j = 0;
  for(k = l ; k < r ; k++){
    if(L[i].num <= R[j].num) A[k] = L[i++];
    else A[k] = R[j++];
  }
}

void mergeSort(struct Card A[], int n, int l, int r){
  int m;
  if(l + 1 < r){
    m = (l + r) / 2;
    mergeSort(A, n, l, m);
    mergeSort(A, n, m, r);
    Merge(A, n, l, m, r);
  }
}

int Partition(struct Card A[], int n, int p, int r){
  int i, j;
  struct Card x, tmp;

  x = A[r];
  i = p - 1;
  for(j = p ; j < r ; j++){
    if(A[j].num <= x.num){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i + 1];
  A[i + 1] = A[r];
  A[r] = tmp;
  return i+1;
}

void QuickSort(struct Card A[], int n, int p, int r){
  int x;

  if(p < r){
    x = Partition(A, n, p, r);
    QuickSort(A, n, p, x - 1);
    QuickSort(A, n, x + 1, r);
  }
}



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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	vector<int> c(n);
	rep(i,n) scanf("%d",&c[i]);

	vector<int> dp(n);
	dp[1]=abs(c[1]-c[0]);
	for(int i=2;i<n;i++) dp[i]=min(dp[i-1]+abs(c[i]-c[i-1]),dp[i-2]+abs(c[i]-c[i-2]));
	printf("%d\n",dp[n-1]);

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define mp make_pair
#define P pair<ll,ll>
#define F first
#define S second
#define vll vector<ll>
#define pb push_back
#define M 1000000007
#define for1(i,n) for(ll i=1;i<=n;i++)
#define for0(i,n) for(ll i=0;i<n;i++)
#define forab(i,a,b,c) for(ll i=a;i<=b;i+=c)
using namespace std;
int main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n, k;
	cin >> n >> k;
	ll a[n];
	ll sum = 0;
	for (ll i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a, a + n);
	for (ll i = 0; i < min(n, k); i++)
	{
		sum += a[i];
	}
	cout << sum << "\n";
	return 0;
}

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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

struct S {
  int y1,x1,y2,x2;
};

int main()
{
  int h,w; cin>>h>>w;
  vector<vector<int>> a(h, vector<int>(w));
  rep(i, h) rep(j, w) cin>>a[i][j];

  int n = 0;
  vector<S> ans;

  for (int i=0; i<h; i++) {
    if (i % 2) {
      for (int j=w-1; j>=1; j--) {
        if (a[i][j] % 2) {
          a[i][j]--;
          a[i][j-1]++;
          ans.push_back(S{i, j, i, j-1});
          n++;
        }
      }
      if (i < h-1) {
        if (a[i][0] % 2) {
          a[i][0]--;
          a[i+1][0]++;
          ans.push_back(S{i, 0, i+1, 0});
          n++;
        }
      }
    } else {
      for (int j=0; j<w-1; j++) {
        if (a[i][j] % 2) {
          a[i][j]--;
          a[i][j+1]++;
          ans.push_back(S{i, j, i, j+1});
          n++;
        }
      }
      if (i < h-1) {
        if (a[i][w-1] % 2) {
          a[i][w-1]--;
          a[i+1][w-1]++;
          ans.push_back(S{i, w-1, i+1, w-1});
          n++;
        }
      }
    }
  }

  cout << n << endl;
  for (auto v:ans) {
    printf("%d %d %d %d\n", v.y1+1, v.x1+1, v.y2+1, v.x2+1);
  }

  return 0;
}


Measured memory_bytes: 6276
import java.util.*;import java.io.*;import java.math.*;

public class Main
{

    public static void process()throws IOException
    {
        int k=ni(),cnt=0;
        Queue<Long> q=new LinkedList<>();

        for(long i=1;i<=9;i++) q.add(i);
        Long res=1l;
        while(cnt!=k){
            Long n=q.poll();
            res=n;
            cnt++;

            if(n%10!=0)
                q.add(n*10l+(n%10-1l));
            q.add(n*10l+(n%10)*1l);

            if(n%10!=9)
                q.add(n*10l+(n%10)*1l+1);
        }
        pn(res);
    }


    static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new AnotherReader();
        boolean oj = true;

       // oj = System.getProperty("ONLINE_JUDGE") != null;
        if(!oj) sc=new AnotherReader(100);

        long s = System.currentTimeMillis();
        int t=1;
        while(t-->0)
            process();
        out.flush();
        if(!oj)
            System.out.println(System.currentTimeMillis()-s+"ms");
        System.out.close();  
    }

    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);System.out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    static boolean multipleTC=false;



/////////////////////////////////////////////////////////////////////////////////////////////////////////

    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
    
    
    

Measured memory_bytes: 33748
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}


int main(){
  int n;
  cin >> n;
  string s[n];
  vector<vector<int> > alph(n,vector<int>(26,0));
  rep(i,n) cin >> s[i];

  rep(i,n){
    rep(j,s[i].size()){
      alph[i][(int)(s[i][j] - 'a')] ++;
    }
  }
  int alphCnt;
  rep(i,26){
    alphCnt = 100000;
    rep(j,n){
      alphCnt = min(alph[j][i],alphCnt);
    }
    rep(k,alphCnt) cout << (char)('a' + i) ;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[42];
int main() {
	ll n,k;
	cin>>n>>k;
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		ll j=0;
		while(now!=0){
			a[j]+=now%2;
			j++;
			now/=2;
		}
	}
	ll ch=1;
	for(ll i=1;i<41;i++){
		ch*=2;
	}
	//cout <<ch;
	for(ll i=40;i>=0;i--){
		if(a[i]*2>=n||ch>k){
			ch/=2;
			continue;
		}
		a[i]=n-a[i];
		k-=ch;
		ch/=2;
	}
	ch=1;
	ll ans=0;
	for(ll i=0;i<41;i++){
		ans+=ch*a[i];
		ch*=2;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.Collections;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        StringBuilder sb = new StringBuilder();
        while (sc.hasNext()) {
            String s = sc.next();
            
            for (int i = 0; i < s.length(); i++) {
                Character c = s.charAt(i);
                if (Character.isLetter(c)) {
                    if (Character.isUpperCase(c)) {
                        c = Character.toLowerCase(c);
                    } else {
                        c = Character.toUpperCase(c);
                    }
                }
                sb.append(c);
            }
            sb.append(" ");
        }
        
        sb.delete(sb.length()-1, sb.length());
        System.out.println(sb);
    }
}

Measured memory_bytes: 26236
// Jai Mata Di
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define modmax 1000000007
vector<int> graph[200001];
vector<int> order;
vector<int> grev[200001];
bool vis[200001];
int n, m;
void dfs1 (int v) {
    vis[v] = true;
    for (int i=0; i<graph[v].size(); ++i)
        if (!vis[ graph[v][i] ])
            dfs1 (graph[v][i]);
    order.push_back(v);
}
int temp = 0;
void dfs2 (int v) {
    vis[v] = true;
    temp++;
    for (int  i=0; i<grev[v].size(); ++i)
        if (!vis[ grev[v][i] ])
            dfs2 (grev[v][i]);
}
void solveTest(){
  cin>>n>>m;
  int x, y;
  for(int i=0; i<m; i++){
    cin>>x>>y;
    x--; y--;
    graph[x].push_back(y);
    graph[y].push_back(x);
    grev[x].push_back(y);
    grev[y].push_back(x);
  }
  memset(vis, 0, sizeof(vis));
  for (int i=0; i<n; ++i){
    if (!vis[i])
        dfs1 (i);
  }
  int ans = 0;
  memset(vis, 0, sizeof(vis));
  for (int i=0; i<n; ++i) {
      int v = order[n-1-i];
      if (!vis[v]) {
          temp = 0;
          dfs2 (v);
          ans = max(ans, temp);
      }
  }
  cout<<ans<<"\n";
}
int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t=1, i=1;
  //cin>>t;//Comment if only one test case
  while(i<=t){
    //cout<<"Case #"<<i<<": ";
    solveTest();
    i++;
  }
  return 0;
}


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

using namespace std; 


int main(){
	
	int n,m;
	int k,val;
	
	cin >> n >> m; 
	
	vector<int> ans (31);
	
	int res = 0;
	
	for(int i=0;i<n;i++){
		cin >> k;
		
		for(int j=0;j<k;j++){
			cin >> val;
			ans[val]++;
		}
	}
	
	for(int i=0;i<=30;i++){
		if(ans[i]==n) res++;
	}
	
	cout << res << endl;

    return 0;
}


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

int sum(int a, int b)
{
    if(a==1 && b==1) return 1000000;
    int res = 0;
    if(a==1) res += 300000;
    if(a==2) res += 200000;
    if(a==3) res += 100000;
    if(b==1) res += 300000;
    if(b==2) res += 200000;
    if(b==3) res += 100000;
    return res;

}
void solve()
{
  int x, y;
  cin>>x>>y;
  int res = sum(x,y);
  cout<<res<<endl;
}
int main()
{
    int t;
    t=1;
    while(t--)
    {
        solve();

    }
return 0;
}


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

using namespace std;

int main() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    set<int> st;
    int i, j, k;
    for(i = 0; i <= f; i += a * 100) {
        for(j = 0; j <= f - i; j += b * 100) {
            st.insert(i + j);
        }
    }

    set<int> suger;
    for(i = 0; i <= f; i += c) {
        for(j = 0; j <= f - i; j += d) {
            suger.insert(i + j);
        }
    }
    double noudo = 0;
    int total_weight = 100*a, suger_weight = 0;
    for(int x : st) {
        auto it = suger.upper_bound(min(e * x / 100, f - x));
        if(it == suger.begin()) continue;
        it--;
        if((double)*it * 100 / (x + *it) > noudo) {
            noudo = (double)*it * 100 / (x + *it);
            total_weight = x + *it;
            suger_weight = *it;
        }
    }
    cout << total_weight << " " << suger_weight << endl;
    return 0;
}

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

int main(void) {
  int n, x;
  cin >> n >> x;
  vector<int> m(n);
  for (int i = 0; i < n; i++)
    cin >> m.at(i);
  
  for (int i = 0; i < n; i++)
    x -= m.at(i);
  
  sort(m.begin(), m.end());
  int res = n;
  while (x >= m.at(0)) {
    x -= m.at(0);
    res++;
  }
  
  cout << res << endl;   
  
  return 0;
}
         

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


int main() {
	string s;
	cin >> s;

	int K;
	cin >> K;

	set<string> dic;

	for (int i = 0; i < s.length(); i++) {
		for (int k = 1; k <= 5; k++) {
			if(i+k<=s.length())
				dic.insert(s.substr(i, k));
		}
	}

	int cnt=0;
	for (set<string>::iterator it = dic.begin(); it != dic.end(); it++, cnt++) {
		if(cnt+1==K) cout << *it << endl;
	}
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    string s[N];
    long long int ch[5];
    memset(ch, 0, sizeof(ch));
    for (int i = 0; i < N; i++)
    {
        cin >> s[i];
        if(s[i][0] == 'M') ch[0]++;
        if(s[i][0] == 'A') ch[1]++;
        if(s[i][0] == 'R') ch[2]++;
        if(s[i][0] == 'C') ch[3]++;
        if(s[i][0] == 'H') ch[4]++;
    }

    long long int ans = 0;
    for (int i = 0; i < 5; i++)
    {
        for (int j = i+1; j < 5; j++)
        {
            for (int k = j+1; k < 5; k++)
            {
                ans += ch[i] * ch[j] * ch[k];
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 6144
#include<stdio.h>
int main(void) {
	int t, n=0, hyaku=0,zyu=0,iti=0;
	
	scanf("%d", &n);
	for (t = 0; n > 100; t++) {
		n = n - 100;
		hyaku++;
	}

	for (t = 0; n > 10; t++) {
		n = n - 10;
		zyu++;
	}

	for (t = 0; n > 0; t++) {
		n = n - 1;
		iti++;
	}

	if (hyaku == 7) {
		printf("Yes");
	}
	else {
		if (zyu == 7) {
			printf("Yes");
		}
		else {
			if (iti == 7) {
				printf("Yes");
			}
			else {
				printf("No");
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1732
def resolve():
    _, _, X, Y = [int(i) for i in input().split()]
    xx = sorted([int(i) for i in input().split()] + [X])
    yy = sorted([int(i) for i in input().split()] + [Y])
    if xx[-1] >= yy[0]:
        print("War")
    else:
        print("No War")

resolve()


Measured memory_bytes: 9112
N, K, Q = map(int, input().split())
P = [0] * N

for i in range(Q):
    P[int(input())-1] += 1
for i in range(N):
    ans = K - Q + P[i]
    # print(ans)
    if ans > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 4680
x1,y1,x2,y2 = map(int,input().split())
a = x2 - x1
b = y2 - y1
x3,y3 = x2 - b,y2 + a
x4,y4 = x3 - a,y3 - b
print(str(x3) + " " + str(y3) + " " + str(x4) + " " + str(y4))

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

#define Fast           ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO             freopen("in.txt", "r", stdin)
#define FC             freopen("out.txt", "w", stdout)
#define aise           cout<<"aise"<<endl
#define pb             push_back
#define pf             push_front
#define ppb            pop_back
#define ppf            pop_front
#define mp             make_pair
#define ll             long long
#define all(x)         x.begin(), x.end()
#define mset(v, a)     memset(v, a, sizeof(v))
#define pll            pair< ll, ll >
#define pd             pair< double, double >
#define ff             first
#define ss             second
#define pi             acos(-1.0)
#define mxN            2010
#define inf            1e14
#define mod            1000000007

//NCR iterative
/*voidcomb_table(intN)
{
    for(inti=0; i<=N; ++i)
    {
        for(intj=0; j<=i; ++j)
        {
            if(j==0or j==i)
            {
                C[i][j]=1LL;
            }
            else
            {
                C[i][j]=(C[i-1][j-1]+C[i-1][j]);
            }
        }
    }
}*/


//NCR recursive
/*ll dp[55][55];

ll NCR(ll n,ll r)
{

    if(n==r)
        return dp[n][r]=1;
    if(r==0)
        return dp[n][r]= 1;
    if(r==1)
        return dp[n][r]=n ;
    if(dp[n][r] != -1)
        return dp[n][r];
    return dp[n][r] = NCR(n-1,r)+NCR(n-1,r-1);
}*/

//Sieve:
/*bool Flag[1000010];
vector<ll> Prime;

void sieve()
{

    ll val=sqrt(1000010);
    for(ll i=4;i<=1000005; i+=2) Flag[i]=1;
    for(ll i=3;i <= val;i+=2)
    {

        if(Flag[i]==0)
        {

            for(ll j=i*i;j<=1000005;j+=i) Flag[j]=1;
        }
    }
    Flag[1]=1;
    for(ll i=1;i<=1000000;i++)
        if(Flag[i]==0) Prime.pb(i);
}*/


//Conversion
/*string bin(ll x)
{

    string ret;
    while(x)
    {

        ll t=x%2;
        char c;
        if(t==1)
            c='1';
        else
            c='0';
        ret.pb(c);
        x/=2;
    }
    reverse(all(ret));
    return ret;
}*/

/*ll lcm(ll x, ll y)
{

    ll ret=__gcd(x,y);
    return (x*y)/ret;
}*/

/*ll dx[]= {0,0,1,-1};
ll dy[]= {1,-1,0,0};*/

int main()
{

    ll sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    string ans;
    ll r=tx-sx;
    ll u=ty-sy;
    for(ll i=0;i<r;i++) ans.pb('R');
    for(ll i=0;i<u;i++) ans.pb('U');
    for(ll i=0;i<r;i++) ans.pb('L');
    for(ll i=0;i<u;i++) ans.pb('D');
    ans.pb('D');
    for(ll i=0;i<=r;i++) ans.pb('R');
    for(ll i=0;i<=u;i++) ans.pb('U');
    ans.pb('L');
    ans.pb('U');
    for(ll i=0;i<=r;i++) ans.pb('L');
    for(ll i=0;i<=u;i++) ans.pb('D');
    ans.pb('R');
    cout << ans << endl;
}


Measured memory_bytes: 256
from bisect import *
A,B,Q=map(int,input().split())
s=[-10**11]+[int(input()) for i in range(A)]+[10**11]
t=[-10**11]+[int(input()) for i in range(B)]+[10**11]
x=[int(input()) for i in range(Q)]
for i in range(Q):
    S=[0,0]
    T=[0,0]
    sidx=bisect_left(s,x[i])-1
    S[0]=s[sidx]
    S[1]=s[sidx+1]
    tidx=bisect_left(t,x[i])-1
    T[0]=t[tidx]
    T[1]=t[tidx+1]
    ans=10**12
    seq=[(0,1),(1,0),(1,1),(0,0)]
    for a,b in seq:
        tmp=abs(x[i]-S[a])+abs(S[a]-T[b])
        ans=min(ans,tmp)
        tmp=abs(x[i]-T[a])+abs(T[a]-S[b])
        ans=min(ans,tmp)
    print(ans)


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

int main(){
    cin.sync_with_stdio(false);
    int n; cin >> n;

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

    cout<<max({happy[0][0], happy[0][1], happy[0][2]})<<endl;
}


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

int main() {
	int c1, c2, c3;
	while (cin >> c1 >> c2 >> c3) {
		bool seen_card[10] = { false };
		seen_card[c1 - 1] = true;
		seen_card[c2 - 1] = true;
		seen_card[c3 - 1] = true;
		int my_point = c1 + c2;
		double be_under_20=0;
		for (int i = 0; i < 10; i++) {
			if (!seen_card[i])
				if (20 - my_point >= i+1)
					be_under_20++;
		}
		if (be_under_20 / 7.0 >= 0.5)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}


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

int main()
{
    int x;
    int maxv = 1;

    cin >> x;
    for ( int i = 2; i <= x; i++) {

        for (int cp = i * i; cp <= x; cp *= i ) {
            maxv = max(maxv, cp);
        }
    }

    cout << maxv << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,ll>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ins insert
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
string S;map<char,bool>Map;
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	cin>>S;
	for(auto o:S)Map[o]=1;
	puts(Map['S']==Map['N']&&Map['W']==Map['E']?"Yes":"No");
	return 0;
}




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

#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 2e5 + 5;
pair<ll,ll> b[N];
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (fopen(".INP", "r")){
                freopen(".INP", "r", stdin);
                freopen(".OUT", "w", stdout);
        }
        ll n, d, a;
        cin >> n >> d >> a;
        for (int i = 1; i <= n; i++){
                cin >> b[i].first >> b[i].second;
        }
        sort(b + 1, b + n + 1);
        set<pair<ll,ll>> s;
        ll cnt = 0, ans = 0;
        for (int i = 1; i <= n; i++){
                while (s.size() > 0) {
                      if ((*s.begin()).first < b[i].first){
                            cnt -= (*s.begin()).second;
                            s.erase(s.begin());
                      } else {
                            break;
                      }
                }
                if (cnt >= b[i].second) continue;
                ll x = (b[i].second - cnt) / a;
                if (((b[i].second - cnt )% a) != 0) x++;
                cnt += a * x;
                ans += x;
                s.insert({b[i].first + d * 2, a * x});
        }
        cout << ans;
}


Measured memory_bytes: 9600
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using static System.Math;

class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        //(5n+1)*5=
        int[] p = prime(55555).Where(x => x % 5 == 1).Take(n).ToArray();
        Console.WriteLine(string.Join(" ", p));
    }

    static int[] prime(int max)
    {
        if (max < 2) return new int[0];
        List<int> res = new List<int>();
        int sqrtMax = (int)Math.Sqrt(max);
        List<int> sieve = Enumerable.Range(2, max - 2).ToList();
        while (sieve.Count != 0)
        {
            int p = sieve[0];
            if (p > sqrtMax) break;
            res.Add(p);
            sieve.RemoveAll(x => x % p == 0);
        }
        res.AddRange(sieve);
        return res.ToArray();
    }
}

Measured memory_bytes: 13792
package main

import (
	"fmt"
	"io"
	"os"
	"strings"
)

func proc(r io.Reader, w io.Writer) {
	//var n, d int
	//fmt.Fscanf(r, "%d", &n)
	//arr := make([]int, n)
	//for i := 0; i < n; i++ {
	//	fmt.Fscanf(r, "%d", &d)
	//	arr[i] = d
	//}
	var s string
	fmt.Fscanf(r, "%s", &s)
	s = strings.Replace(s, "eraser", "", -1)
	s = strings.Replace(s, "erase", "", -1)
	s = strings.Replace(s, "dreamer", "", -1)
	s = strings.Replace(s, "dream", "", -1)
	if len(s) == 0 {
		fmt.Fprintf(w, "YES")
	} else {
		fmt.Fprintf(w, "NO")
	}
}

func main() {
	proc(os.Stdin, os.Stdout)
}


Measured memory_bytes: 1664