akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int siz[100005],dep[100005],p[100005];
vector <int> vec[100005];
void dfs(int pos,int fa)
{
    siz[pos]=1;
    for (int i=0;i<vec[pos].size();i++)
    {
        int v=vec[pos][i];
        if (v!=fa)
        {
            p[v]=pos;
            dep[v]=dep[pos]+1;dfs(v,pos);
            siz[pos]+=siz[v];
        }
    }
}
int main ()
{
    int u,v,n,i;
    scanf ("%d",&n);
    for (i=1;i<n;i++)
    {
        scanf ("%d%d",&u,&v);
        vec[u].push_back(v);
        vec[v].push_back(u);
    }
    dep[1]=0;dfs(1,0);
    int stp=(dep[n]-1)/2,tar=n;
    while (stp--) 
    {
        n=p[n];
    }
    int num=siz[n];
    if (num*2>=tar) 
    {
        printf ("Snuke\n");
    }
    else {printf ("Fennec\n");}
    return 0;
}

Measured memory_bytes: 14720
#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1000000007
#define bitcount __builtin_popcountll
#define ll long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define mp make_pair
int main()
{
	int i,j,k;
	int a,b,c;
	cin>>a>>b>>c;
	if(a>b)
		swap(a,b);
	if(a>c)
		swap(a,c);
	if(b>c)
		swap(b,c);
	int ans=c-b;
	ans+=(b-a+1)/2;
	if((b-a)%2)
		ans++;
	printf("%d\n",ans );
	return 0;
}

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

using namespace std;

int main()
{
    int n; cin >> n;
    string ans = "YES";
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a.begin(), a.end());
    for (int i = 1; i < n; ++i) {
        if (a[i-1] == a[i]) {
            ans = "NO";
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main()
{
    int r,D,x2000;
    std::cin >>r >>D >>x2000;
    int temp1,temp2;
    temp1=x2000;
    for(int i=0; i<10; i++){
        temp2=r*temp1-D;
        std::cout << temp2 << std::endl;
        temp1=temp2;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;cin>>N>>K;
  vector<int> A(N);
  int ans;
  ans=0;
  for(int i=0;i<N;++i){
    cin>>A[i];
  }
  for(int i=0;i<N;++i){
    if(A[i]>=K){
      ans+=1;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 640
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();

    let mut r: Vec<usize> = Vec::new();

    let mut prev: usize = 0;
    while r.len() < n {
        if prev == 0 {
            prev = 11;
            r.push(11);
        } else {
            let mut i = prev + 5;
            loop {
                if is_prime(i) {
                    prev = i;
                    r.push(i);
                    break;
                }
                i += 5;
            }
        }
    }

    return r.iter().map(|it| it.to_string()).collect::<Vec<String>>().join(" ");
}

fn is_prime(n: usize) -> bool {
    if n <= 1 {
        return false;
    }
    if n == 2 {
        return true;
    }
    if n % 2 == 0 {
        return false;
    }
    let mut i = 3;
    while i * i <= n {
        if n % i == 0 {
            return false;
        }
        i += 2;
    }
    return true;
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>

bool square(int d) {
  for (int i = 1; i*i <= d; ++i)
    if (i*i == d) return true;
  return false;
}

bool ok(std::vector<int> const& x, std::vector<int> const& y) {
  int d = 0;
  size_t D = x.size();
  for (size_t i = 0; i < D; ++i)
    d += (x[i]-y[i]) * (x[i]-y[i]);

  return square(d);
}

int main() {
  size_t N, D;
  scanf("%zu %zu", &N, &D);

  std::vector<std::vector<int>> X(N, std::vector<int>(D));
  for (auto& xi: X)
    for (auto& xij: xi) scanf("%d", &xij);

  int res = 0;
  for (size_t i = 0; i < N; ++i)
    for (size_t j = i+1; j < N; ++j)
      if (ok(X[i], X[j])) ++res;

  printf("%d\n", res);
}


Measured memory_bytes: 256
#include <cstdio>
#include <utility>
typedef long long lld;
const int MAXN = 121;
lld F[MAXN];
int K, X;

lld pow5(int n) { return 1LL*n*n*n*n*n; }

std::pair<int,int> solve() {
  for (int i = 0; i < MAXN; ++i) {
    for (int j = i; j < MAXN; ++j) {
      if (F[i] - F[j] == X) {
        return {i, j};
      } else if (F[i] + F[j] == X) {
        return {i, -j};
      } else if (F[j] - F[i] == X) {
        return {j, i};
      }
    }
  }
  return {0, 0};
}

void init() {
  for (int i = 0; i < MAXN; ++i) {
    F[i] = pow5(i);
  }
}

int main() {
  scanf("%d", &X);
  init();
  auto ret = solve();
  printf("%d %d\n", ret.first, ret.second);
  return 0;
}

Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
#define X           first
#define Y           second
#define pb          push_back
#define pp          pop_back
#define mk          make_pair
#define EPS         1e-9
#define INF         1<<25
#define ln          '\n'
#define sp          ' '
#define all(x)      x.begin(),x.end()
#define Sort(x)     sort(all(x))
#define mem(a,b)    memset(a,b,sizeof(a))
#define lpa(p,v)    for(auto p:(v))
#define lp(a,b,c)   for(int a=(b);a<(c);a++)
#define lp0(a,n)    lp(a,0,n)
#define lpr(a,b,c)  for(int a=(b);a>=(c);a--)
#define faster      ios_base::sync_with_stdio(0);cin.tie(0);
#define debug(a)    cout<<a<<ln;
#define debug2(a,b)    cout<<a<<sp<<b<<ln;
#define debug3(a,b,c)    cout<<a<<sp<<b<<sp<<c<<ln;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<int,string> psi;
typedef map<int,int>mii;

inline bool sc(int &_x){return scanf("%d",&_x)==1;}
inline bool sc(int &_x, int &_y){return sc(_x)&&sc(_y);}
inline bool sc(int &_x, int &_y, int &_z){return sc(_x)&&sc(_y)&&sc(_z);}
inline bool sc(int &_x, int &_y, int &_z, int &_zz){return sc(_x)&&sc(_y)&&sc(_z)&&sc(_zz);}

/*int x4[]= {1,-1,0,0};
int y4[]= {0,0,1,-1};
int x8[]= {0,0,+1,-1,-1,+1,-1,+1};
int y8[]= {-1,+1,0,0,+1,+1,-1,-1};
int kx[]= {2,2,-2,-2,1,-1,1,-1};
int ky[]= {1,-1,1,-1,2,2,-2,-2};*/
const double PI=acos(-1.0);
const int N=1000005;
const int MOD=1e9+7;

int main()
{
    ll r,x,d;cin>>r>>d>>x;
    lp0(i,10){
        x=r*x-d;
        cout<<x<<ln;
    }


}




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

int main() {
  int A,B,C;
  cin>>A>>B>>C;
  if((A==5&&B==5&&C==7)||(A==5&&B==7&&C==5)||(A==7&&B==5&&C==5)) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


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

#define INF (1e9)

ll n,k;
ll h[100010];

int main(){
  scanf("%lld %lld", &n, &k);
  for(int i=0;i<n;i++){
    scanf("%lld", &h[i]);
  }
  ll ans = INF;
  sort(h, h+n);
  for(int i=0;i<n-k+1;i++){
      ans = min(ans, abs(h[i] - h[i+k-1]));
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
class Test
{

    public static void Main()
    {
        var inp = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

        long n = inp[0];
        long k = inp[1];

        long ans = Math.Min(n, k / 2);

        n = n - ans;
        k = k - ans * 2;

        Console.Write((ans + k / 4));
        

    }


}




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

using namespace std;

vector<int> v;

int lis(){

    vector<int> pilha;

    for(int i=0; i<v.size(); i++){

        vector<int> :: iterator it = upper_bound(pilha.begin(),pilha.end(),v[i]);

        if(it==pilha.end()){
            pilha.push_back(v[i]);
        }
        else{
            *it=v[i];
        }
    }
    return pilha.size();
}

int main(){

    int n;

    cin >> n;

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

        int a;

        cin >> a;

        v.push_back(-a);
    }

    cout << lis();
}


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

template <typename T>
string ToString(const T& input) {
	ostringstream oss;
	oss << input;
	return oss.str();
}

int N;
vector<vector<string>> vec(10, vector<string>(10));
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  
  long long ans = 0;
  cin >> N;
  for(int i = 1; i <= N; i++){
    string x = ToString(i);
    int head = x[0] - '0';
    int tail = x[x.length() - 1] - '0';
    vec.at(head).at(tail).push_back(i);
  }
  for(int i = 1; i < 10; i++){
    for(int j = 1; j < 10; j++){
      ans += vec.at(i).at(j).size() * vec.at(j).at(i).size();
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <queue>
#define MAX 100001

using namespace std;

int mark[MAX],t[MAX];

int query(int v){
  if(mark[v]) return v;
  else{
    int a = query(t[v]);
    t[v] = a;
    return a;
  }
}

int main(){
  int n,q;
  while(scanf("%d %d",&n,&q),n){
    long long int ans=0;
    deque<pair<char,int> > qs;

    for(int i=1; i<=n; i++) mark[i]=0; mark[1]=1;

    for(int i=2; i<=n; i++){
      int p;
      scanf("%d",&p);
      t[i] = p;
    }

    for(int i=0; i<q; i++){
      char order; int v;
      scanf(" %c %d",&order,&v);
      if(order=='M') mark[v]++;
      qs.push_front(make_pair(order,v));
    }

    for(int i=0; i<qs.size(); i++)
      if(qs[i].first=='Q')
	ans += query(qs[i].second);
      else
	mark[qs[i].second]--;

    printf("%lld\n",ans);
  }
}

Measured memory_bytes: 2380
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a,b = 0;
        String op = null;

        while (true) {

            a = sc.nextInt();
            op = sc.next();
            b = sc.nextInt();

            if ("?".equals(op)) {
                    break;
            } else if (a < 0 || b < 0 || a > 20000 || b > 20000) {
                System.err.println("Err!");
                break;
            }

            switch (op) {

            case "+":
                System.out.printf("%d%n", a + b);
                break;
            case "-":
                System.out.printf("%d%n", a - b);
                break;
            case "*":
                System.out.printf("%d%n", a * b);
                break;
            case "/":
                System.out.printf("%.0f%n",(double)(a / b));
                break;
            default:
                break;

            }

        }

    }

}


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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        h: usize,
        n: usize,
        ab: [(usize, usize); n],
    }
    let m = 20000;
    let inf = 1000000000;
    let mut dp0 = vec![inf; m];
    let mut dp1 = vec![inf; m];
    for i in 0..n {
        let (ai, bi) = ab[i];
        for j in 0..ai {
            dp1[j] = dp0[j];
        }
        for j in ai..m {
            dp1[j] = std::cmp::min(dp0[j], dp1[j - ai] + bi);
            if j % ai == 0 {
                dp1[j] = std::cmp::min(bi * (j / ai), dp1[j]);
            }
        }
        for j in 0..m {
            dp0[j] = dp1[j];
        }
        // println!("{:?}", dp0);
    }
    let mut result = inf;
    for i in h..m {
        if dp0[i] < result {
            result = dp0[i];
        }
    }
    println!("{}", result);
}


Measured memory_bytes: 4476
#include<vector>
#include<iostream>
#include<algorithm> // sort,reverse,min,lower_bound
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

int main(){
  if(df) printf("*debug mode*\n");
  li n; cin >>n;
  li ans=1;
  while(n){
    ans*=2;
    n/=2;
  }
  cout << ans-1;
}

/// confirm df==0 ///


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mov(i,a,b) for(int i = (a); i < (b); i++)
#define MOD 1000000007
#define INF 1e9+5
typedef long long ll;
using namespace std;

int main(){
	int a,b,c;
  cin>>a>>b>>c;
	if(c>min(a,b) && c <max(a,b)) cout<<"Yes"<<"\n";
  else cout<<"No"<<"\n";
	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
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 = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

vector<int> G[200000];
vector<int> X(200000);
vector<ll> ans(200000);

void dfs(int v = 0, int p = -1) {
    ans[v] += X[v];
    for (auto u : G[v]) {
        if (u == p) continue;
        ans[u] += ans[v];
        dfs(u, v);
    }
}

void solve() {
    int n, q;
    cin >> n >> q;
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    rep(i, q) {
        int p, x;
        cin >> p >> x;
        p--;
        X[p] += x;
    }
    dfs();
    rep(i, n) cout << ans[i] << " \n"[i == n - 1];
}

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


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

long MOD=1e9+7;
long MAX=200000;

long myPow(long x, long n, long m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

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

int main() {
  long n,a,b;
  cin>>n>>a>>b;
  if(a>n/2) a=n-a;
  if(b>n/2) b=n-b;
  long A=1;
  long divA=1;
  for(int i=1;i<=a;i++){
    A*=(n-i+1);
    divA*=i;
    A%=MOD;
    divA%=MOD;
    //cout<<A<<endl;
  }
  long B=1;
  long divB=1;
  for(int i=1;i<=b;i++){
    //cout<<i<<endl;
    B*=(n-i+1);
    divB*=i;
    B%=MOD;
    divB%=MOD;
  }
  A *= modpow(divA,MOD-long(2),MOD);
  A %=MOD;
  B *= modpow(divB,MOD-long(2),MOD);
  B %=MOD;
  //cout<<A<<endl;
  //cout<<B<<endl;

  long N=modpow(2,n,MOD)-1;
  //cout<<N<<endl;
  cout << mod((N%MOD) - (A%MOD)- (B%MOD), MOD) << endl;
}


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

int main() {
    int tm;
    int ans = 0;
    int mx = 0;

    for (int i = 0; i < 5; i++) {
        cin >> tm;
        if (tm % 10 == 0) {
            ans += tm;
        } else {
            mx = max(mx, 10 - (tm % 10));
            ans += tm + (10 - tm % 10);
        }
    }
    cout << ans - mx << endl;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/24  Problem: 011_agc_b / Link: https://agc011.contest.atcoder.jp/tasks/agc011_b?lang=en  ----- */
/* ------問題------

すぬけ君は，N 匹の変わった生き物を見つけました． それぞれの生き物には色と大きさが定まっており，i 番目の生き物の色は i，大きさは Ai で表されます．
どの生き物も，大きさが自分の 2 倍以下であるような他の生き物を吸収することができます． 大きさ A，色 B の生き物が大きさ C，色 D の生き物を吸収すると (C≤2×A)，合体して大きさ A+C，色 B の生き物になります． ここで，2 匹の生き物の大きさによっては，どちらも他方を吸収することが可能な場合があります．
すぬけ君がこの生き物たちを観察していると，合体を繰り返して，最終的に 1 匹になりました． このとき，残った生き物の色として考えられるものは何種類あるかを求めてください．

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	VL a(N);
	FOR(i, 0, N) {
		cin >> a[i];
	}
	RSORT(a);
	VL sum(N + 1, 0);
	FOR(i, 0, N) {
		sum[i + 1] += sum[i] + a[i];
	}

	ans = 1;
	FOR(i, 1, N) {
		if (2 * (sum[N] - sum[i]) >= a[i-1]) {
			ans++;
		}
		else break;
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int solve()
{
    int n,k;
    cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    int dp[n];
    for(int i=0;i<n;i++)dp[i]=INT_MAX;
    dp[0] = 0;
    for(int i=1;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i-j>=0){
                dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
            }
        }
    }
    return dp[n-1];
}



int main(){
  cout<<solve();
  return 0;
}


Measured memory_bytes: 4344
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define LOL cout<<'\n';
#define MOD 1000000007
#define sz(x) ((int)x.size())
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN

void solve(){
	int n; cin>>n;
	int a[n];
	for(int i=0 ; i<n ; i++) cin>>a[i];
	vector<int> v;
	for(int i=1 ; i<n ; i++){
		if(a[i]>a[i-1]){
			v.pb(a[i-1]);
			v.pb(a[i]);
		}
	}
	vector<int> ans;
	int yen=1000,stocks=0;
	for(int i=0 ; i<sz(v) ; i+=2){
		yen=v[i+1]*(yen/v[i])+yen%v[i];
		ans.pb(yen);
	}
    if(sz(ans)==0) {cout<<1000;LOL return;}
	cout<<*max_element(all(ans));LOL
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int _=1;// cin>>_;
  for(int i=1 ; i<=_ ; i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
  return 0;
}

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

int main(){
    int H,W;
    while(1){
        cin>>H>>W;
        if(H==0&&W==0){
            break;    
        }
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if((i==0)||(i==H-1)){
                    cout<<"#";
                }else{
                    if(j==0||j==W-1){
                        cout<<"#";
                    }else{
                        cout<<".";
                    }
                }    
            }
            cout<<endl;
        }
        cout<<endl;
    }
    
}


Measured memory_bytes: 3076
// Created by Manuver
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << " : " << x << endl;


int main() {
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}


Measured memory_bytes: 256
a,b,c,d=gets.chomp.split("").map(&:to_i)
2.times do |i|
  2.times do |j|
    2.times do |k|
      na=a
      nb= i==0 ? b:-b
      nc= j==0 ? c:-c
      nd= k==0 ? d:-d
      if [na,nb,nc,nd].inject(:+)==7
        print na
        [nb,nc,nd].each do |n|
          print n>-1 ? "+"+n.to_s : n
        end
        puts "=7"
        exit
      end
    end
  end
end


Measured memory_bytes: 1788
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int x3, y3, x4, y4;
	x3 = x2+y1-y2;
	y3 = y2+x2-x1;
	x4 = x3+y2-y3;
	y4 = y3+x3-x2;
	cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1

using namespace std;

int main() {
  int n, pre, cur, count;
  string s;
  string org[] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
  vector<string> button(org, org+9);
  cin >> n;
  while (n--) {
    cin >> s;
    pre = 0;
    for (int i = 0; i < s.length(); i++) {
      cur = (int)(s[i]-'0');
      if (pre == 0) {
        if (cur != 0) {
          pre = cur;
        }
      } else {
        if (cur == 0) {
          cout << button[pre-1][count];
          pre = 0;
          count = 0;
        } else {
          count = (count+1)%button[pre-1].length();
        }
      }
    }
    cout << el;
  }
}

Measured memory_bytes: 1208
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {

	if sc.Scan() {
		tmp := strings.Split(sc.Text(), " ")
		a, _ := strconv.Atoi(tmp[0])
		b, _ := strconv.Atoi(tmp[1])
		c, _ := strconv.Atoi(tmp[2])

		if a < b && b < c {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}

	}
}



Measured memory_bytes: 1092
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define f first
// #define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this

const ll MAXN = 3002;
ll dp[MAXN][MAXN][2];
ll n,a[MAXN];

ll rec(ll s,ll e,ll player){
    if(s > e) return 0;

    ll &ans = dp[s][e][player];

    if(ans != -1) return ans;

    if(!player) ans = max(a[s] + rec(s+1,e,1-player),a[e] + rec(s,e-1,1-player));
    else ans = min(-a[s] + rec(s+1,e,1-player),-a[e] + rec(s,e-1,1-player));
    
    return ans;
}

void solve(){
    cin>>n;
    FOR(i,1,n) cin>>a[i];

    memset(dp,-1,sizeof(dp));

    cout<<rec(1,n,0)<<endl;
}

signed main(){


    ll t;
    t = 1; 
    // cin>>t;
    FOR(tt,1,t){
        solve();
    }
    
}

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

const int INF = 1 << 29;
const long long int Mod = 1000000007;
using ll = long long int;
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; ++i)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)



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

	int z = 0;
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		if (a == b) ++z;
		else z = 0;

		if (z == 3) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;

#define Endl endl


/*--------------------template--------------------*/



int main() {
    cin >> n;
    vi va(n), vb(n);
    REP(i, n) {
        cin >> va[i] >> vb[i];
    }
    RREP(i, n) {
        if (va[i] % vb[i] == 0) {
            if (i > 0) {
                va[i - 1] += ans;
            }
        } else {
            k = 0;
            if (va[i] > vb[i]) {
                k = vb[i] - va[i] % vb[i];
            } else {
                k = vb[i] - va[i];
            }
            ans += k;
            if (i > 0) {
                va[i - 1] += ans;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{
	int tate;
	int yoko;
	
	public void solve(){
		Scanner sc = new Scanner(System.in);
		tate = sc.nextInt();
		yoko = sc.nextInt();
		System.out.println((tate*yoko)+" "+(tate*2+yoko*2));
	}
	public static void main(String[] args){
		Main obj = new Main();
		obj.solve();
	}
}

Measured memory_bytes: 17156
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    int sum1 = x*a + y*b;
    int sum2 = 2*min(x,y)*c;
    int sum3 = 2*max(x,y)*c;
    if(x>y) sum2 += (x-y)*a;
    else    sum2 += (y-x)*b;
    cout<<min(sum1,min(sum2,sum3))<<endl;
    return 0;
}



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

#define f first
#define s second

using namespace std;

int n, m;
vector<int> dx = {1, -1, 0, 0};
vector<int> dy = {0, 0, -1, 1};
vector<vector<bool>> vis;
vector<vector<char>> board;

int bfs(int x, int y){
    vis[x][y] = true;
    int ans = 0;
    vector<vector<int>> dist (n, vector<int>(m, 0));
    queue<pair<int, int>> q;
    q.push({x, y});
    while(!q.empty()){
        x = q.front().f;
        y = q.front().s;
        q.pop();
        for(int i = 0; i < 4; ++i){
            if(x + dx[i] >= 0 && x + dx[i] < n && y + dy[i] >= 0 && y + dy[i] < m && !vis[x + dx[i]][y + dy[i]] && board[x + dx[i]][y + dy[i]] != '#'){
                dist[x + dx[i]][y + dy[i]] = dist[x][y] + 1;
                ans = max(ans, dist[x][y] + 1);
                q.push({x + dx[i], y + dy[i]});
                vis[x + dx[i]][y + dy[i]] = true;
            }
        }
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    board.assign(n, vector<char>(m, ' '));
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            cin >> board[i][j];
        }
    }
    int res = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            if(board[i][j] == '#') continue;
            vis.assign(n, vector<bool>(m, false));
            res = max(res, bfs(i, j));
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

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

int IT_MAX = 1 << 18;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

int main() {
	int A, B;
	scanf("%d %d", &A, &B);
	A *= 10;
	if (B >= 10) A *= 10;
	if (B >= 100) A *= 10;
	int v = A + B;

	for (int i = 1; i <= 10000; i++) if (v == i*i) return !printf("Yes\n");
	return !printf("No\n");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define L 100005

typedef struct p{
  char name[10];
  int time;
}P;

void en(P);
P de();
int min(int,int);

P Queue[L];
int head,tail,n;

int main(){
  int t=0;
  int c,q,i;
  P u;

  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s",Queue[i].name);
    scanf("%d",&Queue[i].time);
  }

  head=0;
  tail=n;

  while(head!=tail){
    u = de();
    c = min(q,u.time);
    u.time -= c;
    t += c;
    if(u.time >0)en(u);
    else{
      printf("%s %d\n",u.name,t);
    }
  }
  return 0;
}

void en(P x){
  Queue[tail]=x;
  tail=(tail+1)%L;
}

P de(){
  P x =Queue[head];
  head = (head+1)%L;
  return x;
}

int min(int a,int b){
  return a<b ? a : b;
}
  



Measured memory_bytes: 3344
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		//int n = sc.nextInt();

		// 文字列の入力
		String s1 = sc.next();
		String s2 = sc.next();

		boolean status = s1.charAt(0)==s2.charAt(2) &&
				s1.charAt(1)==s2.charAt(1) &&
				s1.charAt(2)==s2.charAt(0);


		String ans;
		if(status){
			ans = "YES";
		}else{
			ans="NO";
		}
		// 出力
		System.out.println(ans);
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

void solve() {
    int n, m, xx;
    cin >> n >> m >> xx;
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> c(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) cin >> a[i][j];
    }
    ll ans = INT_MAX;
    for (int i = 0; i < 1 << (n); i++) {
        string s = "";
        int x = i;
        while (x > 0) {
            s += char(x % 2 + '0');
            x /= 2;
        }
        int t = s.size();
        for (int j = 0; j < n - t; j++) s += '0';


        ll cost = 0;
        map <int, int> b;
        for (int j = 0; j < n; j++) {
            if (s[j] == '1') {
                cost += c[j];
                for (int k = 0; k < m; k++) {
                    b[k] += a[j][k];
                }
            }
            bool ok = true;
            //cout << j << ' ' << "l\n";
            for (int k = 0; k < m; k++) {
                //cout << b[k] << ' ';
                if (b[k] < xx) {
                    ok = false;
                    break;
                }
            }
            //cout << endl;

            if (ok) {
                //cout << cost << endl;
                ans = min(ans, cost);
                break;
            }
        }
    }
    cout << (ans == INT_MAX ? -1 : ans);
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
	int T = 1; 
    //cin >> T;
    while(T--) solve();
}

Measured memory_bytes: 3676
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,m=map(int,input().split())
A=sorted(map(int,input().split()))
B=[0]+A[:]
for i in range(n):
    B[i+1]+=B[i]

def solve_binary(mid):
    tmp=0
    for i,ai in enumerate(A):
        tmp+=n-bisect.bisect_left(A,mid-ai)
    return tmp>=m

def binary_search(n):
    ok=0
    ng=n
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if solve_binary(mid):
            ok=mid
        else:
            ng=mid
    return ok

binresult=binary_search(2*10**5+1)
for i ,ai in enumerate(A):
    ans+=ai*(n-bisect.bisect_left(A,binresult-ai))+B[n]-B[bisect.bisect_left(A,binresult-ai)]
    count+=n-bisect.bisect_left(A,binresult-ai)
    # print(ans,count)
ans-=binresult*(count-m)
print(ans)
# print(binresult)

Measured memory_bytes: 63472
# 最後の文字を書くことで初めて反例ができたとする
# 判定に関係があるのは末尾4文字のみ
# 制限が小さいのでルール通り書く


from collections import defaultdict
MOD = 10**9 + 7

N = int(input())

dp = [defaultdict(int) for _ in range(N+1)]
dp[0][''] = 1

def test(s):
  if s.find('ABC') != -1:
    return False
  L = len(s)
  for i in range(L-1):
    li = list(s)
    li[i],li[i+1] = li[i+1],li[i]
    t = ''.join(li)
    if t.find('ABC') != -1:
      return False
  return True
    

for n in range(N):
  for s,cnt in dp[n].items():
    for c in 'ABCD':
      ns = s + c
      if test(ns):
        dp[n+1][ns[-3:]] += cnt
        dp[n+1][ns[-3:]] %= MOD

        
answer = sum(dp[N].values())
answer %= MOD
print(answer)


Measured memory_bytes: 4156
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<math.h>
#include<time.h>
#include<vector>
#include<bitset>
#include<memory>
#include<utility>
#include<fstream>
#include<stdio.h>
#include<sstream>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int modo=1000000007;
struct edge
{
    int x;
    int y;
    int weight;
    friend bool operator < (const edge &a,const edge &b)
    {
        return a.weight<b.weight;
    }
    void read()
    {
        scanf("%d%d%d",&x,&y,&weight);
        x--;
        y--;
    }
};
edge a[2005];
int fa[1005];
int size[1005];
int findroot(int x)
{
    int root;
    for (root=x;fa[root]!=-1;root=fa[root]) ;
    int temp;
    for (;fa[x]!=-1;)
    {
        temp=fa[x];
        fa[x]=root;
        x=temp;
    }
    return root;
}
void u(int x,int y)
{
    x=findroot(x);
    y=findroot(y);
    if (size[x]>size[y])
    {
        swap(x,y);
    }
    fa[x]=y;
    size[y]+=size[x];
}
int pow2[2005];
long long vals[2005];
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n,m;
    scanf("%d%d",&n,&m);
    long long x;
    cin>>x;
    int i;
    for (i=0;i<m;i++)
    {
        a[i].read();
    }
    pow2[0]=1;
    for (i=1;i<=m;i++)
    {
        pow2[i]=pow2[i-1]*2%modo;
    }
    sort(a,a+m);
    int ans=0;
    for (i=m-1;i>=1;i--)
    {
        long long val=a[i].weight;
        memset(fa,-1,sizeof(fa));
        int j;
        for (j=0;j<n;j++)
        {
            size[j]=1;
        }
        u(a[i].x,a[i].y);
        int cnt=m-i;
        for (j=0;j<m;j++)
        {
            if (findroot(a[j].x)!=findroot(a[j].y))
            {
                u(a[j].x,a[j].y);
                val+=a[j].weight;
            }
            if ((j>i)&&(vals[j]<x))
            {
                cnt--;
            }
        }
        vals[i]=val;
    }
    for (i=m-1;i>=1;i--)
    {
        long long val=a[i].weight;
        memset(fa,-1,sizeof(fa));
        int j;
        for (j=0;j<n;j++)
        {
            size[j]=1;
        }
        u(a[i].x,a[i].y);
        int cnt=m-i;
        for (j=0;j<m;j++)
        {
            if (findroot(a[j].x)!=findroot(a[j].y))
            {
                u(a[j].x,a[j].y);
                val+=a[j].weight;
            }
            if ((j>i)&&(vals[j]<x))
            {
                cnt--;
            }
            if ((j<i)&&(vals[j]>x))
            {
                cnt++;
            }
        }
        vals[i]=val;
        if (vals[i]==x)
        {
            ans=(ans+pow2[cnt])%modo;
        }
    }
    printf("%d\n",ans);
    return 0;
} 


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

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

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int k;
    string s;
    cin >> k >> s;
    if (s.size() <= k) {
        cout << s << endl;
    } else {
        cout << s.substr(0, k) << "..." << endl; 
    }
    
    return 0;
}



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

#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i,n) for (int i = 0; i < (n); ++i)

template <typename T>
vector<T> getValues(int num){
    vector<T> values(num);
    for(int i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

int main(){
    int N,K;
    cin >> N >> K;
    auto inputs = getValues<int>(N);
    sort(inputs.begin(), inputs.end() );
    int ans = 0;
    rep(i,K){
      ans += inputs.at(i);
    }

    printl(ans);
}


Measured memory_bytes: 3616
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashSet<String> set = new HashSet<>();
        for(int i=0; i<n; i++){
            String s = sc.next();
            set.add(s);
        }
        if(set.size()==3){
            System.out.println("Three");
        }else{
            System.out.println("Four");
        }
    }
}


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

int digit_sum(int n, int base = 10) {
    int res = 0;
    while (n > 0) res += n % base, n /= base;
    return res;
}

int main() {
    int n; cin >> n;
    int ans = digit_sum(n);
    if (ans == 1) ans = 10;
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(a>=c)
        cout << 0 << endl;
    else if(a+b>=c)
        cout << c-a << endl;
    else
        cout << "NA" << endl;
    return 0;
}



Measured memory_bytes: 3100
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    A = [None] * n
    for i in range(n):
        tmp = list(map(lambda x:int(x) - 1, input().split()))
        tmp.reverse()
        A[i] = tmp

    now = set()
    for i in range(n):
        j = A[i][-1]
        if i == A[j][-1]:
            now.add((min(i, j), max(i, j)))

    cnt = 0
    while now:
        next = set()
        for i, j in now:
            A[i].pop()
            A[j].pop()

        for i0, i1 in now:
            for i in (i0, i1):
                if not A[i]:
                    continue
                j = A[i][-1]
                if not A[j]:
                    continue
                if i == A[j][-1]:
                    next.add((min(i, j), max(i, j)))

        now = next
        cnt += 1

    if any(row for row in A):
        print(-1)
        return
    print(cnt)
resolve()

Measured memory_bytes: 65628
#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 n,k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  sort(h.begin(), h.end());
  k = min(n,k);
  rep(i,k){
    h.pop_back();
  }
  ll sum = 0;
  rep(i,h.size()) sum += h[i];
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * Sum of Prime Numbers
 */
public class Main {

	static Main main = new Main();

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		Prime prime = main.new Prime();

		while (!(line = br.readLine()).equals("0")) {

			int n = Integer.parseInt(line);
			System.out.println(prime.calcTo(n).sumTo(n));

		}

	}

	class Prime {
		List<Integer> primes;

		Prime() {
			primes = new ArrayList<Integer>();
			primes.add(0);
			primes.add(2);
			primes.add(3);
			primes.add(5);
			primes.add(7);
		}

		Prime calcTo(int index) {

			int sta = primes.get(primes.size() - 1);

			for (int i = sta;; i++) {

				if (primes.size() > index) {
					break;
				}

				for (int j = 1; j < primes.size(); j++) {
					if (i % primes.get(j) == 0) {
						break;
					} else {
						if (j == primes.size() - 1) {
							primes.add(i);
						}
					}
				}
			}
			return this;
		}

		int sumTo(int index) {
			int result = 0;
			if (index < primes.size()) {
				for (int i = 1; i <= index; i++) {
					result += primes.get(i);
				}
			}
			return result;
		}

	}

}

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

int N, L;
string s[110];

int main() {
  // 入力
  cin >> N >> L;
  for (int i=0; i<N; i++) cin >> s[i];
  // 文字列を昇順に並び替え、前から順に出力していく
  sort(s, s+N);
  for (int i=0; i<N; i++) {
    cout << s[i];
  }
  cout << endl;
  return 0;
}


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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  int n, k;
  cin >> n >> k;
  map<char, int> m;
  cin >> m['s'] >> m['p'] >> m['r'];
  string s;
  cin >> s;
  int ans = 0;
  vector<int> d(s.size());
  for (int i = 0; i < n; i++) {
    if (i < k - 1 || !(s[i] == s[i - k] && d[i - k])) {
      ans += m[s[i]];
      d[i] = 1;
    }
  }
  cout << ans << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 4260
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int v[100005];
int x,n;
int main()
{
	scanf("%d",&n);
	int maxn=-1;
	int ans=0;
	memset(v,0,sizeof(v));
	for(int i=0;i<n;i++)
	{
		scanf("%d",&x);
		v[x]++;
		maxn=max(maxn,v[x]);
		v[x+1]++;
		maxn=max(maxn,v[x+1]);
		if((x-1)<0) ans++,maxn=max(maxn,ans);
		else {v[x-1]++;maxn=max(maxn,v[x-1]);}
	}
	printf("%d\n",maxn);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
const double PI=3.14159265358979323846;

int main() {
    ll r;
    cin >> r;
    double ans = 2 * r * PI;
    cout << ans << endl;
}

Measured memory_bytes: 3788
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int n, m;
	
	cin >> n >> m;
	
	vector<int> st(m*2);
	for (int i = 0; i < m*2; i++) {
		cin >> st.at(i);
	}

	for (int i = 1; i <= n; i++) {
		cout << count(st.begin(),st.end(),i) << endl;
	}
		
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[3];
int main(){
    ios::sync_with_stdio(false);
    cin>>a[0]>>a[1]>>a[2];
    if(a[0]==a[1]&&a[1]==a[2])cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll n; cin >> n;
    vector<ll> a(100001, 0);
    ll sum = 0;
    rep(i, n){
        ll aa; cin >> aa;
        a[aa]++;
        sum += aa;
    }
    ll q; cin >> q;
    rep(i, q){
        ll b, c; cin >> b >> c;
        sum += (c-b)*a[b];
        a[c] += a[b];
        a[b] = 0;
        cout << sum << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3988
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int H, W, N; std::cin >> H >> W >> N;
  int sr, sc; std::cin >> sr >> sc;
  std::string S, T; std::cin >> S >> T;
  int l = 0, r = 0, u = 0, d = 0;

  for (int i = 0; i < N; ++i) {
    // Takahashi
    switch (S[i]) {
      case 'L':
        ++l;
        break;
      case 'R':
        ++r;
        break;
      case 'U':
        ++u;
        break;
      case 'D':
        ++d;
        break;
      defalt:
        break;
    }

    if (sr - u < 1 || sr  + d > H || sc - l < 1 || sc + r > W) {
      std::cout << "NO" << std::endl;
      return 0;
    }

    // Aoki
    switch (T[i]) {
      case 'L':
        if(sc + r > 1) --r;
        break;
      case 'R':
        if(sc - l < W) --l;
        break;
      case 'U':
        if(sr + d > 1) --d;
        break;
      case 'D':
        if(sr - u < H) --u;
        break;
      default:
        break;
    }
  }

  std::cout << "YES" << std::endl;
}


Measured memory_bytes: 776