akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <stack>
#include <queue>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

map<ll,ll> mp;

// 最大公約数
ll gcd(ll a, ll b)
{
    if(a%b == 0){
        return(b);
    }
    else{
        return(gcd(b, a%b));
    }
}

// 素因数分解する
void div_prime(ll n){
    // 割る数の初期値
    ll a = 2;

    // √n>=aの間ループ
    while(n >= a * a){
        if(n % a == 0){
            if(!mp.count(a)) mp[a]=a;

            n /= a;
        }
        else{
            a++;
        }
    }

    // 最後に残ったnは素因数
    if(!mp.count(n)) mp[n]=n;
}

int main(void)
{
    ll A, B, gc, i;

    cin >> A >> B;

    gc = gcd(A, B);

    div_prime(gc);

    if(gc==1) cout << 1 << endl;
    else cout << mp.size()+1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define RALL(X) (X).rbegin(), (X).rend()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define DRVI(N, X) VI X(N); for (int ___I=0; ___I<n; ___I++) scanf("%d", &(X[___I]))  
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second

using namespace std;
VL wpos0;

void arrangewp(){
    int ind=0;
    LL t=1LL<<60;
    while (ind<SZ(wpos0)){
        sort(RALL(wpos0));
        if (wpos0[ind]==0) break;
        while (t>wpos0[ind]) {t>>=1;}
        for (int i=ind+1;i<SZ(wpos0);i++){
            if (wpos0[i]&t) wpos0[i]^=wpos0[ind];
        }
        ind++;
    }
}

LL isUnGenerable(LL n){
    //check n is generable
    //cout<<"ungen "<<n<<endl;
    for (auto c: wpos0){
        //cout<<n<<" "<<c<<" "<<(n^c)<<" "<<((n^c)<n)<<endl;
        if ((n^c)<n) n^=c;
    }
    return n;
}

void addtowpos0(LL n){
    LL left=isUnGenerable(n);
    if (left) wpos0.PB(left);
    arrangewp();
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int nbt;
    cin>>nbt;
    while (nbt--){
        int n;
        cin>>n;
        VL a(n);
        REP(i,n) cin>>a[i];
        string s;
        cin>>s;
        wpos0=VL(1,0);
        bool wins0=true;
        REP(i,n){
            int ind= n-1-i;
            if (s[ind]=='0'){
                addtowpos0(a[ind]);
                //cout<<"added "<<a[ind]<<" ; ";
                //for (auto k:wpos0) {cout<<k<<" ";} cout<<endl;
            }
            if (s[ind]=='1'){
                LL ungen = isUnGenerable(a[ind]);
                //cout<<"tested "<<a[ind]<<" : "<<ungen<<endl;
                //for (auto k:a) {cout<<k<<" ";} cout<<endl;
                if (ungen) {wins0=false; break;}
            }
        }
        if (wins0) cout<<"0\n";
        else cout<<"1\n";
    }

}


Measured memory_bytes: 3624
<?php
	$a = fgets(STDIN);
	$array = explode(" ", fgets(STDIN));
	$int_array = array_map( function($value) {
      return (int)$value; 
    }, $array);

	//var_dump($a);
	//var_dump($int_array);

	$flag = false;
	$cnt=0;
  while(true){
	for($i=0; $i<$a; $i++){
      if($int_array[$i] % 2 != 0)$flag = true;
    }
    if($flag)break; 
    
    for($i=0; $i<$a; $i++){
      $int_array[$i] /= 2;
    }
    
    $cnt++;
  }
echo $cnt;
?>

Measured memory_bytes: 16224
N, C = map(int,input().split())
sushi = list(list(map(int,input().split()))for i in range(N))
r1,l1,r2,l2 = [0]*(N+1),[0]*(N+1),[0]*(N+1),[0]*(N+1)

eat = 0
for i in range(N):
    a,b = sushi[i]
    eat += b
    r1[i+1] = max(r1[i],eat-a)
    r2[i+1] = max(r2[i],eat-a*2)
eat = 0
for i in range(N-1,-1,-1):
    a,b = sushi[i]
    eat += b
    l1[i] = max(l1[i+1],eat-(C-a))
    l2[i] = max(l2[i+1],eat-(C-a)*2)

ans = 0
for i in range(N+1):
    ans = max(ans,r1[i]+l2[i],r2[i]+l1[i])

print(ans)




Measured memory_bytes: 39928
#include<stdio.h>
int main()
{
	int c=0,p[3]={};
	char s[3][101];

	scanf("%s%s%s",s[0],s[1],s[2]);

	while(1){
		if(s[c][p[c]])
			c=s[c][p[c]++]-'a';
		else{
			printf("%c",'A'+c);
			return 0;
		}
	}
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
//l={1,2,3,4}
//greater<int>()
//sort(l,l+N)

int main(void)
{
	char a, b, c;
	cin >> a >> b >> c;
	int ans = 700;
	if (a == 'o')
		ans += 100;
	if (b == 'o')
		ans += 100;
	if (c == 'o')
		ans += 100;
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import Counter
    N, M = map(int, readline().split())
    X = list(map(int, readline().split()))

    c_num = Counter(X)
    c_pair = Counter()
    c_mod = Counter()

    for i in range(1, 10 ** 5 + 1):
        m = i % M
        cnt = c_num[i]
        c_pair[m] += cnt // 2
        c_mod[m] += cnt % 2

    ans = 0
    ans += c_mod[0] // 2
    c_mod[0] -= c_mod[0] // 2

    if M % 2 == 0:
        ans += c_mod[M // 2] // 2
        c_mod[M // 2] -= c_mod[M // 2] // 2

    for i in range(1, (M - 1) // 2 + 1):
        cnt = min(c_mod[i], c_mod[M - i])
        ans += cnt
        c_mod[i] -= cnt
        c_mod[M - i] -= cnt

        if c_mod[i] >= 2:
            c2 = c_mod[i] // 2
            p = c_pair[M - i]
            cnt2 = 2 * min(c2, p)
            ans += cnt2
            c_mod[i] -= cnt2
            c_pair[M - i] -= cnt2 // 2
        if c_mod[M - i] >= 2:
            c2 = c_mod[M - i] // 2
            p = c_pair[i]
            cnt3 = 2 * min(c2, p)
            ans += cnt3
            c_mod[M - i] -= cnt3
            c_pair[i] -= cnt3 // 2

    for i in range(M):
        ans += c_pair[i]

    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
    ll N,A,B,C,D,E; cin >> N >> A >> B >> C >> D >> E;
    ll small = min(A,min(B,min(C,min(D,E))));
    ll ans = 0;

    if(N % small != 0) ans += N/small + 5;
    else ans += N/small + 4;

    cout << ans << endl;
}

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

typedef long long ll;
#define nl "\n"
#define ff first
#define ss second
#define mod 1e9+7
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define pp pop_back
#define bs binary_search
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define sll stack<ll>
#define qll queue<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define vc vector <char>
#define vvll vector<vector<ll>>
#define mod 1e9+7
#define mxn 9e18
#define all(x) x.begin(),x.end()
#define loop(i,s,n) for(ll i=s;i<n;i++)
#define test ll t ; cin>>t; while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve()
{
    ll n,m,l,r,res=0;
    cin>>n>>m;
    ll a[n],ans[n]={0};
    loop(i,0,n)     cin>>a[i];
    while(m--)
    {
        cin>>l>>r;
        if(a[l-1]>a[r-1])   ans[r-1]=1;
        else if(a[l-1]<a[r-1])      ans[l-1]=1;
        else
        {
            ans[r-1]=1;
            ans[l-1]=1;
        }
    }
    loop(i,0,n)     if(!ans[i])     res++;
    cout<<res;
}

int main() {
	fast_io;
	
	solve();
	return 0;
}


Measured memory_bytes: 5196
#include <stdio.h>

int main()
{
  int n, i;
  int ans = 100000;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    ans *= 1.05;
    ans = ((ans+999)/1000) * 1000;
  }

  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
using namespace std;
int main()
{
    ll k;
    string s;
    cin >> s;
    cin >> k;
    k--;
    char ans = '1';
    ll tmp = 0;
    rep(i,s.size()){
        if(s[i]>='2'){
            ans = s[i];
            tmp = i;
            break;
        }
    }
    if(k<tmp){
        cout << '1' << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
n=int(input())
l=list()
if n<=5:
  print("Yes")
  exit()
for i in range(2, n//2+1):
    if n % i == 0: 
        if (n//i,i) not in l:
            l.append((i,n//i))
flag=0
for i in l:
    if i[0]<=9 and i[1]<=9:
        flag=1
        print("Yes")
        exit()
if not flag:
    print("No")


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

using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
typedef double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define MOD 1000000007
#define PI 3.14159265

bool check(string str) {
    int n = str.size();
    for (int i = 0; i < n; i++) {
        if ((str[i] != 'A' && str[i] != 'C') && isupper(str[i])) {
            return false;
        }
    }
    return true;
}

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

    string str;
    cin >> str;

    int n = str.size();
    if (str[0] == 'A' && (count(str.begin() + 2 , str.begin() + n - 1 , 'C') == 1) && check(str)) {
        cout << "AC" << endl;
    }
    else {
        cout << "WA" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
A, B, M = map(int, input().split())
ar = list(map(int, input().split()))
br = list(map(int, input().split()))
ans = min(ar) + min(br)
for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ar[x-1] + br[y-1] - c,ans)
print(ans)

Measured memory_bytes: 18736
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl
#define COUT(x) cerr<<#x<<" = "; cout<<(x)<<endl

struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

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

   double avg = (double)accumulate(a.begin(), a.end(), 0LL) / n;

   vector<P<double,int>> p(n);

   for (int i = 0; i < n; i++) {
      p[i] = make_pair(abs(a[i] - avg), i);
   }

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

   COUT(p[0].second);

   return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<bool> sp(13, false), he(13, false), cl(13, false), di(13, false);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int num;
    cin >> num;
    if (s == "S")
      sp.at(num - 1) = true;
    else if (s == "H")
      he.at(num - 1) = true;
    else if (s == "C")
      cl.at(num - 1) = true;
    else if (s == "D")
      di.at(num - 1) = true;
  }
  for (int i = 0; i < 13; i++) {
    if (sp.at(i) == false) {
      cout << "S " << i + 1 << endl;
    }
  }
  for (int i = 0; i < 13; i++) {
    if (he.at(i) == false) {
      cout << "H " << i + 1 << endl;
    }
  }
  for (int i = 0; i < 13; i++) {
    if (cl.at(i) == false) {
      cout << "C " << i + 1 << endl;
    }
  }
  for (int i = 0; i < 13; i++) {
    if (di.at(i) == false) {
      cout << "D " << i + 1 << endl;
    }
  }
}


Measured memory_bytes: 3144
use proconio::{input, fastout, marker::Usize1};
use std::collections::{VecDeque, HashSet};

#[fastout]
fn main() {
    input! {
        n: usize, x: Usize1, y: Usize1,
    }

    let mut graph: Vec<Vec<usize>> = vec![vec![]; n];
    graph[x].push(y);
    graph[y].push(x);
    for i in 0..n-1 {
        graph[i].push(i+1);
        graph[i+1].push(i);
    }

    let mut set: HashSet<usize> = HashSet::new();
    let mut ans = vec![0; n];
    for i in 0..n-1 {
        let mut queue: VecDeque<(usize, usize)> = VecDeque::new();
        queue.push_back((i, 0));
        while let Some((j, k)) = queue.pop_front() {
            let a = i + n * j;
            if set.contains(&a) { continue; }
            set.insert(a);
            if j > i { ans[k] += 1; }
            for l in &graph[j] { queue.push_back((*l, k+1)); }
        }
    }

    for i in 1..n {
        println!("{}", ans[i]);
    }
}


Measured memory_bytes: 112952
line = input().split(" ")
n = int(line[0])
m = int(line[1])
line = input().split(" ")
x = []
s = []

for i in line:
    x.append(int(i))

x.sort()
count = x[m-1] - x[0]

for i in range(len(x)-1):
    s.append(int(x[i+1] - x[i]))

s.sort(reverse=True)
print(count - sum(s[0:(n - 1)]))


Measured memory_bytes: 15496
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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



  ll a, b, c;
  cin >> a >> b >> c;
  cout << min(b / a, c) << endl;




  return 0;
}

Measured memory_bytes: 256
import bisect

a, b, q = map(int, input().split())
INF = 3*10**10
S = [int(input()) for _ in range(a)]

S = [-INF] + S[:] + [INF]
T = [int(input()) for _ in range(b)]
T = [-INF] + T[:] + [INF]

for _ in range(q):
    x = int(input())
    i = bisect.bisect_left(S, x) 
    j = bisect.bisect_left(T, x) 
    A = [max(S[i]-x, T[j]-x), max(x-S[i-1], x-T[j-1]), S[i]-T[j-1]+min(S[i]-x, x-T[j-1]), T[j]-S[i-1]+min(x-S[i-1], T[j]-x)]
    print(min(A))


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> A(N);
  priority_queue<ll> pq;
  //https://cpprefjp.github.io/reference/queue/priority_queue.html
  //topはデフォルトでは降順に処理されるらしいです．
  //popは次の要素を削除だそうです.
  for(ll i=0; i<N; i++){
    cin >> A.at(i);
    pq.push(A.at(i));
  }
  
  for(int i=0; i<M; i++){
    int t = pq.top();//最大値を取得??
    t /= 2; //割引券を使う
    pq.pop();//最大値を消す??
    pq.push(t);// 割引券使用後の値を入れる
  }
  
  ll ans = 0;
  while(!pq.empty()){//pqの中身があるならループ
    ans += pq.top();//最大値をansに足す??
    pq.pop();//最大値を消す??
  }
  
  cout << ans << endl;
  
  /*私のやりかただとTLEになるので 
  priority_queueを使って解く↑↑https://yamakasa.net/atcoder-abc-141-d/
  int N, M;
  cin >> N >> M;
  vector<ll> A(N);
  
  for(ll i=0; i<N; i++) cin >> A.at(i);
  
  for(int i=0; i<M; i++){
    //vector<ll>::iterator iter = max_element(A.begin(), A.end());
    //size_t index = distance(A.begin(), iter);//TLEになったから降順ソートする方法を試す!!
    //↑↑　https://qiita.com/ryu136/items/08eca54fbbe38cddbc8b
    //A.at(index) /= 2;//N個の中で最大の値段のやつに割引券を使う
    
    std::sort(A.begin(),A.end(),std::greater<int>());//降順ソート これもTLEになった
    A.at(0) /= 2;//N個の中で最大の値段のやつに割引券を使う
    
   
  }
    
  //各要素の和//http://baikichiz.hatenablog.com/entry/2019/02/08/085053
  //ll sum = accumulate(A.begin(), A.end(), 0);
  //cout << sum << endl;なんか上手く行ってないから↓を使う( accumulateがll対応してない??)
  
  ll ans = 0;
  //for(int i=0; i<N; i++) cout << i << " : " << A.at(i) << endl;

  for( int i=0; i<N; i++){
    ans += A.at(i);
    //cout << " 0~"<<i<<": " << ans << endl;
  }  
  cout << ans << endl;
  */
}


Measured memory_bytes: 2168
N = int(input())
A = list(map(int, input().split()))
mod = int(1e+9 + 7)
L = A[0]
def inved(a):
  x, y, u, v, k, l = 1, 0, 0, 1, a, mod
  while l != 0:
    x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
    k, l = l, k % l
  return x % mod
for i in range(N-1):
  a, b = L, A[i+1]
  while b != 0:
    a, b = b, a % b
  b = A[i+1] // a
  L = b * L
L %= mod
S = 0
for i in range(N):
  S += inved(A[i])
  S %= mod
S *= L
S %= mod
print(S)

Measured memory_bytes: 4084
#include <iostream>

using namespace std;

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

    if ( a < 6 ) {
        cout << 0 << endl;
    }
    else if ( a >= 6 && a <= 12 ){
        cout << b/2 << endl;
    } 
    else {
        cout << b << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  vl a(n), b(n),mi,ma;
  rep(i,n){
    cin >> a[i] >> b[i];
    mi.push_back(a[i]);
    ma.push_back(b[i]);
  }
  sort(rng(mi));
  sort(rng(ma));

  int m = n/2;

  if(n%2){
    cout<<ma[m] - mi[m] +1 <<endl;
  }
  else{
    ll x = ma[m-1] + ma[m]; 
    ll y = mi[m-1] + mi[m];
    cout<<x-y+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 9672
import sys


def solve(a, b):
    for i in range(1, 10000):
        if int(i * 0.08) == a and int(i * 0.1) == b:
            return i
    return -1


def main():
    input = sys.stdin.buffer.readline
    a, b = map(int, input().split())
    print(solve(a, b))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9180
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.IArray           as IA
import qualified Data.Array.IO               as AI
import qualified Data.Array.MArray           as MA
import qualified Data.Array.ST               as STA
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import qualified Data.Graph                  as G
import           Data.Int
import qualified Data.IntMap                 as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence               as SQ
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Tree                   as T
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putLn :: Show a => a -> IO ()
putLn = print

putList :: Show a => [a] -> IO ()
putList [n] = put n
putList (n:ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n] = putStr n
putStrList (n:ns) = do
  putStr n
  putStr " "
  putStrList ns

main = do
  [n] <- readInt
  [a] <- readInt
  if n `mod` 500 > a
    then putStrLn "No"
    else putStrLn "Yes"


Measured memory_bytes: 380
import time
startTimeProblem=time.time()

import fileinput, sys, itertools, functools
from math import *
from bisect import *
from heapq import *
from collections import *

def lcm(a, b):  
    return (a*b)/gcd(a, b)

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()

######################################

N = In.int()
A = In.ints()
MOD = 10**9+7

presum = [A[0]]

for i in range(1, len(A)):
    presum.append(presum[-1]+A[i])

ans = 0

for i in range(len(presum)-1):
    ans += A[i]*(presum[-1]-presum[i])
    ans%= MOD

Out.int(ans)

######################################

if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

Measured memory_bytes: 105764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
/* vector<int> A(N);
vector<pair<int, int> > tasks; ＃ソートした場合、１つ目でソート
tie(b, a) = p.at(i); #pair を分割
tasks.emplace_back(b, a) ＃配列 tasks の最後に (b, を追加
x の二乗 : pow(x, 2.0)
小さい順 : sort(v.begin(), v.
*/
int main() {
int A, B, C, count=0, ans=0;
string D, E;

cin >> A >>B>>C;
  
if(A==B)count++;
if(C==B)count++;
if(A==C)count++;

if(count==1) cout << "Yes" << endl;
else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

ll f(ll a, ll b) {
  if (b > a) {
    if (b % a == 0)
      return a * (2 * (b / a) - 1);
    return 2 * a * (b / a) + f(a, b % a);
  } else if (b < a) {
    if (a % b == 0)
      return b * (2 * (a / b) - 1);
    return 2 * b * (a / b) + f(a % b, b);
  } else {
    return a;
  }
}

int main() {
  ll n, x;
  cin >> n >> x;
  cout << n + f(x, n - x) << endl;
}


Measured memory_bytes: 256
#include <iostream>//bit DP
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>PP;
int main(){
  int l,r,d;
  int ans=0;
  cin>>l>>r>>d;
  for(int i=l;i<=r;i++){
    if(i%d==0)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool>    vecbool;
typedef vector<int>     vecint;
typedef vector<ll>      vecll;
typedef vector<string>  vecstr;
typedef vector<vecint>  vec2int;
typedef vector<vecbool> vec2bool;
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
int main()
{
  int n, c, k; cin >> n >> c >> k;
  vecint t(n,0);
  REP(i,n)cin >> t[i];
  sort(all(t));
  int ans = 0;
  int i = 0;
  while(i < n){
    int ts = t[i] + k;
    int cnt = 1;
    i ++;
    while(i < n&& cnt < c && t[i] <= ts){
      i ++;
      cnt ++;
    }

    // cout << "i:" << i << endl; 
    // cout << "ts" << ts << endl; 
    // for(int j = i; j < n; j ++){
    //   if(j - i + 1 > c||t[j] > ts){
    // 	cout << "j:" << j << endl;
    // 	i = j;
    // 	break;
    //   }
    // }
    ans ++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;

int main(){
	vector<int> n(5000);
	int nnn=0;
	bool flg;
	string S;
	cin >> S;
	for (int i = 0; i < 4; i++){
		n[S[i]]++;
	}
	for (int i = 'A'; i < 'Z'+1; i++){
		if (n[i] != 0&&n[i]!=2){
			cout << "No" << endl;
			return 0;
		}
		if (n[i] > 0){
			nnn++;
		}
		
	}
	if (nnn == 2){
		cout << "Yes" << endl;
	}
	return 0;
}

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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}

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


int main(){
  int n;
  cin >> n;

  map<string, int> m;
  rep(i,n){
    string s;
    cin >> s;
    m[s] ++;
  }
  
  int ans = 0;
  for(auto&& e : m){
    if(e.second > ans) ans = e.second;
  }

  for(auto&& e : m){
    if(e.second == ans){
      cout << e.first << endl;
    }
  }

}




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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

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

    if(k <= a)
        cout << a - k << " " << b;
    else if(k <= a + b)
        cout << "0 " << b - (k - a);
    else
        cout << "0 0";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define lli long long
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define REP(i,n) for (lli i=0;i<(n);i++)
#define rep(i,n) for (lli i=0;i<(n);i++)
 
#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>

int main(){
  int N,ans=0;
  int A[20],B[20],C[20];

  cin >> N;

  rep(i,N)
    cin >> A[i];

  rep(i,N)
    cin >> B[i];

  rep(i,N-1)
    cin >> C[i];


  rep(i,N){
    ans += B[A[i]-1];
    if(i > 0 and A[i] == A[i-1]+1)
      ans += C[A[i-1]-1];
  }


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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    char a[3], b[3];
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < 3; i++) {
		cin >> b[i];
	}

	if (a[2] == b[0] && a[1] == b[1] && a[0] == b[2]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

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

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int x1 = in.nextInt();
        int y1 = in.nextInt();
        int x2 = in.nextInt();
        int y2 = in.nextInt();
        out.printf("%d %d %d %d\n", x2 - (y2 - y1), y2 + (x2 - x1), x1 - (y2 - y1), y1 + (x2 - x1));
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

Measured memory_bytes: 20820
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(b<c||d<a)
	printf("0");
	else if(c>a&&c<=b&&b<=d)
	printf("%d",(b-c));
	else if(a>c&&a<=d&&d<=b)
	printf("%d",(d-a));
	else if(a<=c&&d<=b)
	printf("%d",(d-c));
	else if(c<=a&&b<=d)
	printf("%d",(b-a));
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int i,cc[26]={0};
  char c,sl;
  while(scanf("%c",&c)!=EOF){
    if(c>='A'&&c<='Z')c+='a'-'A';
    if(c>='a'&&c<='z')cc[c-'a']++;
  }
  for(i=0;i<26;i++){
    printf("%c : %d\n",'a'+i,cc[i]);
  }
  return 0;
}


Measured memory_bytes: 2104
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	if !sc.Scan() {
		panic("failed scan string")
	}
	return sc.Text()
}

func nextInt() int {
	if !sc.Scan() {
		panic("failed scan int")
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	k := nextInt()
	a := nextInt()
	b := nextInt()

	diff := b - a
	if diff <= 2 {
		fmt.Println(k + 1)
		return

	}
	first := a - 1
	if k < first+2 {
		fmt.Println(k + 1)
		return
	}
	rest := k - first
	times := rest / 2
	if rest%2 == 1 {
		fmt.Println(a + diff*times + 1)
	} else {
		fmt.Println(a + diff*times)
	}
}


Measured memory_bytes: 640
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;


void main() {
    immutable int N = 100;
    auto s = readln.split.map!(to!int);
    auto A = s[0] - 1;
    auto B = s[1] - 1;
    auto C = new bool[][](100, 100);

    foreach (i; 0..N) C[i][99] = true;

    // 横線
    for (int i = 3; i < N-1 && A > 0; i += 4, A -= 1) {
        C[i].fill(true);
    }

    // 縦線
    for (int j = 3; j < N && A > 0; j += 4) {
        for (int i = 0; i < N && A > 0; i += 4, A-= 1) {
            foreach (k; i..i+4) {
                C[k][j] = true;
            }
        }
    }

    for (int i = 1; i < N && B > 0; i += 4) {
        for (int j = 1; j < N && B > 0; j += 4, B -= 1) {
            C[i][j] = true;
        }
    }

    writeln(100, " ", 100);
    C.each!(c => c.map!(cc => cc ? "#" : ".").join("").writeln);
}


Measured memory_bytes: 380
import java.util.Scanner;
public class Main {
     public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(A == B)
			System.out.println("Draw");
		if((A > B && B != 1) || (A == 1 && A != B))
			System.out.println("Alice");
		if((A < B && A != 1) || (B == 1 && A != B))
			System.out.println("Bob");
     }
}

Measured memory_bytes: 23636
#include <cstdio>

int N;
int p[200100];
int a[200100];
int b[200100];

void solve()
{
	int i;
	a[0] = 1;
	for(i=1; i<N; i++)	
		a[i] = a[i-1] + 20000;
	b[p[0]] = 1;
	for(i=1; i<N; i++){
		b[p[i]] = b[p[i-1]] + a[p[i-1]] + 1 - a[p[i]];
	}
	int mn = 1;
	for(i=0; i<N; i++){
		if(b[i] < mn)
			mn = b[i];
	}
	if(mn < 1){
		for(i=0; i<N; i++){
			b[i] += -mn+1;
		}
	}
	printf("%d", a[0]);
	for(i=1; i<N; i++)
		printf(" %d", a[i]);
	printf("\n");
	printf("%d", b[0]);
	for(i=1; i<N; i++)
		printf(" %d", b[i]);
	printf("\n");
}

int suc()
{
	int i;
	if(a[0] <=0 || b[0]<=0)
		return 0;
	for(i=1; i<N; i++){
		if(b[i] <= 0)
			return 0;
		if(a[i-1] >= a[i])
			return 0;
		if(b[i-1] <= b[i])
			return 0;
		if(a[i-1]+b[i-1] >= a[i]+b[i])
			return 0;
	}
	return 1;
}

void test()
{
	int i;
	N = 20000;
	for(i=0; i<N; i++)
		p[i] = i;
	solve();
	if(!suc())
		printf("Wrong\n");
}

int main()
{
	//test();
	int i;
	scanf("%d", &N);
	for(i=0; i<N; i++){
		scanf("%d", &p[i]);
		p[i] --;
	}
	solve();
	return 0;
}

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

int M = 1e9 + 7;

int main(){
	int h, w; cin>>h>>w;
	char arr[h][w];
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++) cin>>arr[i][j];
	}
	int dp[h][w]; 
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(arr[i][j] == '.'){
				if(i > 0) dp[i][j] += dp[i-1][j];
				if(j > 0) dp[i][j] += dp[i][j-1];
				dp[i][j] %= M;
			}
		}
	}
	cout<<dp[h-1][w-1]<<endl;
}

Measured memory_bytes: 5120
N,S,Q,*k = open(0).read().split()
N,Q = map(int, (N,Q))
K = map(int, k)
for k in K:
  D = 0
  M = 0
  DM = 0
  DMC = 0
  for i in range(k):
    if S[i]=='D':
      D += 1
    elif S[i]=='M':
      DM += D
      M += 1
    elif S[i]=='C':
      DMC += DM
  for i in range(N-k):
    if S[i]=='D':
      DM -= M
      D -= 1
    elif S[i]=='M':
      M -= 1
    if S[i+k]=='D':
      D += 1
    elif S[i+k]=='M':
      DM += D
      M += 1
    elif S[i+k]=='C':
      DMC += DM
  print(DMC)


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

int max_ham(vector<vector<int>> &w, int N){
	vector<int> p(N);
	int i, ans = 0;
	for(i = 0; i < N; i++){
		p[i] = i;
	}
	do{
/*		for(i = 0; i < N; i++){
			printf("%lld ", p[i]);
		}
		printf("\n");
*/		int now = 0;
		for(i = 1; i < N; i++){
			now += w[p[i - 1]][p[i]];
		}
		ans = max(ans, now);
	}while(next_permutation(p.begin(), p.end()));
	return ans;
}

signed main(){
	int N, i, j;
	int a[] = {1, 2, 4, 7, 12, 20, 29, 38, 52, 73};
	scanf("%lld", &N);
	vector<vector<int>> w(N, vector<int>(N, 0));
	w[0][1] = 1;
	w[1][0] = 1;
	for(i = 2; i < N; i++){
//		printf("i = %lld\n", i);
		int M = max_ham(w, i);
//		printf("M = %lld\n", M);
		for(j = 0; j < i; j++){
			w[i][j] = a[j] * (M + 1);
			w[j][i] = a[j] * (M + 1);
		}
	}
//	printf("%lld\n", max_ham(w, N));
	for(i = 0; i < N; i++){
		for(j = 0; j < N; j++){
			printf("%lld ", w[i][j]);
		}
		printf("\n");
	}
	return 0;
}

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

int main(){
  string s,t;
  cin>>s>>t;
  string ans="zzzzzz";
  for(int i=0;i<(int)s.size()-t.size()+1;++i){
    bool flag=0;
    string tmp=s;
    for(int j=0;j<t.size();++j){
      if(s[i+j]!=t[j]&&s[i+j]!='?'){
        flag=1;
        break;
      }
      else tmp[i+j]=t[j];
    }
    if(!flag){
      for(int i=0;i<s.size();++i){
        if(tmp[i]=='?')tmp[i]='a';
      }
      if(ans>tmp)ans=tmp;
    }
  }
  cout<<(ans=="zzzzzz"?"UNRESTORABLE":ans)<<endl;
}


Measured memory_bytes: 256
#define FNAME ""

#include <bits/stdc++.h>

#define hash padjf9srpi
#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (n); i++)
#define fornr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define forab(i, a, b) for (int i = (a); i < (b); i++)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
 
#ifdef _WIN32
    #define I64 "%I64d"
#else
    #define I64 "%lld"
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair <int, int> pii;                                                                                                                                                                                      
typedef vector <int> vi;

template <class T> T sqr(const T &a) {return a * a;}

int n, m;
char a[505][505];

int main()
{
#ifdef LOCAL
    freopen(FNAME".in", "r", stdin);
    freopen(FNAME".out", "w", stdout);
#endif

    scanf("%d%d ", &n, &m);
    forn(i, n) {
        scanf(" ");
        forn(j, m)
            scanf("%c", &a[i][j]);
    }
    forn(i, m)
        printf("#");
    puts("");
    forn(i, n - 2) {
        forn(j, m) {
            if (j % 2 == 0 || a[i + 1][j] == '#')
                printf("#");
            else
                printf(".");
        }             
        puts("");
    }
    forn(i, m)
        printf(".");
    puts("\n");
    
    forn(i, m)
        printf(".");
    puts("");
    forn(i, n - 2) {
        forn(j, m) {
            if (j % 2 == 1 || a[i + 1][j] == '#')
                printf("#");
            else
                printf(".");
        }             
        puts("");
    }
    forn(i, m)
        printf("#");
    puts("");

}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double N,P,sum=0;
  int p,ans=0;
  cin >> N;
  vector<int> point(N);
  for(int i=0;i<N;i++) {
	cin >> point.at(i);
    sum=sum+point.at(i);
  }
  P=sum/N;
  p=P;
  if(P-p<0.55) P=p;
  else P=p+1;
  for(int i=0;i<N;i++) {
    ans=ans+(point.at(i)-P)*(point.at(i)-P);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

char s[401000];
int n, k;

int main()
{
	scanf("%d%d%s", &n, &k, s + 1);
	bool ok = 1;
	for(int i = 1; i <= n; i++)
		if(s[i] == 'A') {ok = 0; break;} 
	if(ok)
	{
		k--;
		for(int i = 1; i <= n; i++)
			s[i] = 'A';
	}
	int h = 1, t = 0;
	if(n == 1) t = k & 1;
	else
		while(k--)
		{
			if(h > n) break;
			if(t) s[h] = s[h] == 'A' ? 'B' : 'A';
			if(s[h] == 'B')
			{
				t ^= 1;
				if(t == 1) s[n + h] = 'B';
				else s[n + h] = 'A';
				h++;
			}
			else
			{
				if(t == 1) s[h] = 'A';
				else s[h] = 'B';
			}
		}
	if(t)
	{
		for(int i = h; i < h + n; i++)
			s[i] = s[i] == 'A' ? 'B' : 'A';
	}
	if(k >= 0 && !(k & 1) && s[h] == 'A') s[h] = 'B';
	printf("%s\n", s + h);
}

Measured memory_bytes: 2028
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<complex>
#include<numeric>
#include<bitset>
#define INF 1001001001
#define EPS 0.000000001

using namespace std;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int,int> pint;

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

int nextInt(){
	int x;
	scanf("%d",&x);
	return x;
}

int main(){
	while(1){
		int n = nextInt();
		if(n==0) break;
		vector<pint> vp;
		
		vp.push_back(pint(0, 0));
		
		for(int i=1; i<n; i++){
			int m = nextInt();
			int d = nextInt();
			vp.push_back(pint(vp[m].first+dx[d], vp[m].second+dy[d]));
		}
		
		int minx = INF, miny = INF;
		int maxx = -INF, maxy = -INF;
		for(int i=0; i<n; i++){
			minx = min(minx, vp[i].first);
			miny = min(miny, vp[i].second);
			maxx = max(maxx, vp[i].first);
			maxy = max(maxy, vp[i].second);
		}
		printf("%d %d\n", maxx-minx+1, maxy-miny+1);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 1e5;
int n;
V<int> v;
int f(){
  FOR(i, 0, n){
    cin >> v[i];
    v[i]--;
  }
  int ret = 0;
  while(true){
    FOR(i, 0, n) if(v[i]!=n-i-1) goto bad;
    break;
bad:;
    next_permutation(all(v));
    ret++;
  }
  return ret;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  v.resize(n);
  cout << abs(f()-f()) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define LL long long 
LL H, W, A, B;
LL mod = 1000000007;
LL mul[200010];
LL dis[200010];
LL ans;
LL fermat(LL x, LL y) {
	//std::cout << y << std::endl;
	if (y == 0) return 1;
	if (y == 1)	return x;
	if (y % 2 == 1) {
		LL F = fermat(x, y / 2);
		F *= F;
		F%=mod;
		return F*x%mod;
	}
	if (y % 2 == 0) {
		LL F = fermat(x, y / 2);
		F *= F;
		return F%mod;
	}
}

int main() {
	std::cin >> H >> W >> A >> B;
	mul[1] = 1;
	mul[0] = 1;
	for (LL i = 1; i <= H + W - 2; i++) {
		mul[i] = mul[i - 1] * i;
		mul[i]%=mod;
	}
	dis[H + W - 2] = fermat(mul[H + W - 2], mod - 2);
	for (LL i = H + W - 3; i > 0; i--) {
		dis[i] = dis[i + 1] * (i + 1);
		dis[i] %= mod;
	}
	dis[0] = 1;
	for (LL i = B; i < W; i++) {
		LL plus = mul[H - A + i - 1] * dis[i] % mod*dis[H - A - 1] % mod*mul[W + A - i - 2] % mod* dis[A - 1] % mod* dis[W - i - 1] % mod;
		ans += plus;
		ans %= mod;
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

static ll const def=1LL<<40;
template<class V,int NV> class SegTree_3 {
public:
	vector<V> val,ma,key;
	SegTree_3(){
		int i;
		val.resize(NV*2,0);
		ma.resize(NV*2,0);
		key.resize(NV*2,0);
		FOR(i,NV) key[NV+i]=i;
	};
	
	pair<V,V> getval(int x,int y,int l=0,int r=NV,int k=1) {
		if(r<=x || y<=l) return {def,-1};
		if(x<=l && r<=y) return {ma[k],key[k]};
		auto a=min(getval(x,y,l,(l+r)/2,k*2),getval(x,y,(l+r)/2,r,k*2+1));
		a.first+=val[k];
		return a;
	}
	
	void update(int x,int y, V v,int l=0,int r=NV,int k=1) {
		if(l>=r) return;
		if(x<=l && r<=y) {
			val[k]+=v;
			ma[k]+=v;
		}
		else if(l < y && x < r) {
			update(x,y,v,l,(l+r)/2,k*2);
			update(x,y,v,(l+r)/2,r,k*2+1);
			if(ma[k*2]<ma[k*2+1]) {
				ma[k]=val[k]+ma[k*2];
				key[k]=key[k*2];
			}
			else {
				ma[k]=val[k]+ma[k*2+1];
				key[k]=key[k*2+1];
			}
		}
	}
};

SegTree_3<ll,1<<20> st;
vector<int> C;
int N;
int A[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>A[i];
		C.push_back(A[i]);
	}
	sort(ALL(C));
	FOR(i,N) st.update(i,i+1,C[i]);
	
	ll ret=0;
	FOR(i,N) {
		x=lower_bound(ALL(C),A[i])-C.begin();
		auto p=st.getval(x,N);
		ret+=p.first-A[i];
		st.update(0,p.second,1);
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 51188