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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

int main() {
	int K, T; cin >> K >> T;
	vi a(T); rep(i, T) cin >> a[i];

	int m = *max_element(ALL(a));
	cout << max(0, m - 1 - (K - m)) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;
int main(){
    int n,m,lyq=0,ans;
    cin>>n>>m;
    ans=m/n;
    for(int i=1;i<=sqrt(m+1);i++){
    	if(i>ans)break;
    	if(m%i==0)lyq=max(lyq,i);
        if(m%i==0&&m/i<=ans)lyq=max(lyq,m/i);  	
	}
	cout<<lyq;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()
diff = ''

if N % 2 !=0:
  print('No')
else:
  half = int(N / 2)
  
  for i in range(half):
    diff += S[i]
  
  diff += diff
  
  if S == diff:
    print('Yes')
  else:
    print('No')


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

int main(){
  int N;
  cin >> N;
  
  int ans = 0;
  for(int i = 1; i <= N; i++){
      int cnt = 0;
    for(int j = 1; j <= N; j++){
      if(i % j == 0){
        cnt++;
      }
    }
    if(cnt == 8 && i % 2 == 1) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 6000000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int x,y;
	cin>>x>>y;
	if( x + y <= 1){
		cout<<"Brown"<<endl;
	}
	else if( abs(x-y) <= 1){
		cout<<"Brown"<<endl;
	}
	else{
		cout<<"Alice"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
arr = list(map(int, input().split()))
n,k = arr[0], arr[1]
arr2 = []
for i in range(0, n):
  arr2.append(i+1)

di = []
snax = []
  
for i in range(0, k):
  temp = []
  di.append(int(input()))
  temp = list(map(int, input().split()))
  for i in temp: snax.append(i)

count = 0
  
for i in arr2:
  if not(i in snax): count+= 1
    
print(count)

Measured memory_bytes: 9144
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	ll ans;
	if(n%2==0)
	{
		ans=n/2;	
	}
	else
	{
		ans=(n/2)+1;
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int a,b;
cin >> a >> b;
if(a==1) a+=13;
if(b==1) b+=13;
if(a>b) {
  cout << "Alice" << endl;
} else if(a<b) {
  cout << "Bob" << endl;
} else {
  cout << "Draw" << endl;
}
return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

ll N;

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

  std::cin >> N;

  int res = 0;

  for(ll x=2;x*x<=N;++x){
      int t = 0;

      while(N % x == 0){
          t += 1;
          N /= x;
      }

      int s = 0;

      for(;s+1<=t;++s){
          t -= s + 1;
      }

      res += s;
  }

  if(N > 1){
      res += 1;
  }

  std::cout << res << std::endl;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define foro(i, n) for(i=0; i<n; i++)
#define forl(i, n) for(i=1; i<=n; i++)
#define x first
#define y second
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 1e18 + 1;

int main()
{
	int i, j, k, l, tmp;
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	ll a, b, n;
	cin >> n >> a >> b;
	printf("%lld\n", (n/(a+b)) * a + min(n%(a+b), a));
}


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

int main()
{	
	char s[1001];
	
	cin >> s;

	int i = 0;
	while (s[i]) {
		int c = (((int)s[i] - 42) % 26) + 65;
		cout << (char) c;
		i++;
	}

	cout << endl;	

	return 0;
}



Measured memory_bytes: 3088
import java.util.*;

class Main{
	public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      int argInt[] ={a,b,c};
     
      int fiveCount = 0;
      int sevenCount = 0;
       
      for(int arg: argInt){
      	if(arg == 5){
          fiveCount++;
        }
        if( arg == 7){
          sevenCount++;
        }
      }
      
      if(fiveCount == 2 || sevenCount == 1){
        System.out.print("YES");
      }else{
        System.out.print("NO");
      }
    }
}

Measured memory_bytes: 20820
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>

#define all(v) v.begin(), v.end()
typedef long long ll;
#define rep(i, z, n) for(ll i = z; i < n; i++)
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N - 1);
    rep(i, 0, N) cin >> A.at(i);
    rep(i, 0, N) cin >> B.at(i);
    rep(i, 0, N - 1) cin >> C.at(i);
    int sum = 0;
    int con = - 1;
    rep(i, 0, N){
        if(A.at(i) == con + 1) sum += C.at(A.at(i) - 2);
        sum += B.at(A.at(i) - 1);
        con = A.at(i);
    }
    cout << sum << endl;
}


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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
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;
}

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) (x).erase(unique(all(x)), (x).end())
//#define int long long

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;

/* main */
signed main(void)
{
    // string s;
    // int cnt = 0;
    // cin >> s;
    // for (int i = 0; i < s.size(); i++)
    // {
    //     if ((s[i] == '0' && s[i + 1] == '1') || (s[i] == '1' && s[i + 1] == '0'))
    //     {
    //         s.erase(i, 2);
    //         cnt += 2;
    //         i = 0;
    //     }
    // }
    // if ((s[0] == '0' && s[1] == '1') || (s[0] == '1' && s[1] == '0'))
    // {
    //     cnt += 2;
    // }
    // cout << cnt << endl;
    string s;
    cin >> s;
    int cnt1, cnt0;
    cnt1 = count(all(s), '1');
    cnt0 = count(all(s), '0');
    cout << min(cnt1, cnt0) * 2 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <climits>

using namespace std;

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

const ll MOD = 1000000007;
const ll INF = LLONG_MAX;
const ll MAX_N = 100000;

int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };


int main() {
	int n, k, a[200001]{}, ans = 0;
	set<int> st;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		a[t]++;
		st.insert(t);
	}
	sort(a, a + n + 1);
	int siz = st.size();
	for (int i = 0; siz > k;i++) {
		if (a[i] == 0)continue;
		ans += a[i];
		siz--;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10368
#include <iostream>
#include <cmath>

using namespace std;
void func(int);
bool Check(char,char);



char board[4][4][4];
char data[9][4];
bool used[9];

int cnt;

int main(){
  int n;

  string str;
  cin >> n;
  while(n){
    n--;

    for(int i=0;i<4;i++)
      for(int j=0;j<4;j++)
	for(int k=0;k<4;k++)
	  board[i][j][k]='X';


    for(int i=0;i<9;i++){
      used[i]=false;
      cin >> str;
      for(int j=0;j<4;j++){
	data[i][j]=str[j];
      }
    }

    cnt=0;
    func(0);
    cout << cnt << endl;

  }
  return 0;
}




const int dy[9]={1,1,1,2,2,2,3,3,3};
const int dx[9]={1,2,3,1,2,3,1,2,3};

void func(int d){
  if(d==9){
    cnt++;
    return;
  }
  
  int y=dy[d],x=dx[d];
  for(int id=0;id<9;id++){
    if(used[id])continue;
    used[id]=true;

    for(int i=0;i<4;i++){

      for(int j=0;j<4;j++)board[y][x][j]=data[id][(i+j)%4];
      bool r1=Check(board[y-1][x][2],board[y][x][0]);
      bool r2=Check(board[y][x-1][1],board[y][x][3]);
      if(r1==true&&r2==true) func(d+1);
      
    }
    used[id]=false;
  }
  

}

bool Check(char a,char b){
  if(a=='X'||b=='X') return true;
  return (abs(a-b) == abs('A'-'a'));
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a7=1000000007;
ll inf=100000000000000000;

int main()
{
  ll n;cin>>n;
  ll x[n],y[n];
  for(ll i=0;i<n;i++){
    cin>>x[i]>>y[i];
  }
  double sum=0;
  for(ll i=0;i<n;i++){
    for(ll j=i+1;j<n;j++){
      sum+=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
    }
  }
  cout<<setprecision(20)<<2*sum/n<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  map<int, pair<int, int>> pos;     //pos[i]は、時刻iの座標を指す first -> x  second -> y
  queue<int> tq;                                   //time queue
  int num, t, x, y;                                    //座標の個数　時間　x座標　y座標
  bool capable = true;                            //可能であるか　初期は当然可能である
  cin >> num;
  
  /*時刻0のデータを入力  必須*/
  tq.push(0);
  pos[0].first = pos[0].second = 0;

  /*その他のデータを入力*/
  while(cin >>  t){
    tq.push(t);
    cin >> pos[t].first >> pos[t].second;
  }
  
  int start = tq.front();  tq.pop();   //開始座標(0,0)のデータを取得   以降開始座標はwhileで決定
  int end, inter;                                       //到達時刻end 時間間隔inter
  int diff_x, diff_y;                                 //x座標、y座標の差
  while(!tq.empty()){                          //目的先がある限り～
    end  = tq.front();  tq.pop();         //目的先の取得
   
    inter = end - start;
    diff_x = pos[end].first - pos[start].first;  
    diff_y = pos[end].second - pos[start].second;  

    /*目的地まで最短で行けるか　行ける場合、余った時間をうまくつぶせるか*/
    if( (inter - diff_x - diff_y) < 0 || (inter - diff_x - diff_y) % 2 == 1)     
      capable = false;
    start = end;                   //次の開始基準は現在のend
  }

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

}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;

int main()
{
   set<string> s;
   int n;
   cin>>n;
   int i;
   for(i=0;i<n;i++)
   {
       string x;
       cin>>x;
       s.insert(x);
   }
   cout<<s.size();
  



}


Measured memory_bytes: 19228
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int num;
		int answer;

		while(true){
			num = sc.nextInt();

			if(num == 0){break;}
			answer = 0;
			while(num > 1){
				if(num % 2 == 0){
					num /= 2;
				}else{
					num = num * 3 + 1;
				}
				answer++;
			}
			System.out.println(answer);

		}
	}
}

Measured memory_bytes: 17196
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <functional>
#include <map>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif


int main(){
	int q, com;
	std::string key;
	long x;
	std::map<std::string, long> m;
	std::string L, R;
	std::string buf;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif

#if INPUT_FROM_FILE
	ifs >> q;
#else
	std::cin >> q;
#endif
	
	for(int i = 0; i < q; i++){
#if INPUT_FROM_FILE
		ifs >> com;
#else
		std::cin >> com;
#endif
		if(com == 0){
#if INPUT_FROM_FILE
			ifs >> key >> x;
#else
			std::cin >> key >> x;
#endif
			m[key] = x;
		}
		else if(com == 1){
#if INPUT_FROM_FILE
			ifs >> key;
#else
			std::cin >> key;
#endif
			if(m.count(key) > 0){
				std::cout << m[key] << std::endl;
			}
			else{
				std::cout << "0" << std::endl;
			}
		}
		else if(com == 2){
#if INPUT_FROM_FILE
			ifs >> key;
#else
			std::cin >> key;
#endif
			m.erase(key);
		}
		else{
#if INPUT_FROM_FILE
			ifs >> L >> R;
#else
			std::cin >> L >> R;
#endif
			std::map<std::string, long>::iterator it = m.lower_bound(L);
			std::map<std::string, long>::iterator end = m.upper_bound(R);
			for(; it != end; it++){
				std::cout << it->first << " " << it->second << std::endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 27752
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int mod = n % 1000;
		int ans = 1000 - mod;
		ans %= 1000;
		System.out.println(ans);
	}
}


Measured memory_bytes: 35776
<?php
ini_set("memory_limit", "-1");

function Merge($left, $mid, $right) {
    global $A, $cnt;
    $cnt += ($right - $left);

    $n1 = $mid - $left;
    $n2 = $right - $mid;
    
    for ($i = 0; $i < $n1; $i++) {
        $L[] = $A[$left+$i];
        $R[] = $A[$mid+$i];
    }
    if ($n2 > $n1) $R[] = $A[$right-1];

    $L[$n1] = 1000000001;
    $R[$n2] = 1000000001;

    $i = 0;
    $j = 0;
    for ($k = $left; $k < $right; $k++) {
        if ($L[$i] <= $R[$j]) {
            $A[$k] = $L[$i++];
        } else {
            $A[$k] = $R[$j++];
        }
    }
}

function Merge_Sort($left, $right) {
    if ($left + 1 < $right) {
        $mid = (int)(($left + $right) / 2);
        Merge_Sort($left, $mid);
        Merge_Sort($mid, $right);
        Merge($left, $mid, $right);
    }
}

$input = STDIN;

$n = (int)trim(fgets($input));
$A = array_map('intval', explode(' ', trim(fgets($input))));

$cnt = 0;
Merge_Sort(0, $n);

$ans = implode(" ", $A);
print("{$ans}\n{$cnt}\n");


Measured memory_bytes: 167044
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/PCK/Prelim/0357?year=2017

#include <bits/stdc++.h>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    cout << (a + b) / 2 << endl;
    return 0;
}

/*
 *
 */


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

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, M = get_ints
A = get_ints

ax = A.map { |a| a % M }

def cumulative_sum(arr)
  arr.reduce([0]) do |prev, cur|
    prev.push(prev.last + cur)
    prev
  end
end

ruiseki = cumulative_sum(ax).map { |x| x % M }

count = 0

hash = Hash.new { |h, k| h[k] = 0 }
ruiseki[1..].each do |x|
  count += hash[x]
  hash[x] += 1
end
count += hash[0]

puts count


Measured memory_bytes: 25596
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 998244353;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}

int n, q, a[100005],b[100005],c[100005];
ll sum;

int main(){
	cin >> n;
	repn(i, n){
		int aa; cin >> aa; a[aa]++; sum += aa;
	}
	cin>>q;
	rep(i, q){
		cin>>b[i]>>c[i];
		sum -= 1LL*b[i]*a[b[i]];
		sum += 1LL*c[i]*a[b[i]];
		a[c[i]] += a[b[i]];
		a[b[i]] = 0;
		cout<<sum<<'\n';
	}
}


Measured memory_bytes: 4716
#include<iostream>
using namespace std;
int main()
{
  int x,y,z;
  cin>>x>>y>>z;
  if(x<=y)
  {
    cout<<z<<"\n";
  }
  else
  {
    int r=x/y;
    int r1=x%y;
    if(r1!=0)
    {
      cout<<z*(r+1)<<"\n";
    }
    else if(r1==0)
    {
      cout<<z*r<<"\n";
    }
  }
}

Measured memory_bytes: 3632
#pragma gcc optimize("Ofast")

#include "bits/stdc++.h"
using namespace std;
typedef int64_t lld;
typedef pair<int,int> pii;
typedef pair<lld,lld> pll;
typedef pair<int,pll> pip;
typedef pair<pll,int> ppi;
typedef pair<lld,pll> plp;
typedef pair<pll,lld> ppl;
typedef pair<pll,pll> ppp;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
inline void input(int &_x) {
    _x = 0;
    int _tmp = 1; char _tc = getchar();
    while((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
    if(_tc == '-') _tc = getchar(), _tmp = -1;
    while(_tc >= '0' && _tc <= '9') _x = _x*10+(_tc-48), _tc = getchar();
    _x *= _tmp;
}
inline void output(int _x) {
    char _buff[20]; int _f = 0;
    if(_x == 0)putchar('0');
    while(_x > 0)
    {
        _buff[_f++] = _x%10+'0';
        _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
        putchar(_buff[_f]);
    putchar('\n');
}
template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
 }
#ifdef erd1
    #define pprint(x) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<(#x)<<"="<<(x)<<endl
#else
    #define pprint(x)
#endif

// code starts here
vector<int> v[2], a;
const int N = 2000;
int ips[2][N][N+1]={}, dp[N+1][N+1]={}; // ips[k][i][j] = |{x|v[k][x<=i]<v[!k][j]}|
signed main(){
    int n;
    cin >> n;
    for(int i = 0; i < 2*n; i++){
        char c; int x;
        cin >> c >> x;
        v[c=='B'].pb(i);
        a.pb(x);
    }
    sort(all(v[0]), [](int x, int y){ return a[x] < a[y]; });
    sort(all(v[1]), [](int x, int y){ return a[x] < a[y]; });
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            ips[1][i][j+1] = ips[1][i][j] + (v[1][i] < v[0][j]),
            ips[0][i][j+1] = ips[0][i][j] + (v[0][i] < v[1][j]);
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            dp[i+1][j+1] = min(dp[i][j+1]+ips[1][i][j+1], dp[i+1][j]+ips[0][j][i+1]);
    for(int i = 0; i < n; i++)
        for(int j = 0; j < i; j++)
            (dp[n][n]+=(v[0][j] > v[0][i]))+=(v[1][j] > v[1][i]);
    cout << dp[n][n] << endl;
}


Measured memory_bytes: 47232
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

Bcon = [0] * (N + 1)
res = 0
p = 0
for n in range(N):
    while p <= N - 1 and B[n] > A[p]:
        p += 1
    Bcon[n + 1] = p + Bcon[n]
    
p = 0
for n in range(N):
    while p <= N - 1 and C[n] > B[p]:
        p += 1
    res += Bcon[p]
    
print(res)

Measured memory_bytes: 24052
#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

int N;
vector< tuple<string, int, int> > Rest;

signed main()
{
    cin >> N;
    REP(i, N) {
        string s;
        int p;
        cin >> s >> p;
        Rest.push_back(make_tuple(s, -p, i+1));
    }
    SORT(Rest);
    REP(i, N) {
        printf("%lld\n", get<2>(Rest[i]));
    }
    return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
x = [a, b, c, d, e]
k = int(input())
count = 0
for i in range(0, 5):
  for j in range(0, 5):
    if int(x[i]) > int(x[j]):
      q = int(x[i]) - int(x[j])
      if q > k:
        count = 1
    elif int(x[i]) < int(x[j]):
      p = int(x[j]) - int(x[i])
      if p > k:
        count = 1
if count == 1:
  print(':(')
else:
  print('Yay!')

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2e3+10;
int n,a[N],ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			ans+=max(0,(int)(lower_bound(a+1+j,a+1+n,a[i]+a[j])-upper_bound(a+1+j,a+1+n,a[j]-a[i])));
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <deque>
#include <algorithm>
#include <cmath>
#include <climits>
using namespace std;

int main()
{
    ios_base::sync_with_stdio (false);
    int n,k;
    cin >> n >> k;
    deque<long long> heights;
    deque<long long> costs;
    costs.push_back(0);
    long long height;
    cin >> height;
    heights.push_back(height);
    for (int i =1; i < n; ++i){
        cin >> height;
        heights.push_back(height);
        costs.push_back(costs[0] + abs(heights[min(i, k)] - heights[0]));
        for (int j = 1; j < min(i,k); ++j){
            costs[min(i,k)] = min(costs[j] + abs(heights[min(i,k)] - heights[j]),
            costs[min(i,k)]);
        }
        if (i >= k){
            costs.pop_front();
            heights.pop_front();
        }
    }
    cout << costs.back();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  vi e_sum(n+1, 0);
  rep(i,n) e_sum[i+1] = e_sum[i] + (s[i] == 'W' ? +1 : 0);

  int ans = n;
  rep(i, n) {
    int west_cost = e_sum[i];
    int east_cost = (n - i - 1) - (e_sum[n] - e_sum[i+1]);
    chmin(ans, west_cost + east_cost);
  }
  cout << ans << endl;
}


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

int main()
{
    int n;
    std::string s,t,res;
    std::cin >> n;
    std::cin >> s >> t;
    for(int i = 0;i < n;i++){
        res.push_back(s[i]);
        res.push_back(t[i]);
    }
    std::cout << res << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 500005;
  const int M = MAXN * 100;
 int n,q,tot;
 int a[MAXN];
int T[M],lson[M],rson[M],c[M];
 int build(int l,int r)
{
    int root = tot++;
    c[root] = 0;
      if(l != r)
     {
        int mid = (l+r)>>1;
         lson[root] = build(l,mid);
          rson[root] = build(mid+1,r);
      }
      return root;
 }
  int update(int root,int pos,int val)
  {
      int newroot = tot++, tmp = newroot;
      c[newroot] = c[root] + val;
      int l = 1, r = n;
      while(l < r)
      {
          int mid = (l+r)>>1;
          if(pos <= mid)
          {
              lson[newroot] = tot++; rson[newroot] = rson[root];
              newroot = lson[newroot]; root = lson[root];
              r = mid;
          }
          else
          {
              rson[newroot] = tot++; lson[newroot] = lson[root];
              newroot = rson[newroot]; root = rson[root];
              l = mid+1;
          }
          c[newroot] = c[root] + val;
      }
      return tmp;
  }
  int query(int root,int pos)
  {
      int ret = 0;
      int l = 1, r = n;
      while(pos < r)
      {
          int mid = (l+r)>>1;
          if(pos <= mid)
          {
              r = mid;
              root = lson[root];
          }
          else
          {
             ret += c[lson[root]];
              root = rson[root];
              l = mid+1;
          }
      }
      return ret + c[root];
  }

  int main()
 {
      //freopen("in.txt","r",stdin);
      //freopen("out.txt","w",stdout);
      cin>>n>>q;
         tot = 0;
          for(int i = 1;i <= n;i++)
              scanf("%d",&a[i]);
         T[n+1] = build(1,n);
          map<int,int>mp;
          for(int i = n;i>= 1;i--)
         {
             if(mp.find(a[i]) == mp.end())
            {
                 T[i] = update(T[i+1],i,1);
             }
             else
             {
                int tmp = update(T[i+1],mp[a[i]],-1);
               T[i] = update(tmp,i,1);
            }
            mp[a[i]] = i;
        }
        while(q--)
        {
            int l,r;
            scanf("%d%d",&l,&r);
            printf("%d\n",query(T[l],r));
        }

     return 0;
 }


Measured memory_bytes: 253008
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, k, c;
  string s;
  cin >> n >> k >> c >> s;
  vi l(k), r(k);
  int j = 0;
  rep(i, n) {
    if(s[i] == 'o') {
      l[j] = i;
      i += c;
      j++;
      if(j == k) break;
    }
  }
  j = k - 1;
  for(int i = n - 1; i >= 0; i--) {
    if(s[i] == 'o') {
      r[j] = i;
      i -= c;
      j--;
      if(j == -1) break;
    }
  }
  rep(i, k) if(l[i] == r[i]) cout << l[i] + 1 << endl;
}

Measured memory_bytes: 3332
#include <bits/stdc++.h>
#define ll long long
#define f(i, x, n) for(int i = x; i < n; i++)
#define dbg(x) cout << x << endl
#define dbg2(x, y) cout << x << "  " << y << endl
#define dbg3(x, y, z) cout << x << "  " << y << "  " << z << endl
#define mod 1000000007
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    int p, n, a, prev, max_diff = 0;
    cin >> p >> n;
    cin >> prev;
    int first = prev;
    f(i, 1, n){
        cin >> a;
        if(max_diff < a - prev) max_diff = a - prev;
        prev = a;
    }
    if(first + p - a > max_diff) max_diff = first + p - a;
    cout << p - max_diff << endl;
    
}

Measured memory_bytes: 256
numbers = list(map(int, input().split(" ")))

# Check odd numbers
odd_num = 0
for i in numbers:
    if i % 2 != 0:
        odd_num += 1

max_ = max(numbers)
numbers.remove(max_)
min_ = min(numbers)
numbers.remove(min_)
middle = numbers[0]

def even(a, b, c, count=0): # a <= b <= c
    count += (c - b) // 2 + (c - a) // 2
    print(count)
    
# # of odd is 0
if odd_num == 0:
    even(min_, middle, max_)

# # of odd is 1    
elif odd_num == 1:
    if max_ % 2 == 0:
        max_ += 1
    if middle % 2 == 0:
        middle += 1
    if min_ % 2 == 0:
        min_ += 1
    even(min_, middle, max_, 1)

# # of odd is 2
elif odd_num == 2:
    if max_ % 2 != 0:
        max_ += 1
    if middle % 2 != 0:
        middle += 1
    if min_ % 2 != 0:
        min_ += 1
    even(min_, middle, max_, 1) 

# # of odd is 3
else:
    even(min_, middle, max_)

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

using namespace std;

long long dp[105][100005];

long long MOD = 1000000007;

int main() {
    int n, k;
    scanf("%i%i", &n, &k);
    dp[0][0] = 1;
    for (int x = 1; x <= n; x++) {
        long long a;
        scanf("%lli", &a);
        for (int y = 0; y <= k; y++) {
            dp[x][y] += dp[x-1][y] - (y-a > 0 ? dp[x-1][y-a-1] : 0);
            if (y > 0) dp[x][y] += dp[x][y-1];
            dp[x][y] %= MOD; dp[x][y] += MOD; dp[x][y] %= MOD;
        }
    }
    printf("%lli\n", dp[n][k] % MOD);
}


Measured memory_bytes: 81852
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
 
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; }
 
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b)* b; }
 
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
 
inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}
 
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int N,A,B,C;
vi L;
int rec(int i, int a, int b, int c){
  if(i==N){
    if(!a||!b||!c) return INF;
    return abs(A-a)+abs(B-b)+abs(C-c);
  }
  int res=rec(i+1,a,b,c);
  
  chmin(res,rec(i+1,a+L[i],b,c)+(a?10:0));
  chmin(res,rec(i+1,a,b+L[i],c)+(b?10:0));
  chmin(res,rec(i+1,a,b,c+L[i])+(c?10:0));
  
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n,y; cin>>n>>y;
  
  rep(i,n+1){
    rep(j,n+1){
      int k=(y-10000*i-5000*j)/1000;
      if(k<0) continue;
      if(i+j+k==n){
        cout<<i<<" "<<j<<" "<<k<<endl;
        return 0;
      }
    }
  }
  
  cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  int k; cin >> k;
  int ans = 0;
  for(int i = 0; i < n; ++i){
    int p; cin >> p;
    ans += min(p,abs(k-p));
  }
  cout << (ans<<1) << endl;
  return 0;
}

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

int main() {
  int n, m, sum =0;
  int t[105];
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> t[i];
    sum += t[i];
  }
  cin>>m;
  for(int i=0;i<m;i++){
    int p, x;
    cin >> p >> x;
    cout << sum + x - t[p-1]<<endl;
  }
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    int arr[n], garbo[n];
    for(int i = 0; i < n; ++i){
        cin >> arr[i];
        garbo[i] = arr[i];
    }
    sort(garbo, garbo + n, greater<int>());
    for(int i = 0; i < n; ++i){
        if(arr[i] != garbo[0])cout << garbo[0] << endl;
        else cout << garbo[1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	while(true){
		cin>>n;
		if(n==0)	return 0;
		vector<int> card(2*n);
		int in;
		for(int i=0;i<n;i++){
			cin>>in;
			card[in-1]=1;
		}
		vector<vector<int> > data(2);
		for(int i=0;i<2*n;i++){
			if(card[i])	data[0].push_back(i+1);
			else 	data[1].push_back(i+1);
		}
		int current=0;
		int turn=0;
		while(true){
			bool flag=true;
			for(vector<int>::iterator it=data[turn].begin();it!=data[turn].end();it++){
				if(*it>current){
					flag=false;
					current=*it;
					data[turn].erase(it);
					break;
				}
			}
			if(flag)	current=0;
			if(data[turn].size()==0)	break;
			turn^=1;
		}
		cout<<(int)data[1].size()<<endl;
		cout<<(int)data[0].size()<<endl;
	}	
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<bool> dp(110);
	dp[0]=true;
	rep(i,n){
		if(dp[i]){
			dp[i+4]=true;
			dp[i+7]=true;
		}
	}
	if(dp[n]) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if b - a > k or c - a > k or d - a > k or e - a > k or c - b > k or d - b > k or e - b > k or d - c > k or e - c > k or e - d > k:
    print(":(")
else:
    print("Yay!")



Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int h,n;
  cin >> h >> n;
  int sum = 0;
  for(int i = 0;i < n;i++){
    int a;
    cin >> a;
    sum += a;
  }

  if(sum < h)cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  string s;
  cin>>s;
  if(s.size()!=a+b+1){
    cout<<"No"<<endl;
    return(0);
  }
  for(int i=0;i<a;i++){
    if('0'>s[i]||s[i]>'9'){
      cout<<"No"<<endl;
      return(0);
    }
  }
  if(s[a]!='-'){
    cout<<"No"<<endl;
    return(0);
  }
  for(int i=a+1;i<=a+b;i++){
      if('0'>s[i]||s[i]>'9'){
        cout<<"No"<<endl;
        return(0);
      }
  }
  cout<<"Yes"<<endl;
  return(0);
}

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

const int maxn = 4010, mod = 1e9 + 7;

int n, f[maxn][maxn];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  for ( int i = 0; i < n; ++ i) {
    cin >> a[i] >> b[i];
    f[2000 - a[i]][2000 - b[i]] ++;
  }
  for ( int i = 1; i <= 4000; ++ i) {
    f[0][i] = (f[0][i] + f[0][i-1]) % mod;
  }
  for ( int i = 1; i <= 4000; ++ i) {
    f[i][0] = (f[i][0] + f[i-1][0]) % mod;
    for ( int k = 1; k <= 4000; ++ k) {
      f[i][k] = (f[i][k] + (f[i - 1][k] + f[i][k - 1]) % mod) % mod;
    }
  }
  int ret = 0;
  for ( int i = 0; i < n; ++ i) {
    ret = (ret + f[a[i]+2000][b[i]+2000]) % mod;
  }
  function<int(int, int)> _pow = [&](int x, int n) {
    int ret = 1;
    for ( ; n; n >>= 1, x = 1LL * x * x % mod) {
      if( n & 1) {
        ret = 1LL * ret * x % mod;
      }
    }
    return ret;
  };
  vector<int> fac(maxn << 1);
  vector<int> ifac(maxn << 1);
  for ( int i = fac[0] = 1; i <= 8000; ++ i) {
    fac[i] = 1LL * fac[i - 1] * i % mod;
  }
  ifac[8000] = _pow(fac[8000], mod - 2);
  for ( int i = 8000; i; -- i) {
    ifac[i - 1] = 1LL * ifac[i] * i % mod;
  }
  function<int(int, int)> C = [&](int n, int m) {
    return 1LL * fac[n] * ifac[m] % mod * ifac[n-m] % mod;
  };
  for ( int i = 0; i < n; ++ i) {
    ret = (ret - C(a[i]+b[i] << 1, a[i] << 1) + mod) % mod;
  }
  cout << (1LL * ret * (mod + 1 >> 1) % mod) << "\n";
  return 0;
}

Measured memory_bytes: 64640
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const int mnx = 3e5 + 9;
const int mod = 1e9 + 7;

string x;
ll cnt;

int main(){

cin >> x;
int ans = x.size(), s = 0;
for(int i=0; i<x.size(); i++) {
    if (x[i] == 'S') s++;
    else {
        if(s > 0) {
            ans -= 2;
            s--;
        }
    }
}
cout << ans;

return 0;

}















Measured memory_bytes: 640
n = gets.to_i
a = gets.split().map(&:to_i)
c = {}
c[a[0]] = 1
1.upto(n-2) do |i|
	t = {}
	c.each do |k, v|
		ti = k + a[i]
		t[ti] = (t[ti] || 0) + v if ti <= 20
		ti = k - a[i]
		t[ti] = (t[ti] || 0) + v if ti >= 0
	end
	c = t
end
p c[a[-1]] || 0

Measured memory_bytes: 8676
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
int a[MAXN];
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) read(a[i]);
    int f = 0;
    int ans = N;
    for(int i = 2 ; i <= N ; ++i) {
	if(!f) {
	    if(a[i] > a[i - 1]) f = 1;
	    else if(a[i] < a[i - 1]) f = -1;
	    --ans;
	}
	else {
	    if(a[i] > a[i - 1] && f == 1) --ans;
	    else if(a[i] < a[i - 1] && f == -1) --ans;
	    else if(a[i] == a[i - 1]) --ans;
	    else f = 0;
	}
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001

int main(void) {
	int r,d,x; cin >> r >> d >> x;
	rep(i,10){
		x = r*x-d;
		cout << x << endl;
	}

}




Measured memory_bytes: 256
n = int(input())
r_list = [input() for i in range(n)]
a_list = [0,0,0,0]

sult = ["AC","WA","TLE","RE"] 

for r in r_list:
  if r == sult[0]:
    a_list[0] += 1
  elif r == sult[1]:
    a_list[1] += 1
  elif r == sult[2]:
    a_list[2] += 1
  elif r == sult[3]:
    a_list[3] += 1

for i,o in enumerate(sult):
  print(o + " x " + str(a_list[i]))


Measured memory_bytes: 79360
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll MOD = 1e9+7;

int main(){
  string s;
  cin>>s;
  int k=753;
  int mi=1000;
  for(int i=2;i<s.size();i++){
    int t=0;
    t+=(s[i-2]-'0')*100;
    t+=(s[i-1]-'0')*10;
    t+=(s[i]-'0');
    mi=min(mi,abs(t-k));
  }
  cout<<mi<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		int[] b = new int[n-1+2];
		b[0]=10000000;
		b[n-1+2-1]=100000000;
		for(int i=1;i<n-1+2-1;i++){
			b[i]=scanner.nextInt();
		}
		int ans=0;
		int pre = b[0];
		for(int i=1;i<n-1+2;i++){
			int now = b[i];
			ans+=Math.min(pre, now);
			pre=now;
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 21204
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    n = int(input())
    a = int(input())
    if n%500<=a:
        print('Yes')
    else:
        print('No')
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 39916
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define INF (1 << 31) - 1

int main() {
  int A, B;
  cin >> A >> B;
  cout << A*B << endl;
}

Measured memory_bytes: 3596
#include<stdio.h>

int main(){
	int a,b,c,d,e,m,n;
	while(scanf("%d %d",&a,&b)!=EOF){
		if(a<b){c=b;d=a;}
		else{c=a;d=b;}
		while(1){
			if(c%d==0){
				m=d;
				n=a/m*b;
				break;}
			else{
				e=c;
				c=d;
				d=e%d;}}
		printf("%d %d\n",m,n);}
	return 0;
}

Measured memory_bytes: 0
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;

immutable long INF = 1L << 59;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto K = s[2];
    auto A = readln.split.map!(to!long).array;

    auto dp = new long[][](2, N);
    dp[0] = A.dup;
    int cur = 0, tar = 1;

    foreach (i; 1..K) {
        dp[tar].fill(-INF);
        auto q = new long[](2*N+10);
        int x = N/2;
        int y = N/2;
        foreach (j; i..N) {
            int a = j - M - 1;
            int b = j - 1;
            if (a >= 0 && x < y && q[x] == a) x++;
            while (x < y && dp[cur][q[y-1]] < dp[cur][b]) y--;
            q[y++] = b;
            dp[tar][j] = dp[cur][q[x]] + A[j] * (i + 1);
        }
        swap(cur, tar);
    }

    dp[cur].reduce!max.writeln;
}


Measured memory_bytes: 21088