akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        v: [f64; n],
    }
    let mut v = v;
    v.sort_by(|a, b| a.partial_cmp(b).unwrap());
    println!("{:?}", v.iter().fold(v[0], |sum, val| (sum + val) / 2.0));
}


Measured memory_bytes: 4352
#include <cstdio>
#include <vector>

using namespace std;

typedef long long int lli;

vector<int> a;

int find(int m){
	if(a[m] == m)
		return m;
	return find(a[m]);
}


int main(void){
	int n, q, p, v, i;
	lli ans;
	char c;
	while(1){
		scanf("%d%d",&n,&q);
		if(n == 0 && q == 0)
			break;
		ans = 0;
		a.push_back(0);
		a.push_back(1);
		for(i = 2;i <= n;i++){
			scanf("%d%*c",&p);
			a.push_back(p);
		}
		for(i = 0;i < q;i++){
			scanf("%c%d%*c",&c,&v);
			if(c == 'Q'){
				ans += (lli)find(v);
			}
			else if(c == 'M'){
				a[v] = v;
			}
		}
		printf("%lld\n",ans);
		a.clear();
	}
	return 0;
}

Measured memory_bytes: 1524
using System;
using System.Linq;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class program{
  static void Main(string[] args){
    program p = new program();
    p.Run();
  }
  void Run(){
	int n=Readint()[0];
    string s = ReadLine();
    string now=s.Substring(0,1);
    int count=1;
    for (int i=1;i<s.Length;i++){
      if (now!=s.Substring(i,1)){
        count++;
        now=s.Substring(i,1);
      }
    }
    WriteLine(count.ToString());
  }

  int[] Readint(){
    string[] s = ReadLine().Split();
    int[] res=new int[s.Length];
    Parallel.For(0,s.Length,i=>{
      res[i]=int.Parse(s[i]);
    });
    return res;
  }
}


Measured memory_bytes: 15964
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const int sz=401;
const ll inf=1e18;
ll dp[sz][sz];
ll arr[sz][sz];

void preprocess(vector<ll>& picks,ll n){
    for(int i=1;i<=n;++i){
        for(int j=i;j<=n;++j){
            arr[i][j]=picks[j]+((i==j)?0: arr[i][j-1]);
        }
    }
    /*for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            cout<<arr[i][j]<<" ";
        }
        cout<<endl;
    }*/
}


ll solve(vector<ll>& picks,int i,int j){
    if(i==j){
        dp[i][j]=0;
        return dp[i][j];
    }
    if(dp[i][j]!=-1)
        return dp[i][j];
    ll minCost=inf;
    for(ll k=i;k<j;++k){
        minCost=min(minCost,arr[i][j]+solve(picks,i,k)+solve(picks,k+1,j));
    }
    return dp[i][j]=minCost;
}   

int main() {
	ll n=0;cin>>n;
    for(ll i=0;i<sz;++i)
        for(ll j=0;j<sz;++j)
            dp[i][j]=-1;
    vector<ll> picks(n+1,0);
    for(ll i=1;i<=n;++i)
        cin>>picks[i];
    preprocess(picks,n);
    ll ans=solve(picks,1,n);
    cout<<ans<<'\n';
    return 0;
}


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

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

  map<string, int> cnt;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    cnt[s]++;
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    string t;
    cin >> t;
    cnt[t]--;
  }
  int res = 0;
  for (auto &sc : cnt) {
    res = max(res, sc.second);
  }
  cout << res << '\n';
  return 0;

}

Measured memory_bytes: 256
N=int(input())
check=0
Flag=False
for i in range(N):
    d_1,d_2=map(int,input().split())
    if d_1==d_2:
        check+=1
    else:
        check=0
    if check==3:
        Flag=True
if Flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9172
loop do
	h, w = gets.chomp.split.map(&:to_i)
	break if [h, w].all?(&:zero?)

	tile_map = Array.new
	tile_already_arrived = Array.new

	h.times do
		tile_map << gets.chomp.split('')
		tile_already_arrived << Array.new(w, false)
	end

	x = y = 0

	while true
		tile_present = tile_map[y][x]

		if tile_already_arrived[y][x] == true
			goal = "LOOP"
			break
		else
			tile_already_arrived[y][x] = true
			case tile_present
			when '>' 
				x += 1
			when '<'
				x -= 1
			when 'v'
				y += 1
			when '^'
				y -= 1
			when '.'
				goal = "#{x} #{y}"
				break
			end
		end
	end

	puts goal
end

Measured memory_bytes: 6896
a,b,k=map(int,input().split())
lis=[]
for i in range(k):
    if a<=a+i<=b:
        lis.append(a+i)
for i in range(k):
    if a<=b-i<=b:
        lis.append(b-i)
ans=list(set(lis))
ans.sort()
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 3064
n =int(input())
first =[]
second =[]
for i  in range(n):
    d1 , d2 = map(int , input().split())
    first.append(d1)
    second.append(d2)

for i in range(n-2):
    count = 0
    for j in range(i ,i+3):
        if first[j]==second[j]:
            count +=1
        else:
            break
           
    if count ==3:
        print("Yes")
        break
    
else:
    print("No")

Measured memory_bytes: 9192
#include <stdio.h>
 
int main() {
  int K, A, B, i;
  scanf("%d", &K);
  scanf("%d %d", &A, &B);
  
  for (i = A; i <=B; i++) {
    if ((i % K) == 0) {
      printf("OK");
      return 0;
    }
  }
  printf("NG");
  
  return 0;
}

Measured memory_bytes: 1732
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	string s;
	for (int i = 0; i < 3; ++i) {
		cin >> s;
		cout << s[0];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
a=[[] for i in range(n)]
for i in range(n):
    a[i]=list(map(int,input().split()))
#print(a,b,c)
def judge(x,y,z):
    rt=0
    for i in range(len(x)):
        rt+=x[i]*y[i]
    return rt+z
ans=0
for i in range(n):
    jj=judge(a[i],b,c)
    #print(jj)
    if jj>0:
        ans+=1
print(ans)


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

using namespace std;

int main(void) {
	int x,N,H,W;
	cin >> N >> H >> W;
	vector<int> w(N);
	for (int i = 0; i < N; ++i) {
		cin >> x;
		if (i%2 == 0) {
			w[i] = (W*i) + x;
		}
		else {
			w[i] = (W*i) - x;
		}
	}
	sort(w.begin(),w.end());
	int ind = 0;
	int wind = 0;
	int res = 0;
	for (int i = 0; i < N*W; ++i) {
		if (ind < N && i == w[ind]) {
			wind = W-1;
			while (ind < N && i == w[ind]) {
				++ind;
			}
		}
		else {
			if (wind > 0) {
				--wind;
			}
			else {
				++res;
			}
		}
	}
	cout << res*H << endl;
	return 0;
}



Measured memory_bytes: 3156
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	int a = 0, b = 0;
	int x = 0;
	string p;
	cin >> p;
	int n = p.size();
	for (int i = 0; i < n; i++) {
		if (i % 2) {
			if (p[i] == 'g') {
				a++;
			}
			
		}
		else {
			if (p[i] == 'p')a--;
		}
	
	}
	cout << a << endl;

	return 0;

}

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

using namespace std;

const int N = 1e5 + 5;
string s, t;
int S[N], T[N], n, m;

main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> s >> t;
	n = s.size(); s = ' ' + s;
	m = t.size(); t = ' ' + t;
	for(int i = 1; i <= n; ++i) S[i] = S[i - 1] + (s[i] == 'A' ? 1 : 2);
	for(int i = 1; i <= m; ++i) T[i] = T[i - 1] + (t[i] == 'A' ? 1 : 2);
	int test;
	cin >> test;
	while(test--) {
		int x, y, u, v;
		cin >> x >> y >> u >> v;
		if((S[y] - S[x - 1]) % 3 == (T[v] - T[u - 1]) % 3) {
			cout << "YES\n";
		}
		else cout << "NO\n";
	}
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;

template<int M = 1000000007>
struct ModInt {
    int data;

    ModInt(int data) : data(data) {}

    ModInt() : data(0) {}

    inline ModInt<M> operator+(ModInt<M> const &right) const {
        int temp = data + right.data;
        return ModInt(temp > M ? temp - M : temp);
    }

    inline ModInt<M> &operator+=(ModInt<M> const &right) {
        data += right.data;
        data = data > M ? data - M : data;
        return *this;
    }

    inline ModInt<M> operator-(ModInt<M> const &right) const {
        int temp = data - right.data;
        return ModInt(temp < 0 ? temp + M : temp);
    }

    inline ModInt<M> &operator-=(ModInt<M> const &right) {
        data -= right.data;
        data = data < 0 ? data + M : data;
        return *this;
    }

    inline ModInt<M> operator*(ModInt<M> const &right) const {
        int temp = data * right.data % M;
        return ModInt(temp < 0 ? temp + M : temp);
    }

    inline ModInt<M> &operator*=(ModInt<M> const &right) {
        data = data * right.data % M;
        data = data < 0 ? data + M : data;
        return *this;
    }

    inline bool operator==(ModInt<M> const &right) const {
        return data == right.data;
    }

    inline bool operator!=(ModInt<M> const &right) const {
        return data != right.data;
    }

    inline operator int() const {
        return data;
    }
};

template<int M = 1000000007>
inline ostream &operator<<(ostream &os, const ModInt<M> mi) {
    os << mi.data;
    return os;
}

template<int M = 1000000007>
ModInt<M> powm(int a, int b) {
    ModInt<M> res = 1;
    while (b) {
        if (b & 1)res *= a;
        b >>= 1;
        a *= a;
        a %= M;
    }
    return res;
}

constexpr int mod = 1000000007;

ModInt<mod> fact[200200];
ModInt<mod> fact_inv[200200];

ModInt<mod> comb(int n, int r) {
    if (n - r > r)return comb(n, n - r);
    ModInt<mod> nn = fact[n];
    ModInt<mod> rr = fact_inv[r];
    ModInt<mod> nr = fact_inv[n - r];
    return nn * rr * nr;
}

void preCalc() {
    fact[0] = 1;
    fact_inv[0] = 1;
    for (int i = 1; i < 200200; ++i) {
        fact[i] = fact[i - 1] * ModInt<mod>(i);
        fact_inv[i] = powm(fact[i], mod - 2);
    }
}

signed main() {
    preCalc();
    int N, K;
    cin >> N >> K;
    ModInt<mod> ans = 0;
    //空き部屋がi個になる
    for (int i = 0; i <= N - 1; ++i) {
        if (i > K)break;
        int j = N - i;
        //NCi*(i+j-1)!/i!/(j-1)!
        //NCi*(N-1)Ci
        ans += comb(N, i) * comb(N - 1, i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
x = int(input())
l = [1, 4, 8, 16, 32, 64, 128, 256, 512, 9, 27, 81, 243, 729, 25, 125, 625, 36, 216, 49, 343, 100, 1000, 121, 144, 169, 196, 225, 289, 324, 361, 400, 441, 484, 529, 576, 26**2, 28**2, 29**2, 900, 31**2]
l = list(set(l))
l.sort()
for i in range(len(l)):
  if x < l[i]:
    print(l[i-1])
    break
  elif x == 1:
    print('1')
    break
  elif x == 1000:
    print('1000')
    break

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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> mii;
typedef map<ll,int> mli;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;  ///1e9+7

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<=N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///
ll n,k,a,b;

void _case()
{
    cin>>n>>k>>a>>b;
    cout<<(n-a)*(k-b)<<'\n';
}

main()
{
//    fastio();
        _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 3512
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int a, b, c, k;
cin>>a>>b>>c>>k;
if(k <= a){
    cout<<k;
    return 0;
}else
{
    k -= a;
    if(k <= b){
        cout<<a;
        return 0;
    }else
    {
        k -= b;
        cout<<a-k;
        return 0;
    }
    
}
return 0;    
}

Measured memory_bytes: 3668
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include <utility>
#include<map>
#include<functional>
#include<climits>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
	ll n, x, ans = 0,memo[2000][2000];
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> memo[i][0];
		ans += memo[i][0];
	}
	for (int i = 1; i < n; i++) {
		ll sum = 0;
		for (int j = n; j < 2 * n; j++) {
			memo[j%n][i] = min(memo[j%n][i-1], memo[(j - 1)%n][i-1]);
			sum += memo[j%n][i];
		}
		ans = min(ans, sum + i * x);
	}
	cout << ans << endl;

}



Measured memory_bytes: 31488
fn main(){
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let v:Vec<i32> = s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
    let mut X = v[0];
    let mut t = v[1];
    println!("{}", std::cmp::max(X - t, 0));
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>

int main(){
    int cnt0 = 0;
    int cnt1 = 0;
    char S[100000];
    scanf("%s", S);

    for (int i=0; S[i]; i++){
        if(S[i] == '0')
            cnt0++;
        if(S[i] == '1')
            cnt1++;
    }
    if (cnt0 < cnt1)
        printf("%d\n",cnt0 * 2);
    else
        printf("%d\n",cnt1 * 2);
    return 0;
}

Measured memory_bytes: 2224
#include<iostream>
using namespace std;
int N,A;
long sum;
int cnt[9];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>A;
		sum+=A;
		if(A>4)A=4;
		cnt[A]++;
	}
	if(N<=3)
	{
		cout<<(N==1?sum:N==2?sum-1:sum-3)<<endl;
		return 0;
	}
	if(N==4)
	{
		if(cnt[2]==4)cout<<sum-4<<endl;
		else if(cnt[2]==3)cout<<sum-5<<endl;
		else if(cnt[2]==2)cout<<sum-5<<endl;
		else if(cnt[2]==1)cout<<sum-5<<endl;
		else cout<<sum-6<<endl;
	}
	else
	{
		if(cnt[2]==5)cout<<sum-6<<endl;
		else if(cnt[2]==4)
		{
			if(cnt[3]==1)cout<<sum-6<<endl;
			else cout<<sum-7<<endl;
		}
		else if(cnt[2]==3)cout<<sum-7<<endl;
		else if(cnt[2]==2)cout<<sum-7<<endl;
		else if(cnt[2]==1)cout<<sum-8<<endl;
		else
		{
			if(cnt[3]==5)cout<<sum-8<<endl;
			else if(cnt[3]==4)cout<<sum-8<<endl;
			else if(cnt[3]==3)cout<<sum-9<<endl;
			else if(cnt[3]==2)cout<<sum-9<<endl;
			else if(cnt[3]==1)cout<<sum-9<<endl;
			else if(cnt[3]==0)cout<<sum-10<<endl;
		}
	}
}



Measured memory_bytes: 3108
fun main(args: Array<String>) {
    val (r, g, b, n) = readLine()!!.split(" ").map(String::toInt)

    var count = 0
    for (i in 0..n / r) {
        val rc = i * r
        for (j in 0..(n - i * r) / g) {
            val gc = j * g
            val tmp = n - rc - gc
            if (tmp >= 0 && tmp % b == 0) {
                count++
            }
        }
    }
    println(count)
}

Measured memory_bytes: 37948
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s[] = br.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        int Q = Integer.parseInt(s[1]);
        String sc[] = br.readLine().split(" ");
        int[] c = new int[n+1];
        for (int i = 1; i <= n; i++) {
            c[i] = Integer.parseInt(sc[i-1]);
        }
        int[][] q = new int[Q][3];
        for (int i = 0; i < Q; i++) {
            String[] sq = br.readLine().split(" ");
            q[i][0] = Integer.parseInt(sq[0]);
            q[i][1] = Integer.parseInt(sq[1]);
            q[i][2] = i;
        }
        Arrays.sort(q, (x,y) -> x[1] - y[1]);
        int[] ans = new int[Q];
        BIT bit = new BIT(n+1);
        int[] idx = new int[n+1];
        int prer = 0;
        int sum = 0;
        for (int i = 0; i < Q; i++) {
            int l = q[i][0], r = q[i][1];
            while(prer < r){
                prer++;
                if(0 < idx[c[prer]]){
                    bit.add(idx[c[prer]], -1);
                }else{
                    sum++;
                }
                bit.add(prer, 1);
                idx[c[prer]] = prer;
            }
            ans[q[i][2]] = sum - bit.sum(l-1);
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < Q; i++) {
            sb.append(ans[i] + "\n");
        }
        System.out.print(sb.toString());

    }

}

class BIT {

    public int n;
    public int[] bit;

    public BIT(int n){
        this.n = n;
        bit = new int[n+1];
    }

    public int sum(int i){
        int s = 0;
        while(0 < i){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    public void add(int i, int x){
        while(i <= n){
            bit[i] += x;
            i += i & -i;
        }
    }

    public int lowerBound(int k){
        if(k <= 0) return 0;
        int x = 0;
        int max = 1;
        while(max < n) max *= 2;
        for (int i = max; i > 0; i /= 2) {
            if(x + i <= n && bit[x + i] < k){
                k -= bit[x + i];
                x += i;
            }
        }
        return x + 1;
    }

}


Measured memory_bytes: 102936
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

typedef long long int ll;

const ll INF=1e17;

ll A,B;
ll Q;
ll s[100005],t[100005];

ll dist(ll a,ll b,ll x){
    int d;
    if(a<=x&&b<=x)return abs(x-min(a,b));
    if(a>=x&&b>=x)return abs(x-max(a,b));
    else return min(abs(x-a),abs(x-b))+abs(a-b);
}

int main(){
    cin>>A>>B>>Q;
    for(int i=0;i<A;++i)cin>>s[i];
    for(int i=0;i<B;++i)cin>>t[i];
    sort(s,s+A);
    sort(t,t+B);
    for(int i=0;i<Q;++i){
        ll ans=INF;
        ll x;
        cin>>x;
        int shrine1=lower_bound(s,s+A,x)-s;
        int shrine2=upper_bound(s,s+A,x)-s;
        int temple1=lower_bound(t,t+B,x)-t;
        int temple2=upper_bound(t,t+B,x)-t;
        if(s[shrine1]!=x)shrine1--;
        if(t[temple1]!=x)temple1--;
        ll a=s[shrine1],b=s[shrine2],c=t[temple1],d=t[temple2];
        if(shrine1<0)a=INF;
        if(temple1<0)c=INF;
        if(shrine2==A)b=INF;
        if(temple2==B)d=INF;
        //cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
        ans=min(dist(a,c,x),min(dist(a,d,x),min(dist(b,c,x),dist(b,d,x))));
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 2944
#include<iostream>
#define int long long
using namespace std;
int n;
string a,b;
signed main()
{
	cin>>n>>a>>b;
	int ans=1,mod=1000000007;
	for(int i=0;i<n;i++)
		if(a[i]==b[i])
			if(!i)ans=3;
			else if(a[i-1]==b[i-1])ans=(ans*2)%mod;
			else{}
		else
		{
			if(!i)ans=6;
			else if(a[i-1]==b[i-1])ans=(ans*2)%mod;
			else ans=(ans*3)%mod;
			i++;
		}
	cout<<ans<<endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>

using namespace std;

long long int gcd(long long int a, long long int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a%b);
    }
}

int main() {

    long long int n;
    cin >> n;

    vector<long long int> a(n);

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

    vector<long long int> b(n);
    b[0] = a[0];
    for (long long int i = 1; i < n; i++) {
        b[i] = gcd(a[i], b[i-1]);
    }

    vector<long long int> c(n);
    c[n-1] = a[n-1];
    for (long long int i = n-2; i >= 0; i--) {
        c[i] = gcd(a[i], c[i+1]);
    }

    long long int ans = max(c[1], b[n-2]);
    for (long long int i = 1; i < n-1; i++) {
        ans = max(ans, gcd(b[i-1], c[i+1]));
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
N = int(input())
A = input().split()
R = []
L = []
for i,a in enumerate(A):
    if i%2 == 0:
        R.append(a)
    else:
        L.append(a)
ans = list(reversed(L))+R
if N%2 == 0:
    print(' '.join(ans))
else:
    print(' '.join(list(reversed(ans))))

Measured memory_bytes: 29508
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

pll a[100100];
pll b[100100];
ll sum[100100];

int main() {
	ll X, K;
	cin >> X >> K;
	vector<ll> r(K+2);
	r[0] = 0;
	a[0] = pii(X,X);
	rep(i,K) cin >> r[i+1];
	r.back() = 1e9+7;
	for(int i = 1; i < r.size(); i++) {
		if(i%2 == 1) {
			if(b[i-1].se - (r[i] - r[i-1]) < 0) {
				b[i].fi = b[i-1].fi + (r[i]-r[i-1] - b[i-1].se);
				b[i].se = 0;
			}
			else {
				b[i].fi = b[i-1].fi;
				b[i].se = max(b[i-1].se - (r[i]-r[i-1]), 0ll);
			}
			a[i].fi = a[i-1].fi;
			a[i].se = max(a[i-1].se - (r[i]-r[i-1]), 0ll);
			sum[i] = sum[i-1] - (r[i] - r[i-1]);
		}
		else {
			if(a[i-1].se + (r[i] - r[i-1]) > X) {
				a[i].fi = a[i-1].fi - (a[i-1].se + (r[i]-r[i-1]) - X);
				a[i].se = X;
			}
			else {
				a[i].fi = a[i-1].fi;
				a[i].se = min(a[i-1].se + (r[i]-r[i-1]), X);
			}
			b[i].fi = b[i-1].fi;
			b[i].se = min(b[i-1].se + (r[i]-r[i-1]), X);
			sum[i] = sum[i-1] + (r[i] - r[i-1]);
		}
	}

	int Q;
	cin >> Q;
	rep(i,Q) {
		int t, aa;
		cin >> t >> aa;
		int indx = lower_bound(all(r), t) - r.begin() -1;
//		cout << "indx : " << indx << endl;

		ll res = -1;

		if(t==0) {
			res = aa;
		}
		else {
			//cout << a[indx].fi << "," << b[indx].fi << endl;
			if(aa <= b[indx].fi) {
				res = b[indx].se;
			}
			else if(aa >= a[indx].fi){
				res = a[indx].se;
			}
			else {
				res = aa + sum[indx];
			}
//			cout << "*" << res << endl;

			if(indx % 2 == 0) {
				res = max(res - (t-r[indx]), 0ll);
			}
			else {
				res = min(res + (t-r[indx]), X);
			}
		}
		cout << res << endl;
	}
	return 0;
}


Measured memory_bytes: 5888
import Control.Applicative
import Control.Monad

readInts :: IO [Int]
readInts = map read . words <$> getLine

calc :: Int -> Int -> [[Int]] -> [[Int]]
calc rows cols g = [calc' r | r <- [0..rows]]
  where
    calc' r
      | r < rows = g!!r ++ [sum $ g!!r]
      | otherwise = map (\i -> sum [g!!j!!i | j <- [0..rows-1]]) [0..cols-1] ++ [total]
    total = sum $ map sum g

main :: IO ()
main = do
  [r, c] <- readInts
  xs <- replicateM r readInts
  mapM_ putStrLn $ map (unwords . map show) $ calc r c xs

Measured memory_bytes: 6572
import java.util.Scanner;
public class Main {
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n,x,a=0;
            n = sc.nextInt();
            x = sc.nextInt();
            if(n==0&&x==0)break;
            for(int i=1;i<n-1;i++){
                for(int j=i+1;j<n;j++){
                    int c = x - i - j;
                    if(c>j&&c<=n){
                        a++;
                    }
                }
            }
            System.out.println(a);
        }
    }
}


Measured memory_bytes: 26480
n, m = map(int,input().split())

def kaijou(n):
  ans = 1
  for i in range(1,n+1):
    ans *= i
  return ans

ans = 1
ans2 = 1

if n == 1 or n == 0:
  ans = 0
elif n>2:
  ans = kaijou(n)//(2*kaijou(n-2))
elif n==2:
  ans = kaijou(n)//2

if m ==1 or m == 0:
  ans2 = 0
elif m>2:
  ans2 = kaijou(m)//(2*kaijou(m-2))
elif m==2:
  ans2 = kaijou(m)//2

print(ans+ans2)
    


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s.at(i);

    map<string, int> mp;
    rep(i, n) mp[s.at(i)]++;

    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
}

Measured memory_bytes: 6408
import sys
import os

def file_input():
    f = open('../Beginner_Contest_164/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    A,B,C,D=map(int, input().split())

    while True:
        C -= B
        if C <= 0:
            print('Yes')
            break
        A -= D
        if A <= 0:
            print('No')
            break

if __name__ == '__main__':
    main()


Measured memory_bytes: 9180
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}
ll modPow(ll x, ll n) {
    if(n==0) return 1;
    ll res = modPow(x*x%MOD, n/2);
    if(n&1) res=res*x%MOD;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;cin>>s;
    int n = s.size();
    int p = 2019;
    vl val(p,0);
    ll tenfactor=1;
    ll cur = 0;
    val[cur]++;
    rep(i,n) {
        cur = (cur+(s[n-i-1]-'0')*tenfactor)%p;
        tenfactor = (tenfactor*10)%p;
        val[cur]++;
    }
    ll res = 0;
    rep(i,p) {
        res += val[i]*(val[i]-1)/2;
    }
    ct(res);


}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
//using
using intl = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;

//関数マクロ
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl

//定数マクロ
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>

//定数
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);

//テンプレート関数
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; }
//intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); } //c++17からある
//intl lcm(intl a,intl b){ return a / gcd(a, b) * b; } //c++17からある

//自作テンプレート関数
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}//Yes,Noの出力を楽にするよう
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}//上の関数のYes,Noを任意の文字列でできるようにしたもの
intl fact(intl k){ intl a = 1; for(int i = 2; i <= k; i++){ a *= i; } return a; }//k!を求める関数,O(N)
intl digit10(intl a){ intl b = 0; do{ a /= 10; b++; }while(a); return b; }//aを10進数で表したときの桁数を求める関数,O(logN)



signed main(){
    cout << fixed << setprecision(10);
    intl a,b,c,k;
    cin >> a >> b >> c >> k;
    intl cnt = 0;
    while(b <= a){
        b *= 2;
        cnt++;
    }
    while(c <= b){
        c *= 2;
        cnt++;
    }
    fp(cnt <= k);
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

void solve() {
    ll n; cin >> n;
    ll ans = 0;
    for (int i = 0; i <= n; ++i) {
        if(i%3==0 || i%5==0) continue;
        ans += i;
    }
    cout << ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int binpow(int a, int b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

ll gcd(ll a,ll b)
{
    if (b==0) return a;
    return gcd(b,a%b);
}
string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,k;
    cin>>n;
    while (n--)
    {
        cin>>k;
        if (!(k%2))
        {
            if (k%3&&k%5)
            {
                cout<<"DENIED";
                return 0;
            }
        }
    }
    cout<<"APPROVED";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

double CrossProduct3(double x1, double y1, double x2, double y2, double x3, double y3);

int main(void){
  double x1, y1, x2, y2, x3, y3, xp, yp;
  double Crs1, Crs2, Crs3;

  /* ????????§?±??????? */
  while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp) != EOF){
    Crs1 = CrossProduct3(x1, y1, x2, y2, xp, yp);
    Crs2 = CrossProduct3(x2, y2, x3, y3, xp, yp);
    Crs3 = CrossProduct3(x3, y3, x1, y1, xp, yp);
    if((Crs1 > 0 && Crs2 > 0 && Crs3 > 0) || (Crs1 < 0 && Crs2 < 0 && Crs3 < 0)){
      printf("YES\n");
    }else{
      printf("NO\n");
    }
  }
  return 0;
}


double CrossProduct3(double x1, double y1, double x2, double y2, double px, double py){
  double ax, ay, bx, by;

  ax = x2 - x1;
  ay = y2 - y1;
  bx = px - x1;
  by = py - y1;
  return ax*by-ay*bx;
}

Measured memory_bytes: 612
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
start = [0]*(N+1)
attack = 0
enemy = 0

for i in range(N+1):
    start[i] = A[i]

for i in range(N):
    attack = min(A[i],B[i])
    A[i] = A[i] - attack
    B[i] = B[i] - attack
    attack = min(A[i+1],B[i])
    A[i+1] = A[i+1] - attack
    B[i] = B[i] - attack
    
for i in range(N+1):
    enemy = enemy + (start[i]-A[i])
    
print(enemy)

Measured memory_bytes: 19004
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String x = scan.next();
        String y = scan.next();

        if (x.charAt(0) > y.charAt(0)) {
            System.out.println(">");
        } else if (x.charAt(0) < y.charAt(0)) {
            System.out.println("<");
        } else {
            System.out.println("=");
        }
    }
}



Measured memory_bytes: 23124
#include<iostream>
#include<set>
using namespace std;
int main()
{
    set<int> a;
    int n, b;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> b;
        if(a.find(b) == a.end()) a.insert(b);
        else a.erase(b);
    }
    cout << a.size() << endl;
    return 0;
}

Measured memory_bytes: 4864
def bb
    d,n = gets.chomp.split(/\s/).map{|x| x.to_i}

    if n == 100
        case d
        when 0
            puts 101
        when 1
            puts n*101
        when 2
            puts n*100*101
        end
        exit
    end

    case d
    when 0
        puts n
    when 1
        puts n*100
    when 2
        puts n*100*100
    end
end

bb


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

ll mypow(ll b, ll e) {
  if(e==0) return 1;
  if(e%2==0) {
    ll t=mypow(b,e/2);
    return t*t;
  } else return b*mypow(b,e-1);
}

int main() {
  ll a,b,c,k;cin>>a>>b>>c>>k;
  ll ans=0;
  rep(i,k+1) {
    rep(j,k+1) {
      ll t=k-i-j;
      if(t>=0) ans=max(ans,a*mypow(2,i)+b*mypow(2,j)+c*mypow(2,t));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
s=str(input())
t=str(input())

for i in range(len(t)):
    if s.find(t[i])==-1:
        print(-1)
        break
else:
    a=0
    count=0
    for k in t:
        if k in s[a:]:
            a=s.find(k,a)+1
        else:
            count+=1
            a=s.find(k)+1
    print(count*len(s)+a)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
ll fac[10000001];

void init(){
	ll L = 10000001;
	for(ll i = 2;i<=L;i++){
		if(fac[i] != -1) continue;
		fac[i] = i;
		for(ll j = i * 2 ; j <= L ;j += i){
			if(fac[j] == -1){
				fac[j] = i;
			}
		}
	}
}
map<ll, ll> div(ll n){
	map<ll, ll> ma;
	while(n > 1LL){
		ma[fac[n]]++;
		n /= fac[n];
	}
	return ma;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    memset(fac, -1, sizeof(fac));
    init();
    ll n, ans = 0;
    cin >> n;
    for(ll i=1;i<=n;i++){
    	ll num = i;
    	for(auto& j : div(i)){
    		num *= (j.second + 1);
    	}
    	ans += num;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 81784
#include <bits/stdc++.h>
using namespace std;
typedef long double db;

const int MAXN = 300 + 10;

int cnt[4], n, m;

bool vis[MAXN][MAXN][MAXN];
db f[MAXN][MAXN][MAXN];

db dfs(int i, int j, int k) {
    if (i + j + k == 0) return f[i][j][k] = 0;
    if (vis[i][j][k]) return f[i][j][k];
    vis[i][j][k] = true;
    int sum = i + j + k;
    db tmp = 1.0 * n / sum;
    if (i) tmp += (1.0 * i / sum) * dfs(i - 1, j + 1, k);
    if (j) tmp += (1.0 * j / sum) * dfs(i, j - 1, k + 1);
    if (k) tmp += (1.0 * k / sum) * dfs(i, j, k - 1);
    return f[i][j][k] = tmp;
}
int main() {
    scanf("%d", &n);
    for (int i = 1, tmp; i <= n; ++i) {
        scanf("%d", &tmp), cnt[tmp] ++, m;
    }
    db ans = dfs(cnt[3], cnt[2], cnt[1]);
    printf("%.10llf\n", ans);
    return 0;
}

Measured memory_bytes: 479488
#include <stdio.h>
int main() 
{
	int A[250],i,n;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&A[i]);
		
	}
	for(i=1;i<=n;i++)
	{
	printf("node %d: key = %d, ",i,A[i]);
	if(i/2>0) printf("parent key = %d, ",A[i/2]);
	if(i*2<=n) printf("left key = %d, ",A[i*2]);
	if(i*2+1<=n) printf("right key = %d, ",A[i*2+1]);
	printf("\n");
    }
	return 0;
}


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

int main() {
	int n,k;
	cin>>n>>k;
	int a[n],sum=0,max;
	for(int i=0;i<n;i++){
	    cin>>a[i];
	}
	
	for(int j=0;j<k;j++){
	    sum+=a[j];
	}
	max = sum;
	for(int p=k;p<n;p++){
	    int temp = sum+a[p]-a[p-k];
	    max = (max>temp)?max:temp;
	    sum = temp;
	}
	printf("%Lf",(long double)0.5*(long double)(max + k));
	
	return 0;
}



Measured memory_bytes: 1024
s = list(input())
ans = 100
tmp = s
for i in s:
    l = []
    count = 0
    for j in s:
        if j != i:
            count += 1
        else:
            l.append(count)
            count = 0
    l.append(count)
    if max(l) <= ans:
        ans = max(l)
print(ans)

Measured memory_bytes: 3060
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    s = s_input()

    start_index = s.find('A')

    s = s[::-1]

    end_index = len(s) - s.find('Z') - 1 

    print(end_index - start_index + 1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 77684
import copy

S = list(input())
K = int(input())

def Scount():
    cnt_S = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            S[i+1] = "1"
            cnt_S += 1
    return cnt_S

T = copy.copy(S)
T.insert(0, T[len(T)-1])
cnt_T = 0
for i in range(len(T)-1):
    if T[i] == T[i+1]:
        T[i+1] = "1"
        cnt_T += 1

if T[i+1] != "1":
    ans = Scount() + (cnt_T * (K-1))
else:
    TT = S * 2
    cnt_T = 0
    for i in range(len(TT)-1):
        if TT[i] == TT[i+1]:
            TT[i+1] = "1"
            cnt_T += 1
    if K % 2 == 0:
        ans = cnt_T * (K // 2)
    else:
        ans = (cnt_T * (K // 2)) + Scount()
print(ans)

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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  int A;
  cin >> A;
  int B;
  cin >> B;
  int C;
  cin >> C;
  int D;
  cin >> D;
  cout << min(A, B) + min(C, D) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int a = 0, b = 0;
	int n; cin >> n;
	REP(i, n)
	{
		int t; cin >> t;
		if (t & 1) a++;
		else b++;
	}
	if (a & 1) cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 256
/*
	AOJ502 DICE
*/
#include <iostream>
#include <string>



int main()
{
	while (true) {
		int dice[] = {
			1,2,6,3,5,4
			/*
			1
			2354
			6
			*/
		};
		int n;
		int ans = 1;
		std::cin >> n;
		if (n == 0)
			break;

		for (int i = 0; i < n; ++i)
		{
			std::string s;
			std::cin >> s;

			if (s == "North")
			{
				int buf;
				buf = dice[0];
				dice[0] = dice[1];
				dice[1] = dice[2];
				dice[2] = dice[4];
				dice[4] = buf;

			}
			else if (s == "East")
			{
				int buf = dice[0];
				dice[0] = dice[5];
				dice[5] = dice[2];
				dice[2] = dice[3];
				dice[3] = buf;
			}
			else if (s == "West")
			{
				int buf = dice[0];
				dice[0] = dice[3];
				dice[3] = dice[2];
				dice[2] = dice[5];
				dice[5] = buf;
			}
			else if (s == "South")
			{
				int buf = dice[0];
				dice[0] = dice[4];
				dice[4] = dice[2];
				dice[2] = dice[1];
				dice[1] = buf;
			}
			else if (s == "Right")
			{
				int buf = dice[1];
				dice[1] = dice[3];
				dice[3] = dice[4];
				dice[4] = dice[5];
				dice[5] = buf;
			}
			else if (s == "Left")
			{
				int buf = dice[1];
				dice[1] = dice[5];
				dice[5] = dice[4];
				dice[4] = dice[3];
				dice[3] = buf;
			}

			ans += dice[0];
		}

		std::cout << ans << std::endl;
	}
	// std::system("PAUSE");
	return 0;
}

Measured memory_bytes: 1212
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip> //do setprecision
#include <ctime>
#include <complex>
using namespace std;

int main(void){
	int N,M,X,i,j,ans;
	int A[100];
	cin >> N;
	cin >> M;
	cin >> X;
	for(i=0;i<M;i++){
		cin >> A[i];
	}
	for (i = 0; i < M; i++){
		if(X<A[i]){
			j++;
			//cout << i << endl;
			break;
		}
	}
	//cout << i <<" " << j << endl;
	if(M-i<i){
		ans = M-i;
	}else{
		ans = i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

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

    solve(&s);
    // println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"8 3
ACACTACG
3 7
2 3
1 8
"# => r#"2
0
3
"#,
}

fn solve(src: &str) {
    input! {
        source = src,
        n: usize,
        q: usize,
        s: chars,
        lr: [(usize, usize); q],
    }

    // let mut ans:String = "".to_string();

    let mut t = vec![0; n];
    for i in 0..n-1 {
        t[i + 1] = t[i] + if s[i] == 'A' && s[i + 1] == 'C' { 1 } else { 0 };
    }
    // println!("{:?}", t);

    for i in 0..q {
        // println!("l({})={}, r({})={}", lr[i].0, t[lr[i].0-1], lr[i].1, t[lr[i].1-1]);
        // ans = format!("{}{}\n", ans, t[lr[i].1-1] - t[lr[i].0-1]);
        println!("{}", t[lr[i].1-1] - t[lr[i].0-1]);
    }

    // ans.to_string()
}

Measured memory_bytes: 8956