akhauriyash/Code-Regression huggingface dataset:
from math import factorial as fact
def comb(n, r):
  denom = fact(r)*fact(n-r)
  return fact(n)//denom

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

l = sorted(l)

summ = 0

for i in range(n[1]):
  summ+=l[len(l)-1-i]

avg = float(summ)/n[1]
last =  l[len(l)-n[1]]
lasts = l.count(last)
more = sum(1 for i in l if i>last)
print(avg)
if more!=0:
  answer = comb(lasts, n[1]-more)
  print(answer)
else:
  b= min(lasts, n[2])
  answer = 0
  for i in range(n[1], b+1):
    answer += comb(lasts, i)
  print(answer)

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

using namespace std;

int main(void)
{
	long long n;
	cin >> n;
	if (n%2 == 1) {
		cout << 0 << endl;
		return 0;
	}
	long long count2 = 0;
	long long tmp2 = 1;
	for (int i = 1; ; i++) {
		tmp2 *= 2;
		if (tmp2 > n)
			break;
		long long m = n/tmp2;
		if (m%2 == 0)
			m -= 1;
		count2 += i*((m - 1)/2+1);
	}

	long long count5 = 0;
	long long tmp5 = 1;
	for (int i = 1; ; i++) {
		tmp5 *= 5;
		if (tmp5 > n)
			break;
		long long m = n/(tmp5*2);

		int mod = m%5;
		if (mod == 0) {
			count5 += i*m/5*4;
		} else if (mod == 1) {
			count5 += i*((m-1)/5 * 4 + 1);
		} else if (mod == 2) {
			count5 += i*((m-2)/5 * 4 + 2);
		} else if (mod == 3) {
			count5 += i*((m-3)/5 * 4 + 3);
		} else if (mod == 4) {
			count5 += i*((m-4)/5 * 4 + 4);
		}
		//printf("tmp5: %lld, count5: %lld\n", tmp5, count5);

	}
	//printf("2:%lld, 5:%lld\n", count2, count5);
	cout << min(count2, count5) << endl;
	return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define mii map<int,int>
#define MOD 1000000007
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int x,n;
cin>>x>>n;
map<int,int> m;
for(int i=0;i<n;i++)
{
	int a;
	cin>>a;
	m[a]=1;
}
int l=0;
while(true)
{
	if(m[x-l]==0)
	{
	cout<<x-l<<endl;
	return 0;
	}
	if(m[x+l]==0)
	{
		cout<<x+l<<endl;
		return 0;
	}
	l++;
}
return 0;
}
// Problem : C - Forbidden List
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)



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

typedef long long ll;

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

int main() {
  int N;
  cin >> N;
  ll a = 1;
  rep(i,N) a = a*(i+1)%1000000007;
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 3592
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	long INF = Long.MAX_VALUE / 10;

	void run() {
		Scanner sc = new Scanner(System.in);
		int V = sc.nextInt();
		int E = sc.nextInt();
		long[][] D = new long[V][V];
		for (int i = 0; i < V; ++i) {
			Arrays.fill(D[i], INF);
			D[i][i] = 0;
		}
		for (int i = 0; i < E; ++i)
			D[sc.nextInt()][sc.nextInt()] = sc.nextLong();
		for (int t = 1; t < V; t *= 2)
			for (int i = 0; i < V; ++i)
				for (int j = 0; j < V; ++j)
					for (int m = 0; m < V; ++m)
						if (Math.max(D[i][m], D[m][j]) < INF)
							D[i][j] = Math.min(D[i][j], D[i][m] + D[m][j]);
		for (int i = 0; i < V; ++i)
			if (D[i][i] < 0) {
				System.out.println("NEGATIVE CYCLE");
				return;
			}
		for (int i = 0; i < V; ++i)
			for (int j = 0; j < V; ++j)
				System.out.print((D[i][j] >= INF ? "INF" : D[i][j]) + (j == V - 1 ? "\n" : " "));

	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

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

namespace ConsoleApp5
{
    class Program 
        {
        static void Main(string[] args)
        {
            int S = int.Parse(Console.ReadLine());
            int h = S / 3600;
            int m = S % 3600 / 60;
            int s = S % 60;

            Console.WriteLine("{0}:{1}:{2}",h,m,s);
        }
    }
}



Measured memory_bytes: 17996
import os
import heapq
import sys,threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10**5)
from io import BytesIO, IOBase
def gcd(a,b):
    if b==0:

        return a
    else:
        return gcd(b,a%b)
def power(x, p,m):
    res = 1
    while p:
        if p & 1:
            res = (res * x) % m
        x = (x * x) % m
        p >>= 1
    return res
def inar():
    return [int(k) for k in input().split()]

def lcm(num1,num2):
    return (num1*num2)//gcd(num1,num2)

def main():
    n=int(input())
    arr=inar()
    ms=arr[0]
    ans=0
    for i in range(1,n):
        if arr[i]<ms:
            ans+=ms-arr[i]
        else:
            ms=max(arr[i],ms)
    print(ans)


BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()
    #threadin.Thread(target=main).start()


Measured memory_bytes: 95868
#include<cstdio>
int main(){
	int n;
	scanf("%d",&n);
	long long int a,b;
	scanf("%lld%lld",&a,&b);
	long long int x[n]={};
	for(int i=0;i<n;i++){
		scanf("%lld",&x[i]);
	}
	long long int ans=0;
	for(int i=1;i<n;i++){
		if((x[i]-x[i-1])*a<b)ans+=(x[i]-x[i-1])*a;
		else ans+=b;
	}
	printf("%lld",ans);
	return 0;
}
		

Measured memory_bytes: 896
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = 998244353;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}

#define No -1
#define Done -2

int n, m, k, w, req;
vector<int> g[MX];
vector<int> stk, rec(MX, No), color(MX);

void dfs(int x, int par, int c){
	color[x] = c;
	if(c == 0) w++;
	for(auto &y : g[x]){
		if(y == par) continue;
		dfs(y, x, c ^ 1);
	}
}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	int seen[6] = {};
	for(int i = 0; i < 5; ++i){
		int x;
		cin >> x;
		seen[x] = true;
	}

	for(int i = 1; i <= 5; ++i){
		if(!seen[i]) return cout << i, 0;
	}
	
	return 0;
}

Measured memory_bytes: 6208
x,y = map(int,input().split())
g1 = [1,3,5,7,8,10,12]
g2 = [4,6,9,11]
if x in g1 and y in g1:
    print("Yes")
elif x in g2 and y in g2:
    print("Yes")
else:print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n + m == 0) break;
    vector<int> cards_taro(n);
    vector<int> cards_hanako(m);
    int sum_taro = 0;
    int sum_hanako = 0;
    for (int i= 0; i < n; i++) {
      int s;
      cin >> s;
      cards_taro[i] = s;
      sum_taro += s;
    }
    for (int i = 0; i < m; i++) {
      int s;
      cin >> s;
      cards_hanako[i] = s;
      sum_hanako += s;
    }
    int swap_min = 10000;
    pair<int, int> best_swap;
    
    for (int i = 0; i < n; i++) {
      sum_taro -= cards_taro[i];
      sum_hanako += cards_taro[i];
      for (int j = 0; j < m; j++) {
        sum_taro += cards_hanako[j];
        sum_hanako -= cards_hanako[j];
        if (sum_taro == sum_hanako) {
          if (cards_taro[i] + cards_hanako[j] < swap_min) {
            swap_min = cards_taro[i] + cards_hanako[j];
            best_swap.first = cards_taro[i];
            best_swap.second = cards_hanako[j];
          }
        }
        sum_taro -= cards_hanako[j];
        sum_hanako += cards_hanako[j];
      }
      sum_taro += cards_taro[i];
      sum_hanako -= cards_taro[i];
    }
    if (swap_min == 10000) {
      cout << -1 << endl;
    } else {
       cout << best_swap.first << " " << best_swap.second << endl;
    }
  }
  return 0;
}

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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    string s;
    cin >> s;

    int n = s.size();
    vector< vs64 > dp(2, vs64(13, 0));
    dp[0][0] = 1;

    int now = 0;
    rep (i, n)
    {
        int next = now ^ 1;
        rep (j, 13) dp[next][j] = 0;
        if (s[i] == '?')
        {
            rep (num, 10)
            {
                rep (j, 13)
                {
                    dp[next][(j * 10 + num) % 13] = (dp[next][(j * 10 + num) % 13] + dp[now][j]) % MOD;
                }
            }
        }
        else
        {
            int num = s[i] - '0';
            rep (j, 13)
            {
                dp[next][(j * 10 + num) % 13] = (dp[next][(j * 10 + num) % 13] + dp[now][j]) % MOD;
            }
        }
        now = next;
    }

    cout << dp[now][5] << "\n";
    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void){
    int n, m;
    cin >> n >> m;
    for(int i=0; i<=n+1; i++){
        for(int j=0; j<=m+1; j++){
            if(i>0&&i<=n&&j>0&&j<=m){
                char ch;
                cin >> ch;
                cout << ch;
            }else{
                cout << "#";
            }
        }
        cout << endl;
    }
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    bool flag = false;
    if (a == 7) {
        flag = (b == 5 && c == 5);
    } else if (b == 7) {
        flag = (a == 5 && c == 5);
    } else if (c == 7) {
        flag = (b == 5 && a == 5);
    }
    if (flag) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include <cassert>
#include <algorithm>
#include <functional>
#include<stdio.h>
using namespace std;


int main() {
	int A, P, Pi=0;
	cin >> A>> P;
	int P2 = 3*A;
	int P_total = P + P2;
	Pi = P_total / 2;
	cout << Pi << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
#include <cmath>
#include <limits>
#include <iostream>
#include <assert.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	int x,y,cost;
};
int v[101];
ll w[101];
ll dp[101][10001]={};
int main(){

	int n;
	ll W;
	cin>>n>>W;

	rep(i,n){
		cin>>v[i+1]>>w[i+1];
	}
	for(int i=0; i<10001; i++){
		for(int j=0; j<n+1; j++){
			dp[j][i]=10000000000;
		}
	}
	rep(i,n){
		dp[i+1][0]=0;
	}
	dp[0][0]=0;
	for(int i=1; i<10001; i++){
		for(int j=1; j<n+1; j++){
			if(i>=v[j])dp[j][i]=min(dp[j][i],dp[j-1][i-v[j]]+w[j]);
			if(j>1)dp[j][i]=min(dp[j][i],dp[j-1][i]);
		}
	}
	for(int i=10000; i>=0; i--){
		if(dp[n][i]<=W){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;

}




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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
#define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
} 

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

if(N.at(0) == N.at(2)) yes;
else no;

}

Measured memory_bytes: 256
#include <stdio.h> 

#include <stdlib.h> 

#include <math.h> 

 

typedef struct point{ 

  double x; 

  double y; 

  struct point *next; 

}Point; 

 

Point *create(double x, double y) { 

  Point *p = (Point*)malloc(sizeof(Point)); 

  p->x = x; 

  p->y = y; 

  p->next = NULL; 

  return p; 

} 

 

void create_next(double x, double y, Point *p0) { 

  Point *p = create(x,y); 

  p->next = p0->next; 

  p0->next = p; 

} 

 

void rotation(Point *r,double seta) { 

  double temp_x,temp_y; 

  temp_x = r->x;temp_y = r->y; 

  r->x = cos(seta)*temp_x-sin(seta)*temp_y; 

  r->y = sin(seta)*temp_x+cos(seta)*temp_y; 

} 

 

void koch_curve(Point *begin) { 

  Point *p1,*p2; 

  p1 = begin; 

  while(p1->next != NULL) { 

    p2 = p1->next; 

    Point *r = create((p2->x-p1->x)/3,(p2->y-p1->y)/3); 

    create_next(p1->x+r->x,p1->y+r->y,p1); 

    create_next(p1->next->x+r->x,p1->next->y+r->y,p1->next); 

    rotation(r,M_PI/3); 

    create_next(p1->next->x+r->x,p1->next->y+r->y,p1->next); 

    p1 = p2; 

  } 

} 

 

int main() 

{ 

  int i,n; 

  Point *begin,*p; 

  begin = create(0,0); 

  create_next(100,0,begin); 

  scanf("%d", &n); 

 

  for (i = 0; i < n; i++) { 

     koch_curve(begin);  

  } 

   

  p = begin; 

  while(p != NULL) { 

    printf("%lf %lf\n", p->x, p->y); 

    p = p->next; 

  } 

   

  return 0; 

} 


Measured memory_bytes: 2032
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;cin>>N>>K;
  vector<int> A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  for(int i=0;i<N-K;i++){
    cout<<(A[i]<A[i+K]?"Yes":"No")<<endl;
  }
}

Measured memory_bytes: 4048
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ull unsigned long long
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

//最大公約数


int main() {
	ll a,b,t,ans=0;
	cin >> a>>b;
	t = b - a;
	for (int i = t; i > 0; i--) {
		ans += i;
	}
	cout << ans - b << endl;
	return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
a=list(map(int,input().split()))
l=max( len(bin(K)) ,len(bin(max(a))) )-2

K=bin(K)[2:].zfill(l)[::-1]
a=[bin(a[i])[2:].zfill(l)[::-1] for i in range(N)]
val=[[0,0] for i in range(l)]

for i in range(N):
    for j in range(l):
        if a[i][j]=="0": val[j][0]+=1
        else: val[j][1]+=1
        



tmp=0
for j in range(l):
    tmp+=(N-val[j][int(K[j])])*2**j

ans=tmp

for i in range(l):
    tmp=0
    if K[i]=="1":
        for j in range(i):
            tmp+=max(val[j])*2**j
        
        tmp+=val[i][1]*2**i
        
        for j in range(i+1,l):
            tmp+=(N-val[j][int(K[j])])*2**j
            
    ans=max(ans,tmp)
    
print(ans)



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

using namespace std;
typedef long long ll;

const int maxn = 3e5 + 7;
int n, m, k, t;
ll a[maxn], luu[maxn], sum, res;
priority_queue<ll> q;
priority_queue<ll, vector<ll>, greater<ll> > p;

int main()
{
#ifndef ONLINE_JUDGE
#define file "r"
//    freopen(file".inp", "r", stdin);
//  freopen(file".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin >> n;
    for(int i = 1; i <= 3*n; i ++) cin >> a[i];
    for(int i = 1; i <= 2*n; i ++)
    {
        p.push(a[i]); sum += a[i];
        if(i > n)
        {
            sum -= p.top(); p.pop(); luu[i] = sum;
        }
        if(i == n) luu[n] = sum;
    }
    sum = 0;
    for(int i = 3*n; i > n; i --)
    {
        q.push(a[i]); sum += a[i];
        if(i <= 2*n)
        {
            sum -= q.top(); q.pop();
            res = max(res, luu[i - 1] - sum );
        }
        if(i == 2*n + 1) res = luu[i - 1] - sum;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 6004
/* ****revpro**** */
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl	   '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii	    map<ll,ll>
using namespace std;

#define N  100005
ll expo(ll base, ll exponent, ll mod=hell) {								//return base^exponent modulo modulus
    ll ans = 1;
    while(exponent !=0 ) {
        if((exponent&1) == 1) {
            ans = ans*base ;
            ans = ans%mod;
        }
        base = base*base;
        base %= mod;
        exponent>>= 1;
    }
    return ans%mod;
}
ll add(ll x,ll y,ll mod=hell) { x += y; if(x >= mod) x -= mod; return x;}
ll sub(ll x,ll y,ll mod=hell) { x -= y; if(x < 0) x += mod; return x;}
ll mul(ll x,ll y,ll mod=hell) { return (x * 1ll * y) % mod;}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll n;
		cin>>n;
		ll cnt[61]={0};
		rep(i,0,n) {
			ll x;
			cin>>x;
			rep(j,0,61) cnt[j]+=x%2,x/=2;
		}
		ll ans=0;
		rep(i,0,61)
			ans=add(ans,mul(expo(2,i),mul(cnt[i],(n-cnt[i]))));
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys

data = sys.stdin

conversion_data = []
for l in data:
    conversion_data.append([int(i) for i in l.split()])
    

N = conversion_data[0][0]
K = conversion_data[0][1]
conversion_data[1].sort()
price_list = conversion_data[1]

print(sum(price_list[:K]))





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

long long s, c;
int main() {
    int n, t, a;
    cin >> n >> t;
    for (int i = 0; i < n; i++) {
        cin >> a; 
        if (a > c) {
            s += t;
            c = a + t;
        } else if (a + t > c) {
            s += a + t - c;
            c = a + t;
        }
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second

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

typedef struct{
  int x,y;
  int o,st;
  int cost;
}state;

int vis[10][10][1<<10][50];
int in[10][10];

const int qmax=(1<<13)-1;
state Q[qmax+1];

main(){
  std::ios::sync_with_stdio(false);
  int w,h;
  while(cin>>w>>h,w|h){
    memset(vis,0,sizeof(vis));
    rep(i,10)rep(j,10)rep(k,1<<10)rep(l,50)vis[i][j][k][l]=1<<28;
    
    int f,m,o;
    cin>>f>>m>>o;

    rep(i,h)rep(j,w)cin>>in[i][j];


    int qs=0,qnum=0;
    state st;
    st.x=0;
    rep(i,w){
      st.y=i;
      st.o=o-1;
      if(st.o<1)continue;
      if(in[0][i]<0){
	st.cost=-in[0][i];
      }else{
	st.o+=in[0][i];
	st.cost=0;
      }
      if(st.o>m)st.o=m;
      st.st=1<<i;
      if(st.cost>f || st.o<1)continue;
      Q[qs+qnum++&qmax]=st;
    }
    

    while(qnum){
      st=Q[qs++&qmax];--qnum;
      int cx=st.x,cy=st.y,cvis=st.st,cc=st.cost,co=st.o;
      if(vis[cx][cy][cvis][co]<=cc)continue;
      vis[cx][cy][cvis][co]=cc;

      rep(i,3){
	int nx=cx+dx[i],ny=cy+dy[i];
	int nc=cc;
	int no=co-1;
	int nvis=cvis;
	if(no<1)continue;
	if(nx<0 || h<=nx || ny<0 || w<=ny)continue;
	if((dx[i]==0 && (nvis>>ny&1)==0) || dx[i]){
	  if(in[nx][ny]<0)nc-=in[nx][ny];
	  else no+=in[nx][ny];
	  if(no>m)no=m;
	}
	if(dx[i]==0)nvis=cvis|1<<ny;
	else nvis=1<<ny;
	if(nc>f)continue;
	if(vis[nx][ny][nvis][no]<=nc)continue;
	st.x=nx,st.y=ny,st.st=nvis,st.cost=nc,st.o=no;
	Q[qs+qnum++&qmax]=st;
      }
    }
    int ans=f+1;

    rep(i,w)rep(j,1<<w)rep(k,m)ans=min(ans,vis[h-1][i][j][k+1]);

    if(ans==f+1)cout<<"NA"<<endl;
    else cout<<ans<<endl;
  }
}
	   

Measured memory_bytes: 20000
#include <stdio.h>
#include <string.h>
char str[500000];
int a[500001];

void dac(int le, int ri){
  if(ri<le) return;
  if(le>ri) return;
  int i, mina, minidx;
  mina=a[le];
  minidx=le;
  for(i=le+1;i<=ri;i++){
    if(a[i]<mina){
      mina=a[i];
      minidx=i;
    }
  }
  for(i=le;i<=ri;i++){
    a[i]-=mina;
  }
  
  int nle = minidx - 1;
  int nri = minidx;
  while (str[nle] == '>' && nle) nle--;
  if (!(nle == 0 && str[nle] == '>')) nle++; //le is last >
  while (str[nri] == '<') nri++;
  nri--; //ri is last <
  dac(le, nle - 1);
  dac(nri + 2, ri);
  return;
}

int main()
{
  scanf("%s", str);
  int len=strlen(str);
  int i;
  a[0]=0;
  for(i=0;i<len;i++){
    if(str[i]=='<'){
      a[i+1]=a[i]+1;
    }else{
      a[i+1]=a[i]-1;
    }
  }
  int mina, minidx;
  mina=0;
  minidx=0;
  for(i=1;i<=len;i++){
    if(a[i]<mina){
      mina=a[i];
      minidx=i;
    }
  }
  for(i=0;i<=len;i++){
    a[i]-=mina;
  }
  int le=minidx-1;
  int ri=minidx;
  while(str[le]=='>' && le) le--;
  if(!(le==0 && str[le]=='>')){
    le++; //le is last >
    dac(0,le-1);
  }
  while(str[ri]=='<') ri++;
  ri--; //ri is last <
  dac(ri+2,len);
  
  long sum=0;
  for(i=0;i<=len;i++){
    sum+=a[i];
  }
  printf("%ld\n",sum);
  return 0;
}


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

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<int>> happiness(N + 1,vector<int>(3));
    REP(i,N)REP(l,3)cin >> happiness[i + 1][l];
    int dp[100010][3] = {};
    REP(i,N){
        chmax(dp[i + 1][0],dp[i][1] + happiness[i + 1][0]);
        chmax(dp[i + 1][0],dp[i][2] + happiness[i + 1][0]);
        chmax(dp[i + 1][1],dp[i][0] + happiness[i + 1][1]);
        chmax(dp[i + 1][1],dp[i][2] + happiness[i + 1][1]);
        chmax(dp[i + 1][2],dp[i][0] + happiness[i + 1][2]);
        chmax(dp[i + 1][2],dp[i][1] + happiness[i + 1][2]);
    }
    cout <<max(dp[N][0],max(dp[N][1],dp[N][2]))<< "\n";
}

Measured memory_bytes: 6912
#include <iostream>
#include <vector>
#include <numeric>
#include <functional>

using namespace std;
typedef long long ll;

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

    int x=0;

    vector<int> v(n);
    for(int i=0;i<n;++i) cin>>v[i];

    x = accumulate(v.begin(),v.end(),0,bit_xor<int>());

    for(int i=0;i<n;++i) cout<<(x^v[i])<<" ";
}

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

int main(){
    int a,b;
    int f=0;
    cin>>a>>b;
    int x = (int)(a/0.08);
    int y = (int)(b/0.1);
    int z = (int)((a+1)/0.08);
    int k = (int)((b+1)/0.1);
    //cout<<x<<" "<<y;
    for(int i=min(x,y);i<=max(z,k);i++){
        int c = i*0.08;
        int d = i*0.10;
        if(c==a && d==b){
            cout<<i;
            f=1;
            break;
        }
    }
    if(f==0)
        cout<<-1;
    return 0;
}


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

int main(){
  int a, b, ans;
  cin >> a >> b;
  if(a >= 13) ans = b;
  else if(a < 13 && a >= 6) ans = b/2;
  else ans = 0;
  
  cout << ans << endl;
}

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

int main()
{
	int h, w;
	char s[52][52];
	int s2[52][52] = { 0 };
	cin >> h >> w;
	for (int i = 1; i < h+1; i++) {
		for (int j = 1; j < w+1; j++) {
			cin >> s[i][j];
		}
	}

	for (int i = 1; i < h+1; i++) {
		for (int j = 1; j < w+1; j++) {
			if (s[i][j] == '#') {
				s2[i-1][j-1]++;
				s2[i-1][j]++;
				s2[i-1][j+1]++;
				s2[i][j-1]++;
				s2[i][j+1]++;
				s2[i+1][j-1]++;
				s2[i+1][j]++;
				s2[i+1][j+1]++;
				s2[i][j] = 9;
			}
		}
	}

	for (int i = 1; i < h + 1; i++) {
		for (int j = 1; j < w + 1; j++) {
			if (s[i][j] != '#') {
				cout << s2[i][j];
			}
			else {
				cout << '#';
			}
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int K, S;
using namespace std;

int main() {
	cin >> K >> S;
	int sum = 0;
	for (int x = 0; x <= K; x++) {
		for (int y = 0; y <= K; y++) {
			if (0 <= S - x - y && S - x - y <= K)sum++;
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int N, D;
	cin >> N >> D;
	vector<int> X(N), Y(N);
	vector<vector<int> > C(D, vector<int>(D));
	for (int i = 0; i < N; ++i) {
		cin >> X[i] >> Y[i];
		++C[X[i] % D][Y[i] % D];
	}
	int maxnum = 0;
	for (int i = 0; i < D; ++i) {
		for (int j = 0; j < D; ++j) {
			if (C[i][j] == 0) {
				C[i][j] = -1;
			}
			else {
				int num = 0;
				while ((num / 2 + 1) * (num - num / 2 + 1) < C[i][j]) ++num;
				C[i][j] = num;
				maxnum = max(maxnum, num);
			}
		}
	}
	int L = -1, R = (maxnum - maxnum / 2 + 1) * D;
	while (R - L > 1) {
		int M = (L + R) >> 1;
		vector<vector<int> > S(2 * D + 1, vector<int>(2 * D + 1));
		function<void(int, int, int, int, int)> rangeadd = [&](int xl, int yl, int xr, int yr, int val) {
			if (xl >= xr || yl >= yr) return;
			S[xl + D][yl + D] += val;
			S[xr + D][yr + D] += val;
			S[xl + D][yr + D] -= val;
			S[xr + D][yl + D] -= val;
		};
		bool ok = true;
		int num = 0;
		for (int i = 0; i < D && ok; ++i) {
			for (int j = 0; j < D && ok; ++j) {
				if (C[i][j] == -1) continue;
				++num;
				if (C[i][j] % 2 == 0) {
					if (C[i][j] / 2 * D > M) ok = false;
					else {
						rangeadd(max(i - (M - C[i][j] / 2 * D), i - D + 1), max(j - (M - C[i][j] / 2 * D), j - D + 1), i + 1, j + 1, 1);
					}
				}
				else {
					if ((C[i][j] / 2 + 1) * D > M) ok = false;
					else {
						rangeadd(i - D + 1, j - D + 1, i + 1, j + 1, 1);
						rangeadd(i - D + 1, j - D + 1, i - (M - (C[i][j] / 2 + 1) * D), j - (M - (C[i][j] / 2 + 1) * D), -1);
					}
				}
			}
		}
		if (ok) {
			for (int i = 0; i < 2 * D; ++i) {
				for (int j = 0; j <= 2 * D; ++j) {
					S[i + 1][j] += S[i][j];
				}
			}
			for (int i = 0; i <= 2 * D; ++i) {
				for (int j = 0; j < 2 * D; ++j) {
					S[i][j + 1] += S[i][j];
				}
			}
			ok = false;
			for (int i = 0; i < D; ++i) {
				for (int j = 0; j < D; ++j) {
					int val = S[i][j] + S[i + D][j] + S[i][j + D] + S[i + D][j + D];
					if (val == num) ok = true;
				}
			}
		}
		if (ok) R = M;
		else L = M;
	}
	cout << R << endl;
	return 0;
}

Measured memory_bytes: 20748
import sys

N,M=map(int,input().split())
A=list(map(int,input().split()))

total=sum(A)


sou=1/(M*4)
s=0
for a in A:
    tmp=a/total
    if(tmp >= sou):
        s+=1
        if(s == M):
            print("Yes")
            sys.exit()

print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int tmp;
    int flag = 0;
    int max = 0;
    for(int i = 0; i < n; i++) {
        cin >> tmp;
        if(tmp >= max) {
            max = tmp;
            flag++;
        }
    }
    cout << flag << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define repit(i,a) for(__typeof((a).begin()) i=(a).begin();i!=(a).end();i++)

#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())

#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

const int MAX = 32;
int h, w;
bool inrange(int x, int y){
    return x >= 0 && y >= 0 && x < w && y < h;
}
int wall[4][MAX][MAX], done[MAX][MAX];
const int dx[] = {0, 1, 0,-1};
const int dy[] = {-1, 0, 1, 0};
struct node {
    int x, y, step;
};
int main()
{
    while(cin >> w >> h, w||h) {
        memset(wall, 0, sizeof(wall));
        // input
        rep(j, w) wall[0][0][j] = wall[2][h-1][j] = 1;
        rep(i, h) {
            wall[1][i][w-1] = wall[3][i][0] = 1;
            rep(j, w-1) {
                cin >> wall[1][i][j];
                wall[3][i][j+1] = wall[1][i][j];
            }
            if(i == h-1) break;
            rep(j, w) {
                cin >> wall[2][i][j];
                wall[0][i+1][j] = wall[2][i][j];
            }
        }

        queue<node> q;
        memset(done, 0, sizeof(done));
        q.push((node){0, 0, 0});
        int ans = 0;
        while(q.size()) {
            int x = q.front().x;
            int y = q.front().y;
            int step = q.front().step;
            q.pop();
            if(done[x][y]) continue;
            done[x][y] = 1;
            if(x == w-1 && y == h-1) {
                ans = step+1;
                break;
            }
            rep(i, 4) if(!wall[i][y][x]) {
                int nx = x + dx[i];
                int ny = y + dy[i];
                if(inrange(nx, ny)) q.push((node){nx, ny, step+1});
            }
        }
        cout << ans << endl;

    }
    return 0;
}

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

int main(void){
    int n;
    cin>>n;
    vector<int> a(n),b(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    int res = 0;
    rep(k,n){
        int sum = 0;
        rep(x,k+1){
            sum += a[x];
        }
        for(int x=k;x<n;x++){
            sum += b[x];
        }
        res = max(res,sum);
    }
    cout<<res<<endl;
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; i++)
        cin >> v[i];
    sort(v.begin(), v.end());
    double ans = (v[0] + v[1]) / 2.0;
    for (int i = 2; i < N; i++)
        ans = (ans+v[i]) / 2.0;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int M=1e9+7;// M=1e9+7;//M=300000;//
const int N=2e5+5;
typedef long long int ll;
using namespace std;
 
ll cnt(0),sum(0),n,m,x,y,t,i,j,temp,k,ans(1),mn(M),mx(-9e9);
vector<ll> v;
ll mark[N];
ll a[100][100];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin>>x>>y;i=0,j=x;
	while(1)
	{
		temp=(i*2+j*4);
		if(temp==y)
		{
			cout<<"Yes";
			return 0;
		}
		i++;
		j--;
		if(i>x)
		{
			break;
		}
	}
	cout<<"No";
}

Measured memory_bytes: 3636
N = int(input())
S = list()
AC = 0
WA = 0
TLE = 0
RE = 0
for x in range(0,N):
	S.append(input())

for lisss in S:
	if lisss=='AC':
		AC+=1
	elif lisss == 'WA':
		WA+=1
	elif lisss == 'TLE':
		TLE+=1
	elif lisss == 'RE':
		RE+=1

print('AC x %d \n' % AC)
print('WA x %d \n' % WA)
print('TLE x %d \n' % TLE)
print('RE x %d \n' % RE)
	

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;

string s,t;
map<char,vector<int>> mp;

int32_t main()
{
	IOS;
	cin >> s >> t;
	repp(i,0,s.size())
	{
		mp[s[i]].pb(i+1);
	}	
	repp(i,0,t.size())
	{
		if(mp[t[i]].size()==0)
		{
			cout << "-1" << endl;
			return 0;
		}
	}
	int ans=0;
	int cur=0;
	repp(i,0,t.size())
	{
		auto p = upper_bound(mp[t[i]].begin(), mp[t[i]].end(),cur); 
		int x = p-mp[t[i]].begin();
		if(x<mp[t[i]].size())
		{
			cur= mp[t[i]][x];
		}
		else
		{
			ans++;
			cur=0;
			auto q = upper_bound(mp[t[i]].begin(), mp[t[i]].end(),cur); 
			int y = q-mp[t[i]].begin();
			cur = mp[t[i]][y];
		}
	}
	cout << ans*s.size() + cur << endl;
}


Measured memory_bytes: 1736
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <cmath>
#include <vector>

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

    int32_t N;
    std::cin >> N;
    for(int32_t i = 1; i <= 9; i++){
        for(int32_t j = i; j <= 9; j++){
            if(i * j == N){
                std::cout << "Yes";
                return 0;
            }
        }
    }
    std::cout << "No";

    return 0;
}


Measured memory_bytes: 256
n = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
     1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(n[k-1])


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
typedef long long int ll;
ll pow(int a,int b){
    ll w = 1;;
    for(int i = 0; i < b; i++){
        w *= a;
    }
    return w;
}
int main(){
    ll n;cin >> n;
    ll y;
    ll t = 1;
    ll sum = 0;
    
    if(n % 2 == 1) y = 0;
    else{
        while((pow(5,t)) <= n){
        sum += n/(2*pow(5,t));
        t++;
        }
        y = sum;
    }
    cout << y << "\n";
}

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

int main() {
  long long N,sum=0; cin >> N;
  long long A[200010];
  for(int i=0; i<N; i++) cin >> A[i];
  for(int i=0; i<N; i++) {
    if(A[i+1]==0) break;
    if(A[i]>A[i+1]) {
      sum += A[i] - A[i+1];
      A[i+1] += A[i] - A[i+1];
    }
  }
  cout << sum  << endl;
}

Measured memory_bytes: 5156
#include <iostream>

using namespace std;

long long int S[(int)1e5];
long long int T[(int)5e4];

bool binary(int s, int e, int t) {
  if(s == e) {
    return false;
  }

  if(s + 1 == e) {
    return S[s] == t;
  }

  int mid = (s + e)/2;

  if(t == S[mid]) {
    return true;
  } else if (t < S[mid]) {
    return binary(s, mid, t);
  } else {
    return binary(mid+1, e, t);
  }
}

int main() {
  int n;
  int q;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> T[i];
  }

  int count = 0;

  for (int i = 0; i < q; i++) {
    if(binary(0, n, T[i])) {
      count++;
    }
  } 

  cout << count << endl;
  return 0;
}



Measured memory_bytes: 4176
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    ABC = [list(map(int, input().split())) for _ in range(3)]
    A = ABC[0]
    B = ABC[1]
    C = ABC[2]

    ans = 0
    for i in range(N):
        a = A[i]
        ans += B[a-1]
        if i != N-1:
            if A[i+1] == A[i] + 1:
                ans += C[a-1]

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 39892
#include<iostream>
using namespace std;
int main(){
	int a,b,n,i,j,counta=0,countb=0;
	while(true){
		cin>>n;
		if(n==0){
			break;
		}
		for(i=0;i<n;i++){
		cin>>a>>b;
		if(a>b){
		counta+=(a+b);
		}
		else if(a<b){
		countb+=(a+b);
		}
		else{
		counta+=a;
		countb+=b;
		}	
	}
	cout<<counta<<" "<<countb<<endl;
	counta=0;
	countb=0;
    }
return 0;
}

Measured memory_bytes: 2992
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def div(n, t):
    if n < t:
        return n
    else:
        return div(n // t, t) + n % t


def main():
    N = int(input())
    print(min(div(i, 6) + div(N - i, 9) for i in range(N + 1)))


if __name__ == "__main__":
    main()


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

int main() {
  bool ans=true;
  vector<int> data(6);
  for(int i=0;i<6;i++)
    cin >> data[i];
  
  for(int i=0;i<5;i++){
    for(int j=i;j<5;j++){
      if(data[j]-data[i]>data[5])
        ans=false;
    }
  }
  
  if(ans)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;
}

Measured memory_bytes: 256
import heapq

def main():
    [V, E, r] = [int(num) for num in input().split()]

    edges = {}
    for i in range(V):
        edges[i] = []
    for i in range(E):
        num_list = [int(num) for num in input().split()]
        edges[num_list[0]].append((num_list[1], num_list[2]))

    dist = [10**10 for _ in range(V)]

    dist[r] = 0

    PQ = []

    heapq.heappush(PQ, (0, r))
    # for i, val in enumerate(dist):
    #     heapq.heappush(PQ, (val, i))

    while len(PQ) > 0:
        (_, node_num) = heapq.heappop(PQ)

        for edge in edges[node_num]:
            # print(edge)
            new_len = dist[node_num] + edge[1]

            if new_len < dist[edge[0]]:
                heapq.heappush(PQ, (new_len, edge[0]))
                dist[edge[0]] = new_len

    for i in range(V):
        if dist[i] == 10**10:
            print('INF')
        else:
            print(dist[i])

if __name__ == '__main__':
    main()



Measured memory_bytes: 96596
from functools import reduce
N = int(input())

prime_table = [1] * (N+1)

for x in range(2, N+1):
    for t in range(2, x+1):
        while x % t == 0:
            prime_table[t] += 1
            x //= t
print(reduce(lambda x, y: x * y % (int(1e9) + 7), prime_table))

Measured memory_bytes: 3572
#include<stdio.h>
int main(void){
	int a,b,i,j;
	while(1){
		scanf("%d %d",&a,&b);
		if(a==0 && b==0) break;
		for(i=0;i<a;++i){
			for(j=0;j<b;++j){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
X, K, D = list(map(int, input().split()))

if X < 0:
    X = -X

if X > K * D:
    print(X - K * D)
else:
    count = X // D
    coodinate = X - count * D
    if (K - count) % 2 == 0:
        print(coodinate)
    else:
        print(D - coodinate)

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

#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) c.begin(),c.end()
static const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
static const int MOD = (int)(1e9 + 7);

signed main() {
	int n, m, l; cin >> n >> m >> l;
	vector<vector<int>> a(n, vector<int>(m, 0));
	rep(i, 0, n) rep(j, 0, m) cin >> a[i][j];
	vector<vector<int>> b(m, vector<int>(l, 0));
	rep(i, 0, m) rep(j, 0, l) cin >> b[i][j];
	vector<vector<int>> c(n, vector<int>(l, 0));
	rep(i, 0, n) rep(j, 0, l) rep(k, 0, m) {
		c[i][j] += a[i][k] * b[k][j];
	}
	rep(i, 0, c.size()) {
		cout << c[i][0];
		rep(j, 1, c[i].size()) { cout << " " << c[i][j]; }
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3152
n = int(input())
lst = list(map(int, input().split()))
ans = 1
for i in range(n):
  if lst[i] == 0:
    print(0)
    exit()
for i in range(n):
  ans = ans*lst[i]
  if ans > 10**18:
    print(-1)
    exit()
print(ans)

Measured memory_bytes: 21588
#include <iostream>
#include <cmath>
#include <string.h>
#include <iomanip>

using namespace std;

#define INF 100000000;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main(){
    string S,SS;
    cin >> S >> SS;
    rep(i,S.length()){
        if (S[i] == SS[i]){
            continue;
        }
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3616
fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    val set = mutableSetOf<Int>()
    while (n --> 0) {
        val Ai = readLine()!!.toInt()
        if (set.contains(Ai)) {
            set.remove(Ai)
        } else {
            set.add(Ai)
        }
    }
    println(set.size)
}

Measured memory_bytes: 43808
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
int main(){
  int A, B, C, D ,E ,F;
  string S,Sa,Sb,Sc;
  cin >> S;
  if(S[0] == '9')S[0] = '1';
  else if(S[0] == '1')S[0] = '9';
  if(S[1] == '9')S[1] = '1';
  else if(S[1] == '1')S[1] = '9';
  if(S[2] == '9')S[2] = '1';
  else if(S[2] == '1')S[2] = '9';

cout << S << endl;
        return 0;
}

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

using namespace std;

int main() {
    string x,y;
    cin>>x>>y;

    if(x==y){
        cout<<"="<<endl;
    }
    else if(x>y) {
        cout<<">"<<endl;
    }
    else{
        cout<<"<"<<endl;
    }

}


Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-



H,W = map(int, input().split())
builds = []
for h in range(H):
  l = str(input())
  for w in range(W):
    if l[w] == "B":
      builds.append([h,w])

# [min,max]
lu = [H+W,0]
ld = [H+W,0]
for h,w in builds:
  lu = [min(lu[0],h+w),max(lu[1],h+w)]
  ld = [min(ld[0],H-h+w),max(ld[1],H-h+w)]
print(max(lu[1]-lu[0],ld[1]-ld[0]))



Measured memory_bytes: 73392
#include<bits/stdc++.h>
using namespace std;
const int M = 1e5+1;
int a[M];
int main ()
{
 int n, i, ans;
 cin >> n;
 for(i = 1; i <= n; i++)
 {
   cin >> a[i];
 }
 sort(a+1, a+n+1);
 ans = a[(n/2)+1] - a[n/2];
 cout << ans << endl;
}

Measured memory_bytes: 640
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const inputs = input.trim().split('\n');
const n = Number(inputs.shift());
const adj = inputs.map((s) => s.split(' ').map(Number));

class Time {
  constructor(now = 0) {
    this.now = now;
  }
  getNow() {
    return ++this.now;
  }
}
const time = new Time();

class Node {
  constructor(id) {
    this.id = id;
    this.children = [];
  }
  add(node) {
    this.children.push(node);
  }
  isVisited() {
    return !!this.start;
  }
  calc() {
    this.start = time.getNow();
    this.children.sort((a, b) => a.id > b.id);
    this.children.forEach(child => child.isVisited() || child.calc());
    this.end = time.getNow();
  }
  toString() {
    return [this.id, this.start, this.end].join(' ');
  }
}

class Tree {
  constructor() {
    this.map = new Map();
  }
  getNode(id) {
    this.map.has(id) || this.map.set(id, new Node(id));
    return this.map.get(id);
  }
  calc() {
    for (let i = 1; i <= this.map.size; i++) {
      const node = this.map.get(i);
      node.isVisited() || node.calc();
    }
  }
  print() {
    for (let i = 1; i <= this.map.size; i++) {
      const node = this.map.get(i);
      console.log(node.toString());
    }
  }
}

const tree = new Tree();
adj.forEach(([u, k, ...vk]) => {
  const parent = tree.getNode(u);
  vk.forEach(v => {
    const node = tree.getNode(v);
    parent.add(node);
  });
});

tree.calc();
tree.print();



Measured memory_bytes: 16912
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    int e,f;
    e = 0;
    f = 0;
    cin >> a >> b >>c;
    if(a == 5){
        e++;
    }
    if(b == 5){
        e++;
    }
    if(c == 5){
        e++;
    }
    if(a == 7){
        f++;
    }
    if(b == 7){
        f++;
    }
    if(c == 7){
        f++;
    }
    if(e == 2 && f == 1){
        cout << "YES"<<endl;
    }else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256