akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		long w = stdIn.nextInt();
		long h = stdIn.nextInt();
		int x = stdIn.nextInt();
		int y = stdIn.nextInt();
		
		
		if(2*x == w && 2*y == h) {
			System.out.println(w*h/2.0 + " 1");
		}else {
			System.out.println(w*h/2.0 + " 0");
		}
		
		
		
	}

}


Measured memory_bytes: 23764
import java.util.*;

public class Main{
  public static void main(String[] arg){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int a[] = new int[N];
    double sum = 0;
    double ans = 0;
    double totalAns = 0;
    for(int i = 0 ;i < N;i++){
      a[i] = sc.nextInt();
    }
    for(int i = 0 ;i < N;i++){
      sum += a[i];
    }
    sum = Math.round(sum/N);
    for(int j = 0;j < N; j++){
      if(a[j] != sum){
        ans = Math.pow((sum - a[j]),2);
        totalAns += ans;
      }
    }
    System.out.println((int)totalAns);
  }

}


Measured memory_bytes: 21844
#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;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  vector<ll> L(N);
  rep(i, N) L[i] = A[i] + i;
  map<ll, ll> M;
  rep(i, N) {
    M[L[i]]++;
  }
  ll ans = 0;
  rep(i, N) {
    ll R = i - A[i];
    ans += M[R];
  }
  cout << ans << endl;
}

Measured memory_bytes: 28912
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
	if(ch=='A'){
		return 1;
	}else if(ch=='C'){
		return 2;
	}else if(ch=='G'){
		return 3;
	}else if(ch=='T'){
		return 4;
	}else return 0;
} 
long long getKey(char str[]){
	long long sum=0,p=1;
	for(long long i=0;i<strlen(str);i++){
		sum+=p*(getChar(str[i]));
		p*=5;
	}
	return sum;
} 

int h1(int key){
	return key%M;
}
int h2(int key){
	return 1+(key%(M-1));
}

int find(char str[]){
	long long key,i,h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0){
			return 1;
		}else if(strlen(H[h])==0){
			return 0;
		}
	}
	return 0;
}

int insert(char str[]){
	long long key,i,h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0){
			return 1;
		}else if(strlen(H[h])==0){
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}

int main(){
	int i,n,h;
	char str[L],com[9];
	for(i=0;i<M;i++){
		H[i][0]='\0';
	}
	cin>>n;
	for(i=0;i<n;i++){
		cin>>com>>str;
		if(com[0]=='i'){
			insert(str);
		}else{
			if(find(str)){
				cout<<"yes"<<endl;
			}else{
				cout<<"no"<<endl;
			}
		}
	}
	return 0;
}


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

#define ll long long
ll solve(ll n,ll k){
    if(n==1)return k;
    if(n%2==0)return solve(n/2,k+1);
    else return solve(3*n+1,k+1);
}
using namespace std;

int main(){
    ll n = 1;
    while(cin >> n && n != 0){
        cout << solve(n,0) << endl;
    }
    return 0;
}

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

const ll DICE_SIZE = 6;

const map<pair<ll, ll>, ll> tf2r = {
    {{0, 1}, 2},
    {{0, 2}, 4},
    {{0, 3}, 1},
    {{0, 4}, 3},

    {{1, 2}, 0},
    {{1, 3}, 5},
    {{1, 5}, 2},

    {{2, 4}, 0},
    {{2, 5}, 4},

    {{3, 4}, 5},
    {{3, 5}, 1},

    {{4, 5}, 3}
};

ll get_right(ll top, ll front){
    if(front < top){
        return 5 - get_right(front, top);
    }
    return tf2r.at({top, front});
}

int main(){
    array<ll, DICE_SIZE> i2v;
    map<ll, ll> v2i;
    REP(i, DICE_SIZE){
        ll v;
        cin >> v;
        i2v.at(i) = v;
        v2i[v] = i;
    }

    ll q;
    cin >> q;
    REP(i, q){
        ll x, y;
        cin >> x >> y;
        ll xi = v2i.at(x);
        ll yi = v2i.at(y);
        ll zi = get_right(xi, yi);
        cout << i2v.at(zi) << endl;
    }
    return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  REP(i, n) cin >> x[i] >> y[i];
  vector<int> v(n), buf(n);
  iota(v.begin(), v.end(), 1);
  ld ans = 0;
  do {
    int p = 0;
    for(auto x : v) {
      buf[p] = x - 1;
      p++;
    }
    REP(i, n - 1) {
      ld xx = (ld)(x[buf[i]] - x[buf[i + 1]]) * (x[buf[i]] - x[buf[i + 1]]);
      ld yy = (ld)(y[buf[i]] - y[buf[i + 1]]) * (y[buf[i]] - y[buf[i + 1]]);
      ans += sqrt(xx + yy);
    }
  } while(next_permutation(ALL(v)));
  FOR(i, 2, n + 1) ans /= (ld)i;
  cout << fixed << setprecision(15) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

//lli gcd(lli a,lli b){
//    lli x,y;
//    x=max(a,b);
//    y=min(a,b);
//    if(x%y==0){
//        return y;
//    }
//    else{
//        return gcd(y,x%y);
//    }
//}
//
//lli lcm(lli a,lli b){
//    lli x,y;
//    x=max(a,b);
//    y=min(a,b);
//    return x*y/gcd(x,y);
//}

int main(){
    lli n,p,ans=1;
    map<lli,lli> map;
    lli i=1,j,k;
    cin>>n>>p;
    if(log2(p)<n){
        ans=1;
    }
    else{
        if(n==1){
            ans=p;
        }
        else{
            while(1){
                    lli x=pow(i,n);
//                    cout<<i<<"の"<<n<<"乗は"<<x<<endl;
                    if(x>p){
                        break;
                    }
                    if(p%x==0){
                        ans=i;
                    }
                    i++;
                }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
open Printf;;
open Scanf;;

let max2 (x, y) z = if x < z then (z, x) else if y < z then (x, z) else (x, y);;
    
let () =
  let n = scanf " %d" (fun x -> x) in
  let a = Array.init (1 lsl n) @@ fun x -> scanf " %d" (fun x -> x) in
  let dp = Array.make (1 lsl n) ((-1, -1), (-1, -1)) in
  for i = 0 to (1 lsl n) - 1 do
    dp.(i) <- ((a.(i), i), (-1, -1))
  done;
  for i = 0 to n - 1 do
    for j = 0 to (1 lsl n) - 1 do
      if (j land (1 lsl i)) = 0 then begin
          dp.(j lor (1 lsl i)) <- max2 dp.(j lor (1 lsl i)) (fst dp.(j));
          dp.(j lor (1 lsl i)) <- max2 dp.(j lor (1 lsl i)) (snd dp.(j))
        end
    done;
  done;
  let ans = ref min_int in
  for i = 1 to (1 lsl n) - 1 do
    let (x, _), (y, _) = dp.(i) in
    ans := max !ans (x + y);
    printf "%d\n" !ans
  done;
  


Measured memory_bytes: 34560
import itertools

H, W, K = map(int, input().split())
S = []
for _ in range(H):
    S.append([int(s) for s in input()])

ans = 2000
for t in itertools.product([0, 1], repeat=H - 1):
    cnt = t.count(1)
    lst = [[s for s in S[0]]]
    for h in range(H - 1):
        if t[h]:
            lst.append(S[h + 1])
        else:
            lst[-1] = [lst[-1][i] + S[h + 1][i] for i in range(W)]
    L = len(lst)
    sum_lst = [0] * L
    for w in range(W):
        if max(lst[i][w] for i in range(L)) > K:
            break
        tmp = [sum_lst[i] + lst[i][w] for i in range(L)]
        if max(tmp) > K:
            cnt += 1
            sum_lst = [lst[i][w] for i in range(L)]
        else:
            sum_lst = tmp
    else:
        ans = min(ans, cnt)
print(ans)


Measured memory_bytes: 3188
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;

  double answer = 0.0;
  for (i64 i = 0; i < N; ++i) {
    double x_i;
    std::string u_i;
    std::cin >> x_i >> u_i;
    if (u_i == "JPY") {
      answer += x_i;
    } else if (u_i == "BTC") {
      answer += x_i * 380000.0;
    } else {
      std::exit(EXIT_FAILURE);
    }
  }

  std::cout << std::fixed << std::setprecision(8) << answer << std::endl;
  return 0;
}

Measured memory_bytes: 256
<?php
        $A = fgets(STDIN);
        $B = fgets(STDIN);
        $C = fgets(STDIN);
        $sum = fgets(STDIN);
        $count = 0;
        for($a = 0; $a <= $A; $a++){
            for($b = 0; $b <= $B; $b++){
                for($c = 0; $c <= $C; $c++){
                    $total = $a*500 + $b*100 + $c*50;
                    if($sum == $total){
                        $count++;
                    }
                }
            }
        }

        echo $count;

?>


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
int i,j,k,count1=0,count2=0;

int main(void){
    string s;
    int p=0,d=0,q=0,n;
    cin>>s;
    n=s.length();
    for(i=0;i<n;i++){
        if(s[i]=='P')cout<<"P";
        if(s[i]=='D')cout<<"D";
        if(s[i]=='?')cout<<"D";
    }
    cout<<endl;
}

Measured memory_bytes: 3720
import itertools
N=int(input())
L=list(map(int,input().split()))
d=list(itertools.combinations(L,3))
count=0
for i in range(len(d)):
  a=d[i][0]
  b=d[i][1]
  c=d[i][2]
  if a==b or b==c or c==a:
    continue
  elif a+b>c and b+c>a and c+a>b:
      count+=1
      
print(count)

Measured memory_bytes: 20540
#pragma region GNUC
//以下を参考にした
//https://yukicoder.me/wiki/auto_vectorization
#ifdef __GNUC__
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#endif
#pragma endregion

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>

#include <string>
#include <cstring>
#include <vector>
#include <valarray>
//#include <array>//x C++ (G++ 4.6.4)

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <cassert>//assert();
#include <fstream>
#include <random>
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)

/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#define PII pair<int,int>
/////////
using namespace::std;

// 最大公約数
template<class T>
inline T gcd(T a, T b){return b ? gcd(b, a % b) : a;}
//inline T gcd(T a, T b){return b == 0 ? a : gcd(b, a % b);}

// 最小公倍数
template<class T>
inline T lcm(T a, T b){return a / gcd(a, b) * b;}
//inline T lcm(T a, T b){return a * b / gcd(a, b);}
////////////////////////////////

void solve(){
	int A,B,C;
	cin >> A >> B >> C;
	if( A+B==C)cout << "Yes";
	else if(B+C==A)cout << "Yes";
	else if(C+A==B)cout << "Yes";
	else cout << "No";
}

signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//std::cout << std::fixed;//小数を10進数表示
	//cout << setprecision(16);//小数点以下の桁数を指定
	
	solve();
}


Measured memory_bytes: 256
n,l = map(int,input().split())

taste_int =  int(n * (n +1) / 2  + ( l - 1 ) * n)

if 0 <= l :
	result = taste_int - l
elif l <= -1 * n :
	result = taste_int - (n + l -1 )
else:
	result = taste_int

print( result)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const ll INF = 1e18 + 10;

int N;

int LIS(const vector<long long> &a) {
    int N = (int)a.size();
    vector<long long> dp(N, INF);
    for (int i = 0; i < N; ++i) {
        auto it = upper_bound(dp.begin(), dp.end(), a[i]);
        *it = a[i];
    }
    return lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
}

int main() {
    cin >> N;
    vector<ll> a(N);
    rep(i,N) cin >> a[i];
    reverse(ALL(a));
    cout << LIS(a) << endl;
}

Measured memory_bytes: 4768
#include<iostream>
#include<string>
#include<algorithm>


using namespace std;

int main()
{
	long long x;
	cin >> x;
	long long  a,answer;
	int b;
	a = x / 11 * 2;
	b = x % 11;
	if (b == 0) {
		answer = a;
	}
	else {
		if (b < 7) {
			answer = a + 1;
		}
		else {
			answer = a + 2;
		}
	}

	cout << answer << endl;
	return 0;

}

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

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

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)
#define MOD 1000000007

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  ll N, M;
  cin >> N >> M;

  rep(m, M){
    if(m % 2 == 0) printf("%lld %lld\n", 1+m/2, N-m/2);
    else printf("%lld %lld\n", (N+1)/2-1-m/2, (N+1)/2+1+m/2);
  }

  return 0;
}



Measured memory_bytes: 3740
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//↑templete
int main(){
	int X, Y;
	cin>>X>>Y;
	if(X==1 && Y==1){
		cout<<1000000<<endl;
	}
	else{
		int ans=0;
		if(X<=3)
			ans+=(4-X)*100000;
		if(Y<=3)
			ans+=(4-Y)*100000;
		cout<<ans<<endl;
	}

	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld eps = 1e-12;
constexpr int inf = numeric_limits<int>::max() / 2;
constexpr ll mod = 1e9 + 7;
mt19937_64 rnd{random_device()()};

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

template <typename T>
class FenwickTree {
  int n;
  std::vector<T> bt;

 public:
  FenwickTree(int _n) : n(_n), bt(_n, 0) {}

  void add(int pos, const T &w) {
    assert(0 <= pos && pos < n);
    for (int i = pos; i < n; i |= i + 1) bt[i] += w;
  }
  // [0, pos)
  T sum(int pos) {
    assert(0 <= pos && pos <= n);
    T res = 0;
    for (int i = pos - 1; i >= 0; i = (i & (i + 1)) - 1) {
      res += bt[i];
    }
    return res;
  }
  // [l, r)
  T sum(int l, int r) {
    assert(0 <= l && l <= r && r <= n);
    return sum(r) + (-sum(l));
  }
};

map<char, int> cnt;

ll calc_cost(string src, string dst) {
  int n = src.size();
  assert(src.size() == dst.size());
  map<char, queue<int>> pos;
  FenwickTree<int> ft(n + 10);
  for (int i = 0; i < n; i++) {
    auto c = src[i];
    pos[c].push(i);
    ft.add(i, 1);
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    auto c = dst[i];
    auto p = pos[c].front();
    pos[c].pop();
    ans += ft.sum(0, p);
    ft.add(p, -1);
  }
  return ans;
}

void solve_even(const string &s) {
  string pre = "", post = "";
  map<char, int> usd;
  for (auto c : s) {
    assert(cnt[c] % 2 == 0);
    if (usd[c] >= cnt[c] / 2) {
      post += c;
      continue;
    }
    usd[c]++;
    pre += c;
  }
  auto dst = pre;
  reverse(pre.begin(), pre.end());
  dst += pre;
  auto ans = calc_cost(s, dst);
  cout << ans << endl;
}

void solve_odd(const string &s) {
  string pre = "", pos = "", mid = "";
  map<char, int> usd;
  for (auto c : s) {
    if (usd[c] < cnt[c] / 2) {
      usd[c]++;
      pre += c;
      continue;
    }
    if (cnt[c] % 2 && usd[c] == cnt[c] / 2) {
      usd[c]++;
      mid += c;
      continue;
    }
  }
  auto dst = pre + mid;
  reverse(pre.begin(), pre.end());
  dst += pre;
  cout << calc_cost(s, dst) << endl;
}

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

  string s;
  cin >> s;
  int n = s.size();
  for (auto c : s) {
    cnt[c]++;
  }
  int odd = 0;
  for (auto p : cnt) {
    if (p.second % 2) odd++;
  }
  if (odd > 1) {
    cout << -1 << endl;
    return 0;
  }
  if (n % 2) {
    solve_odd(s);
  } else {
    solve_even(s);
  }
}


Measured memory_bytes: 5912
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>

using namespace std;

typedef pair<long long int, long long int> P2;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 998244353;

long long int P[210000];

int const TREE_SIZE = (1 << 19);
long long int seg_tree[TREE_SIZE], seg_tree1[TREE_SIZE];

// 1-indexed

void change(int a, long long int w){
	
	// a番目をwに変更する O(log N)
	
	a += TREE_SIZE / 2;
	
	seg_tree[a] = w;
	
	for(int x = a / 2; x > 0; x /= 2){
		seg_tree[x] = min(seg_tree[2 * x], seg_tree[2 * x + 1]);
	}
}

long long int query(int a, int b, int index, int l, int r){
	
	// 区間 [a, b) の最小値を求める O(log N)
	// query(a, b, 1, 0, TREE_SIZE / 2) のように呼ぶ
	
	if(r <= a || b <= l){
		return INF;
	}
	if(a <= l && r <= b){
		return seg_tree[index];
	}
	
	return min(query(a, b, index * 2, l, (l + r) / 2), query(a, b, index * 2 + 1, (l + r) / 2, r));
}

void change1(int a, long long int w){
	
	// a番目をwに変更する O(log N)
	
	a += TREE_SIZE / 2;
	
	seg_tree1[a] = w;
	
	for(int x = a / 2; x > 0; x /= 2){
		seg_tree1[x] = max(seg_tree1[2 * x], seg_tree1[2 * x + 1]);
	}
}

long long int query1(int a, int b, int index, int l, int r){
	
	// 区間 [a, b) の最小値を求める O(log N)
	// query(a, b, 1, 0, TREE_SIZE / 2) のように呼ぶ
	
	if(r <= a || b <= l){
		return -INF;
	}
	if(a <= l && r <= b){
		return seg_tree1[index];
	}
	
	return max(query1(a, b, index * 2, l, (l + r) / 2), query1(a, b, index * 2 + 1, (l + r) / 2, r));
}

int main(){
	int N, K;
	cin >> N >> K;
	for(int i = 0; i < N; i++){
		cin >> P[i];
		change(i + 1, P[i]);
		change1(i + 1, P[i]);
	}
	queue<int> que;
	for(int i = 0; i < K - 1; i++){
		if(P[i] > P[i + 1]){
			que.push(i);
		}
	}
	int ans = !que.empty();
	int flag = que.empty();
	for(int i = K; i < N; i++){
		if(!que.empty() && que.front() <= i - K){
			que.pop();
		}
		if(P[i - 1] > P[i]){
			que.push(i - 1);
		}
		if(!que.empty()){
			if(P[i - K] > query(i - K + 2, i + 1, 1, 0, TREE_SIZE / 2) || query1(i - K + 2, i + 1, 1, 0, TREE_SIZE / 2) > P[i]){
				ans += 1;
			}
		}else{
			flag = 1;
		}
	}
	cout << ans + flag << endl;
	return 0;
}

Measured memory_bytes: 9984
#include <iostream>
using namespace std;
int n, a[200009];
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; ++i) cin >> a[i];
	int r = 0, cur = 0;
	long long ret = 0;
	for (int i = 0; i < n; ++i) {
		while (r != n && (cur & a[r]) == 0) cur += a[r], ++r;
		ret += r - i;
		cur -= a[i];
	}
	cout << ret << '\n';
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main () {
	char name [18];
	scanf("%[^\n]", &name);
	for(int x = 0 ; name[x] !='\0'; x++){

		if (x==5 || x==13){
		printf(" ");
		}
		else{
			printf("%c",name[x]);
		}
	
	
	}	
		

	return 0;
}


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

struct city {
  int x;
  int y;
  int64_t p;
};

struct linescore {
  int lineid;
  int64_t s;
};

int64_t recursive_score(int K,
                        vector<vector<linescore>> &city_line_scores,
                        int min_select,
                        int selected_num,
                        vector<bool> &exist_lines) {
  if (selected_num == K) {
    int64_t s = 0;
    for (int i = 0; i < (int)city_line_scores.size(); i++) {
      // 各都市の一番近い線のスコアを合計
      for (auto line_score : city_line_scores[i]) {
        if (exist_lines[line_score.lineid]) {
          s += line_score.s;
          break;
        }
      }
    }
    return s;
  }

  int64_t min_score = 100000000000000LL;
  int addable_lines = exist_lines.size() - 2;
  for (int i = min_select; i < addable_lines; i++) {
    int next_min_select;
    if (i % 2 == 0) {
      next_min_select = i + 2;  // 同じ都市に縦線と横線を両方置くのは無駄
    } else {
      next_min_select = i + 1;
    }

    exist_lines[i] = true;
    int64_t s = recursive_score(
        K, city_line_scores, next_min_select, (selected_num + 1), exist_lines);
    exist_lines[i] = false;

    min_score = min(min_score, s);
  }
  return min_score;
}

int main() {
  int N;
  cin >> N;
  vector<city> cities(N);
  for (int i = 0; i < N; i++) {
    int x, y, p;
    cin >> x;
    cin >> y;
    cin >> p;
    cities[i] = city{x, y, p};
  }

  // 線の存在を表現.
  // 各都市の縦横で2N本、原点から出る2本
  vector<bool> exist_lines(N * 2 + 2);
  for (int j = 0; j < N; j++) {
    exist_lines[j * 2] = false;      // 縦 (xが都市の位置と同じ)
    exist_lines[j * 2 + 1] = false;  // 横 (yが都市の位置と同じ)
  }
  exist_lines[N * 2] = true;
  exist_lines[N * 2 + 1] = true;

  // 線-都市ペアでのスコア事前計算
  vector<vector<linescore>> city_line_scores(N);
  for (int i = 0; i < N; i++) {
    int xi = cities[i].x;
    int yi = cities[i].y;
    int64_t pi = cities[i].p;

    vector<linescore> line_score;

    for (int j = 0; j < N; j++) {
      int xj = cities[j].x;
      int yj = cities[j].y;

      line_score.push_back(linescore{j * 2, pi * abs(xi - xj)});
      line_score.push_back(linescore{j * 2 + 1, pi * abs(yi - yj)});
    }
    line_score.push_back(linescore{N * 2, pi * abs(xi)});
    line_score.push_back(linescore{N * 2 + 1, pi * abs(yi)});

    // 合計スコア計算時に最小の値を使うため昇順ソート
    sort(line_score.begin(), line_score.end(), [](linescore a, linescore b) { return a.s < b.s; });
    city_line_scores[i] = line_score;
  }

  for (int K = 0; K < N; K++) {
    int64_t S = recursive_score(K, city_line_scores, 0, 0, exist_lines);
    cout << S << endl;
  }
  cout << 0 << endl;  // 最後は確実に0なので計算しない
}


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

int main(){
    string s;
    int alpha[26]={};
    while(getline(cin,s)){
        for(int i=0;i<s.size();i++){
            if(isalpha(s[i])){
                if(isupper(s[i])) s[i]=tolower(s[i]);
                alpha[s[i]-'a']+=1;
            }
        }
    }
    for(int i=0;i<26;i++){
        cout<<char('a'+i)<<" : "<<alpha[i]<<'\n';
    }
}


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

int main()
{
  long long int i,j,n,k,w,x,y,z;
  cin>>n>>w;
  vector<long long int>a(n);
  vector<long long int>b(n);
  for(i=0;i<n;i++)
   {
    cin>>a[i];
    cin>>b[i];
   }
  vector<vector<long long int>>v(n+1,vector<long long int>(w+1,0));
  for(i=1;i<=n;i++)
  {
   for(j=1;j<=w;j++)
   {
    if(a[i-1]<=j)
     v[i][j]=max(v[i-1][j-a[i-1]]+b[i-1],v[i-1][j]);
    else
     v[i][j]=v[i-1][j];
   }
  }
  cout<<v[n][w]<<"\n";
 return 0;
}



Measured memory_bytes: 83040
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}

int h,w,k;
char s[20][2000];
int ans=inf;

void f(int bit,int c){
    int res=c;
    vi cnt(c+1);

    rep(j,w){
        int l=0;
        bool flag=false;
        rep(i,h){
            cnt[l]+=(s[i][j]=='1');
            flag|=(cnt[l]>k);
            if(bit&(1<<i)) l++;
        }
        /*
        if(bit==2){
            cout<<j<<' '<<res<<endl;
            rep(i,c+1){
                cout<<cnt[i]<<' ';
            }
            cout<<endl;
        }
        */
        if(flag){
            res++;
            l=0;
            flag=false;
            rep(i,c+1) cnt[i]=0;
            rep(i,h){
                cnt[l]+=(s[i][j]=='1');
                flag|=(cnt[l]>k);
                if(bit&(1<<i)) l++;
            }
            if(flag) return;
        }
    }
        
    //cout<<bit<<' '<<res<<endl;

    ans=min(ans,res);
}




signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);

    cin>>h>>w>>k;
    rep(i,h){
        rep(j,w){
            cin>>s[i][j];
        }
    }

    rep(bit,(1<<h)){
        int c=0;
        rep(i,h){
            c+=!!(bit&(1<<i));
        }
        f(bit,c);
    }

    cout<<ans<<endl;


}

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

int main() {
  int N;
  cin>>N;
  
  int sum=0;
  int nok=N;
  while(nok>=10){
    sum+=nok%10;
    nok/=10;
  }
  sum+=nok;

  if(N%sum==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  
}
        
    
  
  

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

  int N;
  int a[200];
  //even_flag
  int even_f = 1;
  int cnt = 0;
  
  cin >> N;
  
  for(int i = 0; i < N; i++){
	cin >> a[i];
	if(a[i]%2){
	  even_f=0;
	}
  }

  while(even_f){
	cnt++;
	for(int i = 0; i < N; i++){
	  a[i] = a[i] / 2;
	  if(a[i]%2){
		even_f=0;
		break;
	  }
	}
  }

  cout << cnt << "\n";
  
  return 0;
}


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

using namespace std;
int n, m;
long long x[55], y[55];
int p[55];
int main()
{
   int i, j;
 cin >> n >> m;
 long long x1[55];
long long y1[55];
 for(i = 1; i <= n; i++) cin >> x[i] >> y[i];
 for(i = 1; i <= m; i++) cin >> x1[i] >> y1[i];
 for(i = 1; i <= n; i++)
 {
 	long long t = 1e18 * 4;
 	int k = 0;
 	for(j = 1; j <= m; j++) 
 	{
 		if(t > abs(x[i] - x1[j]) + abs(y[i] - y1[j])){
 			t = abs(x[i] - x1[j]) + abs(y[i] - y1[j]);
 			k = j;
		 }
	 }
	 cout << k << '\n';
 }
 return 0;	
}

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

int n,k,ans;
int dp[105][100005];
int a[105];

signed main()
{
    //freopen("file.inp","r",stdin);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i <= k; i++)
    {
        dp[0][i] = 1;
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            if (j <= a[i])
            {
                dp[i][j] += dp[i - 1][j];
                if (dp[i][j] > MOD) dp[i][j] -= MOD;
            } else {
                int res = dp[i - 1][j] - dp[i - 1][j - a[i] - 1];
                res %= MOD;
                if (res < 0) res += MOD;
                dp[i][j] += res;
                if (dp[i][j] > MOD) dp[i][j] -= MOD;
            }
            if (j > 0) dp[i][j] += dp[i][j - 1];
            if (dp[i][j] > MOD) dp[i][j] -= MOD;
        }
    }
    if (k == 0)
    {
        cout << 1;
        return 0;
    }
    ans = dp[n][k] - dp[n][k - 1];
    if (ans < 0) ans += MOD;
    cout << ans;
    return 0;
}


Measured memory_bytes: 80128
N,A,B = map(int,input().split(" "))

mod = 10**9+7

def pow_fast(x,n):
    if n == 0:
        return 1
    x %= mod
    if n%2 == 0:
        return pow_fast(x ** 2,n//2)
    else:
        return x*pow_fast(x ** 2,(n-1)//2)

def cmb_mod(n,k):
    mod_table = []
    for i in range(k):
        mod_table.append(pow(i+1,mod-2,mod))
    ans = 1
    for i in range(k):
        ans *= n-i
        ans *= mod_table[i]
        ans %= mod
    return ans
result = (pow_fast(2,N)-1)%mod - cmb_mod(N,A) - cmb_mod(N,B)
print(result%mod)


Measured memory_bytes: 11072
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    vector<int> b(M);
    vector<int> c(M);
    for(int i = 0; i < M; i++){
        cin >> b[i] >> c[i];
    }
    int flag = 0;
    for(int i = 0; i < M; i++){
        for(int j = i; j < M; j++){
            if(b[i] == b[j] && c[i] != c[j]) flag = 1;
        }
        if(N != 1 && b[i] == 1 && c[i] == 0) flag = 1;
    }
    if(flag == 1) cout << -1 << endl;
    else{
        int ans = 0;
        for(int i = 0; i < M; i++){
            if(N == 3){
                if(b[i] == 1) ans += 100*c[i];
                else if(b[i] == 2) ans += 10*c[i];
                else if(b[i] == 3) ans += c[i];
            }
            else if(N == 2){
                if(b[i] == 1) ans += 10*c[i];
                else if(b[i] == 2) ans += c[i];
            }
            else if(N==1) ans += c[i];
            for(int j = i + 1; j < M; j++){
                if(b[i] == b[j] && c[i] == c[j]) c[j] = 0;
            }
        }
        if(N == 3 && ans < 100) ans += 100;
        if(N == 2 && ans < 10) ans += 10;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
class Dice
	def initialize()
		@cent = 1
		@west = 4
		@south = 2
		@east = 3
		@north = 5
		@bottom = 6
		@sum = 1
	end

	def change(name)
		case name
		when "North" 
			tmp = @cent
			@cent = @south
			@south = @bottom
			@bottom = @north
			@north = tmp

		when "East"
			tmp = @cent
			@cent = @west
			@west = @bottom
			@bottom = @east
			@east = tmp

		when "West"
			tmp = @cent
			@cent = @east
			@east = @bottom
			@bottom = @west
			@west = tmp

		when "South"
			tmp = @cent
			@cent = @north
			@north = @bottom
			@bottom = @south
			@south = tmp

		when "Right"
			tmp = @north
			@north = @west
			@west = @south
			@south = @east
			@east = tmp

		when "Left"
			tmp = @north
			@north = @east
			@east = @south
			@south = @west
			@west = tmp
		end

		@sum += @cent
	end

	def getSum
		@sum
	end
end



ans = Array.new

loop do
	num = gets.to_i
	if num==0
		break
	end
	dice = Dice.new
	num.times do 
		name = gets.to_s.chomp
		name.strip!
		dice.change(name)
	end
	ans.push(dice.getSum)

end

ans.each do |n|
	puts n
end

Measured memory_bytes: 8608
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    float sum=0;
    for(int i=0;i<n;i++){
        sum+=1.0/float(a[i]);
    }
    sum=1.0/sum;

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    while(true){
         
        int year=0,n;
        int a[50]={0};
        cin >> n;
         
        if(n==0)    break;
         
        a[1]=1;
        a[2]=2;
        a[3]=4;
        for(int i=4;i<=30;i++){
            a[i]=a[i-1]+a[i-2]+a[i-3];
        }
         
        year=a[n]/3650+1;
        cout << year << endl;
         
    }
}


Measured memory_bytes: 3068
(defn input []
  (->> (repeatedly (Integer/parseInt (read-line)) read-line)
    (map (comp (partial mapv #(Integer/parseInt %)) #(clojure.string/split % #"\s")))))

(defn Theater [Ss]
  (->> (map #(- (% 1) (% 0)) Ss)
    (map inc)
    (reduce +)))

(-> (input)
  Theater
  println)

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

int main(){ 
  long double A, B, H, M;
  cin >> A >> B >> H >> M;
  
  long double PI = asin(1.0) * 2.0;
  
  long double da = (H * 60.0 + M) * 2.0 * PI /12.0/60.0;
  long double db = M * 2.0 * PI /60.0;
  
  long double theta  = fabs(da - db);
  
  long double ans2 = A * A + B * B - 2.0 * A * B * cos(theta);
  long double ans = sqrt(ans2);
  
  cout << fixed << setprecision(15) << ans << endl;
}
  

Measured memory_bytes: 4132
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

int N,L,Q;
int dp[19][200010];

int main(){
	cin >> N;
	vector<int> X(N);
	for(int i=0;i<N;i++){
		cin >> X[i];
	}
	cin >> L >> Q;
	for(int j=0;j<N;j++){
		decltype(X)::iterator it = upper_bound(X.begin(),X.end(),X[j]+L);
		int t = it-X.begin()-1;
		dp[0][j] = t;
	}	
	for(int i=1;i<=18;i++){
		for(int j=0;j<N;j++){
			dp[i][j] = dp[i-1][dp[i-1][j]];
		}
	}
/*	for(int i=0;i<5;i++){
		for(int j=0;j<N;j++){
			cout << dp[i][j] << (j!=N-1? " ":"\n");
		}
	}
*/	int a,b;
	int beki[20] = {1};
	for(int i=1;i<=18;i++) beki[i] = 2*beki[i-1];
	for(int i=0;i<Q;i++){
		cin >> a >> b;
		a--; b--;
		if(a>b) swap(a,b);
		int ans = 0;
		int l = 0,r = 1e9;
		while(l+1<r){
			int m = (l+r)/2,res = m;
			int now = a;
			for(int i=18;i>=0;i--){
				if(res<=0) break;
				if(res>=beki[i]){
					res -= beki[i];
					now = dp[i][now];
				}
			}
			if(now>=b) r = m;
			else l = m;
		}
		cout << r << endl;
	}
}

Measured memory_bytes: 14848
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        int n, q;
        cin >> n;
        int a[n];
        int sum = 0;
        int mp[100001];
        memset(mp, 0, sizeof(mp));
        for (int i = 0; i < n; ++i)
        {
            cin >> a[i];
            sum += a[i];
            mp[a[i]]++;
        }
        cin >> q;
        while (q--)
        {
            int val = 0;
            int a, b;
            cin >> a >> b;
            int dif = b - a;
            if (mp[a] > 0)
                val = mp[a];
            //        cout << val << "vv\n";
            sum += val * dif;
            mp[b] += mp[a];
            mp[a] = 0;
            cout << sum << "\n";
        }
    }
}

Measured memory_bytes: 5148
let () = Scanf.scanf "%s" @@ fun s ->
  let ss = Array.init (String.length s) @@ fun i -> String.get s i in
  let f = fun (maximum, prev) i -> 
    match (i = 0, ss.(i) = 'A' || ss.(i) = 'T' || ss.(i) = 'C' || ss.(i) = 'G') with
    | (true, true) -> (1, 1)
    | (true, false) -> (0, 0)
    | (false, true) -> (max maximum (prev + 1), prev + 1)
    | (false, false) -> (max maximum 0, 0) in
  let fin_pair = List.fold_left f (0, 0) @@ List.init (String.length s) Fun.id in
  Printf.printf "%d\n" @@ fst fin_pair


Measured memory_bytes: 3804
#include <iostream>
#include <vector>
using namespace std;
int main () {
    vector<int> x;
    int N, cnt=0, ans=0;
    cin >> N;
    for (int i=1;cnt<N;i++){
        cnt+=i;
        ans=i;
    }
    cnt=0;
    for (int i=ans;i>0;i--){
        cnt+=i;
        if (cnt<=N)
            x.push_back(i);
        else
            cnt-=i;
    }
    for (int i=0;i<x.size();i++)
    cout << x[i] << "\n";
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n;

int main(){
	while(cin>>n){
		if(!n)return 0;
		int s=-n;
		for(int i=1;i*i<=n;i++){
			if(n%i==0){
				if(n!=i*i)s+=i+n/i;
				else s+=i;
			}
		}
		if(s<n)cout<<"deficient number"<<endl;
		else if(s>n)cout<<"abundant number"<<endl;
		else cout<<"perfect number"<<endl;
	}
}

Measured memory_bytes: 0
from collections import deque

h, w = map(int, input().split())
c = []
d = [[-1 for i in range(w)] for j in range(h)]
q = deque()
for i in range(h):
	s = input()
	c.append(s)
	for j in range(w):
		if c[i][j] == '#':
			q.append([i, j, 0])
			d[i][j] = 0

dirr = [[1, 0], [0, 1], [-1, 0], [0, -1]]

while len(q) != 0:
	y, x, z = q[0]

	for i in range(4):
		ny, nx = y + dirr[i][0], x + dirr[i][1]
		if 0 <= ny < h and 0 <= nx < w and d[ny][nx] == -1 and c[ny][nx] != "#":
			q.append([ny, nx, z + 1])
			d[ny][nx] = z + 1

	q.popleft()

print(z)



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

int N;
vector<P> state[20];

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    rep(i, N) {
        int A; cin >> A;
        rep(j, A) {
            int x, y; cin >> x >> y;
            state[i].pb(P(x-1, y));
        }
    }
    int ans = 0;
    rep(S, 1<<N) {
        bool flag = true;
        int cnt = 0;
        rep(i, N) if ((S>>i)&1) {
            cnt++;
            rep(j, state[i].size()) {
                int x = state[i][j].first, y = state[i][j].second;
                if (((S>>x)&1)!=y) flag = false;
            }
        }
        if (flag) ans = max(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static void Main(string[] args) {
        int N;
        Input(out N);
        int[] a;
        InputArray(out a);
        int j = 1;
        int k = 0;
        for(int i = 0; i < N; i++) {
            if(a[i] == j) {
                j++;
            } else {
                k++;
            }
        }
        if(k == N) {
            Console.WriteLine("-1");
        } else {
            Console.WriteLine(k);
        }
    }

    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void InputArray<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
}

Measured memory_bytes: 33628
n,l = map(int,input().split())
#n + l - 1
sum = 0
for i in range(n):
    sum += l + i
if l <= 0 and l + n - 1 >= 0:
    print(sum)
elif l < 0:
    print(sum - (n + l - 1))
elif l > 0:
    print(sum - l)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long int
using namespace std;
vector<vector<int> >v;
int n;
int vis[10005]={0};
int ans[10005]={0};

int cnt;
void dfs(int i,int a[])
{
    vis[i]=1;
    ans[i]=a[cnt];
    cnt--;
    for(auto j:v[i])
    {
        if(vis[j]==0)
            dfs(j,a);
    }
}

signed main()
{
    cin>>n;
    int a[n];
    int sum=0;
    v.resize(n);

    int x,y;
    for (int i = 0; i < n-1; ++i) {
        cin>>x>>y;
        x--;
        y--;
        v[x].push_back(y);
        v[y].push_back(x);
    }

    for (int i = 0; i < n; ++i) {
        cin>>a[i];
        sum+=a[i];
    }
    sort(a,a+n);

    sum-=a[n-1];

    cnt=n-1;
    dfs(0,a);

    cout<<sum<<endl;
    for (int i = 0; i < n; ++i) {
        cout<<ans[i]<<" ";
    }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 9, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int dp[N],array1[N],n;
int solution(int i){
    if(i>=n){
        return 0;
    }
    if(dp[i]!=-1){
        return dp[i];
    }
    if(i+2<n){
        return dp[i]=min(abs(array1[i]-array1[i+1])+solution(i+1),abs(array1[i]-array1[i+2])+solution(i+2));
    }
    if(i+1<n){
        return dp[i]=abs(array1[i]-array1[i+1])+solution(i+1);
    }
    return 0;


}
int main()
{
memset(dp,-1,sizeof(dp));
int i;
scanf("%d",&n);
for(i=0;i<n;++i){
    scanf("%d",&array1[i]);
}
printf("%d\n",solution(0));



    return 0;
}


Measured memory_bytes: 7656
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("5");
            WillReturn.Add("3 2 2 4 1");
            WillReturn.Add("1 2 2 2 1");
            //14
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("4");
            WillReturn.Add("1 1 1 1");
            WillReturn.Add("1 1 1 1");
            //5
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("7");
            WillReturn.Add("3 3 4 5 4 5 3");
            WillReturn.Add("5 3 4 4 2 3 2");
            //29
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("1");
            WillReturn.Add("2");
            WillReturn.Add("3");
            //5
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static int UB_X;

    static void Main()
    {
        List<string> InputList = GetInputList();
        int N = int.Parse(InputList[0]);
        UB_X = N - 1;
        int[,] BanArr = new int[UB_X + 1, 2];

        int[] wkArr = { };
        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();

        SplitAct(InputList[1]);
        for (int LoopX = 0; LoopX <= UB_X; LoopX++) BanArr[LoopX, 0] = wkArr[LoopX];

        SplitAct(InputList[2]);
        for (int LoopX = 0; LoopX <= UB_X; LoopX++) BanArr[LoopX, 1] = wkArr[LoopX];

        //最大値[X,Y]なDP表
        int[,] DPArr = new int[UB_X + 1, 2];
        DPArr[0, 0] = BanArr[0, 0];

        for (int LoopX = 1; LoopX <= UB_X; LoopX++)
            DPArr[LoopX, 0] = BanArr[LoopX, 0] + DPArr[LoopX - 1, 0];

        DPArr[0, 1] = BanArr[0, 1] + DPArr[0, 0];

        for (int LoopX = 1; LoopX <= UB_X; LoopX++) {
            int wkMax = Math.Max(DPArr[LoopX - 1, 1], DPArr[LoopX, 0]);
            DPArr[LoopX, 1] = BanArr[LoopX, 1] + wkMax;
        }

        Console.WriteLine(DPArr[UB_X, 1]);
    }

    //盤面を出力
    static void PrintBan(int[,] pBanArr)
    {
        var sb = new System.Text.StringBuilder();
        for (int Y = 0; Y <= 1; Y++) {
            for (int X = 0; X <= UB_X; X++) {
                sb.Append(pBanArr[X, Y]);
            }
            sb.AppendLine();
        }
        Console.WriteLine(sb.ToString());
    }
}


Measured memory_bytes: 13396
#include <iostream>

using namespace std;

int main() {
    int a, b;   cin >> a >> b;
    int b_ = b, j = 0;
    while (b_) {
        j++;
        b_ /= 10;
    }
    for (int i = 0; i < j; i++)
        a *= 10;

    int n = a+b;
    
    for (int i = 1; i <= 100100; i++) {
        if (i*i == n) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=105;
short f[N][N][N][N],sum1[N][N],sum2[N][N];char a[N][N];
inline void ckmax(short&x,short y){
	x=(x<y?y:x);
}
int main (){
	int n,m;scanf ("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		scanf ("%s",a[i]+1);
	int tx,ty;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++){
			if (a[i][j]=='E') tx=i,ty=j;
            sum1[i][j]=sum1[i][j-1]+(a[i][j]=='o');
            sum2[i][j]=sum2[i-1][j]+(a[i][j]=='o');
		}
	int limi=tx-1,limj=n-tx,limk=ty-1,liml=m-ty;
	for (int i=0;i<=limi;i++)
		for (int j=0;j<=limj;j++)
			for (int k=0;k<=limk;k++)
				for (int l=0;l<=liml;l++){
					int L=max(ty-k,l+1),R=min(ty+l,m-k);
					if (L<=R){
						ckmax(f[i+1][j][k][l],f[i][j][k][l]+(tx-i-1>=j+1?sum1[tx-i-1][R]-sum1[tx-i-1][L-1]:0));
						ckmax(f[i][j+1][k][l],f[i][j][k][l]+(tx+j+1<=n-i?sum1[tx+j+1][R]-sum1[tx+j+1][L-1]:0));
					}
					L=max(tx-i,j+1),R=min(tx+j,n-i);
					if (L<=R){
						ckmax(f[i][j][k+1][l],f[i][j][k][l]+(ty-k-1>=l+1?sum2[R][ty-k-1]-sum2[L-1][ty-k-1]:0));
						ckmax(f[i][j][k][l+1],f[i][j][k][l]+(ty+l+1<=m-k?sum2[R][ty+l+1]-sum2[L-1][ty+l+1]:0));
					}
				}
	printf ("%d",f[limi][limj][limk][liml]);
	return 0;
}

Measured memory_bytes: 211328
#include <stdio.h>
int main(void)
{
    int n;
    int i;
    int a, b, c;
	
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        scanf("%d %d %d", &a, &b, &c);
		
        if ((c > a) && (c > b)) {
            if ((c * c) == (a * a) + (b * b)) {
				printf("YES\n");
            }
            else {
                printf("NO\n");
            }
        }
         
        else if ((b > a) && (b > c)) {
            if ((b * b) == (a * a) + (c * c)) {
                printf("YES\n");
            }
            else {
                printf("NO\n");
            }
        }
        else if ((a > b) && (a > c)) {
            if ((a * a) == (b * b) + (c * c)) {
                printf("YES\n");
            }
            else {
                printf("NO\n");
            }
        }
        else {
            printf("NO\n");
        }
    }
    
    return (0);
}

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

using ll = long long;


vector<ll> divisor(ll n) {
    vector<ll> ret;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}


int main()
{
  ll X;
  cin >> X;
  vector<ll> test = divisor(X);

  for(ll di: test){
    for(int a = 0; ; a++){
      int b = a - di;
      ll mul = pow(a, 5) - pow(b, 5);
      if(mul== X){
        cout << a << " " << b << endl;
        return 0;
      }
      if(b > 0 && mul > X){
        break;
      }
    }

  }


}

Measured memory_bytes: 4048
//ABC112B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include<stdio.h>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> h(n);
	for(int i=0;i<n;i++){
		cin >> h.at(i);
	}
	int k=0;
	vector<int> count(n);
	for(int i=0;i<n;i++){
		count.at(i) = 0;
	}
	for(int i=0;i<n-1;i++){
		if(h.at(i)>=h.at(i+1)){
			count.at(k)++;
		}else{
			k++;
		}
	}
	sort(count.begin(),count.end());
	cout << count.at(n-1) << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF=1<<30;
using vec = vector<vector<int>>;

int main(){
   int n;
  cin>>n;
  vector<string> a(n);
  vector<int> b(n);
  rep(i,n) cin>>a[i]>>b[i];
  string x;
  cin>>x;
  int ans=0;
  int y=0;
  for(int i=0;i<n;i++){ 
    if(a[i]==x) y=1;
    else if(y==0) continue;
    else ans += b[i];
  }
  cout<<ans;
}


Measured memory_bytes: 256