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

int main(){
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  int price = A * X + B * Y;
  int Z = max(X, Y);
  
  for(int i = 1; i <= Z; i++){
    if(min(X, Y) - i >= 0 ){
      if(price > A * (X - i) + B * (Y - i) + C * 2 * i) price =  A * (X - i) + B * (Y - i) + C * 2 * i;
    }else{
      if(Y - i < 0 && price > A * (X - i) + C * 2 * i) price =  A * (X - i) + C * 2 * i;
      if(X - i < 0 && price > B * (Y - i) + C * 2 * i) price = B * (Y - i) + C * 2 * i;
    }
  }
  cout << price;
}


Measured memory_bytes: 256
import java.util.*;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			String str=in.next();
			int i=0;
			while(n-->0)
			{
				int now;
				StringBuilder sb= new StringBuilder();
				for(;;)
				{
					now=str.charAt(i)-'0';
					int cnt=1;
					while(i<str.length()-1&&str.charAt(i)==str.charAt(i+1))
					{
						cnt++;
						i++;
					}
					sb.append(cnt).append(now);
					if(i==str.length()-1)
						break;
					i++;
				}
				i=0;
				str=sb.toString();
			}
			System.out.println(str);
		}
	}
}

Measured memory_bytes: 12000
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, W;
  cin >> N >> W;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int64_t> w(N + 1);
  vector<int64_t> v(N + 1);
  for (int64_t i = 1; i <= N; ++i) {
    cin >> w[i] >> v[i];
  }
  vector<vector<int64_t>> dp(N + 1, vector<int64_t>(W + 1, 0));
  for (int64_t end = 1; end <= N; ++end) {
    for (int64_t cap = 1; cap <= W; ++cap) {
      dp[end][cap] = max(dp[end][cap], dp[end - 1][cap]);
      if (cap - w[end] >= 0) {
        dp[end][cap] = max(dp[end][cap], dp[end - 1][cap - w[end]] + v[end]);
      }
    }
  }
  cout << dp[N][W] << endl;
  return 0;
}


Measured memory_bytes: 83136
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define DEBUG(a) cerr<<#a<<"="<<a<<endl
#define DEBUG_ARRAY(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define NO do{cout<<-1<<endl;return;}while(0)
typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> P;
typedef pair<ll,P> PP;
typedef vector<ll> vll;

const ll INF=(1LL<<50);


void solve(long long N, long long K, std::vector<long long> a){
    priority_queue<P> qq,rr;
    priority_queue<P>& q=qq,r=rr;
    REP(N)q.push(P(a[i],i));
    P o={-1,-1};
    vector<ll> ans;
    while(K>=0){
        while(q.size()>1){
            P tmp=q.top();q.pop();
            if(tmp.first==0){
                NO;
            }
            tmp.first--;
            ans.push_back(tmp.second);
            r.push(tmp);
        }
        if(o.second!=-1){
            r.push(o);
        }
        o=q.top();q.pop();
        swap(q,r);
        if(o.first==0){
            NO;
        }
        o.first--;
        ans.push_back(o.second);
        K--;
    }
    cout<<ans.size()<<endl;
    REP(ans.size()){
        cout<<ans[i]+1;
        if(i!=ans.size()-1){
            cout<<" ";
        }else{
            cout<<endl;
        }
    }
    return ;
}


int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, K, std::move(a));
    return 0;
}


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

int main() {
  int N,p,f = 0,g = 10000000;
  cin >> N;
  p = N;
    for(int i = 0; i < 8; i++) {
      f += p/g;
      p %= g;
      g /= 10;
    }
  if(N % f == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,c,i;
	scanf("%d%d%d",&a,&b,&c);
	int d=a+b;
	int e=b+c;
	int f=a+c;
	if(d>e){i=d; d=e; e=i;}
	if(e>f){i=e; e=f; f=i;}
	if(d>e){i=d; d=e; e=i;}
	printf("%d\n",d);
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{int a,b,x,y,n,i;
   scanf("%d%d%d%d",&a,&b,&x,&y);
    if(x>b||a>y)
      {
      	printf("0\n");
      	return 0;}
      else
	   if(a<=x)
	     {if(b<=y)
	       printf("%d\n",b-x);
	      else
	       printf("%d\n",y-x);
	     }
	        if(a>x)
			{if(b<=y)
			  printf("%d\n",b-a);
			  else
			  printf("%d\n",y-a);
				}    
		return 0;
 } 
 

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 5000100;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll dx[8] = { 0,0,-1,1 };
ll dy[8] = { -1,1,0,0 };
ll dp[101010];

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank2[x] == rank2[y]) {
			rank2[x]++;
		}
	}
}

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

bool graph[101][101];
vector<ll> to[101010];
vector<ll>ball(101010, 1);
char c[10][10];
bool visited[10][10];
char math[1010][1010];

//long longしか使わない
//素数は1より大きい
int main() {
	ll n;
	cin >> n;
	vector<ll>a(n), b(n), c, d;
	ll res = 0;
	ll res2 = 0;
	bool flag = true;
	ll ans = 0;
	ll total = 0;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		cin >> b[i];
	}
	rep(i, n) {
		res += a[i];
		res2 += b[i];
		if (b[i] > a[i]) {
			flag = false;
			ans++;
			total += b[i] - a[i];
		}
		else if(b[i]<a[i]) {
			c.push_back(a[i] - b[i]);
		}
	}
	sort(c.rbegin(), c.rend());
	if (flag) {
		cout << 0 << endl;
		return 0;
	}
	if (res2 > res) {
		cout << -1 << endl;
		return 0;
	}
	else{
		rep(i, c.size()) {
			ans++;
			if (total > c[i]) {
				total -= c[i];
			}
			else {
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6268
while True:
    n=list(map(int,input().split()))
    if n[0]==-1 and n[1]==-1 and n[2]==-1:
        break
    elif n[0]==-1 or n[1]==-1:
        print("F")
    elif n[0]+n[1]>=80:
        print("A")
    elif 80>n[0]+n[1]>=65:
        print("B")
    elif 65>n[0]+n[1]>=50:
        print("C")
    elif 30>n[0]+n[1]:
        print("F")
    elif 50>n[0]+n[1]>=30:
        if n[2]>=50:
            print("C")
        else:
            print("D")




Measured memory_bytes: 5596
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_variables)]

use std::cmp::{max, min};

const INF: i32 = 1001001001;
const LNF: i64 = 1001001001001001001;
const MOD: i32 = 1000000007;

macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
      let mut iter = $s.split_whitespace();
      input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
      let s = {
          use std::io::Read;
          let mut s = String::new();
          std::io::stdin().read_to_string(&mut s).unwrap();
          s
      };
      let mut iter = s.split_whitespace();
      input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

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

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
      ( $(read_value!($iter, $t)),* )
  };

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

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

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

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

fn main() {
  input! {
    n: usize,
    q: usize,
    line: [(i32, usize, usize); q],
  }
  let mut st = SegmentTree::new(n, 2147483647);
  for i in 0..q {
    let (com, x, y) = line[i];
    if com == 0 {
      st.update(x, y as i32);
    } else {
      println!("{}", st.query(x, y + 1));
    }
  }
}

struct SegmentTree {
  v: Vec<i32>,
  e: i32,
  n: usize,
}

impl SegmentTree {
  fn new(size: usize, e: i32) -> Self {
    let mut n = 1;
    while n < size {
      n <<= 1;
    }
    let v: Vec<i32> = vec![e; n * 2];
    SegmentTree { v, e, n }
  }
  fn set(&mut self, k: usize, x: i32) {
    self.v[k + self.n] = x;
  }
  fn build(&mut self) {
    for i in (1..self.n).rev() {
      self.v[i] = min(self.v[i * 2 + 0], self.v[i * 2 + 1]);
    }
  }
  fn update(&mut self, mut k: usize, x: i32) {
    self.v[k + self.n] = x;
    k += self.n;
    while (k >> 1) > 0 {
      k >>= 1;
      self.v[k] = min(self.v[k * 2 + 0], self.v[k * 2 + 1]);
    }
  }
  fn query(&self, mut a: usize, mut b: usize) -> i32 {
    let mut l = self.e;
    let mut r = self.e;
    a += self.n;
    b += self.n;
    while a < b {
      if a & 1 == 1 {
        l = min(l, self.v[a]);
        a += 1;
      }
      if b & 1 == 1 {
        b -= 1;
        r = min(self.v[b], r);
      }
      a >>= 1;
      b >>= 1;
    }
    min(l, r)
  }
  fn reset(&mut self, k: usize) {
    self.update(k, 2147483647);
  }
}



Measured memory_bytes: 13108
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
typedef long long ll;
ll inf = 1e18;

class network_flow{
private:
	int N;
	struct edge{int to; ll cap; int rev; bool is_rev;};
	vector<vector<edge>> G;
	vector<int> level,iter;
	void bfs(int s){
		for(int i=0;i<=N;i++) level[i] = -1;
		queue<int> Q;
		level[s] = 0;
		Q.push(s);
		while(!Q.empty()){
			int v = Q.front(); Q.pop();
			for(auto& e:G[v]){
				if(e.cap > 0 && level[e.to]<0){
					level[e.to] = level[v]+1;
					Q.push(e.to);
				}
			}
		}
	}
	ll dfs(int v,int t,ll f){
		if(v==t) return f;
		for(int &i=iter[v];i<G[v].size();i++){
			edge &e = G[v][i];
			if(level[v]<level[e.to] && e.cap>0){
				ll d = dfs(e.to,t,min(f,e.cap));
				if(d>0){
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}
public:
	network_flow(int n){
		N = n;
		G = vector<vector<edge>>(N+1);
		level = iter = vector<int>(N+1);
	}
	void add_edge(int from, int to,ll cap){
		G[from].push_back((edge){to,cap,(int) G[to].size(),false});
		G[to].push_back((edge){from,0,(int) G[from].size()-1,true});
	}
	ll max_flow(int s,int t){
		ll flow = 0;
		for(;;){
			bfs(s);
			if(level[t]<0) return flow;
			for(int i=0;i<=N;i++) iter[i] = 0;
			ll f;
			while((f=dfs(s,t,inf))>0) flow += f;
		}
	}
};

int V,E;

int main(){
	cin >> V >> E;
	network_flow flow(V);
	for(int i=0;i<E;i++){
		int t,c,r;
		cin >> t >> r >> c;
		flow.add_edge(t,r,c);
	}
	cout << flow.max_flow(0,V-1) << endl;
}


Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
const char *nl = "\n";

double a, b, h, m;

#define sq(a) ((a) * (a))

int main() {
    cin >> a >> b >> h >> m;
    double ha = (h * 60 + m) / (60 * 12) * 2 * M_PI;
    double ma = m / 60 * 2 * M_PI;
    double hx = sin(ha) * a;
    double hy = cos(ha) * a;
    double mx = sin(ma) * b;
    double my = cos(ma) * b;
    double distsq = sq(hx - mx) + sq(hy - my);
    cout.precision(20);
    cout << sqrt(distsq) << nl;
    return 0;
}



Measured memory_bytes: 4120
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define FOR(i, n, m) for (int i = n; i <= (int)(m); i++)
#define RFOR(i, n, m) for (int i = (int)(n); i >= m; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
using namespace std;
vector<int> dy = {1, 0, -1, 0};
vector<int> dx = {0, 1, 0, -1};
template <class T>
vector<T> make_vec(size_t a)
{
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts)
{
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int d[200][200];
int main()
{
    rep(i, 200) rep(j, 200) d[i][j] = INF;
    int n, m, r;
    cin >> n >> m >> r;
    vector<int> t(r);
    rep(i, r)
    {
        cin >> t[i];
        t[i]--;
    }
    sort(all(t));

    rep(i, m)
    {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        d[a][b] = c;
        d[b][a] = c;
    }

    rep(k, n)
    {
        rep(i, n)
        {
            rep(j, n)
            {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    int ans = INF;
    do
    {
        int tmp = 0;
        rep(i, r - 1)
        {
            tmp += d[t[i]][t[i + 1]];
        }
        ans = min(ans, tmp);
    } while (next_permutation(all(t)));

    cout << ans << endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main() {

    ll N, K;
    cin >> N >> K;

    ll ans = min(abs(N - N / K * K), abs(N - (N / K + 1) * K));
    out(ans);



    return 0;
}






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

int main() {
  int N;
  cin >> N;
  int A = 0, B = 1000000007, ans = 0;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    if (a > A) {
      A = a;
      B = b;
      ans = a + b;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    string s;cin >> s;
    ll k; cin >> k;
    ll n = s.size();
    ll ret;
    bool is_one = true;
    rep(i,min(k,n)){
        if(s[i] - '0' != 1)is_one = false;
        if(!is_one) {
            ret = s[i] - '0';
            break;
        }
    }
    if(is_one)ret = 1;
    cout << ret << endl;
}

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

ll run(vector<ll> b) {
  ll sum = 0;
  rep(i,sz(b)-1) sum += abs(b[i+1] - b[i]);
  return sum;
}

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];

  sort(a.begin(),a.end());
  
  ll res = 0;

  vector<ll> b(n);
  if (n%2 == 0) {
    rep(i,n/2) b[i*2+1] = a[i];
    rep(i,n/2) b[i*2] = a[i+n/2];
    res = run(b);
  } else {
    rep(i,n/2) b[i*2+1] = a[i];
    b[n-1] = a[n/2];
    rep(i,n/2) b[i*2] = a[i+n/2+1];
    res = max(res,run(b));

    b[0] = a[n/2];
    rep(i,n/2) b[i*2+2] = a[i];
    rep(i,n/2) b[i*2+1] = a[i+n/2+1];
    res = max(res,run(b));
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 2560
from heapq import heappop,heappush
N,K=map(int,input().split())
table=[]
for i in range(N):
    t,d=map(int,input().split())
    t=t-1
    table.append((d,t))
table=sorted(table,reverse=True)
L=[0]*N
H=set()
W=[]
ans=-1
num=0
for i in range(K):
    d,t=table[i]
    L[t]+=1
    H.add(t)
    num+=d
    if L[t]>=2:
        heappush(W,(d,t))
ans=len(H)**2+num
for i in range(K,N):
    d,t=table[i]
    L[t]+=1
    if L[t]>=2:
        continue
    if len(W)==0:
        continue
    d1,t1=heappop(W)
    H.add(t)
    num=num-d1+d
    ans=max(ans,len(H)**2+num)
print(ans)

Measured memory_bytes: 64728
#include<iostream>
#include<cstdio>
#include<set>
#include<algorithm>
using namespace std;
const int N=100005;
int n;
int a[N],b[N];
pair<int,int> p[N];
int q[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),p[i]=make_pair(a[i],i);
	sort(p+1,p+n+1,greater<pair<int,int> >());
	set<pair<int,int> >S;
	for(int i=1;i<=n;i++)
		scanf("%d",&b[i]),q[i]=i,S.insert(make_pair(b[i],i));
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		int u=p[i].second;
		if(a[u]<=b[q[u]])
		{
			S.erase(S.lower_bound(make_pair(b[q[u]],u)));
			continue;
		}
		set<pair<int,int> >::iterator A=S.lower_bound(make_pair(b[q[u]],u)),B=S.lower_bound(make_pair(a[u],0));
		if(B==S.end())
		{
			printf("No");
			return 0;
		}
		int v=B->second;
		S.erase(A);
		S.erase(B);
		swap(q[u],q[v]);
		S.insert(make_pair(b[q[v]],v));
		ans++;
	}
	if(ans<=n-2) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 10212
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			int[] a = in.nextIntArray(n);

			long ans = 0;
			long num = 0;
			int r = 0;
			for (int l = 0; l < n; l++) {
				while (r < n && (num & a[r]) == 0) {
					num ^= a[r++];
				}
				num ^= a[l];
				ans += r - l;
			}

			out.println(ans);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 42080
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;

int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    int index = 1;
    for(int i = 0; i < N; i++){
        index = a[index-1];
        if(index == 2){
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 640
def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)


N = int(input())
a = list(map(int, input().split()))
a.sort()

g_left = []
g_right = []

t = a[0]
for i in range(N):
    t = gcd(t, a[i])
    g_left.append(t)

t = a[-1]
for i in range(N - 1, -1, -1):
    t = gcd(t, a[i])
    g_right.append(t)

g_right.reverse()

g = 1
for i in range(1, N - 1):
    g = max(g, gcd(g_left[i - 1], g_right[i + 1]))
g = max(g, g_left[N - 2])
g = max(g, g_right[1])

print(g)


Measured memory_bytes: 14584
"use strict";
// inputに入力データ全体が入る
const main = (input) => {
  const [A, B, C] = input.trim().split(" ");
  if (B == "+") {
    console.log(Number(A) + Number(C));
  } else {
    console.log(Number(A) - Number(C));
  }
};

// ※この行以降は編集しない (標準入力から一度に読み込みMainを呼び出します)
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 30608
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define N 100005
#define inf (1ll<<60)
#define rep(i,j,k) for (ll i=j;i<=k;++i)
#define per(i,j,k) for (ll i=j;i>=k;--i)
using namespace std;
inline ll read(){
	char ch=getchar(); ll x=0,f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}
ll T,lcm,x,tmp;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
int main(){
	T=read(); lcm=read();
	rep(i,2,T){
		x=read();
		tmp=gcd(lcm,x);
		lcm*=x/tmp;
	}
	printf("%lld",lcm);
}

Measured memory_bytes: 128
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    def solve(p):
        cur = p
        cnt = 1
        while cur > 0:
            pop = f'{cur:b}'.count("1")
            cur = cur % pop
            cnt += 1

        return cnt

    n = int(readline())
    s = input()

    c = s.count("1")
    cp = c + 1
    cm = c - 1

    fp = 0
    fm = 0

    for i, x in enumerate(s[::-1]):
        if x == "1":
            if cp <= n:
                fp += pow(2, i, cp)
                fp %= cp
            if cm > 0:
                fm += pow(2, i, cm)
                fm %= cm

    for i in range(n):
        if s[i] == "0":
            a = pow(2, n - (i + 1), cp)
            cur = (fp + a) % cp
            print(solve(cur))
        else:
            if cm > 0:
                a = pow(2, n - (i + 1), cm)
                cur = (fm - a) % cm
                print(solve(cur))
            else:
                print(0)


if __name__ == '__main__':
    main()


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

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private static final int INF = Integer.MAX_VALUE / 2;

    private static final long MOD = 1_000_000_007;

    private void solve(Scanner sc) {
        long N = sc.nextLong();

        _out.println((dfs(N, N) % MOD));
    }
    private Map<String, Long> memo = new HashMap<>();
    private long dfs(long s, long x) {
        if (s == 0) {
            return 1;
        }

        String key = s + "/" + x;
        Long tmp = memo.get(key);
        if (tmp != null) {
            return tmp;
        }

        long res = 0;

        res = (res + dfs(s >>> 1, x >>> 1)) % MOD;

        if (s >= 2) {
            res = (res + dfs((s - 2) >>> 1, x >>> 1)) % MOD;
        }

        res = (res + dfs((s - 1) >>> 1, (x - 1) >>> 1)) % MOD;

        memo.put(key, res);
        return res;
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 21844
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<long long>::max();
const double PI = acos(-1);
#define fir first
#define sec second
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, s, t, q, ans, sum, a, last, cnt = 25000;
struct Edge { LL to,cost; };
vector<LL>v[50000];
string str[3];
bool f;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	rep(i, 3)cin >> str[i];
	if (str[0][str[0].size() - 1] == str[1][0] && str[1][str[1].size() - 1] == str[2][0])f = 1;
	YN(f);
		return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, M; cin >> N >> M;
  vector<vector<char>> NN(N, vector<char>(N));
  vector<vector<char>> MM(M, vector<char>(M));
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cin >> NN.at(i).at(j);
    }
  }
  for(int i=0;i<M;i++){
    for(int j=0;j<M;j++){
      cin >> MM.at(i).at(j);
    }
  }
  int check=0;
  for(int i=0;i<=N-M;i++){
    for(int j=0;j<=N-M;j++){
      if(NN.at(i).at(j)==MM.at(0).at(0)){
          check=0;
          for(int k=0;k<M;k++){
            for(int l=0;l<M;l++){
              if(MM.at(k).at(l)!=NN.at(i+k).at(j+l)){
                check=1;
                break;
              }
            }
            if(check==1){
              break;
            }
          }
        if(check==0) {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <intrin.h>
//#include <chrono>
//#include <random>
//#include <unordered_map>

using namespace std;

typedef long long ll;

void solve() {
	int n;
	cin >> n;
	vector<ll> h(n), a(n);
	for (int i = 0; i < n; i++)
		cin >> h[i];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	set<pair<ll, ll>> st;
	st.insert({ 0, 0 });
	vector<ll> dp(n, 0);
	for (int i = 0; i < n; i++) {
		pair<ll, ll> p = { h[i], -1 };
		auto lb = --st.lower_bound(p);
		dp[i] = a[i] + lb->second;
		p = { h[i], -1 };
		lb = st.lower_bound(p);
		while (lb != st.end() && lb->second <= dp[i]) {
			st.erase(lb);
			lb = st.lower_bound(p);
		}
		lb = --st.lower_bound(p);
		if (lb->second < dp[i]) {
			p = { h[i], dp[i] };
			st.insert(p);
		}
	}
	cout << *max_element(dp.begin(), dp.end());
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		//cout << '\n';
	}
}

Measured memory_bytes: 20308
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC123
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = int.Parse(Console.ReadLine());
            var b = int.Parse(Console.ReadLine());
            var c = int.Parse(Console.ReadLine());
            var d = int.Parse(Console.ReadLine());
            var e = int.Parse(Console.ReadLine());
            var k = int.Parse(Console.ReadLine());

            var output = e - a <= k
                ? "Yay!"
                : ":(";

            Console.Write(output);
        }
    }
}


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

int main(){
    int d, g;
    cin >> d >> g;
    int p[d], c[d];
    for(int i = 0; i < d; i++)  cin >> p[i] >> c[i];
    int ans = 1<<30;
    for(int s = 0; s < 1<<d; s++){
        int tmp = 0, num = 0;
        for(int i = 0; i < d; i++){
            if((s>>i)&1)    num += p[i], tmp += 100*(i+1)*p[i] + c[i];
        }
        if(tmp < g){
            for(int j = 0; j < d; j++){
                if((s>>j)&1)    continue;
                if((p[j]-1)*(j+1)*100+tmp >= g){
                    int tnum = num+(g-tmp+(j+1)*100-1)/((j+1)*100);
                    ans = min(ans, tnum);
                }
            }
        }else{
            ans = min(ans, num);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59


int main(){
    ll i,j;
    ll s;
    cin>>s;
    ll m=1000000000;
    if(s==m*m){
        cout<<0<<" "<<0<<" "<<m<<" "<<0<<" "<<0<<" "<<m<<endl;
        return 0;
    }
    ll d=(s/m + 1);
    ll c=d*m-s;
    cout<<0<<" "<<0<<" "<<m<<" "<<1<<" "<<c<<" "<<d<<endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N+1), B(N);
  rep(i, N+1) cin >> A[i];
  rep(i, N) cin >> B[i];
  ll ans = 0;
  rep(i, N) {
    ll def = min(A[i], B[i]);
    ans += def;
    B[i] -= def;
    ll def2 = min(A[i+1], B[i]);
    ans += def2;
    A[i+1] -= def2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
s=list(input())
n=len(s)
s.reverse()
mod=10**9+7
dp=[[0]*13 for i in range(n+1)]
dp[0][0]=1
x=1
for i in range(n):
  for j in range(13):
    if s[i]=='?':
      for k in range(10):
        dp[i+1][j]+=dp[i][(j-(k*x)%13+13)%13]
    else:
      dp[i+1][j]+=dp[i][(j-(int(s[i])*x)%13+13)%13]
    dp[i+1][j]%=mod
  x*=10
  x%=13
print(dp[n][5])

Measured memory_bytes: 66876
let N = stdin.ReadLine()
let A = stdin.ReadLine().Split(' ') |> Array.map int64

let MOD = 1000000007L

let mutable sum = 0L
for i in 0 .. A.Length - 1 do
    sum <- sum + A.[i]

let mutable ans = 0L
for i in 0 .. A.Length - 2 do
    sum <- sum - A.[i]
    ans <- (ans + A.[i] * (sum % MOD)) % MOD

printf "%d" ans


Measured memory_bytes: 49296
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); ++i)
#define repf(i, from, to) for (int i = (from); i < (to); ++i)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  int price = 700;
  string order;

  cin >> order;

  rep(i, order.size()) {
    if(order[i] == 'o') {
      price += 100;
    }
  }

  cout << price << endl;
}


Measured memory_bytes: 3556
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip> 
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 2000
#define PI 3.14159265359
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define mkp(a,b) make_pair(a,b)
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int h , w , ch , cw , dh , dw , dp[N][N] , ans = INF;
char a[N][N];
int movex[] = {1 , 0 , -1 , 0};
int movey[] = {0 , 1 , 0 , -1};
set < pair<int,int> > q;
bool check(int x , int y){
    if(x < 0 || y < 0) return 0;
    if(x >= h || y >= w) return 0;
    return 1;
}
int main(){
fcin;
    cin >> h >> w;
    cin >> ch >> cw;
    cin >> dh >> dw;
    dh--; dw--;
    ch--; cw--;
    for(int i = 0 ; i < h ; i++){
        for(int j = 0 ;j < w ; j++) cin >> a[i][j];
    }
    for(int i = 0 ; i < h ; i++){
        for(int j = 0 ; j < w ; j++){
            dp[i][j] =INF;
        }
    }
    dp[ch][cw] = 0;
    q.insert(mkp(ch,cw));
    while(sz(q) > 0){
        auto it = q.begin();
        int x = it->F , y = it->S;
        q.erase(it);
        for(int i = max(0,x-2) ; i <= min(h-1,x + 2) ; i++){
                for(int j = max(0,y-2) ; j <= min(w-1,y+2) ; j++){
                    if(!check(i,j)) continue;
                    int d = abs(i-x) + abs(j-y) <= 1 ? 0 : 1;
                    if(a[i][j]=='.' && dp[i][j]>dp[x][y]+d) {
                        dp[i][j] = dp[x][y] + d;
                        q.insert(mkp(i,j));}
                }
        }        
    }
    if(dp[dh][dw] == INF) cout <<"-1";
    else cout << dp[dh][dw] << '\n';

}

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

#define FasterIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main(){
    FasterIO;

    int n, a, b;

    while(cin>>n>>a>>b){
        cout<<min(a, b)<<" "<<max(0, a+b-n)<<endl;
    }

    return 0;
}



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

int main() {
    
    int N;
    cin >> N;
    long long A[N + 1];
    for(int i = 0; i < N + 1;i++){
        cin >> A[i];
        //cout << A[i] <<endl;
    }
    
    long long lim[N+1];
    lim[0] = 1;
    
    for(int i = 1; i < N + 1;i++){
        long long m = (lim[i-1] - A[i-1])*2LL;
        if(m<0){cout << -1 <<endl;return 0;}
        lim[i] = min(m,1000000000000000LL);
        //cout <<"lim"<< lim[i] <<endl;
    }
    
    if(lim[N]<A[N]){cout << -1 <<endl;return 0;}
    
    
    long long res = A[N];
    long long calc = A[N];
    for(int i = N-1; i >= 0;i--){
        calc += A[i];
        calc = min(lim[i],calc);
        //cout << calc <<endl;
        res += calc;
        //cout << lim[i] <<endl;
    }
    cout << res <<endl;
}


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

using namespace std;
typedef long long ll;
bool valid(int a, int b, int x, double d) {
	double pi = 3.14159265359;
	double area = (double)x / a;
	double left = (double)b * cos(d * pi / 180);
	double right = (double)a * sin(d * pi / 180);
	if (left <= right) {
		return ((double)b * left / sin(d * pi / 180)) / 2 >= area;
	} else {
		return ((double)a * b - ((double)a * tan(d * pi / 180) * a / 2)) >= area;
	}
}
int main()
{
	int a, b, x;
	cin >> a >> b >> x;
	double lo = 0, hi = 90;
	double res;
	while (hi - lo >= 1e-7) {
		double mid = (lo + hi) / 2;
		if (valid(a, b, x, mid)) {
			res = mid;
			lo = mid;
		} else {
			hi = mid;
		}
	}
	cout << setprecision(10) << res << endl;
}

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

int main(){
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int ans = (h2-h1)*60 + (m2-m1-k);
    if(ans < 0) ans += 60*24;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c,s,area;
scanf("%d%d%d",&a,&b,&c);

s=(a+b+c)/2;

area=s*(s-a)*(s-b)*(s-c);
area=sqrt(area);

printf("%d",area);



}


Measured memory_bytes: 128
N, Q = list(map(int, input().split()))
S = input()
L = []
R = []
for _ in range(Q):
  l, r = list(map(int, input().split()))
  L.append(l)
  R.append(r)

AC  = [0 for _ in range(N)]
lastA=False

for i, s in enumerate(S):
  if lastA and s=='C':
    AC[i] = AC[i-1] +1 
    lastA=False
    continue
  elif s=='A':
    AC[i] = AC[i-1]
    lastA=True
    continue
  else:
    AC[i] = AC[i-1]
    lastA=False

for i in range(Q):
  print(AC[R[i]-1] - AC[L[i]-1])
   

Measured memory_bytes: 14248
#include <stdio.h>
#include <string.h>

int main () {

        int n=0,i, a1=0,a2=0 ,ans;
        char s[100000]="", tmp[2]="";

        scanf("%s", s);
        n = strlen(s);

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

                tmp[0] = s[i];

                if(atoi(&tmp) == (i+1)%2)
                {
                        a1++;
                }
                else
                {
                        a2++;
                }
        }

        if( a1 <= a2 )
        {
                ans = a1;
        }
        else
        {
                ans = a2;
        }

        printf( "%d\n", ans);

        return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
//#define MOD 998244353

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return true; } return false; }

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

	string s;
	vl st;

	cin >> s;



	ll ret = 0;
	if (s.size() < 3) {
		cout << 0 << endl;
		return 0;
	}
	rep(i, s.size() - 1) {
		if (s[i] == 'B' && s[i + 1] == 'C') {
			//s[i] = 'B';
			//s[i+1] = 'C';
			//s[i+2] = 'A';
			//i -= 2;
			//if (i < 0)i = 0;
			//ret++;
			st.push_back(1);
			i++;
		}else if (s[i] == 'A') {
			st.push_back(0);
		}
		else {
			st.push_back(-1);
		}
	}

	ll plus = 0;
	ll count = 0;
	rep(i, st.size()) {
		if (st[i] == -1) {
			plus = 0;
		}
		else if (st[i] == 0) {
			plus++;
		}
		else {
			count += plus;
		}

	}


	cout << count << endl;


	return 0;
}



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

using namespace std;

int main() {
	int N;
	int K;
	cin >> N >> K;
	long long ans = 0;
	for (int i = K + 1; i <= N; i++) {
		for (int j = 0; i * j + K <= N; j++) 
			ans += min(i - K, N - (i * j + K) + 1);
	}
	if (K == 0) ans -= N;
	cout << ans << endl;
	return 0;
}


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

int main()
{
	int x[10][10];
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> x[i][j];
		}
	}
	int can[10][10][10][10][10];
	for (int a = 0; a < 10; a++) {
		for (int b = 0; b < 10; b++) {
			for (int c = 0; c < 10; c++) {
				for (int d = 0; d < 10; d++) {
					for (int e = 0; e < 10; e++) {
						can[a][b][c][d][e] = x[x[x[x[x[0][a]][b]][c]][d]][e] == 0;
					}
				}
			}
		}
	}
	int res = 0;
	int t[5];
	for (t[0] = 0; t[0] < 10; t[0]++) {
		for (t[1] = 0; t[1] < 10; t[1]++) {
			for (t[2] = 0; t[2] < 10; t[2]++) {
				for (t[3] = 0; t[3] < 10; t[3]++) {
					bool flag = false;
					int cnt = 0;
					for (t[4] = 0; t[4] < 10; t[4]++) {
						if (can[t[0]][t[1]][t[2]][t[3]][t[4]]) {
							cnt++;
							for (int i = 0; i < 5; i++) {
								for (int j = 0; j < 10; j++) {
									if (t[i] != j) {
										int u[] = { t[0], t[1], t[2], t[3], t[4] };
										u[i] = j;
										if (can[u[0]][u[1]][u[2]][u[3]][u[4]]) {
											flag = true;
										}
									}
								}
							}
							for (int i = 1; i < 5; i++) {
								if (t[i - 1] == t[i]) continue;
								swap(t[i - 1], t[i]);
								if (can[t[0]][t[1]][t[2]][t[3]][t[4]]) {
									flag = true;
								}
								swap(t[i - 1], t[i]);
							}
						}
					}
					if (flag || cnt != 1) {
						res++;
					}
				}
			}
		}
	}
	cout << res << endl;
	return 0;
}

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


int main() {

    int a, b;
    cin >> a >> b;
    if ((a+b) % 2 == 0) cout << (a+b)/2 << endl;
    else cout << (a+b)/2 + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// typedef pair<ll,ll> Pair;
// ll mod=1000000007;
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    ll t,c,i,j,k,temp,temp2,n,m,sum=0;
    string a,b,tem;
    
    cin >> n;
    cout << (n+1)/2;
    
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int x = fs.nextInt();
		int y = fs.nextInt();
		int z = fs.nextInt();
		
		System.out.println(z+" "+x+" "+y);
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 21844
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(10 ** 9)



INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n, q = LI()
G = [[] for _ in range(n)]
for a, b in LIR(n - 1):
    G[a - 1] += [b - 1]
    G[b - 1] += [a - 1]

D = [0] * n
for p, x in LIR(q):
    D[p - 1] += x


que = [0]
par = [-1] * n
par[0] = 0
while que:
    u = que.pop()
    for v in G[u]:
        if par[v] == -1:
            par[v] = u
            D[v] += D[u]
            que += [v]


print(*D)












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

int main() {
  int k,n;
  cin >> k >> n;
  int A[n]; //家の地点
  int d[n]; //ある地点からの最短距離
  int way = k; //最短距離
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    if(i > 0){
      d[i-1] = k - (A[i] - A[i-1]);
    }
  }
   d[n-1] = A[n-1] - A[0];
   for (int i = 0; i < n; i++) {
  if(way > d[i]){
    way = d[i];
     }
   }
  cout << way;
 return 0;
}

Measured memory_bytes: 1920
using System;

namespace AtCoder
{
    internal static class Program
    {
        private static void Main()
        {
            int[] AB = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int res = 0;

            for (int i = 0; i < AB[1] - AB[0] + 1; i++)
            {
                string temp = (i + AB[0]).ToString();
                bool palindrome = true;
                for (int y = 0; y < temp.Length; y++)
                    if (temp[y] != temp[temp.Length - 1 - y])
                    {
                        palindrome = false;
                        break;
                    }

                if (palindrome)
                    res++;
            }
                


            Console.WriteLine(res);
        }
    }
}

Measured memory_bytes: 15188
w, h, n = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(n)]
sikaku_x = [0, w]
sikaku_y = [0, h]
for x, y, a in xya:
    if a == 1:
        if sikaku_x[0] < x:
            sikaku_x[0] = x
    elif a == 2:
        if sikaku_x[1] > x:
            sikaku_x[1] = x
    elif a == 3:
        if sikaku_y[0] < y:
            sikaku_y[0] = y
    elif a == 4:
        if sikaku_y[1] > y:
            sikaku_y[1] = y

white_x = sikaku_x[1] - sikaku_x[0]
if white_x < 0:
    white_x = 0
white_y = sikaku_y[1] - sikaku_y[0]
if white_y < 0:
    white_y = 0
print(white_x*white_y)

Measured memory_bytes: 38256