akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n = sc.read();
    let q = sc.read();
    let mut a: Vec<i64> = sc.read_vec(n);
    let x: Vec<i64> = sc.read_vec(q);
    let biggest = a.pop().unwrap();
    let n = a.len();

    let mut rest = vec![0];
    for i in 0..n {
        if n % 2 == i % 2 {
            if rest.is_empty() {
                rest.push(a[i]);
            } else {
                let r = rest[rest.len() - 1];
                rest.push(r + a[i]);
            }
        }
    }

    let mut head = vec![0; n + 1];
    for i in 0..n {
        head[i + 1] = head[i] + a[n - 1 - i];
    }

    for &x in x.iter() {
        let num_removed = solve(x, &a);
        let rest_num = (n - num_removed * 2) / 2;
        let mut ans = biggest + rest[rest_num] + head[num_removed];
        println!("{}", ans);
    }
}

fn solve(x: i64, cards: &Vec<i64>) -> usize {
    let n = cards.len();
    let mut ok = 0;
    let mut ng = n;
    while ng - ok > 1 {
        let num_removed = (ok + ng) / 2;
        if binary_search(x, num_removed, cards) {
            ok = num_removed;
        } else {
            ng = num_removed;
        }
    }
    ok
}

fn binary_search(x: i64, num_removed: usize, cards: &Vec<i64>) -> bool {
    let n = cards.len();
    if num_removed * 2 > n {
        return false;
    }
    if num_removed == 0 {
        return true;
    }
    let lowest_first = cards[n - num_removed];
    let lowest_second = cards[n - num_removed * 2];
    if (x - lowest_second).abs() > (x - lowest_first).abs() {
        false
    } else {
        true
    }
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 7804
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  int x;
  cin >> x;
  vector<int> kyu={400,600,800,1000,1200,1400,1600,1800,2000};
  int ans = 0;
  rep(i,9) if(kyu[i] <= x) ans = i;
  cout << 8-ans << endl;
}

Measured memory_bytes: 3568
use std::io::*;
use std::str::FromStr;

fn parse_line<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn parse_pair<T: FromStr, U: FromStr>() -> (T, U) {
    let line = parse_line::<String>();
    let mut iter = line.split_whitespace();
    (
        iter.next().unwrap().parse().ok().unwrap(),
        iter.next().unwrap().parse().ok().unwrap(),
    )
}

fn println<T: ToString>(s: T) {
    println!("{}", s.to_string());
}

// ------------------------------------------------------------------------

fn main() {
    let (n, l) = parse_pair::<isize, isize>();

    let eaten_apple_quality = if l + n <= 0 {
        n - 1 + l
    } else if l > 0 {
        l
    } else {
        0
    };

    let total_quality: isize = (0..n).map(|n| n + l).sum();

    println(total_quality - eaten_apple_quality);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(){
int K,A,B;
  cin>>K;
  cin>>A>>B;
bool count=false;
  for(int i=1;i<1001;i++){
    if((A<= i*K)  && (i*K <= B)  ){
    
      count=true;
     }
  }
  if(count){
  cout<<"OK";
  }
  else {
  cout<<"NG";
  }
}

Measured memory_bytes: 3592
class FenwickTree():
    def __init__(self, n):
        self.n = n
        self.data = [0] * n

    def build(self, arr):
        #assert len(arr) <= n
        for i, a in enumerate(arr):
            self.data[i] = a
        for i in range(1, self.n + 1):
            if i + (i & -i) <= self.n:
                self.data[i + (i & -i) - 1] += self.data[i - 1]

    def add(self, p, x):
        #assert 0 <= p < self.n
        p += 1
        while p <= self.n:
            self.data[p - 1] += x
            p += p & -p

    def sum(self, r):
        s = 0
        while r:
            s += self.data[r - 1]
            r -= r & -r
        return s

    def range_sum(self, l, r):
        #assert 0 <= l <= r <= self.n
        return self.sum(r) - self.sum(l)

import sys
input = sys.stdin.buffer.readline

N, Q = map(int, input().split())
A = map(int, input().split())

ft = FenwickTree(N)
ft.build(A)
res = []

for _ in range(Q):
    q, x, y = map(int, input().split())
    if q:
        res.append(str(ft.range_sum(x, y)))
    else:
        ft.add(x, y)

print('\n'.join(res))

Measured memory_bytes: 143840
n = int(input())
a = list(input())
b = list(input())
c = list(input())

ans = 0
for i in range(n):
  aa = a[i]
  bb = b[i]
  cc = c[i]
  if len(set([aa,bb,cc])) == 1:
    continue
  elif len(set([aa,bb,cc])) == 2:
    ans += 1
  else:
    ans += 2
print(ans)


Measured memory_bytes: 3060
let () =
  let n, k = Scanf.scanf "%d %d" (fun n k -> n, k) in
  let a =
    Array.init n (fun _ ->
        Scanf.scanf " %d" (fun x -> x)) in
  Printf.printf "%d\n" (1 + int_of_float (ceil (float (n - k) /. float (k - 1)) ))


Measured memory_bytes: 4864
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <math.h>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
#pragma GCC optimize ("-O3")
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
#define tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define ll long long int
ll max(ll a, ll b) {  return a > b ? a : b; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } return b == 0 ? a : gcd(b, a % b);}
#define case(i) cout<<"Case #"<<i<<": ";
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << '\n'; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
#define debug2(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
void err(istream_iterator<string> it, T a, Args... args) { cerr << "[ " << *it << " = " << a << " ]"; err(++it, args...);}
#define time__(d) for (auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); blockTime.second; debug2("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
#define pii pair <ll , ll >
#define pb push_back
#define PRECISION 10
const ll inf = 9223372036854775800;
const int MAXN = 100001;
const int LOGN = 22;
const int MAXBIT = 62;
const long double PI = 3.141592653589793;
const int DIGITSIZE = 18;
ll mod = 1e9 + 7;
ll MOD = 998244353;
int x4[] = {1, -1, 0, 0};
int y4[] = {0, 0, 1, -1};
int x8[] = {1, 1, 1, -1, -1, -1, 0, 0};
int y8[] = {1, 0, -1, 1, 0, -1, 1, -1};
bool takeTestCases = 0;
bool printCaseNo = 0;

void getac(int T) {
	int n;
	cin >> n;
	ll arr[n];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		arr[i] %= mod;
	}
	ll suff[n];
	ll curr = 0;
	for (int i = n - 1; i >= 0; i--) {
		suff[i] = curr;
		curr += arr[i];
		suff[i] %= mod;
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ans += arr[i] * suff[i];
		ans %= mod;
	}
	cout << ans % mod << '\n';
}
int  main()
{

	fastio;
	int t = 1;
	if (takeTestCases) { cin >> t; }
	int t_t = 1;
	while (t--) {
		if (printCaseNo)
		case (t_t);
		getac(t_t);
		t_t++;
	}
	cerr << "Total time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
	return 0;
}


Measured memory_bytes: 6936
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	vector<int> H(n);
	for (int i = 0; i < n; ++i) scanf("%d", &H[i]);
	int lo = 1, hi = 1e9;
	while (lo < hi) {
		int m = (lo + hi) >> 1;
		ll tot = 0;
		for (int i = 0; i < n; ++i) {
			ll lef = H[i] - (ll)m * b;
			if (lef < 0) continue;
			tot += (lef + (a - b - 1)) / (a - b);
		}
		if (tot <= m) hi = m;
		else lo = m + 1;
	}
	printf("%d\n", lo);
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n); i >= 0; i--)
#define revrepr(i, a, b) for (int i = (a); i >= b; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

int main() {
    int n, k;
    cin >> n >> k;
    int d = 0;
    while (n > 0) {
        d++;
        n /= k;
    }
    cout << d << endl;
}

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

public class Problem_C
{
  public static void Main()
  {
    var N = int.Parse(Console.ReadLine());
    var deck = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    long total = deck.Sum();
    long snuke = 0;
    long minDiff = long.MaxValue;
    for (var i = 0; i < N - 1; i++)
    {
      snuke += deck[i];
      minDiff = Math.Min(minDiff, Math.Abs(snuke - (total - snuke)));
    }
    Console.WriteLine($"{minDiff}");
  }
}


Measured memory_bytes: 32092
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
#define P pair<int, int>
using namespace std;

const int M = 1000005;

int main() {
  int n;
  cin >> n;
  vector<tuple<string, int, int>> v;
  rep(i, n){
    string s;
    int tmp;
    cin >> s >> tmp;
    v.push_back(make_tuple(s, tmp*(-1), i+1));
  }

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

  rep(i, n){
    cout << get<2>(v[i]) << endl;
  }

  return 0;
}

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

int_fast64_t ans(int_fast64_t N, int_fast64_t X){
    if(X == 0)return 0;
    if(N == 0)return 1;
    auto P = 1LL << N;
    if(X >= 2 * P - 1){
        return P + ans(N - 1, X + 1 - P * 2);
    }
    return ans(N - 1, X - 1);
}

int main(){
    int_fast64_t N, X;
    cin >> N >> X;
    cout << ans(N, X) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int i,a,b,c,k;
    int w=0;
    scanf("%d%d%d%d",&a,&b,&c,&k);
    
    if(k>a){
        for(i=0;i<a;++i){w+=1;}
        if(k-a-b>0){for(i=0;i<k-a-b;++i){w-=1;}}
        }
    else if(k<=a){
        for(i=0;i<k;++i){w+=1;}
    }
    printf("%d",w);
    return 0;
}


Measured memory_bytes: 1732
#include <cstdio>
#include <algorithm>

using namespace std;

long long a[5043];
int dp[5043];

bool cmp(int u, int v) {
  return u > v;
}

int main(int argc, char const *argv[]) {
  int n, k;
  scanf("%d%d", &n, &k);
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
    sum += a[i];
  }
  sort(a + 1, a + n + 1, cmp);
  int ans = 0;
  dp[0] = 1;
  for (int i = 1; i <= n; ++i) {
    bool flag = false;
    for (int j = 0; j < k; ++j) {
      if (dp[j] == 1 && j + sum >= k) {
        flag = true;
        break;
      } 
    }
    if (!flag) {
      ans = n - i + 1;
      break;
    }
    sum -= a[i];
    for (int j = k - 1; j >= a[i]; --j) {
      dp[j] |= dp[j - a[i]];
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int r;
  cin>>r;
  cout<<3*r*r<<endl;
  return 0;
}


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

using namespace std;

const int MAXN = 100 + 10;

int n;
multiset<int> S;

void impossible()
{
	cout << "Impossible" << endl;
	exit(0);
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		S.insert(x);
	}
	int d = *S.rbegin();
	for(int i = d; i >= (d + 1) / 2; i--)
		if(S.find(i) == S.end())
			impossible();
		else
			S.erase(S.find(i));
		
	for(int i = d; i >= d / 2 + 1; i--)
		if(S.find(i) == S.end())
			impossible();
		else
			S.erase(S.find(i));

	for(multiset<int>::iterator it = S.begin(); it != S.end(); it++)
		if(*it < (d + 1) / 2 + 1)
			impossible();

	cout << "Possible" << endl;

	return 0;
}


Measured memory_bytes: 256
# 2019/08/07
# Bのソートは不要！！

from bisect import bisect_left,bisect_right

n=int(input())
a=sorted(list(map(int,input().split())))
b=list(map(int,input().split()))
c=sorted(list(map(int,input().split())))
ans=0

for i in range(n):
    bc=n-bisect_right(c,b[i])
    ba=bisect_left(a,b[i])
    ans+=bc*ba    

print(ans)


Measured memory_bytes: 23744
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
long long  dp[1001][1001];
char s[1001][1001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w;
    cin>>h>>w;
    for(int i=0;i<h;i++)
    {
        cin>>s[i];
    }
    memset(dp,0,sizeof(dp));
    for(int i=0;i<h&&s[i][0]=='.';i++)
    {
        dp[i][0]=1;
    }
    for(int i=0;i<w&&s[0][i]=='.';i++)
    {
        dp[0][i]=1;
    }
    for(int i=1;i<h;i++)
    {
        for(int j=1;j<w;j++)
        {
            if(s[i][j]=='.')
            {
                if(s[i-1][j]=='.')
                    dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
                if(s[i][j-1]=='.')
                    dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
                dp[i][j]%=mod;
            }
        }
    }
    cout<<dp[h-1][w-1];
    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    set<int> pen;
    int a, b, c;
    cin >> a >> b >> c;
    pen.insert(a);
    pen.insert(b);
    pen.insert(c);
    printf("%zu\n", pen.size());
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    String S = scanner.next();
    char[] s = S.toCharArray();
    int money = 700;

    for (int i = 0; i < 3; i++){
      if (s[i] == 'o')
        money += 100;
    }
    System.out.println(money);
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

struct edge{
  ll to, cost;
  edge(){}
  edge(ll t, ll c){to = t; cost = c;}
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vector<vector<edge>> G(N, vector<edge>(0));
  for(int i = 0; i < N-1; i++){
    ll a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    G.at(a).push_back(edge(b, c));
    G.at(b).push_back(edge(a, c));
  }

  ll Q, K;
  cin >> Q >> K;
  K--;

  vll res(N, -1);
  function<void(ll, ll)> dfs = [&](ll v, ll cost){
    res.at(v) = cost;
    for(int i = 0; i < G.at(v).size(); i++){
      ll nextv = G.at(v).at(i).to;
      ll nextc = G.at(v).at(i).cost;
      if(res.at(nextv) != -1) continue;
      dfs(nextv, cost + nextc);
    }
  };
  dfs(K, 0);
  
  vll ans(0);
  for(int i = 0; i < Q; i++){
    ll x, y;
    cin >> x >> y;
    x--; y--;
    ans.push_back(res.at(x) + res.at(y));
  }
  for(auto x: ans) cout << x << endl;
}

Measured memory_bytes: 18424
using System;
using System.Linq;

public class AtCoder_Pana_A
{
    public static void Main()
    {
        int[] a = new int[]
        {
            1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
        };

        int num = int.Parse(Console.ReadLine());

        Console.WriteLine(a[num-1]);
    }
}


Measured memory_bytes: 11092
#!/usr/bin/env python
# coding: utf-8

# In[12]:


abc = list(map(int, input().split()))


# In[13]:


if abc[0]%2 == 0 or abc[1]%2 == 0 or abc[2]%2 == 0:
    print(0)
else:
    abc_s = sorted(abc)
    print(abc_s[0]*abc_s[1])


# In[ ]:






Measured memory_bytes: 2940
module Main where
import qualified Control.Monad as C
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Array as A

int = read :: String -> Int
getWord :: IO String
getWord = do
  c <- getChar
  if C.isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = id
printer = unlines . (:[])

solver x = 
  if x!!2 == x!!3 && x!!4 == x!!5
  then "Yes"
  else "No"

Measured memory_bytes: 380
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int[] a;
    int l, i, j;

    a = new int[21];
    for(j = 0;;){
      a[0] = sc.nextInt(); l = sc.nextInt();
      if(a[0] == 0 && l == 0)break;
      for(i = 1;i < 21;i++){
        a[i] = solve(a[i - 1], l);
        for(j = 0;j < i;j++)if(a[i] == a[j])break;
        if(i != j)break;
      }
      out.println(j + " " + a[i] + " " + (i - j));
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
  private static int solve(int a, int l){
    int[] d;
    int i, j, tmp, x, y, k;
    d = new int[l];
    for(i = 0;i < l;i++){
      d[i] = a % 10; a /= 10;
    }
    for(i = 0;i < l - 1;i++)for(j = 0;j < l - 1 - i;j++)if(d[j] > d[j + 1]){
      tmp = d[j]; d[j] = d[j + 1]; d[j + 1] = tmp;
    }
    k = 1; x = 0; y = 0;
    for(i = 0;i < l;i++){
      x += d[i] * k;
      y += d[l - 1 - i] * k;
      k *= 10;
    }
    return (x - y);
  }
}

Measured memory_bytes: 20556
#include<stdio.h>
#include<math.h>
int arr[1000090];
int main()
{
    arr[0]=1;
    arr[1]=1;
    int i, j, n;
    while(scanf("%d",&n)!=EOF)
    {
        float sq=sqrt(n);
        sq=ceil(sq);
        int count=0;
        for(i=4; i<=n; i+=2) arr[i]=1;
        for(i=3; i<=sq; i+=2)
            for(j=i*i; j<=n; j=j+i+i)
                arr[j]=1;
        for(i=1; i<=n; i++)
        if(arr[i]==0) ++count;
        printf("%d\n", count);
    }
    return 0;
}

Measured memory_bytes: 4504
#include<stdio.h>

int i,j=0,k;
int a,b,ans;

int main(){
	
	while(scanf("%d %d",&a,&b)!=EOF){
		if(a==0 && b==0)break;
		if(j!=0)printf("\n");
		ans=0;j=1;
		for(i=a;i<=b;i++){
			if(i%4==0){
				if(i%100!=0)printf("%d\n",i),ans++;
				else if(i%400==0)printf("%d\n",i),ans++;
				i+=3;
			}
		}
		if(ans==0)printf("NA\n");
		
	}
	//printf("\b");
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int A[100000];
	ll S[100001];
	S[0] = 0;
	ll kari = 0;
	priority_queue<int, vector<int>, greater<int>> que;
	priority_queue<int> que2;
	int saishou = 1e9;
	int saidai = 0;
	rep(i, N) {
		int a = getint();
		que.push(a);
		S[0] += a;
		saishou = min(saishou, a);
	}
	rep(i, N) A[i] = getint();
	rep(i, N) {
		int a = getint();
		que2.push(a);
		kari += a;
		saidai = max(saidai, a);
	}

	rep(i, N) {
		if (saishou < A[i]) {
			que.push(A[i]);
			S[i + 1] = S[i] + A[i] - que.top();
			que.pop();
		}
		else {
			S[i + 1] = S[i];
			saishou = min(saishou, A[i]);
		}
	}
	ll kotae = S[N] - kari;
	for (int i = N - 1; i >= 0; i--) {
		if (saidai > A[i]) {
			que2.push(A[i]);
			kari += A[i] - que2.top();
			que2.pop();
		}
		else {
			saidai = max(saidai, A[i]);
		}
		kotae = max(kotae, S[i] - kari);
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 2424
/*
    AUTHOR:hruday pabbisetty
    NIT ROURKElA(My_College_Sucks)
*/
#include <bits/stdc++.h>
using namespace std;
#define opt ios_base::sync_with_stdio(0)
#define lli long long int
#define ulli unsigned long long int
#define I int
#define S string
#define D double
#define rep(i,a,b) for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define in(n) scanf("%lld",&n)
#define in2(a,b) scanf("%lld %lld",&a,&b)
#define in3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define out(n) printf("%lld\n",n)
#define inu(a) scanf("%lld",&a)
#define outu(a) printf("%llu",a)
#define ins(s) scanf("%s",&s)
#define outs(s) printf("%s",s)
#define nl printf("\n")
#define mod 1000000007
#define inf 100000000000000
typedef long long       ll;
typedef pair<lli,lli>  plli;
typedef vector<lli>     vlli;
typedef vector<ulli>    vulli;
typedef vector<ll>      vll;
typedef vector<string>  vs;
typedef vector<plli>     vplli;
#define MM(a,x)  memset(a,x,sizeof(a));
#define ALL(x)   (x).begin(), (x).end()
#define P(x)       cerr<<"{"#x<<" = "<<(x)<<"}"<<endl;
#define P2(x,y)       cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<"}"<<endl;
#define P3(x,y,z)  cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<"}"<<endl;
#define P4(x,y,z,w)cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<", "#w" = "<<(w)<<"}"<<endl;
#define PP(x,i)     cerr<<"{"#x"["<<i<<"] = "<<x[i]<<"}"<<endl;
#define TM(a,b)     cerr<<"{"#a" -> "#b": "<<1000*(b-a)/CLOCKS_PER_SEC<<"ms}\n";
#define UN(v)    sort(ALL(v)), v.resize(unique(ALL(v))-v.begin())
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define sz() size()
#define nl cout<<"\n"
#define MX1 100005
#define MX2 1000005
#define sqr(a) a*a*a
#define bs binary_search
#define lb lower_bound
#define ub upper_bound

lli power(lli a,lli b)
    {
    lli value;
    if(b==0)
        {
        return 1;
    }
    else if(b%2==0)
        {
        value=power(a,b/2)%mod;
        return(value*value)%mod;
    }
    else
        {
        value=power(a,b/2)%mod;
        return ((a*value)%mod*(value))%mod;
    }
}
lli a[100005],n,A,B;
lli f(lli k)
{
    lli i,moves=0;
    rep(i,0,n)
    {
        if(a[i]-k*B<=0)
        {
            continue;
        }
        lli temp=a[i]-k*B,temp1=A-B;
        moves+=ceil(temp*1.0/temp1);
        if(ceil(temp/temp1)>k)
        {
            return 0;
        }
    }
    if(moves<=k)
    {
        return 1;
    }
    return 0;
}
int main()
{
      /*  #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif*/
    opt;
    lli i;
    cin>>n>>A>>B;
    rep(i,0,n)
    {
        cin>>a[i];
    }
    lli l=0,r=1000000000;
    lli ans=-1;
    while(l<=r)
    {
        lli mid=(l+r)/2;
        if(f(mid))
        {
            ans=mid;
            r=mid-1;
        }
        else
        {
            l=mid+1;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
    int r,c;
    scanf("%d%d",&r,&c);
    int i,j,k,l;
    int a[101][101]={};
    
    
    
    for(i=0;i<r;i++)
        for(j=0;j<c;j++)
            scanf("%d",&a[i][j]);
    
    //a[r][k]=a[0][k]+a[1][k]+...a[r-1][k]    a[j][k]
    //a[l][c]=a[l][0]+a[l][1]+...a[l][c-1]    a[l][j]
    
    for(k=0;k<c;k++)
        for(j=0;j<r;j++)
            a[r][k]+=a[j][k];
    for(l=0;l<r+1;l++)
        for(i=0;i<c;i++)
            a[l][c]+=a[l][i];
    

    for(i=0;i<r+1;i++){
        printf("%d",a[i][0]);
        for(j=1;j<c+1;j++)
            printf(" %d",a[i][j]);
        printf("\n");
        }
    
}



Measured memory_bytes: 2072
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int L[] = new int[N];
		int max = 0;
		int sum = 0;
		for (int i = 0; i < N; i++) {
			L[i] = sc.nextInt();
			sum += L[i];
			if (L[i] > max) {
				max = L[i];
			}
		}
		sc.close();
		sum = sum - max;
		if (sum - max > 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21972
N = int(input())
h = [int(i) for i in input().split()]
dp = [99999]*(N+1)
dp[1] = 0
dp[2] = abs(h[0] - h[1])

for i in range(3,N+1):
  dp[i] = min(dp[i-2]+abs(h[i-1] - h[i-3]), dp[i-1]+ abs(h[i-2] - h[i-1]))
print(dp[N])

Measured memory_bytes: 20540
// Problem: 
// 			D - Alter Altar
// 			Editorial
// 		
// Contest: AtCoder - AtCoder Beginner Contest 174
// URL: https://atcoder.jp/contests/abc174/tasks/abc174_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*
 *   ﷽
 * In the name of Allah, the Most Gracious, the Most Merciful
 */

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <climits>

using namespace std;

int main()
{
	int n;
	string s;
	cin>>n;
	cin>>s;
	int rc, wc;
	rc = wc = 0;
	for(auto e : s)
	{
		if(e == 'W') wc++;
		else rc++;
	}
	int fr = 0;
	int wb = 0;
	for(int t=0;t<rc; t++)
	{
		if(s[t] == 'W') fr++;
	}
	for(int t=rc;t<n;t++)
	{
		if(s[t] == 'R') wb++;
	}
	int subans = wb > fr? fr : wb;
	int subans2 = rc > wc ? wc : rc;
	int ans = subans > subans2 ? subans2 : subans;
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 3488
#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,q;
	string s;
	cin >> n >> s >> q;
	vector<set<int>> ind(26, set<int>({1<<30}));
	REP(i,n) ind[s[i]-'a'].insert(i);
	REP(qq,q){
		int cmd;
		cin >> cmd;
		if(cmd==1){
			int i;
			char c;
			cin >> i >> c;
			i--;
			ind[s[i]-'a'].erase(i);
			s[i] = c;
			ind[c-'a'].insert(i);
		}else{
			int l,r;
			cin >> l >> r;
			l--;
			int cnt = 0;
			REP(c,26){
				if(ind[c].empty()) continue;
				int lind = *ind[c].lower_bound(l);
				int rind = *ind[c].lower_bound(r);
				if(lind < rind) cnt++;
			}
			cout << cnt << '\n';
		}
	}
	
	return 0;
}



Measured memory_bytes: 25244
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
	long long int ans=100000;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		ans=ans*105/100;
		if(ans%1000!=0){
			ans=ans/1000*1000+1000;
		}
	}
	cout<<ans<<endl;
    return 0;
}

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

int n, m, x, a[101];

int main(){
	cin >> n >> m >> x;
	int cnt[2] = {0};
	for(int i = 0; i < m; i++){
		cin >> a[i];
		if(a[i] < x) cnt[0]++;
		else cnt[1]++;
	}
	
	cout << min(cnt[0], cnt[1]) << endl;
	
	return 0;
}

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

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

#ifdef LOCAL
const int N = 9;
const string Ns = to_string(N);
char query(const string &s) {
    printf("? %s\n", s.c_str());

    LL n = 0;
    REP (i, s.size()) n = n * 10 + s[i] - '0';
    char ret;
    if (n <= N && s < Ns) ret = 'Y';
    else if (n > N && s > Ns) ret = 'Y';
    else ret = 'N';
    printf("ret %c\n", ret);

    return ret;
}
void answer(const string &s) {
    printf("! %s\n", s.c_str());
    printf("j %s\n", Ns.c_str());
    exit(0);
}
#else
char buf[11];
char query(const string &s) {
    printf("? %s\n", s.c_str());
    fflush(stdout);
    scanf("%s", buf);
    return *buf;
}
void answer(const string &s) {
    printf("! %s\n", s.c_str());
    exit(0);
}
#endif

void MAIN() {
    if (query("10000000000") == 'Y') {
	string S = "2";
	REP (i, 10) {
	    if (query(S) == 'Y') {
		S[0] = '1';
		answer(S);
	    }
	    S.push_back('0');
	}
    } else {
	string S = "1";
	for (int i=1; i<=9; i++) {
	    S.push_back('0');
	    if (query(S) == 'N') {
		S.pop_back();
		break;
	    }
	}

	// query(S) == 'Y';
	// query(S + '0') == 'N';
	REP (i, S.size()) S[i] = '9';
	for (int i=0; i<(int)S.size(); i++) {
	    int lo = -1, hi = 9;
	    if (i == 0) lo = 0;

	    while (hi - lo > 1) {
		int mid = (hi + lo) / 2;
		S[i] = mid + '0';
		if (query(S + "9") == 'N') {
		    lo = mid;
		} else {
		    hi = mid;
		}
	    }
	    S[i] = hi + '0';
	}

	answer(S);
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 720
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n, a, b; scanf("%d%d%d", &n, &a, &b);
	
	int ans = 0;
	if(a + b <= n) ans = 0;
	else ans = (a + b) - n;
	printf("%d %d\n", std::min(a, b), ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for(int i = 0; i<n; i++) {
      a[i] =sc.nextInt();
    }
    int count = bubbleSort(a, n);
    for(int i = 0; i<n; i++) {
      if(i<n-1){
        System.out.print(a[i] + " ");
      }else {
        System.out.println(a[i]);
      }
    }
    System.out.println(count);
  }

  public static int bubbleSort(int[] a,int n) {
    boolean flag = true;
    int count = 0;
    while(flag == true) {
      flag = false;
      for(int j = n-1;j>0; j--) {
        if(a[j]<a[j-1]) {
          int free = a[j];
          a[j] = a[j-1];
          a[j-1] = free;
          count++;
          flag = true;
        }
      }
    }
    return count;
  }
}

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

template <
    typename TYPE,
    std::size_t SIZE>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;
using vi = vector<ll>;

#define REPS(a, i, n) for (ll(i) = a; (i) < (n); ++(i))
#define REP(i, n) REPS(0, i, n)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 912345678;

int df[112345];
int db[112345];

vi a;

int main()
{
    int n;
    cin >> n;
    a.push_back(0);
    REP(i, n)
    {
        int c;
        cin >> c;
        a.push_back(c);
    }
    a.push_back(0);

    REP(i, n)
    {
        df[i + 2] = df[i + 1] + abs(a[i + 1] - a[i]);
    }
    reverse(ALL(a));
    REP(i, n)
    {
        db[i + 2] = db[i + 1] + abs(a[i + 1] - a[i]);
    }
    reverse(ALL(a));
    REPS(1, i, n + 1)
    {
        cout << df[i] + db[n - i + 1] + abs(a[i + 1] - a[i - 1]) << endl;
    }
}

Measured memory_bytes: 2932
# coding: utf-8

N, M, D = list(map(int, input().split(' ')))
field = [list(input()) for i in range(N)]

pattern_num = 0
cont = 0
for i in range(N):
    for j in range(M):
        if field[i][j] == '.':
            cont += 1
            if cont >= D: pattern_num += 1
        else:
            cont = 0
    cont = 0

cont = 0
for j in range(M):
    for i in range(N):
        if field[i][j] == '.':
            cont += 1
            if cont >= D: pattern_num += 1
        else:
            cont = 0
    cont = 0

print(pattern_num)


Measured memory_bytes: 5648
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<utility>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e9;
ll N;
map<P,ll> height;
map<P,ll> num;
bool IsRollable(ll x, ll y,ll d,ll n){
    if(n<=3)return false;
    ll dx[4]={-1,0,1,0};
    ll dy[4]={0,1,0,-1};
    ll now=height[P(x,y)];
    ll next=height[P(x+dx[d],y+dy[d])];
    return now>next;
}
void Func(ll x,ll y,ll t,ll b,ll l,ll r, ll u,ll d){
    ll v[4]={l,d,r,u};
    ll maxN=0;
    ll maxD=0;
    for(int i=0;i<4;i++){
        if(IsRollable(x,y,i,v[i])){
            if(maxN<v[i]){
                maxN=v[i];
                maxD=i;
            }
        }
    }
    if(maxN==0){
        height[P(x,y)]++;
        num[P(x,y)]=t;
        return;
    }
    ll dx[4]={-1,0,1,0};
    ll dy[4]={0,1,0,-1};
    x+=dx[maxD];
    y+=dy[maxD];
    switch (maxD)
    {
    case 0:
        Func(x,y,r,l,t,b,u,d);
        break;
    case 1:
        Func(x,y,u,d,l,r,b,t);
        break;
    case 2:
        Func(x,y,l,r,b,t,u,d);
        break;
    case 3:
        Func(x,y,d,u,l,r,t,b);
        break;
    default:
        break;
    }
}
void DiceCalc(ll t,ll d,ll &l,ll &r, ll &u,ll & b){
    b=7-t;
    u=7-d;
    ll v[4];
    switch(t){
        case 1:v[0]=2;v[1]=4;v[2]=5;v[3]=3;break;
        case 2:v[0]=1;v[1]=3;v[2]=6;v[3]=4;break;
        case 3:v[0]=1;v[1]=5;v[2]=6;v[3]=2;break;
        case 4:v[0]=1;v[1]=2;v[2]=6;v[3]=5;break;
        case 5:v[0]=1;v[1]=4;v[2]=6;v[3]=3;break;
        case 6:v[0]=2;v[1]=3;v[2]=5;v[3]=4;break;
    }
    for(int i=0;i<3;i++){
        if(d==v[i]){
            l=v[i+1];
        }
    }
    if(d==v[3]){
        l=v[0];
    }
    r=7-l;
}

int main(){
    while(cin>>N,N!=0){
        height.clear();
        num.clear();
        for(int i=0;i<N;i++){
            ll t,b,l,r,u,d;
            cin>>t>>d;
            DiceCalc(t,d,l,r,u,b);
            Func(0,0,t,b,l,r,u,d);
        }
        map<ll,ll> count;
        for(auto o:num){
            count[o.second]++;
        }
        for(int i=1;i<=5;i++){
            cout<<count[i]<<" ";
        }cout<<count[6]<<endl;
    }
}


Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;

int main()
{
	int N;
	cin >> N;
	if (N==1)
	{
		cout << "Hello World" << endl;
	}
	else
	{
		int A, B;
		cin >> A >> B;
		cout << A + B << endl;
	}
	return 0;
}

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

int main() {
    int n; cin >> n;
    int cnt = 0;
    for(int i=0; i<n; i++){
        int d,e;
        cin >> d >> e;
        if(d == e){
            cnt++;
        }
        else{
            cnt = 0;
        }
        if(cnt > 2){
            cout << "Yes" << endl;
            return 0;
        }

    }
    cout << "No" << endl;
}

Measured memory_bytes: 3632
#include <string.h>

typedef struct{
  int no;
  int total;
}Rst;

int main(void){
  int i,j,n,m,x;
  Rst rst[100],tmp;

  while(1){
    scanf("%d%d",&n,&m);
    if(!n && !m) break;

    memset(rst,0,sizeof(rst));
    for(i=0;i<m;i++) rst[i].no=i+1;
    for(i=0;i<n;i++){
      for(j=0;j<m;j++){
        scanf("%d",&x);
        rst[j].total += x;
      }
    }
    for(i=0;i<m-1;i++){
      for(j=i+1;j<m;j++){
        if(rst[i].total < rst[j].total){
          tmp = rst[i];
          rst[i] = rst[j];
          rst[j] = tmp;
        }
        else if(rst[i].total == rst[j].total && rst[i].no > rst[j].no){
          tmp = rst[i];
          rst[i] = rst[j];
          rst[j] = tmp;
        }
      }
    }
    for(i=0;i<m-1;i++){
      printf("%d ",rst[i].no);
    }
    printf("%d\n",rst[i].no);
  }

  return 0;
}

Measured memory_bytes: 0
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input!{
        n: usize,
        s: Chars,
    }
    let r = s.iter().filter(|&&x| x == 'R').count();
    let g = s.iter().filter(|&&x| x == 'G').count();
    let b = s.iter().filter(|&&x| x == 'B').count();
    let all = r * g * b;
    let mut x = 0;
    for i in 0..n - 2 {
        for j in i + 1..n - 1 {
            let r = j - i;
            let k = j + r;
            if k >= n {continue;}
            if s[i] != s[j] 
                && s[i] != s[k]
                && s[j] != s[k] {
                x += 1;        
            }
        }
    }
    println!("{}", all - x);
}


Measured memory_bytes: 2160
//
// Created by TakahiroYamaji on 2020/08/02.
//
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
ll K;

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

//ll calc(ll k){
//    ll s = 0;
//    for (ll i=0;i<k;i++){
//        s += 7 * pow(10, i);
//        if (s % K == 0){
//
//        }
//    }
//}
int main(){
    cin >> K;
    //iは桁数
    ll s = 0;
    int flg = 0;
    for (int i=0;i<K;i++){
        s += 7 * super_pow(10, i, K);
        if (s % K == 0){
            cout << i + 1 << endl;
            flg = 1;
            break;
        }
    }
    if (flg == 0){
        cout << -1 << endl;
    }
    //cout << super_pow(2, 6, 3) << endl;
}



Measured memory_bytes: 3200
n, k = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(k)]
mod = 998244353

dp = [1]
acc = [0, 1]

for i in range(1, n):
  new = 0
  for l, r in LR:
    if i < l:
      continue
    r = min(r, i)
    new += acc[i-l+1] - acc[i-r]
    new %= mod
  dp.append(new)
  acc.append((acc[-1]+new) % mod)

print(dp[-1])

Measured memory_bytes: 24936
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] s = new String[n];
		for(int i = 0 ; i < n ; i++) s[i] = sc.next();
		int cnt = 0;
		for(int i = 0 ; i < n ; i++) {
			if(s[i].equals("Y")) cnt++;
		}
		if(cnt >= 1) {
			System.out.println("Four");
		} else {
			System.out.println("Three");
		}
	}
}


Measured memory_bytes: 21588
#include <stdio.h>
int main()
{

    int i,a,b,c,d,j,n,m,k,l,h,r;
    scanf("%d%d%d",&a,&b,&c);
    i=a*100;
    j=b*10;
    n=i+j+c;
    if(n%4==0){
        printf("YES\n");}
    else{
        printf("NO\n");
    }
    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

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

  ll ans = 0;
  if (a[0] > x) ans += a[0] - x, a[0] = x;
  rep(i, N - 1){
    if (a[i] + a[i + 1] > x) {
      ll diff = a[i] + a[i + 1] - x;
      ans += diff;
      a[i + 1] -= diff;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include<time.h>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1<<30
#define INFTY 1000000000000000001LL
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<Edge> >;//ll or Edge
using Edge=pair<int,ll>;
// g++ -o a a.cpp -Wall -lm -std=c++14
//tree探索dfsを復習siro
void rec(const Graph &G,int v,int p,ll sum,VI &dist){
    dist[v]=sum;
    for(auto u:G[v]){
        if(u.fi==p)continue;
        rec(G,u.fi,v,sum+u.se,dist);
    }
}

int main(){
    int n;cin>>n;
    Graph G(n);
    rep(i,n-1){
        int a,b;ll c;
        cin>>a>>b>>c;
        a--;b--;
        G[a].push_back(make_pair(b,c));
        G[b].push_back(make_pair(a,c));
    }
    int q,k;cin>>q>>k;k--;
    VI dist(n,0);
    rec(G,k,-1,0,dist);//-1は最初どっち方向に行っても良いということ.みたい
    rep(i,q){
        int x,y;cin>>x>>y;x--;y--;
        cout<<dist[x]+dist[y]<<endl;
    }
    
}

Measured memory_bytes: 18840
#include <cstdio>
#include <cstdlib>
 
struct stack{
  int a[101];
  unsigned n;
  stack():a(),n(0){}
  int& top(){return a[n-1];}
  int pop(){return a[--n];}
  void push(int in){a[n++]=in;}
};
 
int main(){
  stack s;
  char buf[100];
 
  while(scanf("%s",buf) != EOF){
    int a;
    switch(buf[0]){
      case '+' : a = s.pop(); s.top() += a; break;
      case '-' : a = s.pop(); s.top() -= a; break;
      case '*' : a = s.pop(); s.top() *= a; break;
      default  : s.push(atoi(buf));
    }
  }
  printf("%d\n",s.top());
}

Measured memory_bytes: 980
import java.util.*;

class Main{
  public static void main(String args[]){

	int n;
	int i, j;
	int v;
	Scanner scan = new Scanner(System.in);
	String str = new String();

	n =  scan.nextInt();
	int A[] = new int[n];

	for(i=0; i<n; i++)
		A[i] = scan.nextInt();

	for(i=0; i<n ; i++){
		v = A[i];
		j = i-1;
		while(j >= 0 && A[j] > v){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		str = Arrays.toString(A);
		str = str.replaceAll("\\[|\\]|,","");
		System.out.println(str);
	}

	return;

  }

}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a == 5 && b == 5 && c == 7 || a == 5 && b == 7 && c == 5 || a == 7 && b == 5 && c == 5){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

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


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, m, d[200000], t[200000];
    cin >> n;
    rep(i, n) {
        cin >> d[i];
    }
    cin >> m;
    rep(i, m) {
        cin >> t[i];
    }

    sort(d, d+n);
    sort(t, t+m);

    int i = 0, j = 0, cnt = 0;
    while(i < m) {
        if (t[i] != d[j]) {  // tとdが違うならjの添字をインクリメント
            j++;
        } else {  // tとdが同じならcntとiをインクリメント
            cnt++;
            j++;
            i++;
        }
        if (cnt == m) {  // cntがmになったらtがdで埋められたということでYES
            puts("YES");
            return 0;
        }
        if (j == n) {  // cntがmになる前にjがnになったらNO
            puts("NO");
            return 0;
        }
    }
	return 0;
}

Measured memory_bytes: 1792
mod = 10 ** 9 + 7

S = input()

dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1

for i, s in enumerate(S):
    c = -1 if s == "?" else int(s)
    for j in range(10):
        if c != -1 and c != j:
            continue
        for k in range(13):
            dp[i + 1][(k * 10 + j) % 13] += dp[i][k]
    for j in range(13):
        dp[i + 1][j] %= mod

print(dp[len(S)][5])

Measured memory_bytes: 62172
def main():
    """"ここに今までのコード"""
    N, K = map(int, input().split())
    dice_list = list(map(int, input().split()))
    max, s = 0, 0

    for i in range(K):
        s += (dice_list[i] + 1) / 2
    
    max = s

    for i in range(N-K):
        s -= (dice_list[i] + 1) / 2
        s += (dice_list[i+K] + 1) / 2
        if s > max:
            max = s
    
    print(max)


if __name__ == '__main__':
    main()

Measured memory_bytes: 32180
#include<bits/stdc++.h>
#define N 123456
using namespace std;
typedef long long ll;
int main(void)
{
//    freopen("in.txt","r",stdin);
    int x,y;
    cin>>x>>y;
    for(int i=0;i<=x;i++) {
        int tt=x-i;
        if(i*2+tt*4 == y)
        {
            puts("Yes");
            return 0;
        }
    }
    puts("No");
    //main();
    return 0;
}


Measured memory_bytes: 3632