akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int a[100005];
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define CONST_RETURN(a) do{cout << (a) << endl; return 0; }while(0)

int main(){
  int n;
  cin >> n;
  if(n==1) CONST_RETURN(1);
  rep(i,n) cin >> a[i];
  int ans = 1,mode = 0;
  rep(i,n-1){
    if(mode==1 && a[i+1]<a[i]){ans++;mode=0;}
    else if(mode == -1 && a[i+1]>a[i]){ans++;mode=0;}
    else if(mode == 0 && a[i+1] > a[i]) mode = 1;
    else if(mode == 0 && a[i+1] < a[i]) mode = -1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
use proconio::*;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
use std::*;

#[allow(dead_code)]
const MOD: i128 = 100_000_007;

#[fastout]
fn main() {
    input!{
        n : usize
    }
    let ans = match n % 10 {
        3 => "bon",
        0 | 1 | 6 | 8 => "pon",
        _ => "hon"
    };
    println!("{}",ans);
}


Measured memory_bytes: 2176
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x / GCD(x, y) * y;
}

ll wazu = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (wazu - inv(wazu % x) * (wazu / x)) % wazu;
        if (a >= 0) { return a; }
        else { return wazu + a; }
    }
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    rep(i, N) cin >> S[i];

    sort(S.begin(), S.end());

    string T = "";

    rep(i, N) T += S[i];

    cout << T << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    ll res=0,tot=0;
    rep(i,n){
        ll a;cin>>a;
        if(a==0){
            res+=tot/2;
            tot=0;
            continue;
        }else{
            tot+=a;
        }
    }
    res+=tot/2;
    cout<<res<<endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
#define INT_MAX 2147483647
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i < (int)n; i++)
#define Loopr(i, n) for(int i= (int)n - 1; i >= 0; i--)
using namespace std;
typedef long long int ll;

struct node {
	int key;
	node *left, *right, *parent;
};

node *NIL = (node*)malloc(sizeof(node));
node *root, *n1, *n2, *n3;
int k;

void insert(node* *focus) {
	if (*focus == NIL) {
		node* buf = (node*)malloc(sizeof(node));
		buf->key = k;
		buf->left = NIL;
		buf->right = NIL;
		buf->parent = n1;
		*focus = buf;
	}
	else if (k < (*focus)->key) {
		n1 = (*focus);
		insert(&((*focus)->left));
	}
	else {
		n1 = (*focus);
		insert(&((*focus)->right));
	}
}

void fnd(node *focus, int func) {
	if (focus->key == k) {
		if(func==0) printf("yes\n");
		else if (func == 1) n2 = focus;
	}
	else if (focus == NIL) printf("no\n");
	else {
		if (k < focus->key) fnd(focus->left, func);
		else fnd(focus->right, func);
	}
}

void insert2(node* *focus) {
	if (*focus == NIL) {
		n3->parent = n1;
		*focus = n3;
	}
	else if (n3->key < (*focus)->key) {
		n1 = (*focus);
		insert2(&((*focus)->left));
	}
	else {
		n1 = (*focus);
		insert2(&((*focus)->right));
	}
}

void del() {
	bool comp = (n2->key < n2->parent->key ? 1: 0) ;
	if (n2->left == NIL&&n2->right == NIL) {
		if (comp) n2->parent->left = NIL;
		else n2->parent->right = NIL;
	}
	else if (n2->left != NIL&&n2->right == NIL) {
		if (comp) {
			n2->parent->left = n2->left;
			n2->left->parent = n2->parent;
		}
		else {
			n2->parent->right = n2->left;
			n2->left->parent = n2->parent;
		}
	}
	else if (n2->left == NIL&&n2->right != NIL) {
		if (comp) {
			n2->parent->left = n2->right;
			n2->right->parent = n2->parent;
		}
		else {
			n2->parent->right = n2->right;
			n2->right->parent = n2->parent;
		}
	}
	else {
		n3 = n2->right;
		while (n3->left != NIL) n3 = n3->left;
		n2->key = n3->key;
		n2 = n3;
		del();
	}
}

void print_in(node* focus) {
	if (focus == NIL) return;
	print_in(focus->left);
	printf(" %d", focus->key);
	print_in(focus->right);
}

void print_pre(node* focus) {
	if (focus == NIL) return;
	printf(" %d", focus->key);
	print_pre(focus->left);
	print_pre(focus->right);
}

void print() {
	print_in(root);
	printf("\n");
	print_pre(root);
	printf("\n");
}

int main() {
	int m;
	root = NIL;
	cin >> m;
	char query[10];
	Loop(i, m) {
		scanf("%s", query);
		if (query[0] == 'i') {
			scanf("%d", &k);
			insert(&root);
		}
		else if (query[0] == 'f') {
			scanf("%d", &k);
			fnd(root, 0);
		}
		else if (query[0] == 'd') {
			scanf("%d", &k);
			fnd(root, 1);
			del();
		}
		else print();
	}
	return 0;
}

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

using namespace std;

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

int main(){
    int n;cin>>n;
    int res=0;
    REP(i,n){
        int l,r;cin>>l>>r;
        res+=(r-l+1);
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define rep(i,s,e)for(int i=s;i<=e;i++)
#define out(a)cout << a << endl;
#define PI 3.141592653589
using namespace std;

int main(){
    double r;
    cin >> r;
    printf("%.8f %.8f\n", PI*r*r, 2*PI*r);
    return 0;
}


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

int main () {
  int N;
  cin >> N;
  vector<int> s(N);
  int n = 0;
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
    n += s.at(i);
  }
  sort(s.begin(), s.end());
  if (n%10 != 0) cout << n << endl;
  else {
    for (int i = 0; i < N; i++) {
      if (s.at(i) %10 != 0) {
        cout << n - s.at(i) << endl;
        return 0;
      }
    }
    cout << 0 << endl;
  }
}
    

Measured memory_bytes: 256
n=int(input())

for i in range(1,3501):
    for j in range(i,3501):
        if (4*i*j-n*i-n*j)>0 and n*i*j%(4*i*j-n*i-n*j)==0:
            w=n*i*j//(4*i*j-n*i-n*j)
            print(i,j,w)
            quit()
        else:
            continue

Measured memory_bytes: 3060
#!/usr/bin/env ruby

s = gets.chomp.split(//)
t = gets.chomp.split(//)

h = Hash.new
hh = Hash.new
result = 'Yes'
s.size.times do |i|
  if h.has_key?(s[i])
    if (h[s[i]] != t[i])
      result = 'No'
    end
  else
    h[s[i]] = t[i]
  end
  if hh.has_key?(t[i])
    if (hh[t[i]] != s[i])
      result = 'No'
    end
  else
    hh[t[i]] = s[i]
  end
end

#if (h.values.size != h.values.uniq.size)
#  result = 'No'
#end

#h.keys.each do |k|
#  v = h[k]
#  if (h[v] != k && !h[v])
#    result = 'No'
#  end
#end

#hh.keys.each do |k|
#  v = hh[k]
#  if (hh[v] != k && !hh[v])
#    result = 'No'
#  end
#end

puts result


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

using namespace std;

#define MAX_V 10000
#define INF 1e9
typedef pair<int,int> pii;

struct edge{
  int to,cost;
};

int V;
bool used[MAX_V];
vector<edge> G[MAX_V];

int prim(){
  priority_queue<pii,vector<pii>,greater<pii> > Q;
  Q.push(pii(0,0));
  memset(used,false,sizeof(used));
  int res = 0;
  
  while(!Q.empty()){
    pii p = Q.top(); Q.pop();
    int v = p.second;
    if(used[v]){ continue; }
    used[v] = true;
    res += p.first;
    for(int i = 0 ; i < (int)G[v].size() ; i++){
      edge e = G[v][i];
      Q.push(pii(e.cost,e.to));
    }
  }
  return res;
}

int main(){
  int E,s,t,w;
  cin >> V >> E;
  for(int i = 0 ; i < E ; i++){
    cin >> s >> t >> w;
    G[s].push_back((edge){t,w});
    G[t].push_back((edge){s,w});
  }
  cout << prim() << endl;
  return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    cout << s1.at(0) << s2.at(1) << s3.at(2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
#define NIL -1
struct Node { int parent, left, right; };
Node T[1000000];
int n, D[1000000], H[1000000];
 
void setDepth(int u, int d) 
{
    if (u == NIL) return;
    D[u] = d;
    setDepth(T[u].left, d + 1);
    setDepth(T[u].right, d + 1);
}
 
int setHeight(int u)
{
    int h1, h2;
    h1 = h2 = 0;
 
    if (T[u].right != NIL) h2 = setHeight(T[u].right) + 1;
 
    if (T[u].left != NIL) h1 = setHeight(T[u].left) + 1;
 
    if (h1 > h2) return H[u] = h1;
    else return H[u] = h2;
}
 
int getSibling(int u)
{
    if (T[u].parent == NIL) return NIL;
    if (T[T[u].parent].left != u && T[T[u].parent].left != NIL) return T[T[u].parent].left;
    if (T[T[u].parent].right != u && T[T[u].parent].right != NIL) return T[T[u].parent].right;
 
    return NIL;
}
 
void print(int u)
{
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].parent << ", ";
    cout << "sibling = " << getSibling(u) << ", ";
    int deg = 0;
    if (T[u].left != NIL) deg++;
    if (T[u].right != NIL) deg++;
    cout << "degree = " << deg << ", ";
    cout << "depth = " << D[u] << ", ";
    cout << "height = " << H[u] << ", ";
 
    if (T[u].parent == NIL) cout << "root" << endl;
    else if (T[u].left == NIL && T[u].right == NIL) cout << "leaf" << endl;
    else cout << "internal node" << endl;
}
 
int main() 
{
    int id, left, right, root = 0;
 
    cin >> n;
    for (int i = 0; i < n; i++) T[i].parent = NIL;
    for (int i = 0; i < n; i++)
    {
        cin >> id >> left >> right;
        T[id].left = left;
        T[id].right = right;
        if (left != NIL) T[left].parent = id;
        if (right != NIL) T[right].parent = id;
    }
 
    for (int i = 0; i < n; i++)
    {
        if (T[i].parent == NIL) root = i;
    }
 
    setDepth(root, 0);
    setHeight(root);
    for (int i = 0; i < n; i++) print(i);
 
    return 0;
}

Measured memory_bytes: 3088
N = int(input())
a = [0 for x in range(N)]
L = int(N**0.5)
for i in range(1,L):
    for j in range(1,L):
        for k in range(1,L):
            n = i*i+j*j+k*k+i*j+j*k+i*k
            if n <= N:
                a[n-1] += 1
for i in range(N):
    print(a[i])


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
 
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)
template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long mod(long long a, long long b) { return (a%b+b)%b; }
long long gcd(long long x, long long y) { return __gcd(x, y); }
long long lcm(long long x, long long y) { return x * 1ll * y / gcd(x, y); }
 
 
const long long MAXN = 1e9 + 9;
const long long SIZE = 3e5 + 5;
const long long MOD = 1e9 + 7;


int main() { speedhack()

	string s; cin >> s;

	long long num = 0;

	for (int i = 0; i < (int)s.size(); i++) {
		num = num + (s[i] - '0');
		num = mod (num, 9);
	}

	if (num) cout << "No" << endl;
	else cout << "Yes" << endl;


	return 0;
}

Measured memory_bytes: 3732
import math

def koch(n,p1x,p1y,p2x,p2y):
    if n == 0:
        return
    
    sx = (2*p1x+1*p2x)/3
    sy = (2*p1y+1*p2y)/3
    tx = (1*p1x+2*p2x)/3
    ty = (1*p1y+2*p2y)/3
    theta = math.pi/3  #180[deg] == math.pi[rad]
    ux = math.cos(theta)*(tx-sx) - math.sin(theta)*(ty-sy)+sx
    uy = math.sin(theta)*(tx-sx) + math.cos(theta)*(ty-sy)+sy

    koch(n-1, p1x, p1y, sx, sy)
    print("{:.8f} {:.8f}".format(sx, sy))
    koch(n-1, sx, sy, ux, uy)
    print("{:.8f} {:.8f}".format(ux, uy))
    koch(n-1, ux, uy, tx, ty)
    print("{:.8f} {:.8f}".format(tx, ty))
    koch(n-1, tx, ty, p2x, p2y)

n = int(input())
p1x,p1y = 0.0,0.0
p2x,p2y = 100.0,0.0
print("{:.8f} {:.8f}".format(p1x, p1y))
koch(n, p1x, p1y, p2x, p2y)
print("{:.8f} {:.8f}".format(p2x, p2y))



Measured memory_bytes: 5772
fn getline() -> String {
    let mut __ret = String::new();
    std::io::stdin().read_line(&mut __ret).ok();
    return __ret;
}

fn solve(k: i32, s: i32) -> i32 {
    let mut ans = 0;
    for x in 0..(k + 1) {
        for y in 0..(k + 1) {
            if s - k <= x + y && x + y <= s {
                ans += 1;
            }
        }
    }

    return ans;
}

fn main() {
    let s = getline();
    let vec: Vec<i32> = s.trim().split(' ').map(|s| s.parse().unwrap()).collect();
    let k = vec[0];
    let s = vec[1];

    let ans = solve(k, s);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>
#include <bitset>

using namespace std;
typedef long long ll;


ll pow(ll x, ll n) {
    ll res = 1;
    for (int i = 0; i < n; i++) {
        res *= x;
    }
    return res;
}

ll calc(int n) {
    ll l = pow(10, n-1);
    ll r = pow(10, n);
    ll th = (r+2)/3 - (l+2)/3;
    ll fi = (r+4)/5 - (l+4)/5;
    ll thfi = (r+14)/15 - (l+14)/15;
    return (th+fi)*4 + n*(r-l - th - fi + thfi);
}


ll calc2(int n, ll l, ll r) {
    ll th = (r+2)/3 - (l+2)/3;
    ll fi = (r+4)/5 - (l+4)/5;
    ll thfi = (r+14)/15 - (l+14)/15;
    return (th+fi)*4 + n*(r-l - th - fi + thfi);
}

ll solve(ll md) {
    string ms = to_string(md);
    int n = (int)ms.size();
    ll res = 0;
    for (int i = 1; i < n; i++) {
        res += calc(i);
    }
    res += calc2(n, pow(10, n-1), md);
    return res;
}

int main() {
    ll s;
    cin >> s; s--;
    // for (int i = 1; i < 20; i++) {
    //     printf("%d %lld\n", i, solve(i));
    // }
    ll l = 1, r = 1LL<<58;
//    printf("%lld %lld\n", r, solve(r));
    while (r-l > 1) {
        ll md = (l+r)/2;
        if (solve(md) <= s) {
            l = md;
        } else {
            r = md;
        }
    }
//    printf("res %lld %lld\n", l, r);
    s -= solve(l);
    string ss;
    for (ll i = 0; i < 100; i++) {
        ll j = i+l;
        if (j % 3 && j % 5) {
            ss += to_string(j);
            continue;
        }
        if (j % 3 == 0) {
            ss += "Fizz";
        }
        if (j % 5 == 0) {
            ss += "Buzz";
        }
    }
    for (int i = 0; i < 20; i++) {
        cout << ss[s+i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll N, S = 0;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    S += A[i];
  }
  ll dp[N];
  ll residual = 0;
  for (int i = 1; i < N; i += 2) {
    residual += A[i];
  }
  dp[0] = S - 2 * residual;
  for (int i = 1; i < N; i++) {
    dp[i] = 2 * A[i - 1] - dp[i - 1];
  }
  for (int i = 0; i < N; i++) {
    cout << dp[i] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 2944
#line 1 "main.cpp"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#line 29 "main.cpp"

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

using ll=long long;

#line 2 "/mnt/c/Users/Imperi/Documents/cp-library/lib/PotentialUnionFind.cpp"

#line 6 "/mnt/c/Users/Imperi/Documents/cp-library/lib/PotentialUnionFind.cpp"

template<typename Group>
class PotentialUnionFind{
  public:
  using value_t=typename Group::value_t;
  using size_t=std::size_t;
  private:
  size_t group;
  std::vector<size_t> par,sz;
  std::vector<value_t> df; //val[par]=val[x]+df[x]

  value_t fold_to_root(size_t x){
    value_t ret=Group::id;
    while(par[x]!=x){
      df[x]=Group::op(df[x],df[par[x]]);
      par[x]=par[par[x]];
      ret=Group::op(ret,df[x]);
      x=par[x];
    }
    return ret;
  }

  public:
  PotentialUnionFind(size_t n=0):group(n),par(n),sz(n,1),df(n,Group::id){
    std::iota(par.begin(),par.end(),0);
  }

  size_t root(size_t x){
    while(par[x]!=x){
      df[x]=Group::op(df[x],df[par[x]]);
      par[x]=par[par[x]];
      x=par[x];
    }
    return x;
  }

  bool same(size_t a,size_t b){return root(a)==root(b);}
  size_t size(){return par.size();}
  size_t groups(){return group;}
  size_t group_size(size_t x){return sz[root(x)];}

  // unite A=B+value
  bool unite(size_t a,size_t b,value_t value){
    size_t aroot=root(a),broot=root(b);
    if(aroot==broot)return false;
    group--;
    if(sz[aroot]<sz[broot]){
      std::swap(aroot,broot);
      std::swap(a,b);
      value=Group::inv(value);
    }
    sz[aroot]+=sz[broot];
    value=Group::op(value,fold_to_root(a));
    value=Group::op(Group::inv(fold_to_root(b)),value);
    df[broot]=value;
    par[broot]=aroot;
    return true;
  }

  // return diff  such as A=B+diff
  value_t diff(size_t a,size_t b){
    assert(same(a,b));
    return Group::op(fold_to_root(b),Group::inv(fold_to_root(a)));
  }
};
#line 38 "main.cpp"

struct Group{
  using value_t=ll;
  static constexpr value_t id=0;
  static constexpr value_t op(value_t a,value_t b){
    return a+b;
  }
  static constexpr value_t inv(value_t a){return -a;}
};

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

  ll n,q;
  std::cin>>n>>q;

  PotentialUnionFind<Group> uni(n);

  while(q--){
    ll mode;
    std::cin>>mode;
    if(mode==0){
      ll x,y,z;
      std::cin>>x>>y>>z;
      if(!uni.same(x,y))uni.unite(y,x,z);
    }else{
      ll x,y;
      std::cin>>x>>y;
      if(!uni.same(x,y))std::cout<<"?\n";
      else std::cout<<uni.diff(y,x)<<"\n";
    }
  }

  return 0;
}



Measured memory_bytes: 5204
n = int(input())
a = list(map(int, input().split()))

INF = 10 ** 20

dp = [[0 for _ in range(n)] for _ in range(n)]

s = [0] * (n+1)
for i in range(n):
    s[i+1] = s[i] + a[i]


for i in range(n):
    dp[i][i] = 0

for k in range(1, n):
    for x in range(n-k):
        y = x + k
        temp = INF
        for i in range(k):
            temp = min(temp, dp[x][x+i] + dp[x+i+1][y] + s[y+1] - s[x])
        dp[x][y] = temp

print(dp[0][n-1])

Measured memory_bytes: 43500
import java.util.Scanner;
public class Main{
  public static void main(String[] arsgs){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int count = 0;
    for (int i  = a; i <= b; i++){
      int i0 = (i/10000);
      int i1 = (i/1000)%10;
      int i3 = (i/10)%10;
      int i4 = i%10;
      if( i0 == i4){
        if ( i1 == i3){
          count++;
        }
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 23636
s = list(map(str,input()))
t = list(map(str,input()))

same = 0

for i in range(0,len(s)-len(t)+1):
    s2 = s[i:i+len(t)]
    count = 0
    for j in range(len(t)):
        if s2[j]==t[j]:
            count += 1
    same = max([same,count])

print(max(0,len(t) - same))


Measured memory_bytes: 9080
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MAXN 100001
#define MOD 1e9+5
#define INF 1e18L+5

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;

int main(){
    int N, K;
    cin >> N >> K;
    ll ans = 0, ent;
    priority_queue<ll> q;
    for(int i = 0; i < N; i++){
        cin >> ent;
        ans += ent;
        q.push(ent);
    }
    while(K-- && q.size()){
        ans -= q.top();
        q.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, K;
    cin >> N >>K;

    int tmp = 1;
    for (int i = 1; i < K; i++){
        tmp += 2;
    }
    if (tmp <= N){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
# coding: utf-8
# Here your code !
while True:
    l = map(int,raw_input().split())
    if l == [0,0]:
        break
    else:
        check = 0
        taro = 0
        l1 = []
        for i in range(l[0]):
            n = int(raw_input())
            l1.append(n)
        l1.sort()
        l2 = []
        for i in range(l[1]):
            n = int(raw_input())
            l2.append(n)
        l2.sort()
        if sum(l1) < sum(l2):
            l3 = l1
            l1 = l2
            l2 = l3
            taro = 1
        if (sum(l1) - sum(l2))% 2 != 0:
            print -1
        else:
            a = (sum(l1) - sum(l2))/2
            for num in l1:
                if num - a in l2:
                    if taro == 1:
                        print num-a,num
                    else:
                        print num,num-a
                    check = 1
                    break
            if check == 0:
                print -1
        

Measured memory_bytes: 6400
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <numeric>

using namespace std;
using ll = long long;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main() {
    int H, W;
    cin >> H >> W;
    string C[H];
    for (int i = 0; i < H; i++) {
        cin >> C[i];
    }

    for (int i = 0; i < H; i++) {
        for (int k = 0; k < W; k++) {
            if (C[i][k] == '#') {
                cout << "#";
                continue;
            }

            if (i == 0) {
                if (k == 0) {
                    cout << (C[i][k+1] == '#') +
                            (C[i+1][k] == '#') +
                            (C[i+1][k+1] == '#');
                } else if (k == W-1) {
                    cout << (C[i][k-1] == '#') +
                            (C[i+1][k-1] == '#') +
                            (C[i+1][k] == '#');
                } else {
                    cout << (C[i][k-1] == '#') +
                            (C[i][k+1] == '#') +
                            (C[i+1][k-1] == '#') +
                            (C[i+1][k] == '#') +
                            (C[i+1][k+1] == '#');
                }
            } else if (i == H-1) {
                if (k == 0) {
                    cout << (C[i-1][k] == '#') +
                            (C[i-1][k+1] == '#') +
                            (C[i][k+1] == '#');
                } else if (k == W-1) {
                    cout << (C[i-1][k-1] == '#') +
                            (C[i-1][k] == '#') +
                            (C[i][k-1] == '#');
                } else {
                    cout << (C[i-1][k-1] == '#') +
                            (C[i-1][k] == '#') +
                            (C[i-1][k+1] == '#') +
                            (C[i][k-1] == '#') +
                            (C[i][k+1] == '#');
                }
            } else {
                if (k == 0) {
                    cout << (C[i-1][k] == '#') +
                            (C[i-1][k+1] == '#') +
                            (C[i][k+1] == '#') +
                            (C[i+1][k] == '#') +
                            (C[i+1][k+1] == '#');
                } else if (k == W-1) {
                    cout << (C[i-1][k-1] == '#') +
                            (C[i-1][k] == '#') +
                            (C[i][k-1] == '#') +
                            (C[i+1][k-1] == '#') +
                            (C[i+1][k] == '#');
                } else {
                    cout << (C[i-1][k-1] == '#') +
                            (C[i-1][k] == '#') +
                            (C[i-1][k+1] == '#') +
                            (C[i][k-1] == '#') +
                            (C[i][k+1] == '#') +
                            (C[i+1][k-1] == '#') +
                            (C[i+1][k] == '#') +
                            (C[i+1][k+1] == '#');
                }
            }
        }
        cout << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

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

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

  string S;
  cin >> S;
  int A, B, C, D;
  A = S[0] - '0';
  B = S[1] - '0';
  C = S[2] - '0';
  D = S[3] - '0';

  int ans_i = 0;
  for(int i = 0; i < 8; i++){
    int sum = A;
    if(i & (1<<2)){
      sum += B;
    }else{
      sum -= B;
    }

    if(i & (1<<1)){
      sum += C;
    }else{
      sum -= C;
    }

    if(i & 1){
      sum += D;
    }else{
      sum -= D;
    }

    if(sum == 7){
      ans_i = i;
      break;
    }
  }

  string ans = "";
  ans += to_string(A);
  if(ans_i & 4){
    ans += "+";
  }else{
    ans += "-";
  }
  ans += to_string(B);
  if(ans_i & 2){
    ans += "+";
  }else{
    ans += "-";
  }
  ans += to_string(C);
  if(ans_i & 1){
    ans += "+";
  }else{
    ans += "-";
  }
  ans += to_string(D);
  ans += "=7";

  cout << ans << endl;


  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<ctype.h>
int main(){
  int i,j;
  char str[1000];
  
  gets(str);
  for(i=0;str[i]!='\0';i++);
  for(j=0;j<i;j++){
    if(isupper(str[j])){
    switch(str[j]){
    case'A':str[j]='X'+3;break;
    case'B':str[j]='Y'+3;break;
    case'C':str[j]='Z'+3;break;
    }
  printf("%c",str[j]-3);
      }else printf("%c",str[j]);
  }
  printf("\n");
  return 0;
}
 

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

int main(){
  int N, K;
  cin >> N >> K;
  
  priority_queue<int> H;
  for(int i = 0; i < N; i++){
    int a;
    cin >> a;
    H.push(a);
  } 
  long long cnt = 0;
  if(N > K){
    for(int i = 0; i < K; i++){
      //cout << H.top() << " ";
      H.pop();
    }
    for(int i = 0; i < (N - K); i++){
      cnt += H.top();
      //cout << H.top() << " ";
      H.pop();
    }
    //cout << endl;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n, k, r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;

    vector<bool> next(n, false);

    long long res = 0;
    for (int i = 0; i < k && i < n; i++) {
        if (t[i] == 'r') {
            res += p;
        } else if (t[i] == 's') {
            res += r;
        } else {
            res += s;
        }
    }

    for (int i = k; i < n; i++) {
        if (t[i] == t[i - k] && !next[i - k]) {
            next[i] = true;
        } else {
            if (t[i] == 'r') {
                res += p;
            } else if (t[i] == 's') {
                res += r;
            } else {
                res += s;
            }
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main() {

    int n, r, minv, maxv = -1'000'000'001;

    cin >> n;
    cin >> minv;

    for (int i = 0; i < n - 1; i++) {
        cin >> r;
        maxv = max(maxv, r - minv);
        minv = min(minv, r);
    }

    cout << maxv << endl;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const ll MOD = 998244353;
const int INF = 1001001001;
// const ll INF = 1000000000000000000LL;
  
int main() {
    ll n,x,m;
    cin >> n >> x >> m;
    ll xx = x;
    ll xxx = x;
    ll top;
    vector<int> id(m,-1);
    int len1 = 0;
    int len2 = 0;
    ll sum1 = 0;
    ll sum2 = 0;
    // ll before_x;
    while(1){
        if(id[x]!=-1) {
            top = x;
            break;
        }
        len1++;
        sum1+=x;
        id[x] = len1;
        // before_x = x;
        x = x*x%m;

    }
    // cout << x << endl; //重複した数
    // cout << len1 << endl;
    //重複した数が最初にあらわれるまでのsum
    while(1){
        if(xx==x) break;
        len2++;
        sum2+=xx;
        xx = xx*xx%m;
    }
    // cout << len2 << endl;
    // cout << sum1 << endl;
    // cout << sum2 << endl;
    ll a = sum2;//ループ検出前のsum
    ll b = sum1 - sum2; //ループのsum
    ll la = len2; //ループ検出前の数の個数
    ll lb = len1 - len2; //ループのなかの数の個数
    // cout << a << endl;
    // cout << b << endl;
    // cout << la << endl;
    // cout << lb << endl;
    //こたい
    ll ans=0;
    if(n<la){
        rep(i,n){
            ans+=xxx;
            xxx = xxx*xxx%m;
        }
        // cout << ans << endl;
        return 0;
    }
    n-=la;
    ans+=a;
    ll nn = n/lb; //ループの出現回数
    // cout << top << endl;
    n%=lb; //残り
    ans+=b*nn;
    // cout << n << endl;
    rep(i,n){
        ans+=top;
        top=top*top%m;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	ll n,a,b;
	cin>>n>>a>>b;
	ll ans=n/(a+b)*a;
	ans+=min(n%(a+b),ll(a));
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    llong a,b,x;
    cin >> a >> b;
    x = max(a,b)-min(a,b);
    if(x%2 == 1) cout << "IMPOSSIBLE" << endl;
    else cout << x/2 + min(a,b) << endl;
}

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

int main(){
    int n; cin >> n;
    map<string,int> mp;
    vector<string> w(n);

    rep(i,n){
        cin >> w[i];
        mp[w[i]]++;
    }

    for(auto x:mp){
        if(x.second > 1){
            cout << "No" << endl;
            return 0;
        }
    }

    for(int i = 1; i < n; i++){
        if(w[i-1][w[i-1].size()-1] != w[i][0]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 200030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;

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

int n;
cin>>n;
int arr[n],brr[n];
rep(i,0,n)
cin>>arr[i];
rep(i,0,n)
cin>>brr[i];
int a[n];
rep(i,0,n)
a[i]=i+1;
int x=0,y=0;
int cnt=0;
do
{
	bool bo=false;
  rep(i,0,n)
  {
  	if(a[i]!=arr[i])
  	bo=true;
  }
  if(!bo)
  x=cnt;
  bo=false;
  rep(i,0,n)
  {
  	if(a[i]!=brr[i])
  	bo=true;
  }
  if(!bo)
  y=cnt;
  cnt++;
  
}while(next_permutation(a,a+n));
cout<<abs(x-y);



}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
vector<ll> v;
int main() {
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	if (n <= k) {
		cout << ans << endl;
		return 0;;
	}
	for (int i = 0;i < n;i++) {
		ll x;
		cin >> x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	for (int i = 0;i < k;i++)v.pop_back();
	for (int i = 0;i < v.size();i++) ans += v.at(i);
	cout << ans << endl;
	return 0;
}

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

using namespace std;
 
#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair
 
#define debug(_x)		cerr << #_x << '=' << (_x) << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << (_x) << ' ' << #_y << '=' << (_y) << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << (_x) << ' '; cerr << endl;

#define HERE debug(__LINE__);

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;

int32_t main() {
	FAST_IO;
	
	string s, t;
	cin >> s >> t;
	
	int n = (int)s.size();
	int m = (int)t.size();
	
	vvi dp(n+1, vi(m+1));
	
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s[i-1] == t[j-1]) {
				dp[i][j] = dp[i-1][j-1] + 1;
			} else {
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	
	int x = n, y = m;
	string ans;
	while (x != 0 && y != 0) {
		if (dp[x-1][y-1]+1 == dp[x][y] && dp[x][y] > dp[x-1][y] && dp[x][y] > dp[x][y-1]) {
			ans += s[x-1];
			x--;
			y--;
		} else {
			if (dp[x-1][y] > dp[x][y-1]) {
				x--;
			} else {
				y--;
			}
		}
	}
	
	reverse(ALL(ans));
	cout << ans << endl;
}

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined

Measured memory_bytes: 70784
#include <iostream>

using namespace std;

long long xo(long long n) {
  switch (n % 4) {
  case 0:
    return n;
    break;
  case 1:
    return 1;
    break;
  case 2:
    return n + 1;
    break;
  case 3:
    return 0;
    break;
  }
}

int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long  a, b;
  cin >> a >> b;
  cout << (xo(a - 1) ^ xo(b)) << "\n";

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

bool isEqualTolow(string &w, string s) {
	for (int i = 0; i < s.size(); i++)
		s[i] = (char)(tolower(s[i]));
	return s == w;
}

int main() {FIN
    
    int i, j, w = 0;
    string line, word;
    cin >> word; cin.get();
    while (getline(cin, line)) {
        j = 0;
        for (i = 0; i < line.size(); i++) {
            if (line[i] == ' ') {
                if (isEqualTolow(word, line.substr(j, i - j))) w++;
                j = i + 1;
            }
        }
        if (isEqualTolow(word, line.substr(j, i - j))) w++;
    }
    cout << w << "\n";
    
    return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
int main(){
	int m, f, r;
	while(cin >> m >> f >> r){
		if(m==-1 && f==-1 && r==-1)
			break;
		if(m==-1 || f==-1)
			cout << 'F' << endl;
		else{
			int t = m+f;
			if(t>=80)
				cout << 'A' << endl;
			else if(t>=65)
					cout << 'B' << endl;
				 else if(t>=50)
				 	cout << 'C' << endl;
				 	else if(t>=30){
				 			if(r>=50)
				 				cout << 'C' << endl;
				 			else
				 				cout << 'D' << endl;
					 }else
					 	cout << 'F' << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3100
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int x, y;
		int maxX = -100;
		int minY = 100;

		if (X >= Y) {
			System.out.println("War");
			return;
		}

		for (int i = 0; i < N; i++) {
			x = sc.nextInt();
			maxX = x > maxX ? x : maxX;
		}

		for (int i = 0; i < M; i++) {
			y = sc.nextInt();
			minY = y < minY ? y : minY;
		}

		if (maxX >= minY || maxX >= Y || X >= minY) {
			System.out.println("War");
			return;
		}

		System.out.println("No War");

		return;
	}
}


Measured memory_bytes: 23636
#include <stdio.h>
int a[200000];
int b[200000];

int main(){
  int n,i,j,check,ballcount=0;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    b[i]=0;
  }
  
  for(i=n-1;i>=0;i--){
    check=0;
    
    for(j=i;j<n;j+=(i+1)){
      check+=b[j];
    }
    
    if(check%2!=a[i]){
      b[i]=1;
      ballcount++;
    }
  }
  
  printf("%d\n",ballcount);
  for(i=0;i<n;i++){
    if(b[i]==1){
      printf("%d ",i+1);
    }
  }
}

Measured memory_bytes: 2432
#include<stdio.h>
int main(){
	int a,b,c,max;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b&&a>c)
		max=a;
	if(b>a&&b>c)
		max=b;
	if(c>a&&c>b)
		max=c;
	if(max==7)
	{
		if(a*b*c==175&&a+b+c==17)
			printf("YES\n");
		else
			printf("NO\n");
	}
	else
		printf("NO\n");
	}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	string s;cin >> s;
	vector<int> e(n + 1), w(n + 1);
	rep(i,n){
		if(s.at(i) == 'E') e.at(i + 1)++;
		else w.at(i + 1)++;
		e.at(i + 1) += e.at(i);
		w.at(i + 1) += w.at(i);
	}
	int ans = n;
	rep(i,n){
		ans = min(ans, w.at(i) + e.at(n) - e.at(i + 1));
	}
	cout << ans << endl;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

template <typename T>
int getFormer(const vector<T> &vec, T x) {
    return upper_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
}

template <typename T>
int getLatter(const vector<T> &vec, T x) {
    return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}

map<long long, int> primeFactor(long long n) {
    map<long long, int> res;
    for (long long i = 2; i * i < n + 1; i++) {
        while (n % i == 0) {
            res[i] += 1;
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

int main() {
    int n;
    cin >> n;
    auto ans = primeFactor(n);
    cout << to_string(n) + ":";
    for (auto itr = ans.begin(); itr != ans.end(); itr++) {
        for (int i = 0; i < (*itr).second; i++) {
            cout << " " << (*itr).first;
        }
    }
    cout << endl;
    return 0;
}


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

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

    int x, y, tmp;

    while(1){
        cin >> x >> y;
        if(x == 0 and y == 0){
            break;
        }else{
            if(x > y){
                tmp = y;
                y = x;
                x = tmp;
            }
            cout << x << " "<< y << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3008
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String []N = line.split("");
        int count = 0; 
        for(int i = 0; i < 3; i++){
            if(N[i].equals("1")){
                count++;
            }
        }
        System.out.println(count);
    }
}


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

int main() {
  vector<int> g1 = {1,3,5,7,8,10,12};
  vector<int> g2 = {4,6,9,11};
  int x,y;
  cin >> x >> y;
  int ans1 = 0;
  int ans2 = 0;
  for(int i = 0;i < 7;i++){
    if(g1.at(i) == x){
      ans1++;
    }
    if(g1.at(i) == y){
      ans1++;
    }
    if(ans1 == 2){
    break;
    }
  }
  if(ans1 != 2){
    for(int j = 0;j < 4;j++){
      if(g2.at(j) == x){
        ans2++;
      }
      if(g2.at(j) == y){
        ans2++;
      }
      if(ans2 == 2){
        break;
      }
    }
  }
    if(ans1 == 2 || ans2 == 2){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
}
        

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A_ = [a--1-i for i,a in enumerate(A)]
A_.sort()

b = int(0.5 * (A_[len(A_)//2] + A_[len(A_)//2 - (len(A_)+1)%2]))

print(sum([abs(a-b) for a in A_]))



Measured memory_bytes: 28020
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv,  digitDP//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal ,RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 998244353; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag; vll path; vl D;
//***********//
int main() {
	ld A, B;
	cin >> A >> B;
	ll ans = A * B;
	cout << ans;
}

Measured memory_bytes: 3708
import sys
sys.setrecursionlimit(10**6)

N,Q = map(int,input().split())
adj = [ [] for _ in range(N) ]
for _ in range(N-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  adj[a].append(b)
  adj[b].append(a)

from collections import defaultdict
counter = defaultdict(int)
for _ in range(Q):
  p,x = map(int,input().split())
  p -= 1
  counter[p] += x

weight = [-1] * N
def dfs(node, wei):
  weight[node] = wei

  for nei in adj[node]:
    if weight[nei] == -1:
      dfs(nei, wei+counter[nei])

dfs(0, counter[0])
print(" ".join(map(str,weight)))

Measured memory_bytes: 256656
// author : ksumit

// jo darr gya vo gya

#include<unordered_map>
#include<bits/stdc++.h>
typedef long long ll;

bool isPrime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0) return 0;
	}
	return 1;
}

using namespace std;

void solve() {
	string n;
	cin >> n;
	long sd = 0;
	for (char c: n) {
		sd += c - '0';
	}
	if (sd % 9 == 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	// int tt;
// 	cin >> tt;
// 	while (tt--)
		solve();
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5+10;
int dp[MAX][3];
int getMax(const vector<vector<int>>&p, int days, int lastUse){
  if(days == 0){
    int max = 0;
    for(int i=0;i<3;i++){
      if(i!=lastUse)
        if(p[i][0]>max)
          max = p[i][0]; 
    }
    return max;
  }
  if(lastUse != -1 && dp[days][lastUse]!=0){
    return dp[days][lastUse];
  }
  int max = 0;
  for(int i=0;i<3;i++){
    if(i!=lastUse){
      int t = getMax(p, days-1, i)+p[i][days];
      if(max < t){
        max = t;
      }
    }
  }
  if(lastUse != -1)
    dp[days][lastUse] = max;
  return max;
}

int main(){
  #ifdef LOCAL
	freopen("input.txt","r",stdin);
 // freopen("out.txt","w",stdout);
	#endif
    int n;
    cin >> n;
    vector<vector<int>>c(3, vector<int>(n));
    for(int i=0;i<n;i++){
      cin >> c[0][i] >> c[1][i] >> c[2][i];
      dp[i][0]=dp[i][1]=dp[i][2]=0;
    }
    int ans = getMax(c, n-1, -1);
    cout << ans ;
  return 0;
}



Measured memory_bytes: 13552