akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int n;
    cin >> n;
    vector<long long int> v(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    long long int s = accumulate(v.begin(), v.end(), (long long int)0);
    long long int res = -1;
    long long int c = 0;
    for (int i = 0; i < n - 1; i++) {
        c += v[i];
        long long int diff = abs(s - c - c);
        if (res == -1 || res > diff) {
            res = diff;
        }
    }
    cout << res << endl;
}




Measured memory_bytes: 4848
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))

A, B, C = 0, 0, 0

for i in p:
    if i <= a:
        A += 1
    elif a < i <= b:
        B += 1
    else:
        C += 1

print(min(A, B, C))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int N;
    string s, t;
    string ans;


    cin >> N >> s >> t;
    ans = "";
    rep(i, N){
        ans = ans + s[i] + t[i];
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
int main(){
int n;
  ll d;
  cin >> n >> d;
  int ans=0;
  rep(i,n){
ll x,y;
    cin >> x >> y;
    if(x*x+y*y<=d*d) ans ++;
  }
  cout << ans << endl;
return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>

int compare(const void *a, const void *b) {
        return *(int*)b - *(int*)a;
}

int main(){
  int i,n,x=0,y=0;

  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++){
    scanf(" %d",&a[i]);
  }
  qsort(a, n, sizeof(int), compare);
  for(i=0;i<n-1;i++){
    x+=a[i];
    y+=a[i+1];
    i++;
  }
  if(n%2==1){
    x+=a[n-1];
  }
  printf("%d",x-y);
  return 0;
}


Measured memory_bytes: 128
def main():
	n,k=map(int,input().split())
	a=[0]+list(map(int,input().split()))
	p=[]
	for i in range(n):
		a[i+1]+=a[i]
	for i in range(n+1):
		for j in range(i):
			p.append(a[i]-a[j])
	p.sort()
	ans=0
	from math import log,ceil
	r=ceil(log(sum(p))+10**-3)
	for i in range(r+2,-1,-1):
		cnt=0
		for j in range(len(p)):
			if (ans+2**i)&p[j]==ans+2**i:
				cnt+=1
				if cnt==k:
					break
		if cnt==k:
			ans+=2**i
	print(ans)
if __name__ == '__main__':
	main()

Measured memory_bytes: 111948
s = list(input())
t = list(input())
tmp = 0
ans = len(t)
for i in range(len(s) - len(t) + 1):
    tmp = 0
    for j in range(len(t)):
        if s[i + j] != t[j]:
            tmp += 1
    if tmp < ans:
        ans = tmp
print(ans)


Measured memory_bytes: 8972
package main

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

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	m := sc.ReadInt()
	q := sc.ReadInt()
	abcds := make([]ABCD, q)
	for i := 0; i < q; i++ {
		a := sc.ReadInt()
		b := sc.ReadInt()
		c := sc.ReadInt()
		d := sc.ReadInt()
		abcds[i] = ABCD{a, b, c, d}
	}

	combinations := generateCombinations(1, m, n)

	maxScore := 0
	for _, combi := range combinations {
		score := computeScore(abcds, combi)
		if score > maxScore {
			maxScore = score
		}
	}

	fmt.Println(maxScore)
}

func generateCombinations(min, max, n int) []SeqA {
	if n == 0 {
		return []SeqA{make(SeqA, 0)}
	}

	combinations := make([]SeqA, 0)
	for i := min; i <= max; i++ {
		restCombinations := generateCombinations(min, i, n-1)
		for _, combi := range restCombinations {
			combinations = append(combinations, append(combi, i))
		}
	}
	return combinations
}

func computeScore(abcds []ABCD, seqA SeqA) int {
	totalD := 0
	for _, abcd := range abcds {
		if seqA[abcd.B-1]-seqA[abcd.A-1] == abcd.C {
			totalD += abcd.D
		}
	}
	return totalD
}

type SeqA []int

type ABCD struct {
	A int
	B int
	C int
	D int
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


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

int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>> jobs(m);
    rep(i,n){
        int a,b;
        cin>>a>>b;
        if (a>m) continue;
        jobs[m-a].push_back(b);
    }
    priority_queue<int> q;
    ll ans=0;
    for(int i=m-1;i>=0;i--){
        for(int b:jobs[i]){
            q.push(b);
        }
        if(!q.empty()){
            ans+=q.top();
            q.pop();
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5632
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  int a, b, c;

  unused = scanf("%d %d %d", &a, &b, &c);
  if(a==b && b==c) printf("1");
  else if(a==b || b==c || a==c) printf("2");
  else printf("3");

  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>

int main(){
	double a;
	double b;
	double now=90;
	double x=0,y=0;
	double PI=3.14159265358;
	while(1){
		scanf("%lf,%lf",&a,&b);
		if(a==b&&b==0)break;
		x+=cos(now*PI/180)*a;
		y+=sin(now*PI/180)*a;
		now-=b;
	}
	printf("%d\n%d\n",(int)x,(int)y);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0; i<(n); i++)
int a[100100];
int cnt[100100];
int main() {
  int n;
  cin >> n;
  rep(i,n) cin >> a[i];
  rep(i,n) cnt[i]=0;
  rep(i,n) cnt[a[i]]++;
  if(n%2==0){
    int limit = n-1;
    bool ok = true;
    int count = 0;
    while(limit>0){
      if(cnt[limit]!=2) ok = false;
      limit -=2;
      count++;
    }
    if(!ok){
      cout << 0 << endl;
      return 0;
    }
    else{
      ll ans = 1;
      while(count>0){
        ans *= 2;
        ans %= 1000000007;
        count--;
      }
      cout << ans << endl;
      return 0;
    }
  }
  else{
    int limit=n-1;
    bool ok=true;
    int count=0;
    while(limit>=0){
      if(limit>0 && cnt[limit]!=2) ok=false;
      else if(limit==0 && cnt[limit]!=1) ok=false;
      limit-=2;
      count++;
    }
    if(!ok){
      cout << 0 << endl;
      return 0;
    }
    else{
      ll ans = 1;
      count--;
      while(count>0){
        ans *= 2;
        ans %= 1000000007;
        count--;
      }
      cout << ans << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 1024
# _*_ coding:utf-8 _*_
#  Atcoder__KeyenceProgramingContest-A
#  TODO https://keyence2019.contest.atcoder.jp/tasks/keyence2019_a

def solveProblem(charList):
	count = 0
	if '1' in charList:
		count = count + 1
	else:
		count = count
	if '9' in charList:
		count = count + 1
	else:
		count = count
	if '7' in charList:
		count = count + 1
	else:
		count = count
	if '4' in charList:
		count = count+1
	else:
		count = count

	if count == 4:
		result = "YES"
	else:
		result = "NO"

	answer = result
	return answer


if __name__ == '__main__':
	charList = list(map(str,input().strip().split(' ')))
	solution = solveProblem(charList)
	print("{}".format(solution))


Measured memory_bytes: 3064
class Main
{
	public static void main( String[] args )
	{
		java.util.Scanner sc = new java.util.Scanner( System.in );
		
		int[] street = new int[sc.nextInt()+1];
		int   n = sc.nextInt();
		
		for( int w = 1 ; w < street.length ; w++ )
			street[w] = w;
			
		String in;
		String[] sp;
		int work = 0;
		int change1 = 0;
		int change2 = 0;
		for( int i = 0 ; i < n ; i++ )
		{
			in = sc.next();
			sp = in.split( "," );
			change1 = Integer.parseInt(sp[0]);
			change2 = Integer.parseInt(sp[1]);
			
			work = street[change1];
			street[change1] = street[change2];
			street[change2] = work;
		}
		for( int w = 1 ; w < street.length ; w++ )
			System.out.println( street[w] );
	}
}

Measured memory_bytes: 26228
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String[] str=sc.nextLine().split(" ");
		int[] hyo=new int[str.length];
		int max=0;
		String maxhyo="";
		String maxlength="";
		for(int i=0;i<str.length;i++){
			for(int j=i+1;j<str.length;j++){
				if(str[i].equals(str[j])){
					hyo[i]++;
				}
			}
		}
		for(int i=0;i<str.length;i++){
			if(max<hyo[i]){
				max=hyo[i];
				maxhyo=str[i];
			}
		}
		max=0;
		for(int i=0;i<str.length;i++){
			if(max<str[i].length()){
				max=str[i].length();
				maxlength=str[i];
			}
		}
		System.out.println(maxhyo+" "+maxlength);
	}
}

Measured memory_bytes: 17136
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,d,e;
  int k;
  cin >> a >> b >> c >> d >> e;
  cin >> k;
  string ans;
  if ((e-a) <= k) ans = "Yay!";
  else ans = ":(";
  cout << ans << endl;
}


Measured memory_bytes: 256
N = gets.chomp.to_i
d = gets.chomp.split.map(&:to_i)
# S = gets.chomp.chars

ans = 0
0.upto(N-1).each do |i|
  (i+1).upto(N-1).each do |j|
    ans += d[i] * d[j]
  end
end

p ans

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

int main()
{
    int A, B;
    cin >> A >> B;
    vector<int> ans = {0, 0, 0};
    ans[0] = A + B;
    ans[1] = A - B;
    ans[2] = A * B;
    cout << *max_element(ans.begin(), ans.end()) << endl;
}

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

#define f(i,a,b) for (int i = a; i < b; i++)
#define fr(i,a,b) for (int i = b-1; i >= a; i--)
#define Max(a,b) a=max(a,b)

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	string s; cin >> s;
	int n = s.length();
	int K; cin >> K;
	int dp[n+1][n+1][K+1];
	f(i,0,n+1) f(j,0,n+1) f(k,0,K+1)
		dp[i][j][k] = 0;
	int ans = 0;
	f(i,0,n) fr(j,i,n) f(k,0,K+1) {
		if (s[i] == s[j]) {
			if (j) Max(dp[i+1][j-1][k],dp[i][j][k]+1+(i!=j));	
			else Max(ans,dp[i][j][k]+1+(i!=j));
		} else if (k) {
			if (j) Max(dp[i+1][j-1][k-1],dp[i][j][k]+1+(i!=j));
			else Max(ans,dp[i][j][k]+1+(i!=j));
		}
		if (i<n) Max(dp[i+1][j][k], dp[i][j][k]);
		if (j) Max(dp[i][j-1][k], dp[i][j][k]);
	}
	f(i,0,n+1) f(j,0,n+1) f(k,0,K+1)
		Max(ans,dp[i][j][k]);
	cout << ans << endl;

#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	
	return 0;
}



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

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
char land[20][20];

void dfs(int y, int x) {
   land[y][x] = '0';
   for (int i = 0; i < 4; i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if (ny >= 0 && ny < 12 && nx >= 0 && nx < 12 && land[ny][nx] == '1') {
         dfs(ny, nx);
      }
   }
   return;
}

int main() {
   while (scanf("%s", land[0]) != EOF) {
      for (int i = 1; i < 12; i++) {
         scanf("%s", land[i]);
      }

      int cnt = 0;
      for (int i = 0; i < 12; i++) {
         for (int j = 0; j < 12; j++) {
            if (land[i][j] == '1') {
               cnt++;
               dfs(i, j);
            }
         }
      }
      printf("%d\n", cnt);

   }

   return 0;
}


Measured memory_bytes: 3196
N,M = map(int, input().split())
for i in range(M):
    if i == 0 :
        L,R = map(int, input().split())
    else:
        l,r = map(int, input().split())
        L = max(L,l)
        R = min(R, r)
print(R - L + 1) if R - L + 1 >= 0 else print(0)


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
    char buf[256];
    int i, len, max = 0;
    fgets(buf, sizeof(buf), stdin);
    len = strlen(buf)-2;

    for ( i = 0; i < len/2; i++ ){
        if ( memcmp(buf, buf+i+1, i+1) == 0 ){
            if ( i > max ){
                max = i;
            }
        }
    }

    printf("%d\n", (max + 1)*2);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
//C++14 (GCC 5.4.1)
int main() {
    int N;
    cin >>N;
    vector<int> D(N);

    rep(i,N) cin >> D.at(i);
    //-----------------------------------
    int Ans=1;
    std::sort(D.begin(),D.end());
    int last=D.at(0);
    for(int i=1;i<N;i++){
        if(last!=D.at(i)){
            Ans++;
            last=D.at(i);
        }
    }

    cout << Ans <<endl;
}

Measured memory_bytes: 256
n=int(input())

p=10**9+7

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

binA=[]
for i in range(n):
  binA.append(format(A[i],"060b"))

exp=[1]
for i in range(60):
  exp.append((exp[i]*2)%p)


ans=0
for i in range(60):
  num0=0
  num1=0
  for j in range(n):
    if binA[j][i]=="0":
      num0+=1
    else:
      num1+=1
  ans=(ans+num0*num1*exp[59-i])%p

print(ans)



  


Measured memory_bytes: 153248
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int mod =1e9+7;
const int N = (int)2e5 + 5;



void solve(){
	string s;
	cin>>s;
	if(s[0]=='A'){
		int x=0;
		rep(i,sz(s)){
			if(s[i]>='A' &&s[i]<='Z'){
				x++;
			}
		}
		if(x!=2){
			cout<<"WA";
			return;
		}
		for(int i=2;i<=sz(s)-2;i++){
			if(s[i]=='C'){
				cout<<"AC";
				return;
			}
		}
		cout<<"WA";
	}
	else cout<<"WA";	

}

int main(){
	Red;
	int t=1;
	// cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 256
/**********************************************************************/
/********                                                      ********/
/********                     Writer:孙~~                      ********/
/********                       Lang:C++                       ********/
/********                     Status:Unknow                    ********/
/********                                                      ********/
/**********************************************************************/
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <list>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <cstring>
#include <cmath>
//#include<bits/stdc++.h>
using namespace std;

const int INF=0x3f3f3f3f;
const int SIZE=100005;

int n,m;
vector<pair<int,int> > mp[SIZE];
bool vis[SIZE];
long long val[SIZE];

bool bfs(int i){
	queue<int> que;
	que.push(i);
	val[i]=0;
	while(!que.empty()){
		int v=que.front();
		que.pop();
		for(int i=0;i<mp[v].size();i++){
			pair<int,int> u=mp[v][i];
			int to=u.first;
			if(val[to]==INF){
				val[to]=val[v]+u.second;
				que.push(to);
			}
			else if(val[to]!=val[v]+u.second){
				return false;
			}
		}
	}
	return true;
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int l,r,d;
		scanf("%d%d%d",&l,&r,&d);
		l--;
		r--;
		mp[l].push_back(make_pair(r,d));
		mp[r].push_back(make_pair(l,-d));
	}
	for(int i=0;i<n;i++) val[i]=INF;
	for(int i=0;i<n;i++) if(val[i]==INF) if(!bfs(i)){
		puts("No");
		return 0;
	}
	puts("Yes");
	return 0;
}




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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	int A[51];
	vector<pii> ansv;

	cin >> N;
	int mv = 0, ma = 0, mi = -1;
	rep(i, 0, N)
	{
		cin >> A[i];
		if (chmax(ma, abs(A[i])))
		{
			mv = A[i];
			mi = i;
		}
	}

	if (mv > 0)
	{
		ansv.push_back(mp(mi + 1, 1));
		ansv.push_back(mp(mi + 1, 1));
		rep(i, 0, N - 1)
		{
			ansv.push_back(mp(i + 1, i + 2));
			ansv.push_back(mp(i + 1, i + 2));
		}
	}
	else if (mv < 0)
	{
		ansv.push_back(mp(mi + 1, N));
		ansv.push_back(mp(mi + 1, N));
		rrep(i, 1, N)
		{
			ansv.push_back(mp(i + 1, i));
			ansv.push_back(mp(i + 1, i));
		}
	}

	cout << SZ(ansv) << endl;
	for (auto p : ansv)
	{
		cout << p.first << " " << p.second << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 300000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real()* b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real()* b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
vector<long long> geko;
int main() {
	int n, m;
	cin >> n >> m;
	long long ans = 0;
	REP(i, n) {
		long long a;
		cin >> a;
		ans += a;
		geko.push_back(a);
	}
	sort(geko.begin(), geko.end());
	vector<pair<long long, long long>> input;
	REP(i, m) {
		long long a, b;
		cin >> a >> b;
		input.push_back(make_pair(b, a));
	}
	sort(input.begin(), input.end(), greater<pair<long long,long long>>());
	int now_itr = 0;
	for (int i = 0; i < input.size(); ++i) {
		for (int q = 0; q < input[i].second; ++q) {
			if (now_itr == geko.size()) break;
			if (input[i].first - geko[now_itr] < 0) break;
			ans += input[i].first - geko[now_itr];
			now_itr++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3188
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use proconio::input;
//use proconio::marker::Usize1;
//use proconio::marker::Chars;
//use std::collections::HashSet;
//use std::cmp::*;
fn main() {
    input! {
        r: i32
    }
    let ans = r * r;
    println!("{}", ans);
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> g[110000];
ll dp[110000];
ll solve(ll u)
{
    if(dp[u]!=-1)
    return dp[u];
    ll ret=0;
    for(ll i=0;i<g[u].size();i++)
    {
        ret=max(ret,solve(g[u][i])+1);
    }
    return dp[u]=ret;
}
int main()
{
 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n,m;
  cin>>n>>m;
  for(ll i=0;i<m;i++)
  {
    ll a,b;
    cin>>a>>b;
    --a;
    --b;
    g[a].push_back(b);
  }
  for(ll i=0;i<n;i++)
  {
      dp[i]=-1;
  }
  ll ret=0;
  for(ll i=0;i<n;i++)
  {
    ret=max(ret,solve(i));
  }
  cout<<ret<<'\n';
   
  return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
main(){
  int n,r,t;
  cin >> n >> r >> t;
  int p[105];
  for(int i=0;i<n;i++) cin>>p[i];
  int cnt[1005]={0};
  int now[105]={0};
  queue<int> que[2];
  int sum = 0;
  for(int i=0;i<min(t,2);i++){
    for(int j=0;j<n;j++){
      now[j]+=p[j];
      now[j]%=r;
      if(i==1){
	que[1].push(now[j]);
      }
      sum++;
    }
  }
  for(int i=2;i<t;i++){
    while(!que[(i+1)%2].empty()){
      cnt[que[(i+1)%2].front()]++;
      que[(i+1)%2].pop();
    }
    for(int j=0;j<n;j++){
      now[j]+=p[j];
      now[j]%=r;
      if(cnt[now[j]]==0){
	sum++;
      }
      else{
	cnt[now[j]]--;
      }
      que[i%2].push(now[j]);
    }
    /*
    for(int j=1;j<r;j++){
      cout << cnt[j] << " ";
    }
    cout<<cnt[0]<<" "<<sum<<endl;
    */
  }
  /*
  for(int i=0;i<t;i++){
    for(int j=0;j<n;j++){
      if(i > 0){
	if(cnt[now[j]] == 0) {
	  sum++;
	} else {
	  cnt[now[j]]--;
	}
      }
      now[j] = (now[j]+p[j])%r;
      if(i > 0){
	cnt[now[j]]++;
      }
    }
    for(int j=0;j<r;j++){
      cout << cnt[j] << " ";
    } 
    cout << endl;
    }
  */
  cout << sum << endl;
}

Measured memory_bytes: 3116
'use strict'

function main(input) {
    const sum = input
        .split('')
        .map(v => ~~v)
        .reduce((a, b) => a + b)
    const ans = Number(input) % sum === 0 ? 'Yes' : 'No'
    console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
# coding: utf-8
try:
    from fractions import gcd
except:
    from math import gcd
N = int(input())
T = []
for i in range(N):
    t = int(input())
    T.append(t)
ans = T[0]
for i in range(1, N):
    ans = (ans * T[i]) // gcd(ans, T[i])
print(ans)

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  string s, t;
  cin >> s >> t;
  if (s.size() < t.size()) swap(s, t);
  int n, m;
  n = s.size();
  m = t.size();
  int ans = INF;
  dump(n, m);
  rep(i, n - m + 1) {
    int cnt = 0;
    rep(j, m) {
      if (s[i + j] != t[j]) cnt++;
    }
    dump(i, cnt);
    mins(ans, cnt);
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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

int main(){
  int x,n[10000],d,s=0;
  cin >> x;
  for(int i=0;i<x;i++) cin >> n[i];
    
  for(int i=0;i<x;i++){
	  d=1;
	  for(int j=2;j*j<=n[i];j++){
		  if(n[i]%j==0){
			  d=0;
			  break;
		  }
	  }
	  if(d==1) s++;
  }
  cout << s << "\n";
  return 0;
}

Measured memory_bytes: 1200
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
for i in range(N):
  ans += B[A[i]-1]
  if i > 0 and A[i-1] + 1 == A[i]:
    ans += C[A[i-1]-1]
print(ans)

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

int main(){
    int n,cost[10001],h[100001];
    cost[0]=0;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>h[i];
        if(i>=1){
            cost[i]=abs(h[i]-h[i-1]);                    
        }
        if(i>=2){
            cost[i]=min(cost[i-2]+abs(h[i]-h[i-2]),cost[i-1]+abs(h[i]-h[i-1]));
        }
    }
    cout<<cost[n-1]<<"\n";
return 0;
}

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

#define endl "\n"
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

void header() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

int p[maxn];
string s[maxn];

void solve() {
	int n, m, res = 0, x = 0;
	cin >> n >> m;
	map<int, int> wa, ac;
	for (int i = 1; i <= m; i++) {
		cin >> p[i] >> s[i];
		if (s[i] == "WA") wa[p[i]]++;
		else {
			if (!ac.count(p[i])) {
				res++;
				ac[p[i]] = 1;
				x += wa[p[i]];
			}
		}
	}
	cout << res << " " << x << endl;
}

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


Measured memory_bytes: 24576
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s1,s2;
  cin>>s1>>s2;
  int ctr=0;
  for(int i=0;i<3;i++)
  {
  if(s1[i]==s2[i])
    ctr++;
  }
  cout<<ctr;
  return 0;
}
    

Measured memory_bytes: 256
// Aizu Vol-2 0242: Input Candidates
// 2017.8.8

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

char *gets(char *);
char buf[1500], *p;

char *getStr(int *len)
{
	char *w;
	while (isspace(*p)) p++;
	if (!*p) return NULL;
	w = p;
	while (isalnum(*p)) *p++;
	*len = p - w;
	if (*p) *p++ = 0;
	return w;
}

typedef struct { char *w; short k; } T;

#define MAX 3000
char word[MAX][21];		// Word body
T wt[MAX]; int end;		// Word table

#define HSIZ 4999
T ht[HSIZ+2];				// Hash table

int lookup(char *w, int len, char *nw, int k)
{
	T *tp;
	int i = (101 * *w + 103 * *(w + len - 1) + 107 * len) % HSIZ;

	tp = ht + i;
	if (tp->w != NULL) {
		int inc = *w + (*(w + 1) << 1);
		while (1) {
			if (!memcmp(tp->w, w, len)) return tp->k;
			i += inc;
			if (i >= HSIZ) i -= HSIZ;
			tp = ht + i;
			if (tp->w == NULL) break;
		}
	}
	tp->w = nw, tp->k = k;
	return -1;
}

int main()
{
	int n, i, j, k, g;
	char *w;

	while (1) {
		gets(buf); n = atoi(buf); if (!n) break;
		end = 0, memset(ht, 0, sizeof(ht));
		while (n-- > 0) {
			gets(p = buf);
			while (1) {
				if ((w = getStr(&k)) == NULL) break;
				if ((i = lookup(w, k, word[end], end)) < 0) {
					strcpy(word[end], w);
					wt[end].w = word[end];
					wt[end++].k = 1;
				}
				else wt[i].k++;
			}
		}

		gets(p = buf); while (isspace(*p)) p++;
		g = *p;

		for (i = j = 0; i < end; i++) {
			if (*(wt[i].w) == g) {
				if (i != j) wt[j].w = wt[i].w, wt[j].k = wt[i].k;
				j++;
			}
		}
		if ((end = j) == 0) { puts("NA"); continue; };
		for (i = 0; i < end; i++) {
			k = i;
			for (j = i + 1; j < end; j++) {
				if (wt[k].k < wt[j].k ||
					wt[k].k == wt[j].k && strcmp(wt[k].w, wt[j].w) > 0) k = j;
			}
			if (k != i) {
				T tmp;
				memcpy(&tmp, wt + k, sizeof(T)), memcpy(wt + k, wt + i, sizeof(T));
				memcpy(wt + i, &tmp, sizeof(T));
			}
		}
		for (i = 0; i < 5 && i < end; i++) {
			if (i > 0) putchar(' ');
			printf("%s", wt[i].w);
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 652
H = int(input())

A = [None] * (H + 1)

for cnt, key in enumerate(map(int, input().split())):
    A[cnt + 1] = key

index_min = 1
index_max = len(A) - 1

for id in range(1, len(A)):
    k = A[id]
    print(f"node {id}: key = {k}, ", end="")

    index_pk = id // 2
    if index_min <= index_pk <= index_max:
        pk = A[index_pk]
        print(f"parent key = {pk}, ", end="")

    index_lk = 2 * id
    if index_min <= index_lk <= index_max:
        lk = A[index_lk]
        print(f"left key = {lk}, ", end="")

    index_rk = 2 * id + 1
    if index_min <= index_rk <= index_max:
        rk = A[index_rk]
        print(f"right key = {rk}, ", end="")

    print()



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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a >= b && a >=c){
    cout << 10 * a + b + c << endl;
  }
  else if(b >= a && b >= c){
    cout << 10 * b + a + c << endl;
  }
  else{
    cout << 10 * c + a + b << endl;
  }
}


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

const long long md=998244353;
const int maxn=300100;
long long fac[maxn],inv[maxn];
long long powd(long long x,long long y){
	long long res=1;
	while(y){
		if(y&1) res=res*x%md;
		x=x*x%md;
		y>>=1;
	}
	return res;
}
void csh(){
	fac[0]=1;
	for(int i=1;i<=300000;i++)
		fac[i]=fac[i-1]*i%md;
	inv[300000]=powd(fac[300000],md-2);
	for(int i=300000;i>=1;i--)
		inv[i-1]=inv[i]*i%md;
}
long long C(int x,int y){
	return fac[x]*inv[y]%md*inv[x-y]%md;
}

int main(){
  csh();
  long long N, A, B, K;
  cin >> N >> A >> B >> K;
  long long ans = 0;
  for (int i=0; i<N+1; i++){
    if (((K - i*A) % B != 0) || (K - i*A < 0) || ((K-i*A)/B > N)) continue;
    ans = (ans + C(N,i) * C(N,(K-i*A)/B)) % md;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4992
#![allow(unused_imports)]pub mod pcl{pub mod stdin{use std::io::prelude::*;use std::io::stdin;use std::str::FromStr;pub fn read<T:FromStr>()->T{read_read(stdin())}pub fn read_line()->String{let mut s=String::new();stdin().read_line(&mut s).unwrap();s.trim().to_string()}pub fn read_read<R:Read,T:FromStr>(read:R)->T{let s:Vec<u8>=read.bytes().take_while(|x|{x.as_ref().map(|x|![b' ',b'\r',b'\t',b'\n'].contains(&x)).unwrap_or(true)}).collect::<Result<_,_>>().unwrap_or_else(|_|panic!("failed to read bytes"));String::from_utf8_lossy(&s).parse().unwrap_or_else(|_|panic!("failed to parse a value"))}}}
use pcl::stdin::*;
fn main() {
    let (a, b): (i32, i32) = (read(), read());
    for i in 0..1001 {
        if (i as f64 * 0.08) as i32 == a && (i as f64 * 0.1) as i32 == b {
            println!("{}", i);
            return;
        }
    }
    println!("-1");
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;

struct Dice {
    array<int, 6> dice;

    void _roll(int a, int b, int c, int d)
    {
        int tmp = dice[a];
        dice[a] = dice[b];
        dice[b] = dice[c];
        dice[c] = dice[d];
        dice[d] = tmp;
    }

    void roll(char dir)
    {
        switch (dir) {
        case 'S':
            _roll(0, 1, 5, 4);
            _roll(0, 1, 5, 4);
        case 'N':
            _roll(0, 1, 5, 4);
            break;
        case 'E':
            _roll(0, 2, 5, 3);
            _roll(0, 2, 5, 3);
        case 'W':
            _roll(0, 2, 5, 3);
            break;
        }
    }

    int right(int _top, int _front)
    {
        for (size_t i = 0; i < 6; i++) {
            for (size_t j = 0; j < 4; j++) {
                if (dice[0] == _top && dice[1] == _front)
                    goto out;

                _roll(1, 2, 4, 3);
            }

            if (i % 2) {
                _roll(0, 1, 5, 4);
            } else {
                _roll(0, 2, 5, 3);
            }
        }

    out:
        return dice[2];
    }

    bool operator==(Dice& other)
    {
        bool ret = false;

        for (size_t i = 0; i < 6; i++) {
            for (size_t j = 0; j < 4; j++) {
                if (dice == other.dice) {
                    ret = true;
                    goto out;
                }

                _roll(1, 2, 4, 3);
            }

            if (i % 2) {
                _roll(0, 1, 5, 4);
            } else {
                _roll(0, 2, 5, 3);
            }
        }

    out:
        return ret;
    }
};

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

    vector<Dice> dices(n);

    for (auto&& dice : dices) {
        for (auto&& d : dice.dice) {
            cin >> d;
        }
    }

    bool res = false;
    for (size_t i = 0; i < n; i++) {
        for (size_t j = i + 1; j < n; j++) {
            if (dices[i] == dices[j]) {
                res = true;
                goto out;
            }
        }
    }

out:
    cout << (res ? "No" : "Yes") << endl;
}



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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

const int N = 200100;
int n, m;
int a[N];
int t[N];
int kol[N];

int main () {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	cin >> n >> m;
	forn(i, n) {
		cin >> a[i];
		a[i]--;
		kol[a[i]]++;
	}
	forn(i, n) {
		forn(j, kol[i]) {
			if (i - j < 0)
				break;
			t[i - j]++;	
		}
	}
	int ans = 0;
	forn(i, n) {
		if (t[i] > 0)
			ans++;
	}
	debug(t, t + n);
	debug(kol, kol + n);
	forn(i, m) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		kol[a[x]]--;
		if (a[x] >= kol[a[x]]) {
			t[a[x] - kol[a[x]]]--;
			if (!t[a[x] - kol[a[x]]])
				ans--;
	 	}
	 	a[x] = y;
	 	kol[y]++;
	 	if (y + 1 >= kol[y]) {
	 		t[y - kol[y] + 1]++;
	 		if (t[y - kol[y] + 1] == 1)
	 			ans++;
	 	}
	 	cout << n - ans << "\n";
	}
	
	
	return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
    int a, b, k;
    while(cin >> a >> b >> k)
    {
        for(int i = min(a, b); i >= 1; i--)
        {
            if(a % i == 0 && b % i == 0)
                k--;
            if(!k)
            {
                cout << i << endl;
                break;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<iomanip>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<28)
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS) 
#define pow2(a) ((a)*(a)) 
#define MAX 100010
using namespace std;
struct Point
{
  double x,y;
  Point(double x=-inf,double y=-inf):x(x),y(y){}
  bool operator < (const Point& a)const{ return !equals(x,a.x)?x < a.x:y < a.y; }
};
int AN,BN,R;
Point ps[MAX];
int dx[] = {0,0,1,0,-1,1,+1,-1,-1};
int dy[] = {0,1,0,-1,0,1,-1,-1,+1};


int main()
{

  while(1)
    {

      scanf("%d %d %d",&AN,&BN,&R);
      if(!(AN|BN))break;
      rep(i,AN)scanf("%lf %lf",&ps[i].x,&ps[i].y);
      vector<Point> G[251][251];
      {
	Point p;
	rep(i,BN)
	  {
	    scanf("%lf %lf",&p.x,&p.y);
	    G[(int)p.y/40][(int)p.x/40].push_back(p);
	  }
      }
      double r = R;
      int power = 0;
      rep(i,AN)
	{
	  int index_y = (int)ps[i].y/40;
	  int index_x = (int)ps[i].x/40;
	  rep(k,9)
	    {
	      index_x += dx[k];
	      index_y += dy[k];
	      if(!(0 <= index_x && index_x <= 250 && 0 <= index_y && index_y <= 250))goto Skip;
	      rep(j,G[index_y][index_x].size())
		{
		  Point p = G[index_y][index_x][j];
		  double dist = sqrt(pow2(ps[i].x-p.x)+pow2(ps[i].y-p.y)) - 2*r;
		  if(equals(dist,2.0*r) || dist < 2.0*r)power++;
		}
	    Skip:;
	      index_x -= dx[k];
	      index_y -= dy[k];
	    }
	}
      printf("%d\n",power);
    }
  return 0;
}

Measured memory_bytes: 6272
#include <iostream>
#include <map>

using namespace std;


int main () {
  int n, i;
  int *num;
  long long  ret = 0;
  map<int, long long> mp;
	
  cin >> n;
  
  num = (int*)calloc(n, sizeof(int));
  
  for ( i = 0; i< n; i++ ) {
    cin >> num[i];
    mp[num[i]] += 1;
  }
  
  /* コンビネーション算出 */
  for (auto itr = mp.begin(); itr != mp.end(); ++itr ) {
    ret += itr->second * (itr->second - 1) / 2;
  }

  /* n回繰り返す */
  for ( i = 0; i < n; i++ ) {
  	cout << ret - ((long long)(mp[num[i]] - 1)) << "\n" << endl;
  }
  
	return 0;
}


Measured memory_bytes: 10496
#include<stdio.h>
int main(void){
  int x,h,m,s;
  scanf("%d",&x);
  s=x%60;
  m=((x-s)/60)%60;
  h=(x-s-60*m)/3600;
  printf("%d:%d:%d\n",h,m,s);
  return 0;
  }

Measured memory_bytes: 592
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
vector<i64> a, b;
int main() {
  cin >> n;
  read_n(a, 1 << n);
  init_n(b, 1 << n);
  i64 m = 1 << n;

  for (i64 e = 1; e < m; e <<= 1) {
    for (i64 s = 0; s < m; ++s) {
      if (!(e & s)) {
        i64 t = e | s;
        b[t] = max(b[t], a[s]);
        if (a[t] < b[t]) swap(a[t], b[t]);
        b[t] = max(b[t], b[s]);
      }
    }
  }

  i64 ans = 0;
  for (i64 k = 1; k < m; ++k) {
    ans = max(ans, a[k] + b[k]);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 7424
import sys

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N, K = MI()
    H = LI()
    Hs = sorted(H)
    ans = 0

    if N > K:
        for i in range(N-K):
            ans += Hs[i]
        print(ans)
    else:
        print(0)

if __name__ == "__main__":
	main()

Measured memory_bytes: 31524
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 998244353;
using ll = long long;
using P = pair<ll, ll>;
double PI = acos(-1);
signed main(){
    int n;
    cin >> n;
    cout << n+n*n+n*n*n << endl;


    return 0;
}



Measured memory_bytes: 3632
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 H, W;
  std::cin >> H >> W;
  std::vector<std::string> A;
  tools::read(A, H);

  for (i64 y = 0; y < H; ++y) {
    for (i64 x = 0; x < W; ++x) {
      if (A[y][x] == '.') continue;
      const char L = x > 0 ? A[y][x - 1] : '.';
      const char R = x < W - 1 ? A[y][x + 1] : '.';
      const char U = y > 0 ? A[y - 1][x] : '.';
      const char D = y < H - 1 ? A[y + 1][x] : '.';
      if (y == 0 && x == 0) {
        if (L == '.' && R == '#' && U == '.' && D == '.') continue;
        if (L == '.' && R == '.' && U == '.' && D == '#') continue;
      } else if (y == H - 1 && x == W - 1) {
        if (L == '#' && R == '.' && U == '.' && D == '.') continue;
        if (L == '.' && R == '.' && U == '#' && D == '.') continue;
      } else {
        if (L == '.' && R == '#' && U == '#' && D == '.') continue;
        if (L == '#' && R == '.' && U == '.' && D == '#') continue;
        if (L == '#' && R == '#' && U == '.' && D == '.') continue;
        if (L == '.' && R == '.' && U == '#' && D == '#') continue;
      }
      goto FAILED;
    }
  }

  std::cout << "Possible" << std::endl;
  return 0;

FAILED:
  std::cout << "Impossible" << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=9999999999999999;

int main() {
   string S;
   cin>>S;
   set<char>t;
   t.insert(S[0]);
   t.insert(S[1]);
   t.insert(S[2]);
   if(t.size()==3){cout<<"Yes"<<endl;}
   else{cout<<"No"<<endl;}
return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }




 
template<typename T>
struct BinaryIndexedTree{
   vector<T> data;
   BinaryIndexedTree(int sz){
       data.assign(sz+1, 0);
   }
   // 区間[0,k]の合計 sum(v[0]~v[k])
   T sum(int k){
       T ret=0;
       for(++k;k>0;k-=(k&-k)) ret+=data[k];
       return ret;
   }
   // v[a]+=x
   void add(int k,T x){
       for(++k;k<data.size();k+=(k&-k)) data[k]+=x;
   }
   // wを超える最小のv[i]のiを返す(0indexedのを返す)(data上のindexを返したいならreturn x+1)
   int lower_bound(T w){//T?
       if(w<=0) return 0;
       //左右どっちに行くか考える
       int x=0,r=1;
       while(r<data.size()) r<<=1;
       for(int k=r;k>0;k>>=1){
           if(x+k<=data.size()&&data[x+k]<w){
               //左部分を引いて右へ，再起っぽい
               w-=data[x+k];
               x+=k;
           }
       }
       // return x+1;
       return x;
   }
};
 
 
ll g(vector<int> v){
    int n=v.size();
    if(n<=1){
        return 0;
    }
    int vmax=*max_element(ALL(v));
    BinaryIndexedTree<ll> bit(vmax+1);
    ll ret=0;
    rep(i,n){
        ret+=bit.sum(v[i]);
        bit.add(v[i],1);
    }
    return ret;
}



ll n;
vector<ll> a;


//m以上の中央値になるような区間がn(n+1)/4+1以上あるかどうか
bool f(ll m){
    vector<int> pm(n);//+?-?
    rep(i,n){
        if(a[i]<m)  pm[i]=-1;
        else        pm[i]=1;
    }

    vector<int> sum(n+1);
    sum[0]=0;
    rep(i,n) sum[i+1]=sum[i]+pm[i];
    int geta=-(*min_element(ALL(sum)));
    rep(i,n+1) sum[i]+=geta;
    ll k=g(sum);
    // cout<<m<<" : "<<k<<endl;
    return k>=n*(n+1)/4;
}

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

    cin>>n;
    a.resize(n);
    rep(i,n) cin>>a[i];
    if(n==1){
        cout<<a[0]<<endl;
        return 0;
    }

    ll lw=0,hi=LINF,ans=0;
    while(lw<=hi){
        ll mid=(lw+hi)/2;
        if(f(mid)){
            ans=mid;
            lw=mid+1;
        }else{
            hi=mid-1;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

const string YES = "Yes";
const string NO = "No";
using ll = long long;

void solve(long long N, long long K, std::vector<long long> A){
    for(int i = 0;i < N - K;i++){
        if(A[i + K] > A[i]){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, K, std::move(A));
    return 0;
}


Measured memory_bytes: 4864
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

const int maxn = 100005;
const int inf = 1e9;
int n, m, ed;
int he[maxn], L[maxn], R[maxn], ans[maxn];
struct Edge{
  int v, nx;
  Edge(){;}
  Edge(int _v, int _nx){v = _v, nx = _nx;}
}e[maxn << 1];
void Add(int u, int v){
  e[++ed] = Edge(v, he[u]);he[u] = ed;
}

void Dfs(int x, int fa){
  for(int i = he[x], v;i;i = e[i].nx){
    v = e[i].v;
    if(v == fa)continue;
    Dfs(v, x);
    L[x] = max(L[x], L[v] - 1);
    R[x] = min(R[x], R[v] + 1);
  }
}
void Dfss(int x, int fa){
  for(int i = he[x], v;i;i = e[i].nx){
    v = e[i].v;
    if(v == fa)continue;
    L[v] = max(L[v], L[x] - 1);
    R[v] = min(R[v], R[x] + 1);
    Dfss(v, x);
  }
}
void Solve(int x, int fa){
  for(int i = he[x], v;i;i = e[i].nx){
    v = e[i].v;
    if(v == fa)continue;
    if(ans[x] + 1 <= R[v])ans[v] = ans[x] + 1;
    else ans[v] = ans[x] - 1;
    Solve(v, x);
  }
}

int main(){
  scanf("%d", &n);
  for(int i = 1;i <= n;++i){
    L[i] = -inf;
    R[i] = inf;
  }
  for(int i = 1, u, v;i < n;++i){
    scanf("%d%d", &u, &v);
    Add(u, v);Add(v, u);
  }
  scanf("%d", &m);
  for(int i = 1, x, y;i <= m;++i){
    scanf("%d%d", &x, &y);
    L[x] = R[x] = y;
  }
  Dfs(1, 1);Dfss(1, 1);
  for(int i = 1;i <= n;++i){
    // cout<<"get "<<i<<' '<<L[i]<<' '<<R[i]<<endl;
    if(L[i] > R[i]){
      puts("No");
      return 0;
    }
  }
  ans[1] = L[1];
  Solve(1, 1);
  for(int i = 1;i <= n;++i){
    if(ans[i] < L[i] || ans[i] > R[i]){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  for(int i = 1;i <= n;++i)printf("%d\n", ans[i]);
  return 0;
}


Measured memory_bytes: 8704
#include<bits//stdc++.h>
using namespace std;
#define int long long
signed main(){
	string s;
	cin>>s;
	int a[3]={0,0,0};
	for(int i=0;i<3;i++){
		a[(int)s[i]-'a']++;
	}
	if(a[0]&&a[1]&&a[2]) cout<<"Yes\n";
	else cout<<"No\n";
}


Measured memory_bytes: 256