akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long A, long long B){
    REP(i, 1500){
        if(i==0) continue;
        ll x1 = (ll) floor(i*0.08), x2 = (ll) i/10;
        if(x1 ==A && x2 == B){
            cout<<i<<endl;
            return;
        }
    }
    cout<<-1<<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

int main() {
  int a,cnt,cntt;cin >> a;
  cnt = 0;
  for(int i=1;i<a+1;i++){
    cntt = 0;
    for(int j=1;j<i+1;j++){
      if(i%j==0){
        cntt++;
      }else{
        continue;
      }
    }
    if(cntt==8 && i%2!=0)cnt++;
  }

  cout << cnt << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  
  int count = 0;
  int max = 101;
  for (int i = 0; i < N; i++) {
    if (A.at(i) < max) {
      count++;
      max = A.at(i);
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int N =  200200;
const int Mod = 1e9 + 7;

int a[N];
int b[N];
char s[N];

int mul(int x,int y){
    return (ll) x * y % Mod;
}

int main()
{
    int n;  scanf("%d%s", &n, s);

    for(int i = 0; i < 2 * n; i++)  a[i] = (s[i] == 'B');

    int Open = 0;

    for(int i = 0; i < 2 * n; i++)
    {
        int B = (Open & 1);

        b[i] = (a[i] ^ B);

        if(b[i])    Open++;
        else        Open--;

        if(Open < 0)    return 0 * puts("0");
    }

    if(Open > 0)    return 0 * puts("0");

    int Ans = 1;

    for(int i = 1; i <= n; i++) Ans = mul( Ans, i);

    int Close = 0;

    for(int i = 2 * n - 1; ~i; --i)
    {
        if(b[i])    Ans = mul( Ans, Close), Close--;
        else        Close++;
    }

    cout << Ans << endl;
}


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

using namespace std;
typedef long long LL;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	vector<int> A;

	int denied = 0;
	for(int i=0; i<N; i++){
		int a; cin >> a;
		if((a % 2) == 0){
			if((a % 3) != 0 && (a % 5) != 0){
				denied = 1;
				break;
			}
		}
	}
	if(denied == 1){
		printf("DENIED\n");
	}
	else{
		printf("APPROVED\n");
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  long long sum=0;
  vector<int> num(100001);
  for(int i=0;i<N;i++){
    int A;
    cin >> A;
    sum+=A;
    num.at(A)++;
  }
  int Q;
  cin >>  Q;
  for(int i=0;i<Q;i++){
    int B,C;
    cin >> B >> C;
    sum+=(C-B)*num.at(B);
    num.at(C)+=num.at(B);
    num.at(B)=0;
    cout << sum << endl;
  }
}
  

Measured memory_bytes: 3764
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())

#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7:合同式の法
 
int main(){
    ll n;
    cin >> n;

    ll count=0;
    REP(i,n+1){
        count += i;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3628
package main

import (
	"fmt"
	"os"
	"strconv"
	"bufio"
	"strings"
)

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

var ans int

func check(sum int, s string) {
	num, _ := strconv.Atoi(s)
	ans += sum + num
	if len(s) > 1 {
		for i:=1; i<len(s); i++{
			left, _ := strconv.Atoi(s[:i])
			check(sum+left, s[i:])
		}
	}
}

func main(){
	var S string
	fmt.Scan(&S)
	check(0, S)
	fmt.Println(ans)
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  double n,m,sum=0;
  cin>>n>>m;
  vector<int> A(n);
  for(int i=0;i<n;i++){
    cin>>A[i];
    sum+=A[i];
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  double flag=sum/(4*m);
  if(A[m-1]>=flag)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    ll x, k, d;
    cin >> x >> k >> d;
    x=abs(x);
    ll moves=x/d;
    if(k<moves)
        cout << x-((ll)k*d) << endl;
    else{
        k-=moves;
        ll pos=x-((ll)moves*d);
        if(k&1)
            cout << abs(pos-d) << endl;
        else
            cout << pos << endl;
    }

	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

int main () {
  int N, K; cin >> N >> K;
  vi A(N); rep(i,N) cin >> A[i];

  int i1;
  rep(i,N) {
    if(A[i] == 1) {
      i1 = i;
      break;
    }
  }

  int cnt_L, cnt_R;
  cnt_L = (i1+(K-2))/(K-1);
  int L_used = (K-1)*(cnt_L-1) + K;
  cnt_R = ((N-L_used)+(K-2))/(K-1);
  
  cout << cnt_L + cnt_R << endl;
  return 0;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string inp;
    cin >> inp;
    bool ans = false;
    for(int i=0; i<inp.size(); i++){
        if( (inp[i] == 'R' && i%2 == 1) || (inp[i] == 'L' && i%2 == 0) )
            ans = true;
    }
    cout << ((!ans) ? ("Yes") : ("No"));
    return 0;
}

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

fn main() {
    input! {
        a:i64,
        b:Chars,
    }

    let mut sumb = 0;

    for b1 in b {
        if let Some(bi) = b1.to_digit(10) {
            sumb = sumb * 10 + bi;
        }
    }

    let ret = a * sumb as i64 / 100;

    println!("{}", ret);
}


Measured memory_bytes: 2144
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    B = []
    ans = 0
 
    for i, a in enumerate(A):
        B.append(a - i - 1)

    B.sort()

    b = B[len(B)//2]
    for i, a in enumerate(A):
        ans += abs(a - b - i - 1)

    print(ans)


Measured memory_bytes: 26184
#define LOCAL
#include <iostream>
#include <map>
#include <iterator>
#include <bits/stdc++.h>
#include <stdbool.h>
#include <math.h>
#define io() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define show(x)     cout << (#x) << ":" << x << endl;
#define show2(x,y)  cout << (#x) << ":" << x << " " << (#y) << ":" << y << endl;
#define ll long long
#define ld long double
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define en "\n"
#define rep(i,a,b) for(int (i)=(a);(i) < (b); (i)++)
using namespace std;

template<class T> ostream& operator<<(ostream &os, vector<T> V){os << "[ "; for(auto v  : V) os << v << " "; return os << "]";}
template<class T> ostream& operator<<(ostream &os, set<T> V){os << "[ "; for(auto v  : V) os << v << " "; return os << "]";}
template<class T , class R > ostream& operator<<(ostream &os, map<T , R> V){os << "[ "; for(auto v  : V) os << "(" << v.first << ":" << v.second << ")"; return os << "]";}
template<class T , class R > ostream& operator<<(ostream &os, pair<T , R> V){return os << "(" << V.first << "," << V.second << ")";}
 
#define cerr cout
#ifdef LOCAL
    #define TRACE
#endif
#ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){cerr << "T->";cerr << name << " : " << arg1 << endl;}
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){cerr << "T->";const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | "; __f(comma+1, args...);}
    clock_t clk=clock();
    #define checktime() cout<<"\nTime Elapsed : "<<float(clock()-clk)/CLOCKS_PER_SEC<<endl
#else
    #define trace(...);
    #define checktime();
#endif

#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<"\n"
#define d2(x,y) cout<<(x)<<" "<<(y)<<"\n"
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<"\n"
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<"\n"
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<"\n"
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<"\n"
#define print(a) for(auto x:a) cout<<x<<" "; cout<<"\n"; 
// Use max({a,b,c,d,....}) instead
// #define max3(a,b,c) max(max((a),(b)),(c))
// #define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))

const ll MOD = 1000 * 1000 * 1000 + 7;
const ll MOD1 = 998244353;


void solve(){
    ld n,d;
    cin>>n>>d;
    int c=0;
    rep(i,0,n){
        ld x,y;
        cin>>x>>y;
        if(sqrt(x*x+y*y)<=d)
            c++;
    }
    cout<<c<<endl;
}

int main() {
    io();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //int t;
    //#pragma comment(linker, "/STACK:2000000")
    //cin>>t;
    //rep(i,0,t){
        solve();
    //}
    //h=1;
    return 0;
}

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

using namespace std;

const int nmax = 1e5 + 10;

int n;
int a[nmax], d[nmax];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);

    long long sum = 0;
    for (int i = 1; i <= n; ++i)
        sum += a[i];

    if (sum % (1LL * n * (n + 1) / 2)) {
        printf("NO\n");
        return 0;
    }

    int k = sum / (1LL * n * (n + 1) / 2);

    for (int i = 1; i < n; ++i)
        d[i] = a[i+1] - a[i];
    d[n] = a[1] - a[n];

    for (int i = 1; i <= n; ++i)
        if (k - d[i] < 0 || (k - d[i]) % n) {
            printf("NO\n");
            return 0;
        }


    printf("YES\n");
    return 0;
}


Measured memory_bytes: 1024
/*6.22.a.c*/
#include <stdio.h>
#define N (4)
int main()
{
  char s[N];
  int i,n;
  int b=0;

  scanf("%4s",s);

  for(i=0;i<N;i++)
    {
      if(s[i]==s[i+1])
        {
          b=1;
        }
    }
  if(b==1)
  {
    printf("Bad\n");
  }
  else
  {
    printf("Good\n");
  }

return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
const string YES = "Yes";
const string NO = "No";
  
void solve(std::string S){
  cout << (S[2] == S[3] && S[4] == S[5] ? YES:NO) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct Edge{
  ll to,cost;
};
const ll MAX_V=5510;
vector<vector<Edge>> E(MAX_V);
vi dist(MAX_V,llINF);
bool bellman_ford(ll s){
  queue<ll>que;
  que.push(s);
  dist[s]=0;
  for(int i = 0;i < MAX_V;i++){
    ll n = que.size();
    bool used[MAX_V] = {};
    for(int j = 0;j < n;j++){
      ll now=que.front();
      que.pop();
      for(int k = 0;k < E[now].size();k++){
	Edge e = E[now][k];
	if(dist[e.to] > dist[now] + e.cost){
	  dist[e.to] = dist[now] + e.cost;
	  if(i == MAX_V-1)
	      return true;
	  if(used[e.to] == false){
	    que.push(e.to);
	    used[e.to] = true;
	  }
	}
      }
    }
  }
  return false;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m,p;cin>>n>>m>>p;
  vector<vector<Edge>>E2(n+1);
  for(int i=0;i<m;i++){
    ll a,b,c;cin>>a>>b>>c;
    E2[--b].pb({--a,p-c});
  }
  queue<ll>que;
  que.push(n-1);
  vi vis(n+10);
  vis[n-1] = true;
  while(!que.empty()){
    ll now = que.front();
    que.pop();
    for(auto e:E2[now]){
      E[e.to].pb({now,e.cost});
      if(vis[e.to])continue;
      vis[e.to] = true;
      que.push(e.to);
    }
  }
  if(bellman_ford(0)){
    cout<<-1<<endl;
  }else{
    cout<<max(0LL,-dist[n-1])<<endl;
  }
  return 0;
}


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

using namespace std;

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a <= 0  && b >= 0){
		puts("Zero");
		return 0;
	}
	if(a > 0){
		puts("Positive");
		return 0;
	}
	puts(a - b & 1 ? "Positive":"Negative");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main(){
  
  int i, j, k, N, cnt=0;
  cin>>N;
  vector<long long> L(N);
  for(int i=0; i<N; i++){
    cin>>L[i];
  }
  
  for(i=0; i<N; i++){
    for(j=i+1; j<N; j++){
      for(k=j+1; k<N; k++){
        
        
        if(L[i]!=L[j] && L[j]!=L[k] && L[k]!=L[i] && max(max(L[i], L[j]), L[k])<(L[i]+L[j]+L[k] - max(max(L[i], L[j]), L[k]))){
          cnt++;
        }
      }
    }
  }
  
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
using namespace std;
bool f(int a)
{
	if(a<2)return 0;
	for(int i=2;i*i<=a;i++)if(a%i<1)return 0;
	return 1;
}
int n;
main()
{
	while(cin>>n,n)
	{
		if(n==1)
		{
			cout<<0<<endl;
			continue;
		}
		int r=n,l=n;
		while(!f(r))r--;
		while(!f(l))l++;
		cout<<l-r<<endl;
	}
}


Measured memory_bytes: 3052
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

const ll MOD = 998244353;

ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}

char get(char a, char b) {
	return 'a' ^ 'b' ^ 'c' ^ a ^ b;
}

int main() {
#ifdef BZ
	freopen("in", "r", stdin);
#endif
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	string s;
	cin >> s;
	if (s.size() <= 3) {
		set<string> ss;
		queue<string> qu;
		ss.insert(s);
		qu.push(s);
		while (!qu.empty()) {
			string s = qu.front();
			qu.pop();
			for (int i = 0; i + 1 < s.size(); ++i) {
				if (s[i] != s[i + 1]) {
					string t = s;
					t[i] = t[i + 1] = get(s[i], s[i + 1]);
					if (!ss.count(t))
						ss.insert(t), qu.push(t);
				}
			}
		}
		cout << ss.size() << "\n";
		return 0;
	}
	int fl = 0;
	for (int i = 1; i < s.size(); ++i)
		if (s[i] != s[0])
			fl = 1;
	if (!fl) {
		cout << 1 << "\n";
		return 0;
	}

	ll ans = 0;
	for (int i = 0; i + 2 < s.size(); ++i) {
		ans = (ans + pw(2, i) * pw(3, s.size() - i - 2)) % MOD;
	}
	if (s.size() % 3 == 0) {
		int cnt = s.size() / 3 * 2 - 1;
		int sum = 0;
		for (char c: s)
			sum = (sum + c - 'a') % 3;
		ll cc[3] = {1, 0, 0};
		for (int i = 0; i < cnt; ++i) {
			ll dp[3] = {0, 0, 0};
			for (int j = 0; j < 3; ++j)
				for (int k = 0; k < 3; ++k)
					if (k != j)
						dp[k] = (dp[k] + cc[j]) % MOD;
			copy(dp, dp + 3, cc);
		}
		ans = (ans + cc[sum] * 3 % MOD * pw(2, s.size() / 3 - 1)) % MOD;
	}
	else {
		ans = (ans + pw(2, s.size() - 2)) % MOD;
	}
	fl = 0;
	for (int i = 0; i + 1 < s.size(); ++i)
		if (s[i] == s[i + 1])
			fl = 1;
	if (!fl)
		ans = (ans + 1) % MOD;
	cout << ans << "\n";
	return 0;
}



Measured memory_bytes: 720
#include <stdio.h>
#include <ctype.h>

const
char  cls[ ] = { 'I', 'O' };

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    int   n, m;
    int   res = 0;
    int   cont = 0;
    int   req = 0;

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

    while ( m-- )
    {
      int   ch = ' ';

      while ( isspace ( ch ) )  ch = getchar ( );

      if  ( ch == cls[ req ] )
      {
        ++cont;
        req = !req;
      }
      else
      {
        if ( cont > 2 * n )
        {
          res += ( cont + 1 ) / 2 - n;
        }
        cont =
        req = !!( ch == cls[ 0 ] );
      }
    }

    printf ( "%d\n", res );
  }

  return ( 0 );
}

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

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

const long long INF = 1LL << 60;

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

  REP(i, a, b){
    if(i <= a+(k-1) || b-(k-1) <= i){
      cout << i << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
for i in range(M):
    st,sp = map(int,input().split())
    if i == 0:
        N_List = [st,sp]
    else:
        if st > N_List[0]:
            N_List[0] = st
        if sp < N_List[1]:
            N_List[1] = sp   
print(len(list(range(N_List[0],N_List[1]+1))))

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

void solve(){
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        ll maxi=-1e18;
        maxi=max({maxi,a*c,b*d,a*d,b*c});
        cout<<maxi;
    }
int main(){
	solve();
}

Measured memory_bytes: 3580
import Data.List
import Text.Printf

ans:: [Int] -> [Int]
ans x = sort x

main = do
    c <- getContents
    let i = map words $ lines c :: [[String]]
        j = map (map read) i :: [[Int]]
        k = takeWhile (/= [0,0]) j
        o = map ans k
    mapM_ (\x -> printf "%d %d\n" (x!!0) (x!!1)) o
    

Measured memory_bytes: 4568
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>

using namespace std;

typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)

ll const INF = 1000000000000000000;
int const I_MAX = 2147483647;
ll const MOD = 1e9 + 7;
int const POW_MAX = 1e5;

ll po[POW_MAX + 2];

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

ll mod_inv (ll x) {
  return mod_pow(x, MOD - 2) % MOD;
}

ll comb(int n, int r) {
  return (((po[n] * mod_inv(po[r])) % MOD) * mod_inv(po[n - r])) % MOD;
}

ll gcd(ll a, ll b) {
  while (a % b != 0) {
    ll tmp = a;
    a = b;
    b = tmp % b;
  }
  return b;
}

int N, X;
priority_queue<int> xs;
priority_queue<ll> dQ;

int main() {
  scanf("%d %d", &N, &X);
  xs.push(X);
  rep(i, N) {
    int x;
    scanf("%d", &x);
    xs.push(x);
  }

  int bef = xs.top();
  xs.pop();
  while (!xs.empty()) {
    dQ.push(bef - xs.top());
    bef = xs.top();
    xs.pop();
  }

  ll df = dQ.top();
  dQ.pop();
  while(!dQ.empty()) {
    ll d = dQ.top();
    dQ.pop();
    df = gcd(df, d);
  }
  printf("%lld\n", df);
}


Measured memory_bytes: 1784
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;




int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	if (B / A >= C)cout << C << endl;
	else cout << B / A << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public 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 x = sc.nextInt();
		int y = sc.nextInt();
		sc.close();
		int ans = 0;
		int min = Math.min(x, y);
		int minac = Math.min(a, c*2);
		int minbc = Math.min(b, c*2);
		
		if(a+b <= c*2) {
			ans = a*x + b*y;
		}else {
			ans = c*2*min + minac*(x-min) + minbc*(y-min); 
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int n, m, q, ans = 0;
VI a, b, c, d;
void dfs(VI& x) {
    if (x.size() == n) {
        int sum = 0;
        FOR(i, 0, q)if (x[b[i]] - x[a[i]] == c[i])sum += d[i];
        chmax(ans, sum);
    }
    else {
        eFOR(i, (x.empty() ? 1 : x.back()), m) {
            x.push_back(i);
            dfs(x);
            x.pop_back();
        }
    }
}

int main() {
    init();

    cin >> n >> m >> q;
    a.resize(q), b.resize(q), c.resize(q), d.resize(q);
    FOR(i, 0, q)cin >> a[i] >> b[i] >> c[i] >> d[i];
    each(i, a)--i; each(i, b)--i;
    VI x;
    dfs(x);
    cout << ans << "\n";
}


Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;

const int N=2e5+20;

int n,r,a,x[N],h[N],damage;
pair <int,int> p[N];
queue <pair <int,int>> q;
long long ans;

bool cmp(pair <int,int> &a,pair <int,int> &b)
{
	if(a.first!=b.first) return a.first<b.first;
	return a.second>b.second;
}

void add(int x,int min_damage)
{
	int d=(min_damage+a-1)/a*a;
	q.push({x,d});
	damage+=d;
	ans+=d/a;
}

void remove()
{
	damage-=q.front().second;
	q.pop();
}

int main()
{
	scanf("%d%d%d",&n,&r,&a);
	for(int i=0;i<n;i++) scanf("%d%d",&p[i].first,&p[i].second);

	sort(p,p+n,cmp);
	add(p[0].first+r,p[0].second);
	for(int i=1;i<n;i++)
	{
		while(not q.empty() and p[i].first-q.front().first>r) remove();
		if(p[i].second<=damage) continue;
		add(p[i].first+r,p[i].second-damage);
	}

	printf("%lld",ans);
}

Measured memory_bytes: 6144
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int TScore = 0;
	int HScore = 0;
	for (int i = 0; i < n; i++)
	{
		string TCard, HCard;
		cin >> TCard >> HCard;
		if (TCard > HCard)
			TScore += 3;
		else if (TCard < HCard)
			HScore += 3;
		else
		{
			TScore++;
			HScore++;
		}
	}
	cout << TScore <<" "<< HScore << endl;
}


Measured memory_bytes: 3164
import sys
import os
import math
 
for s in sys.stdin:
 
    n = int(s)
    if n == 0:
        break
    P = []
 
    for i in range(n):
        x, y = map(float, input().split(','))
        P.append(complex(x, y))
 
    def get_intersections(p0, p1):
        """
        :type p0: complex
        :type p1: complex
        :return:
        """
        dist = abs(p0 - p1)
 
        if dist > 2:
            return []
        elif dist == 2:
            return [(p0 + p1) / 2]
        else:
            m = (p0 + p1) / 2
            v = m - p0
            w = complex(v.imag, -v.real)
            n = w / abs(w)
            d = abs(v)
            l = math.sqrt(1 - d ** 2)
 
            inter0 = m + l * n
            inter1 = m - l * n
            return [inter0, inter1]
 
 
    intersections = []
    for i in range(n):
        for j in range(i+1, n):
            intersections += get_intersections(P[i], P[j])
 
    counts = []
 
    # each intersection, it is in how many circles?
    for intersection in intersections:
        cnt = 0
        for p in P:
            if abs(intersection - p) <= 1.01:
                cnt += 1
        counts.append(cnt)
 
    if counts:
        print(max(counts))
    else:
        print(1)



Measured memory_bytes: 5712
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define inver(a) power(a,mod-2)
using namespace std;
inline char nc()
{
    // return getchar();
    static char buf[100000],*l=buf,*r=buf;
    return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x)
{
    x=0; int f=1,ch=nc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
    while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
    x*=f;
}
typedef long long ll;
const int mod=998244353;
const int maxm=5e5+50;
int n,m;
int fac[maxm];
int inv[maxm];
ll power(ll x,ll y)
{
    ll re=1;
    while(y)
    {
        if(y&1) re=re*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return re;
}
inline ll binom(int x,int y)
{
    return (ll)fac[x]*inv[y]%mod*inv[x-y]%mod;
}
void init(int n)
{
    fac[0]=1;
    for(int i=1;i<=n;++i) fac[i]=(ll)fac[i-1]*i%mod;
    inv[n]=inver(fac[n]);
    for(int i=n;i>=1;--i) inv[i-1]=(ll)inv[i]*i%mod;
}
int main()
{
    read(n),read(m);
    if(n>m) swap(n,m);
    init(m);
    int an=0;
    for(int i=0,f=1;i<=n;++i)
    {
        an=(an+f*power(m+1,n-i)%mod*power(n+1,m-i)%mod*fac[i]%mod*binom(n,i)%mod*binom(m,i))%mod;
        f=mod-f;
    }
    printf("%d\n",an);
    return 0;
}

Measured memory_bytes: 4096
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <time.h>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll n, ans=1;

int main(void)
{
	cin>>n; ll i;
	for(i=2 ; i<=n ; i++)
	{
		if(isprime(i))
		{
			ll tt=(n-bsum(n,i))/(i-1);
			ans=(ans*(tt+1))%mod;
		}
	}
	cout<<ans; return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());

    int b = n / 2;

    int ans = a.at(b) - a.at(b - 1);

    cout << ans << endl;
}

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

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

    string s,t; cin>>s>>t;
    int N=s.size(),M=t.size();

    for(int i=0;i+M<=N;i++){
        if(s.substr(i,M)==t) cout<<i<<endl;
    }
    return 0;
}


Measured memory_bytes: 3228
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    int N,K;cin>>N>>K;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin >> A[i];
    for(int i=0;i<N-K;i++){
        if(A[i]>=A[i+K]) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 4048
fun main(args: Array<String>) {
    a82(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

fun a82(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    val avg = args[0].split(" ").map { it.toInt() }.average()
    println(if (avg == avg.toInt().toDouble()) avg.toInt() else avg.toInt() + 1)
}

Measured memory_bytes: 36304
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,x,l,d=0,res=1;
    cin >> n >> x;
    while(n--)
    {
        cin >> l;
        if(d+l <= x)
        res++;
        d = d+l;
    }
    cout << res << endl;
    return 0;
}

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

int main() {
	int N, M;
	cin >> N >> M;
	
	vector< int > A(N);
	for (int i=0; i<N; ++i) cin >> A[i];
	
	for (int k=1; k<=M; ++k) {
		for (int i=0; i<N-1; ++i) {
			if (A[i] % k > A[i+1] % k) swap(A[i], A[i+1]);
		}
	}
	
	for (int i=0; i<N; ++i) cout << A[i] << endl;
}


Measured memory_bytes: 3112
from math import ceil


def f(n, h, A, B):
    cnt = 0

    a = max(A)
    for b in sorted(B, reverse=True):
        if b <= a:
            break
        if h <= 0:
            return cnt
        h -= b
        cnt += 1

    return cnt + ceil(h / a)


n, h = map(int, input().split())
A = [0] * n
B = [0] * n
for i in range(n):
    A[i], B[i] = map(int, input().split())
print(f(n, h, A, B))


Measured memory_bytes: 12080
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long int ld;
typedef unsigned long long int lu;
typedef vector< int > vi;
typedef vector < ld > vd;
typedef set <ld> sd;
typedef vector< vi > vvi;
typedef vector< vd > vvd;
typedef pair< int,int > ii;
typedef pair< ld,ld > id;
#define sz(a) ld((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

#define rep(i,a,b) for(i=a;i<b;i++)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define reprev(i,a,b) for(i=a;i>=b;i--)


#define Vi vector
#define pr pair
#define isnum(a) (a>=48 && a<=57)
#define isS(a) (a>='a' && a<='z')
#define isU(a) (a>='A' && a<='Z')
#define toS(a) (isU(a)?a+32:a)
#define toU(a) (isS(a)?a-32:a)
#define toC(a) a&15

vector<char> prime (10000000+1, true);
void sieve(ld n)
{	
	//O(nloglogn) time
	prime[0] = prime[1] = false;
	for (ld i=2; i<=n; ++i)
		if (prime[i])
			if (i * 1ll * i <= n)
				for (ld j=i*i; j<=n; j+=i)
					prime[j] = false;
}


vd v1;

vd g[100004];
//vd g1[100004];
//vd ar;
//vvd final;
//ld mind = 1000000006;
//vd mind;
//ld c;
bool visit[100004];
ld dist[100004];
//for topological sort of a graph
void dfs(ld i,ld n)
{
	visit[i] = true;
	ld j,k;
	for(j=0;j<g[i].size();j++)
	{
		if(!visit[g[i][j]])
		{
			dfs(g[i][j],n);
		}
	}
	v1.pb(i);
}

void dfs1(ld i,ld n)
{
	visit[i] = true;
	ld j,k;
	for(auto x : g[i])
	{
		if(!visit[x])dfs1(x,n);
		dist[i]=max(dist[i],dist[x]+1);
	}
}
ld p = 1e9+7;

int main(){
	ld h,w,i,j;
	cin >> h >> w;
	char ch[h][w];
	rep(i,0,h)
	{
		rep(j,0,w)
		{
			cin >> ch[i][j];
		}
	}
	ld dp[h][w];
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	rep(i,1,w)
	{
		if(ch[0][i]=='#')dp[0][i]=0;
		else dp[0][i]=(dp[0][i-1])%p;
	}
	rep(i,1,h)
	{
		if(ch[i][0]=='#')dp[i][0]=0;
		else dp[i][0]=(dp[i-1][0])%p;
	}
	rep(i,1,h)
	{
		rep(j,1,w)
		{
			if(ch[i][j]=='#')dp[i][j]=0;
			else dp[i][j]=(dp[i-1][j]+dp[i][j-1])%p;
		}
	}
	cout << dp[h-1][w-1] << endl;
	return 0;
}

/*
//next step
//from transposed graph g1,get strongly connected components
void dfs1(ld i,ld n,ld len)
{
	visit[i] = true;
	ld j,k;
	final[len].pb(i);
	mind[len] = min(mind[len],ar[i]);
	rep(j,0,g1[i].size())
	{
		if(!visit[g1[i][j]])
		{
			dfs1(g1[i][j],n,len);
		}
	}
}
*/

Measured memory_bytes: 21120
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	a := iSScan(3 * n)
	hx := &IntHeap{}
	heap.Init(hx)
	for i := 0; i < n; i++ {
		heap.Push(hx, a[i])
	}
	dpx := make([]int, 3*n)
	dpx[n-1] = sum(a[:n])
	for i := n; i < n*2; i++ {
		z := heap.Pop(hx).(int)
		if a[i] > z {
			dpx[i] = dpx[i-1] + a[i] - z
			heap.Push(hx, a[i])
		} else {
			dpx[i] = dpx[i-1]
			heap.Push(hx, z)
		}
	}
	hy := &IntHeap{}
	heap.Init(hy)
	for i := 2 * n; i < 3*n; i++ {
		heap.Push(hy, -a[i])
	}
	dpy := make([]int, 3*n)
	dpy[2*n] = sum(a[2*n:])
	for i := 2*n - 1; i >= n; i-- {
		z := heap.Pop(hy).(int) * -1
		if -a[i] > -z {
			dpy[i] = dpy[i+1] + a[i] - z
			heap.Push(hy, -a[i])
		} else {
			dpy[i] = dpy[i+1]
			heap.Push(hy, -z)
		}
	}
	ans := -mod * mod
	for i := n - 1; i < 2*n; i++ {
		ans = larger(ans, dpx[i]-dpy[i+1])
	}
	fmt.Println(ans)
}

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vector<double> dp(n+1);
    dp[0] = 1;
    for (int i = 1; i <= n; i++) {
        double p_head; cin >> p_head;
        for (int j = i; j >= 0; j--) {
            dp[j] = (j == 0 ? 0 : dp[j-1] * p_head) + dp[j] * (1-p_head);
        }
    }
    double prob = 0;
    for (int heads = 1; heads <= n; heads++) {
        int tails = n - heads;
        if (heads > tails) {
            prob += dp[heads];
        }
    }
    printf("%.10lf", prob);
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int A = sc.nextInt();

        System.out.println(solve(N, A) ? "Yes" : "No");

        sc.close();
    }

    static boolean solve(int N, int A) {
        return N % 500 <= A;
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,n,h) for(int i = n; i < h; ++i)
#define rep3(l,n,h) for(int l = n; l <= h; ++l)
#define INF LLong_MAX // long long INF
#define inf INT_MAX // int inf

typedef pair<int,int> int_pair;
typedef pair<string,string> string_pair;


int  main(void) {
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    ll H = min(h,q*2);
    ll S = min(s,H*2);
    if(2*S <= d) {
        cout << S*n << endl;
    } else {
        if(n%2 == 0) {
            cout << n/2 * d << endl;
        } else {
            cout << n/2 * d + S << endl;
        }
    }
    return 0;

}

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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
bool compare_by(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second > b.second;
    }
}

vector<pair<int,ll>> vec[100000];
ll cost[100000];
void dfs(int now,ll COST){
    cost[now]=COST;
    int next;
    REP(i,vec[now].size()){
        next=vec[now][i].first;
        if(cost[next]<0){
            dfs(next,COST+vec[now][i].second);
        }
    }
}
int counter(int x){
    if(!x)return 0;
    return counter(x>>1)+(x&1);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;int M;
    cin>>N>>M;
    int ans=0;
    if(N<M){
        REP(i,M){
            ans*=10;
            ans+=N;
        }
    }else{
        
        REP(i,N){
            ans*=10;
            ans+=M;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<cmath>
using namespace std;
int tt=0x7fffffff;
int main()
{
	int n;
    int a[1001];
    int sum;
    int sum1;
    cin>>n;
    int min=tt,max=-tt;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum+=a[i];
        if(a[i]<min) min=a[i];
        if(a[i]>max) max=a[i];
    }
    int t=sum/n;
    for(int k=min;k<=max;k++)
    {
        sum1=0;
        for(int i=1;i<=n;i++)
        {
            sum1+=(a[i]-k)*(a[i]-k);
        }
        if(sum1<tt) tt=sum1;
    }
    cout<<tt;
    return 0;
}

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

#include <unordered_map>

//#include <iostream>//POJ
//#include <vector>
//#include <string>
//#include <iomanip>
//#include <math.h>
//#include <algorithm>
//#include <cstring>
using namespace std;
#define setc cin.tie(0);ios::sync_with_stdio(0)
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
//template<typename T> T vpop(vector<T> *v) {
//	T res = v->back();
//	v->pop_back();
//	return res;
//}
//char vpop(string *v) {
//	char res = v->back();
//	v->pop_back();
//	return res;
//}
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define contain(q) !q.empty()
#define cont(q) !q.empty()
//#define qpop(q, a, b) a=q.back().first;b=q.back().second;q.pop()
//#define pqpop(p, a, b) a=q.top().first;b=q.top().second;q.pop()
#define el "\n"
#define sp " "
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#define wildcard(T) numeric_limits<T>::min()

#define pb push_back
#define pq priority_queue
#define np next_permutation

#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
const unsigned int bf0 = (1 << 0);
const unsigned int bf1 = (1 << 1);
const unsigned int bf2 = (1 << 2);
const unsigned int bf3 = (1 << 3);
const unsigned int bf4 = (1 << 4);
const unsigned int bf5 = (1 << 5);
const unsigned int bf6 = (1 << 6);
const unsigned int bf7 = (1 << 7);

typedef long long lint;
typedef vector<int> ivec; typedef vector<string> svec;
typedef vector<lint> lvec;
typedef vector<vector<int>> ivvec;
typedef pair<int, int> P;

const int
	dx8[8] = { 0,1,1,1,0,-1,-1,-1 },
	dy8[8] = { 1,1,0,-1,-1,-1,0,1 },
	dx4[4] = { 0,1,0,-1 },
	dy4[4] = { 1,0,-1,0 };

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

int n, we;
int v[1010],w[1010];
int dp[110][10010];//n, we

//i以降で重さがj以下になる価値の最高値
int dfs(int i, int j){
	if(dp[i][j]!=-1)return dp[i][j];
	if(i==n)return dp[i][j] = 0;
	if(j<w[i])return dp[i][j] = dfs(i+1,j);//入らない
	return dp[i][j] = max(dfs(i+1,j),dfs(i+1,j-w[i])+v[i]);
}

int main() {
	setc;
	memset(dp,-1,sizeof(dp));

	cin>>n>>we;
	rep(i, n){
		cin>>v[i]>>w[i];
	}
	co(dfs(0,we));
	gc();
}


Measured memory_bytes: 7516
N = int(input())
A = list(map(int, input().split()))

S = sum(A)
count = 0
Near = 10 ** 15
for i in range(N-1):
    count = count + A[i]
    if abs(2 * Near - S) > abs(2 * count - S):
        Near = count
print(abs(2 * Near - S))


Measured memory_bytes: 23800
N = int(input())
ls = list(map(int,input().split()))
ii = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if ls[i] == ls[j] or ls[i] == ls[k] or ls[j] == ls[k]:
                pass
            else:
                ls2 = [ls[i],ls[j],ls[k]]
                ls2.sort()
                if ls2[2] < ls2[1] + ls2[0]:
                    ii += 1
print(ii)

Measured memory_bytes: 9204
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   string s;
   cin >> s;
   if(s[0]>='A'&&s[0]<='Z') {
       cout << "A" << endl;
   } else {
       cout << "a" << endl;
   }
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;
    bool f=0;
    for(int i=1;i<=9;i++)
        for(int j=1;j<=9;j++)
            if(n==i*j)
                f=1;
    if(f)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 256