akhauriyash/Code-Regression huggingface dataset:
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

type Query struct {
	l, r, idx int
}

type Queries []Query

func (a Queries) Len() int           { return len(a) }
func (a Queries) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Queries) Less(i, j int) bool { return a[i].r < a[j].r }

// 1-indexed
type BIT [2][]int

func NewBIT(n int) *BIT {
	var b BIT
	for i := range b {
		b[i] = make([]int, n)
	}
	return &b
}

// [l,r)にxを加算
func (b *BIT) add(l, r, x int) {
	add_sub := func(p, idx, x int) {
		for idx < len(b[p]) {
			b[p][idx] += x
			idx += idx & (-idx)
		}
	}
	add_sub(0, l, -x*(l-1))
	add_sub(0, r, x*(r-1))
	add_sub(1, l, x)
	add_sub(1, r, -x)
}

// [l,r)の和
func (b *BIT) sum(l, r int) int {
	sum_sub := func(p, idx int) int {
		s := 0
		for idx > 0 {
			s += b[p][idx]
			idx -= idx & (-idx)
		}
		return s
	}
	return sum_sub(0, r-1) + sum_sub(1, r-1)*(r-1) - (sum_sub(0, l-1) + sum_sub(1, l-1)*(l-1))
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, q := nextInt(), nextInt()
	c := nextInts(n)
	queries := make(Queries, q)
	for i := 0; i < q; i++ {
		l, r := nextInt(), nextInt()
		queries[i] = Query{l, r, i}
	}
	sort.Sort(queries)

	// right[i]: 色iの玉のうち最も右にある玉=良い玉の場所
	right := make([]int, n+1)
	// 良い玉のある場所:1, それ以外:0をとり，区間和をとるため
	bit := NewBIT(n + 10)
	ans := make([]int, q)
	// 1-indexed
	i := 1
	for _, query := range queries {
		for i <= query.r {
			col := c[i-1]
			if right[col] > 0 {
				bit.add(right[col], right[col]+1, -1)
			}
			right[col] = i
			bit.add(i, i+1, 1)
			i++
		}
		ans[query.idx] = bit.sum(query.l, query.r+1)
	}

	for i := range ans {
		puts(ans[i])
	}
}


Measured memory_bytes: 44980
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    int x,y;

    map<pii,int> mp;

    ll fact[3000001],inv[3000001];

    ll power(ll a, ll b)    //a is base, b is exponent
    {
        if(b==0)
            return 1;
        if(b==1)
            return a;
        if(b%2 == 1)
            return (power(a,b-1)*a)%mod;
        ll q = power(a,b/2);
        return (q*q)%mod;
    }

    void init()
    {
        fact[0]=1;
        inv[0]=1;
        for(int i=1;i<=1000000;++i)
        {
            fact[i]=(fact[i-1]*i)%mod;
            inv[i]=power(fact[i],mod-2);
        }
    }

    ll ncr(int n,int r)
    {
        // cout<<n<<" "<<r<<endl;
        if(n<r || r<0)
            return 0;
        return ((fact[n]*inv[r])%mod*inv[n-r])%mod;
    }

    int func(int i,int j)
    {
        if(i<0 || j<0)
            return 0;
        if(i==0 && j==0)
            return 1;
        if(mp.find({i,j})!=mp.end())
            return mp[{i,j}];
        return mp[{i,j}]=(func(i-1,j-2)+func(i-2,j-1))%mod;
    }

    ll func(ll n,ll k)
    {
        return ncr(n+k,2*k);
    }
    ll func2(ll n,ll k)
    {
        //cout<<n<<" "<<k<<endl;
        return ncr(k,n-k);
    }

    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        init();
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            cin>>x>>y;
            ll st,ed,ct,i,j;
            if(x%2==0)
            {
                st=x/2;
                ct=x/2;
                for(i=0;i<=ct;++i)
                {
                    if(y==st+3*i)
                    {
                        cout<<ncr(st+i,2*i)<<endl;
                        return 0;
                    }
                }
            }
            else
            {
                st=x/2+2;
                ct=x/2;
                ed=x/2;
                //cout<<ed<<endl;
                for(i=0;i<=ct;++i)
                {
                    if(y==st+3*i)
                    {
                        //cout<<(x+1)/2<<" "<<ed+i+1<<endl;
                        cout<<func2(x,ed+i+1)<<endl;
                        return 0;
                    }
                }
            }
            cout<<0<<endl;
        }
        return 0;
    }


Measured memory_bytes: 18688
global cnt
cnt = 0

def merge(A, left, mid, right):
    L = A[left:mid] + [float("inf")]
    R = A[mid:right] + [float("inf")]

    i = 0
    j = 0
    global cnt
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

        cnt += 1

def mergesort(A, left, right):
    rsl = []
    if left+1 < right:
        mid = int((left+right)/2)
        mergesort(A, left, mid)
        mergesort(A, mid, right)
        rsl = merge(A, left, mid, right)

    return rsl

n = int(input())
S = list(map(int, input().split()))

mergesort(S, 0, n)
print(*S)
print(cnt)


Measured memory_bytes: 63428
/*
created on 22/4/2020
*/
#include<bits/stdc++.h>
using namespace std;
#define Endl '\n'
typedef long long int lli;
void solve();
int main(int argc, char const *argv[]){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
}
int const maxlen = 3005;
lli N;
lli arr[maxlen];
lli memo[maxlen][maxlen][2];
lli find_ans(int i, int j, int cur){
  if(i>j){
    return 0;
  }
  lli& ret = memo[i][j][cur];
  if(ret!=-1)
    return ret;
  if(cur == 1){
    ret= min(-arr[i] + find_ans(i+1, j, 0), -arr[j] + find_ans(i, j-1, 0));
  }else {
    ret= max(arr[i] + find_ans(i+1, j, 1), arr[j] + find_ans(i, j-1, 1));
  }
  return ret;
}
void solve(){
  cin>>N;
  memset(memo, -1, sizeof memo);
  for(int i=0;i<N;i++)
    cin>>arr[i];
  lli ans = find_ans(0, N-1,0);
  cout<<ans<<Endl;
}


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

int main() {
    string s;
    cin >> s;
    bool b = true;
    int a = s.size();
    rep(i, a) {
        if(i%2==0 && s[i]=='L') b = false;
        if(i%2==1 && s[i]=='R') b = false;
    }
    if(b) printf("Yes\n");
    else printf("No\n");
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
#define INF 1<<21
using pii = std::pair<int,int>;
#define SORT(v) std::sort(v.begin(), v.end())
long long gcd(long long i, long long j) {
    if (i < j) std::swap(i, j);
    if (i%j == 0) return j;
    return gcd(j, i%j);
}
long long lcm(long long a, long long b) {
    return (a / gcd(a,b))*b;
}
int main(){
    int N;
    std::cin >> N;
    long long a, b,ans=1LL;
    for (int i = 0; i < N; i++) {
        std::cin >> b;

        ans = lcm(ans, b);
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
import sys
input=sys.stdin.readline
n,m = map(int, input().split())
uf = UnionFind(m)
lang=set()
for i in range(n):
    lis = list(map(int,input().split()))
    for i in range(1,len(lis)-1):
        lang.add(lis[i]-1)
        uf.union(lis[i]-1,lis[i+1]-1)
    lang.add(lis[-1]-1)
e = next(iter(lang))
if lang == set(uf.members(e)):
    print("YES")
else:
    print("NO")



Measured memory_bytes: 70764
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
from numba import njit
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
A = LI()
Q = I()
BC = [LI() for _ in range(Q)]

sum_A = sum(A)
c = collections.Counter(A)

for pair in BC:
    num_from = pair[0]
    num_to = pair[1]
    if num_from in c:
        diff = (num_to - num_from) * c[num_from]
        sum_A += diff
        print(sum_A)
        c[num_to] += c[num_from]
        c[num_from]=0
    else:
        print(sum_A)

Measured memory_bytes: 118424
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

int main(int argc, char const *argv[])
{

    int n;
    cin >> n;
    int sumtime = 0;
    vector<int> v(n);
    rep(i, n)
    {
        int t;
        cin >> t;
        v[i] = t;
        sumtime += t;
    }
    int m;
    cin >> m;
    rep(i, m)
    {
        int p, x;
        cin >> p >> x;
        p--;
        cout << sumtime - v[p] + x << endl;
    }
    return 0;
}


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

int main() {
  int a,b,c,x,y;cin>>a>>b>>c>>x>>y;
  int ans=1e9;
  for(int i=0;i<=max(x,y);i++){
    int cnt=2*i*c+max(x-i,0)*a+max(y-i,0)*b;
    ans=min(ans,cnt);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3576
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();

    if ((X == 3) || (X == 5) || (X == 7)) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }

  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
 
typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
  int n; cin >> n;
  while(n--) {
    string s; cin >> s;
    set<string> se;
    se.insert(s);
    for(int i = 1; i < s.size(); i++) {
      string f = s.substr(0, i);
      string b = s.substr(i);
      se.insert(b+f);
      reverse(all(f));
      se.insert(f+b);
      se.insert(b+f);
      reverse(all(b));
      se.insert(f+b);
      se.insert(b+f);
      reverse(all(f));
      se.insert(f+b);
      se.insert(b+f);
    }
    cout << se.size() << endl;
  }
}

Measured memory_bytes: 1296
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	int num = 0;
	string s, t;
	cin >> s >> t;
	if (s == t) {
		cout << "Yes" << endl;
		return 0;
	}
	while (s != t && num < s.size()) {
		char c = s[s.size() - 1];
		for (int i = s.size() - 1; i > 0; i--) {
			s[i] = s[i - 1];
		}
		s[0] = c;
		if (s == t) {
			cout << "Yes" << endl;
			return 0;
		}
		num++;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    n, k, *v = map(int, open(0).read().split())
    w = v[::-1]

    ans = 0
    m = min(n, k)
    for i in range(m + 1):
        for j in range(m + 1 - i):
            d = k - (i + j)
            g = v[:i] + w[:j]
            ps = sum(x for x in g if x > 0)
            ng = [x for x in g if x < 0]
            ng.sort()
            val = ps + sum(ng[d:])
            ans = max(ans, val)

    print(ans)


if __name__ == '__main__':
    main()


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

int	main()
{
	int t_attack, t_hp, a_attack, a_hp;

	cin >> t_hp >> t_attack >> a_hp >> a_attack;
	int win, lose;
	win = a_hp / t_attack;
	if (a_hp % t_attack != 0)
		win++;
	lose = t_hp / a_attack;
	if (t_hp % a_attack != 0)
		lose++;
	if (win <= lose)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
ll gcd(ll a, ll b);
int main(){
cin.tie(0);
  ll l,r,d,result=0;
cin >>l>>r>>d;
for(ll i=l;i<=r;i++){
 if(i%d==0)result++; 
  
}
cout <<result;
return 0;
}






ll gcd(ll a, ll b){

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

}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n;  cin >> n;
  set<string> key;
  for(int i=0; i<n; i++){
    string s; cin >> s;
    key.insert(s);
  }
  cout << key.size() << endl;
}


Measured memory_bytes: 19260
#include<bits/stdc++.h>
using namespace std;
struct edge{
  int to,cost;
};
typedef pair<int,int> P;
int V;
vector<edge> G[100000];
int d[100000];
void dijkstra(int s){
  priority_queue<P ,vector<P>,greater<P> >que;
  fill(d,d+V,1e9+1);
  d[s]=0;
  que.push(P(0,s));
  //
  while(!que.empty()){
    P p=que.top();
    que.pop();
    int v=p.second;
    if(d[v]<p.first)continue;

    for(int i=0;i<G[v].size();i++){
      edge e=G[v][i];
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        que.push(P(d[e.to],e.to));
      }
    }
  }
}
int main(){
  int k,u,v,c;
  cin >> V;
  for(int i=0;i<V;i++){
    cin >> u >> k;
    for(int j=0;j<k;j++){
      cin >> v >> c;
      edge ed;
      ed.to=v;
      ed.cost=c;
      G[u].push_back(ed);
    }
  }
  dijkstra(0);
  for(int i=0;i<V;i++){
    cout << i << " " << d[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 10148
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    ll N, K; cin >> N >> K;
    vector<ll> A(N), F(N);
    REP(i, 0, N) cin >> A[i];
    REP(i, 0, N) cin >> F[i];

    sort(ALL(A));
    sort(ALL(F), greater<>());

    ll l = -1, r = (ll)1e12, mid;
    while (r - l > 1) {
        mid = l + (r - l) / 2;
        ll cnt = K;
        REP(i, 0, N) {
            cnt -= A[i] - min(A[i], mid / F[i]);
        }
        if (cnt >= 0) r = mid;
        else l = mid;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 6372
from sys import stdin

def main():
    M = stdin.readline().strip()
    S,E,N,W=False,False,False,False
    for i in M:
        if i == 'S':
            S = True
        elif i == 'E':
            E = True
        elif i == 'N':
            N = True
        elif i == 'W':
            W = True
    if S == N and E == W:
        print('Yes')
    else:
        print('No')

main()


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

int main() {
  int n;
  cin>>n;
  ll a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  int res=1;
  if(n==1) cout<<res<<endl;
  else {
    int plus[n-1]={0};
    for(int i=0;i<n-1;i++){
      if(a[i+1]-a[i]>0) plus[i]=1;
      else if(a[i+1]-a[i]<0) plus[i]=-1; 
    }
    int temp=plus[0];
    for(int i=0;i<n-1;i++){
      if(temp==0){
        if(plus[i]==1) temp=1;
        else if(plus[i]==-1) temp=-1;
      }
      if(temp==1){
        if(i!=n-2 && plus[i]==-1 && plus[i+1]!=-1) {
          for(int j=i+1;j<n-1;j++){
            if(plus[j]==0) {
              if(j!=n-1) continue;
              else res++;
            }
            else if(plus[j]==1){
              res++;
              break;              
            }
            else {
              temp=-1;
              res++;
              break;
            }
          }
        }
        else if(plus[i]==-1){
          temp=-1;
          res++;
        }
      }
      if(temp==-1){
        if(i!= n-2 && plus[i]==1 && plus[i+1]!=1) {
          for(int j=i+1;j<n-1;j++){
            if(plus[j]==0) {
              if(j!=n-1) continue;
              else res++;
            }
            else if(plus[j]==-1){
              res++;
              break;              
            }
            else {
              temp=1;
              res++;
              break;
            }
          }
        }
        else if(plus[i]==1){
          temp=1;
          res++;
        }
      }
    }
    cout<<res<<endl;
  }
  return 0;
}

Measured memory_bytes: 1408
/* * * * * * * * * * * **
*                      *
*	   saurabh8522	   *
*	  I will handle	   *
*		   it.		   *
*                      *
* * * * * * * * * * * **/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a),0,sizeof((a)))
#define one(a) memset((a),1,sizeof((a)))
#define minus(a) memset((a),-1,sizeof((a)))
#define all(g) g.begin(),g.end()
#define ppb pop_back
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> //indexed_set;
typedef long long int ll;
#define MOD 1000000007
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b,ll m) {ll res=1;a%=m;for(;b;b>>=1){if(b&1)res=res*a%m;a=a*a%m;}return res;}
ll numdigit(ll n){return floor(log10(n)) + 1;}
bool isPowerTwo (ll x) { return x && (!(x&(x-1))); } 
int  main(){
	FastRead;
	ll t=1;
	// cin>>t;
	while(t--){
		ll n;
		cin>>n;
		map<ll,ll>mp;
		ll ans=0;
		for(int i=0;i<n;i++){
			ll a;cin>>a;
			ans+=mp[i-a];
			mp[i+a]++;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 26296
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();

		if ((a*b)%2 == 1){
			System.out.println("Odd");
		}
		else {
			System.out.println("Even");
		}
	}

}


Measured memory_bytes: 21460
#include <iostream>
# include<string>

using namespace std;

int waru(int num) {
	int sum = 0;
	while (num > 0) {
			sum += num % 10;
			num /= 10;
	}
	return sum;
}

int main() {
	int N;
	cin >> N;
	int sum = waru(N);
	if (N % sum == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}



Measured memory_bytes: 256
#include<cstdio>
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)

using namespace std;

//Nは桁数が大きい場合があるので文字列として受け取る
string N;
vector<int> n;  //Nの各桁の数字を格納するベクター
long long dp[105][2][5];

int main(){
  cin>>N;
  int k; cin >> k;

  //ベクターnを構成
  for(auto a : N){
    n.push_back(a-'0');
  }
  int l = N.size();  //nの長さ

  dp[0][0][0] = 1;
  for(int i = 0; i < l; i++){
    for(int smaller = 0; smaller < 2; smaller++){
      for(int j = 0; j < 4; j++){
        for(int x = 0; x <= (smaller ? 9 : n[i]); x++){
          dp[i + 1][smaller || x < n[i]][j + (x!=0)] += dp[i][smaller][j];
        }
      }
    }
  }

  cout << dp[l][0][k] + dp[l][1][k] << endl;

  return 0;
}

Measured memory_bytes: 256
package main

import(
  "fmt"
)

func max( array []int )int{
  max := 0
  index := -1
  for i := 0 ; i < len( array ) ; i++ {
    if max < array[i] {
      max = array[i]
      index = i
    }
  }

  array[index] = 0
  return max
}

func main(){
  var n , a int

  fmt.Scan(&n)
  array := make( []int , 0 , n )

  for i := 0 ; i < n ; i++ {
    fmt.Scan(&a)
    array = append( array , a)
  }

  var alice , bob int
  for i := 0 ; i < n ; i++ {
    point := max( array )
    if i % 2 != 1 {
      alice += point
    }else{
      bob += point
    }
  }

  sub := alice - bob
  fmt.Print( sub )
}


Measured memory_bytes: 512
cnt = 0
N,A,B = map(int,input().split())
for n in range(1,N+1):
    digit_sum = 0
    str_N = str(n)
    for digit in str_N:
        digit_sum += int(digit)
    if A <= digit_sum <= B:
        cnt += n
        #print(n)
print(cnt)

Measured memory_bytes: 2940
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>A;//きゅー
int main(void)
{
	int A, B;
	scanf("%d%d", &A, &B);
	if (A < 10 && B < 10) {
		printf("%d", A * B);
		return 0;
	}
	printf("-1");
	return 0;
	
}

Measured memory_bytes: 256
# Studying https://atcoder.jp/contests/abc168/tasks/abc168_f
#      and https://atcoder.jp/contests/abc168/submissions/13393878

N,M = gets.split.map(&:to_i)
縦線,横線 = [[N,0,1,2],[M,1,2,0]].map{|n,*va|
	n.times.map{ gets.split.map(&:to_i).values_at(*va) }.group_by{_3}
}
経線,緯線 = [縦線,横線].map{|l|
	[-Float::INFINITY] + l.keys.sort + [Float::INFINITY]
}
右？,下？ = [[縦線,経線,緯線],[横線,緯線,経線]].map{|l1,l2,l3|
	Hash.new{|h,k|
		h[k] = l1[l2[k+1]].inject([true]*(l3.size-2)){|a,(b,c,_)|
			l = l3.bsearch_index{|_| b<=_ }
			r = l3.bsearch_index{|_| c<_ }-1
			next a.fill(false,l...r)
		}
	}
}

area = 0
cow = [経線,緯線].map{|l| l.bsearch_index{|_| 0<_ }-1 }
Q = [cow]
Qd = Array.new(経線.size-1){ [false]*(緯線.size-1) }
Qd[cow[0]][cow[1]] = true
until Q.empty?
	横,縦 = Q.pop

	area += (経線[横+1]-経線[横])*(緯線[縦+1]-緯線[縦])
	break if area.infinite?

	(Q << [横+1,縦]; Qd[横+1][縦] = true) if ! Qd[横+1][縦] && 右？[横][縦]
	(Q << [横-1,縦]; Qd[横-1][縦] = true) if ! Qd[横-1][縦] && 右？[横-1][縦]
	(Q << [横,縦+1]; Qd[横][縦+1] = true) if ! Qd[横][縦+1] && 下？[縦][横]
	(Q << [横,縦-1]; Qd[横][縦-1] = true) if ! Qd[横][縦-1] && 下？[縦-1][横]
end

puts(area.finite? ? area : 'INF')


Measured memory_bytes: 43092
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    i64 n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    i64 g = __gcd(n, m);

    string ss = "", tt = "";
    for (int i = 0; i < n; i++) {
        if (i % (n / g) == 0) {
            ss += s[i];
        }
    }
    for (int i = 0; i < m; i++) {
        if (i % (m / g) == 0) {
            tt += t[i];
        }
    }
    cout << (ss == tt ? n / g * m : -1) << endl;
}

Measured memory_bytes: 512
n = int(input())
l = list(map(int,input().split()))
 
ans = 0
 
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if l[i] != l[j] and l[j] != l[k] and l[i] != l[k]:
        if l[i]+l[j]>l[k] and l[j]+l[k]>l[i] and l[i]+l[k]>l[j]:
          ans += 1
        
print(ans)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;



int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int n, k;
    ios::sync_with_stdio(false);
    cin >> n >> k;
    if(k == 0) {
        cout << 1LL * n * n;
        return 0;
    }
    ll ans = 0;
    for(int b = k + 1; b <= n; b++) {
        for(int val = 0; val <= n; val += b) {
            // val = a - r
            // k <= r < b
            // a - b < val <= a - k
            // a < val + b
            // a >= val + k
            ans += min(val + b - 1, n) - min(n + 1, val + k) + 1;
        }
        //printf("%d %d\n" ,b,ans);
    }
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	static Scanner s=new Scanner(System.in);
	static int n=s.nextInt();
	static int[]a=new int[n],b=new int[n],min=new int[n],max=new int[n];
	
	public static void main(String[]$){
		Arrays.setAll(a,i->s.nextInt());
		Arrays.setAll(b,i->s.nextInt());
		Arrays.fill(min,1);
		Arrays.fill(max,Integer.MAX_VALUE);
		
		if(!f(a,0,n,1)||!f(b,n-1,-1,-1)) {
			System.out.println(0);
			return;
		}
		
		long r=1;
		for(int i=0;i<n;++i) {
			r*=Math.max(0,max[i]-min[i]+1);
			r%=1000000007;
		}
		System.out.println(r);
	}
	static boolean f(int[]b,int f,int t,int d) {
		for(int i=f;i!=t;i+=d) {
			if(i==f||b[i]!=b[i-d]) {
				if(min[i]>b[i]||max[i]<b[i])
					return false;
				min[i]=max[i]=b[i];
			}else {
				max[i]=Math.min(max[i],b[i]);
			}
		}
		return true;
	}
}


Measured memory_bytes: 88816
N, K = map(int, input().split())
lst = [int(x) for x in input().split()]
while True:
    l = [s for s in str(N)]
    f = True
    for n in set([int(x) for x in l]):
        if n in lst:
            f = False
            break
    if f:
        print(N)
        exit()
    N += 1

Measured memory_bytes: 3064
import scala.io.StdIn._

object Main extends App {
  val N = readLine.toInt
  val V = readLine.split(' ').map(s => s.toInt)
  val C = readLine.split(' ').map(s => s.toInt)

  var result = 0
  (0 until N).foreach(i => {
    val diff = V(i) - C(i)
    if (diff > 0) {
      result += diff
    }
  })
  println(result)
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;
using graph=vector<vector<int>>;

using rolling_hash=pair<lint,lint>;

const lint base=10007,mod1=1e9+7,mod2=998244353;

lint modpow(lint a,lint k,int m){
	lint r=1;
	for(lint x=a%m;k>0;k>>=1,x=x*x%m) if(k&1) r=r*x%m;
	return r;
}

bool is_DAG(const graph& G){
	int n=G.size();
	vector<int> deg(n);
	rep(u,n) for(int v:G[u]) deg[v]++;

	int cnt=0;
	queue<int> Q;
	rep(u,n) if(deg[u]==0) Q.emplace(u);
	while(!Q.empty()){
		int u=Q.front(); Q.pop();
		cnt++;
		for(int v:G[u]) if(--deg[v]==0) Q.emplace(v);
	}
	return cnt==n;
}

vector<int> topological_order(const graph& D){
	int n=D.size();
	vector<int> deg(n);
	rep(u,n) for(int v:D[u]) deg[v]++;

	vector<int> res;
	queue<int> Q;
	rep(u,n) if(deg[u]==0) Q.emplace(u);
	while(!Q.empty()){
		int u=Q.front(); Q.pop();
		res.emplace_back(u);
		for(int v:D[u]) if(--deg[v]==0) Q.emplace(v);
	}
	return res;
}

int main(){
	string s,t; cin>>s>>t;

	int m=s.length(),n=t.length();
	lint basepow1=modpow(base,n,mod1);
	lint basepow2=modpow(base,n,mod2);

	rolling_hash ht;
	rep(i,n){
		ht.first =(ht.first *base+t[i])%mod1;
		ht.second=(ht.second*base+t[i])%mod2;
	}

	vector<rolling_hash> hs(m);
	rep(i,n){
		hs[0].first =(hs[0].first *base+s[i%m])%mod1;
		hs[0].second=(hs[0].second*base+s[i%m])%mod2;
	}
	rep(i,m-1){
		hs[i+1].first =(hs[i].first *base-s[i%m]*basepow1+s[(n+i)%m])%mod1;
		hs[i+1].second=(hs[i].second*base-s[i%m]*basepow2+s[(n+i)%m])%mod2;
		if(hs[i+1].first <0) hs[i+1].first +=mod1;
		if(hs[i+1].second<0) hs[i+1].second+=mod2;
	}

	graph G(m);
	rep(u,m) if(ht==hs[u]) G[u].emplace_back((u+n)%m);

	if(!is_DAG(G)) return puts("-1"),0;

	vector<int> dp(m);
	auto p=topological_order(G);
	for(int i=m-1;i>=0;i--){
		int u=p[i];
		for(int v:G[u]) dp[u]=dp[v]+1;
	}
	printf("%d\n",*max_element(dp.begin(),dp.end()));

	return 0;
}


Measured memory_bytes: 43744
#include <cstdio>
#include <stdint.h>
#include <algorithm>

const int64_t INF=1e18;

int hs[200005];
int64_t dp[200005];

struct Line{
  int64_t m,b;
  Line(int64_t m,int64_t b):m(m),b(b){
  }
  int64_t operator()(int64_t x){
    return m*x+b;
  }
};

struct LiChao{
  int left,right;
  struct Line line;
  LiChao():left(-1),right(-1),line(0,INF){
  }
}nodes[200005];
int nodes_cnt=0;

int new_node(struct Line line){
  nodes[nodes_cnt].left=-1;
  nodes[nodes_cnt].right=-1;
  nodes[nodes_cnt].line=line;
  return nodes_cnt++;
}

int insert(int root,int L,int R,struct Line line){
  if(L>R) return -1;
  if(root==-1) return new_node(line);
  int M=(L+R)/2;
  if(line(M)<nodes[root].line(M)){
    std::swap(line,nodes[root].line);
  }
  if(line(L)<nodes[root].line(L)){
    nodes[root].left=insert(nodes[root].left,L,M-1,line);
  }else{
    nodes[root].right=insert(nodes[root].right,M+1,R,line);
  }
  return root;
}

int64_t query(int root,int L,int R,int x){
  if(root==-1) return INF;
  int M=(L+R)/2;
  int64_t res=nodes[root].line(x);
  if(x<M){
    return std::min(res,query(nodes[root].left,L,M-1,x));
  }else if(x>M){
    return std::min(res,query(nodes[root].right,M+1,R,x));
  }else{
    return res;
  }
}

int root=-1;

int main(){
  int N;
  int64_t C;
  scanf("%d %ld",&N,&C);
  for(int i=0;i<N;i++){
    scanf("%d",&hs[i]);
  }
  std::fill(dp+1,dp+N,INF);
  for(int i=0;i<N;i++){
    if(i>0){
      dp[i]=query(root,0,1000000,hs[i])+1LL*hs[i]*hs[i]+C;
    }
    root=insert(root,0,1000000,Line(-2*hs[i],1LL*hs[i]*hs[i]+dp[i]));
    //printf("dp[%d]=%ld\n",i,dp[i]);
  }
  printf("%ld\n",dp[N-1]);
  return 0;
}


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

ans = []
diff = 0
for i in range(N-1):
  if A[i] > A[i+1]:
    diff = A[i]-A[i+1]
    A[i+1] = A[i+1] + diff
    ans.append(diff)
    diff = 0
  else:
    ans.append(diff)

print(sum(ans))


Measured memory_bytes: 32224
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n=1,t;
    while(cin>>n,n){
        int num=0,count=0;
        vector<int> v;
        for(int i=0;i<n;i++){
            cin >>t;
            count++;
            v.push_back(t);
            num+=t;
        }
        num -= *max_element(v.begin(),v.end());
        num -= *min_element(v.begin(),v.end());
        int ans=(double)num/(count-2);
        cout<<ans<<endl; 
    }
}

Measured memory_bytes: 3088
#include<stdio.h>
int main(){
int i,a,b,c[7];
for(i=0;i<7;i++){
	scanf("%d%d",&a,&b);
	c[i] = a-b;
}
for(i=0;i<7;i++){
printf("%d\n",c[i]);
}
return 0;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    string s;
    cin>>s;
    int K;
    cin>>K;
    set<string> st;
    REP(i,s.size()) {
        for (int j=1;j<s.size()-i+1&&j<=K;j++) {
            st.insert(s.substr(i,j));
        }
    }
    int count = 0;
    for (auto x:st) {
        count++;
        if (count==K) {
            cout<<x<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define N 100010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n)	for(int i = n - 1; i >= 0; --i)
#define forr1(i, n)	for(int i = n; i >= 1; --i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
#define elif else if
 
const ll inf = 1e12 + 7;
const lld EPS = 0.00000001;
const ll modw = 1e9 + 7;

using namespace std;

ll dp[N];
ll a[N];

int main()
{
	barnarnar
	int n, k;
	cin >> n >> k;
	forn1(i, n)	cin >> a[i];
	dp[1] = 0;
	dp[2] = abs(a[2] - a[1]);
	for(int i = 3; i <= n; i++)
	{
		ll ans = inf;
		for(int j = i - 1, cur = 0; cur < k && j >= 1; cur++, j--)	ans = min(ans, dp[j] + abs(a[j] - a[i]));
		dp[i] = ans;
	}
	cout << dp[n];
	return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
//#include "toollib.h"
//#include "puzzle.h"
#define INT_MAX 2147483647
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#pragma warning (disable:4018)
#pragma warning (disable:4244)

using namespace std;
typedef long long int lint;


//***** Main Program *****

int cnt = 0;

void insertion(vector<int>* A, int g) {
	for (int i = g; i < (*A).size(); i++) {
		int v = (*A)[i];
		int j = i - g;
		while (j >= 0 && (*A)[j]>v) {
			(*A)[j + g] = (*A)[j];
			j = j - g;
			cnt++;
		}
		(*A)[j + g] = v;
	}
}

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	Loop(i, N) cin >> A[i];
	deque<int> g{ 1 };
	while (g.front() * 3 + 1 < N) g.push_front(g.front() * 3 + 1);
	cout << g.size() << endl;
	cout << g[0];
	for (int i = 1; i < g.size(); i++) cout << " " << g[i];
	cout << endl;
	Loop(i, g.size()) {
		insertion(&A, g[i]);
	}
	cout << cnt << endl;
	Loop(i, A.size()) cout << A[i] << endl;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> p(m), y(m);
  vector<vector<ll>> yd(n + 1);

  rep(i, m) cin >> p[i] >> y[i], yd[p[i]].push_back(y[i]);
  rep(i, n) sort(yd[i + 1].begin(), yd[i + 1].end());
  rep(i, m) printf("%06lld", p[i]),
      printf("%06lld\n", lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) -
                             yd[p[i]].begin() + 1);
}


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


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


int main(){
	ll N;
	cin>>N;
	vector<ll> A(N);
	ll sum=0;
	REP(i,N){
		cin>>A[i];
		if((A[i])%2==1) sum++;
	}
	
	if(sum%2==0){
		cout<<"YES"<<endl;
	}
	else cout<<"NO"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> P;
char tile[20][21];
bool vis[20][20];
int d[20][20];
int dist[11][11];
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
int w, h;
void calc(int sx, int sy) {
	memset(vis, 0, sizeof(vis));
	memset(d, -1, sizeof(d));
	vis[sy][sx] = 1;
	d[sy][sx] = 0;
	queue<P> Q;
	Q.push(P(sx, sy));
	while (!Q.empty()) {
		P p = Q.front(); Q.pop();
		int x = p.first, y = p.second;
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (nx < 0 || nx >= w || ny < 0 || ny >= h||tile[ny][nx]=='x'||vis[ny][nx]) continue;
			vis[ny][nx] = 1;
			d[ny][nx] = d[y][x] + 1;
			Q.push(P(nx, ny));
		}
	}
}
int main() {
	while (cin >> w >> h, w) {
		int sx, sy;
		vector<P> dirty;
		for (int i = 0; i < h; i++) {
			cin >> tile[i];
			for (int j = 0; j < w; j++) if (tile[i][j] == 'o') sx = j, sy = i;
		}
		dirty.emplace_back(sx, sy);
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) if (tile[i][j] == '*') dirty.emplace_back(j, i);
		}
		for (int i = 0; i < dirty.size(); i++) {
			calc(dirty[i].first, dirty[i].second);
			for (int j = 0; j < dirty.size(); j++) {
				dist[i][j] = d[dirty[j].second][dirty[j].first];
			}
		}
		int perm[11];
		for (int i = 0; i < dirty.size(); i++) perm[i] = i;
		int ans = 1 << 30;
		do {
			int sum = 0;
			int prev = 0;
			bool ok = 1;
			for (int i = 1; i < dirty.size(); i++) {
				int t = dist[prev][perm[i]];
				if (t == -1) {
					ok = 0;
					break;
				}
				sum += t;
				prev = perm[i];
			}
			if (!ok) continue;
			ans = min(ans, sum);
		} while (next_permutation(perm + 1, perm + dirty.size()));
		if (ans == 1 << 30) cout << -1 << endl;
		else cout << ans << endl;
	}
}


Measured memory_bytes: 3072
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



namespace AtCoder.BeginnersSelections
{
    class Test
    {
        static void Main(string[] args)
        {
            int[] suu = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = suu[0];
            int A = suu[1];
            int B = suu[2];

            Console.WriteLine(N * A > B ? B : A * N);

        }
    }
}

Measured memory_bytes: 13396
def play(a,b)
	sa = 0
	sb = 0
	a.zip(b).each {|l,r|
		if l > r
			sa += l+r
		elsif l < r
			sb += l+r
		else
			sa += l
			sb += r
		end
	}
	[sa,sb]
end

while (n = gets.to_i)!=0
	a = []
	b = []
	n.times {
		l,r = gets.split.map(&:to_i)
		a << l
		b << r
	}
	puts play(a,b)* ' '
end

Measured memory_bytes: 6984
if __name__ == '__main__':
    x, k, d = list(map(int, input().split()))
    x = abs(x)
    if k * d > x:
        rest = (k - int(x / d))
        rest %= 2
        print(abs(x % d) if rest == 0 else abs(x % d - d))
    else:
        print(x - k * d)


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

typedef long long s64;

int main()
{
	//freopen("1.in","r",stdin);
	s64 n,a,b;
	cin>>n>>a>>b;
	if(a>b)puts("0"); else
	if(n==1)puts(a==b?"1":"0");
	else cout<<(n-2)*(b-a)+1;
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a / g * b;
}

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

    ll a, b;
    cin >> a >> b;
    cout << lcm(a, b) << "\n";
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (long long i = 0; i < N; i++)
using ll = long long;
template <class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INF = 1LL << 60;

int main() {
    ll W, H, x, y;
    cin >> W >> H >> x >> y;
    printf("%.10lf ", (W * H) / 2.0);
    if (x == W / 2.0 && y == H / 2.0) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = [int(i) for i in input()]

ans = 0
R = [0]*N
L = [0]*N
memoR = [S[N-1]]
memoL = [S[0]]
L[0] = 1
R[N-1] = 1
count = [0]*10

for i in range(1,N):
  L[i] = L[i-1]
  if S[i] not in memoL:
    L[i] +=1
    memoL.append(S[i])
for i in range(N-2,-1,-1):
  R[i] = R[i+1]
  if S[i] not in memoR:
    R[i] += 1
    memoR.append(S[i])
    
for i in range(1,N-1):
  if L[i-1] > count[S[i]]:
    ans += (L[i-1]-count[S[i]])*R[i+1]
    count[S[i]] = L[i-1]
print(ans)

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

#define pb push_back
#define mp make_pair
#define ft first
#define sc second
#define ull unsigned long long int
#define lli long long int
#define li long int

#define si(n) scanf("%d",&n)
#define sl(n) scanf("%ld",&n)
#define sll(n) scanf("%lld",&n)

#define pi(n) printf("%d",n)
#define pl(n) printf("%ld",n)
#define pll(n) printf("%lld",n)

using namespace std;

const int MAX=2e5+5;

lli A[MAX];
unordered_map<lli, int> M;

int main() {
    // freopen("a.in","r",stdin);
    // freopen("a.out","w",stdout);
    int N; si(N);
    for(int i=0; i<N; i++) {
        sll(A[i]); M[A[i]]++;
    }

    sort(A, A+N);

    int ans = 0;
    for(int i = N-1; i >= 0; i--) {
        lli base = 1;
        while(base <= A[i])
            base <<= 1;
        int ret = M[base-A[i]];
        if(base == 2*A[i] && ret >= 2) {
            ans++; M[A[i]] -= 2;
        }
        else if(base != 2*A[i] && ret != 0 && M[A[i]]>0) {
            ans++; M[A[i]]--; M[base-A[i]]--;
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 18420
//code by 27;
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	string st;
	cin>>st;
	sort(st.begin(),st.end());
	long long g=1;
	long long s=st.size()*(st.size()-1)/2;
	//cout<<st<<endl;
	for(int i=1;i<st.size();i++)
	{
		if(st[i]!=st[i-1])
		{
			s-=g*(g-1)/2;
			g=1;
		}
		else g++;
	}
	s-=g*(g-1)/2;
	cout<<s+1;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

long long N, A[1009][1009], cnt[1009];

vector<pair<int, int>> solve(vector<int> K) {
	vector<pair<int, int>> L;
	for (int pos : K) {
		if (cnt[pos] == N) continue;
		int v1 = A[pos][cnt[pos]];
		int v2 = A[v1][cnt[v1]];
		if (v2 != pos) continue;

		int a1 = v1, a2 = pos; if (a1 > a2) swap(a1, a2);
		L.push_back(make_pair(a1, a2));
	}
	sort(L.begin(), L.end());
	L.erase(unique(L.begin(), L.end()), L.end());
	return L;
}

int main() {
	scanf("%lld", &N);
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N - 1; j++) scanf("%lld", &A[i][j]);
		cnt[i] = 1;
	}

	vector<int> J; for (int i = 1; i <= N; i++) J.push_back(i);
	vector<pair<int, int>> R1 = solve(J); int ret = 0;
	while (R1.size() >= 1) {
		vector<int> R2;
		for (int i = 0; i < R1.size(); i++) {
			cnt[R1[i].first]++; R2.push_back(R1[i].first);
			cnt[R1[i].second]++; R2.push_back(R1[i].second);
		}
		R1 = solve(R2); ret++;
	}

	for (int i = 1; i <= N; i++) {
		if (cnt[i] == N) continue;
		cout << "-1" << endl;
		return 0;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;



signed main()
{
    int N, A, B, C, D;

    cin >> N >> A >> B >> C >> D;
    REP(plus,N) {
        int minus = N - 1 - plus;
        if (A + plus * C - minus * D <= B && B <= A + plus * D - minus * C) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repi(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)
#define rep(i, n) repi(i, 0, n)
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
struct Vec{
    double x, y;
};
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;
}
template<class T>
T min(T a, T b)
{
    if (a < b) return a;
    return b;
}
template<class T>
T max(T a, T b)
{
    if (a > b) return a;
    return b;
}
using namespace std;
int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    int N, rc=0;
    string b;
    cin >> N;
    cin >> b;

    rep(i, N) {
        if (b[i] == 'R') {
            rc++;
        }
    }
    ll ans = 0;
    rep(i, rc){
        if (b[i] == 'W') ans++;
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
    int A[100][100] = {};
    for(int i = 0; i < 3; i++){
        cin >> A[i][0] >> A[i][1] >> A[i][2];
    }
    int n;
    cin >> n;
    int B[n-1] = {};
    for(int i = 0; i < n; i++){
        cin >> B[i];
    }

    bool C[100][100] = {};

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < n; k++){
                if(A[i][j] == B[k]){
                    C[i][j] = 1;
                }
            }
        }
    }

    for(int i = 0; i < 3; i++){
        if(C[i][0] == 1 && C[i][1] == 1 && C[i][2] == 1){
            cout << "Yes" << endl;
            return 0;
        }
        else if(C[0][i] == 1 && C[1][i] == 1 && C[2][i] == 1){
            cout << "Yes" << endl;
            return 0;
        }
    }

    if(C[0][0] == 1 && C[1][1] == 1 && C[2][2] == 1){
        cout << "Yes" << endl;
        return 0;
    }else if(C[0][2] == 1 && C[1][1] == 1 && C[2][0] == 1){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
    
}




Measured memory_bytes: 256
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=1e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			cerr<<#x<<": "<<x<<endl
#define trace2(x, y)			 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)			 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)		 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)		 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

ll n,k;
ll h[100001];
ll cache[100001];

ll dp(ll x){
    if(x>n) return inf;
    if(x==n) return 0;
    ll &ans=cache[x];
    if(ans!=-1) return ans;
    ans=inf;
    for(ll i=1; i<=k && i+x<=n; i++){
        ans=min(ans,dp(x+i)+abs(h[i+x]-h[x]));
    }
    return ans;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k;
	rep(i,1,n+1) cin >> h[i];
	mst(cache,-1);
	cout << dp(1);
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int n;
    cin >> n;
    vector<int> w(n);
    for (int i = 0; i < n; i++) {
        cin >> w[i];
    }
    int s1 = w[0], s2 = 0;
    for (int i = 1; i < n; i++) {
        s2 += w[i];
    }
    int min_abs = abs(s1 - s2);
    for (int i = 1; i < n; i++) {
        s1 += w[i];
        s2 -= w[i];
        min_abs = min(min_abs, abs(s1 - s2));
    }
    cout << min_abs << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main()
{
    long double x1, y1;
    long double x2, y2;
 
    cin >> x1 >> y1 >> x2 >> y2;

    long double len = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));

    cout << setprecision(16) << len << endl;

    return 0;
}


Measured memory_bytes: 3312