akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int n;
ll ten,nine,eight;
int main()
{
	cin>>n;
	ten=1,nine=1,eight=1;
	for (int i=1;i<=n;i++) ten=ten*10%mod,nine=nine*9%mod,eight=eight*8%mod;
	ll ans=ten+mod-nine+mod-nine+mod+eight;
	cout<<ans%mod<<endl;
	return 0;
}



Measured memory_bytes: 3612
S  = input()
N = len(S)
n1,n2 = ((N-1)/2),(N+3)/2
n1,n2 = int(n1),int(n2)
sh,st = S[:n1],S[n2-1:N]

if sh == sh[::-1] and st == st[::-1] and S==S[::-1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
function main(lines) {
    const input = lines.split('\n')
    const inputS = input[1].split(' ').map(Number)
    const inputT = input[3].split(' ').map(Number)
    const arrayS = Array.from( new Set(inputS) )
    const arrayT = Array.from( new Set(inputT) )
    
    let count = 0
    for(let i=0; i<arrayS.length; i++){
        if(arrayT.includes(arrayS[i])){
            count++
        }
    }
    console.log(count)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));




Measured memory_bytes: 17700
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  double ans=0.0;
  cin >> n;
  vi x(n),y(n);
  REP(i,n){
    cin>>x[i]>>y[i];
  }


  REP(i,n){
    REP(j,n){
      double xx=x[i]-x[j];
      double yy=y[i]-y[j];
      double ln=sqrt(xx*xx+yy*yy);
      ans+=ln;
    }
  }
  ans/=n;

  //cout<<ans<<endl;
  //小数点表記
std::cout << std::setprecision(10) << ans<<endl; // "3.1"
  return 0;
}

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

using namespace std;

const int mx = 1e5+5;

int h[mx];
int dp[mx];

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

	for(int i=1;i<=n;i++)
	{
		cin>>h[i];
	}

	dp[1]=0;
	dp[2]=abs(h[2]-h[1]);

	for(int i=3;i<=n;i++)
	{
		dp[i]=min((dp[i-2]+abs(h[i]-h[i-2])),(dp[i-1]+abs(h[i]-h[i-1])));
	}

	cout<<dp[n]<<'\n';
	return 0;	
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())
 
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);

    ll n,k,i,j;
    cin>>n>>k;
    cout<<min((n%k), k-(n%k));
    
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		Dish[] ds = new Dish[N];
		for (int i = 0; i < N; i++) {
			long A = sc.nextInt();
			long B = sc.nextInt();
			ds[i] = new Dish(A, B);
		}
		Arrays.sort(ds);
		long ans = 0;
		for (int i = 0; i < N; i++) {
			if (i % 2 == 0) {
				ans += ds[i].a;
			} else {
				ans -= ds[i].b;
			}
		}
		System.out.println(ans);
	}

	static class Dish implements Comparable<Dish> {
		long a, b;

		public Dish(long a, long b) {
			this.a = a;
			this.b = b;
		}

		@Override
		public int compareTo(Dish o) {
			return -Long.compare(this.a + this.b, o.a + o.b);
		}
	}
}

Measured memory_bytes: 91812
n = input()
sum = 0
ans = 0

if len(n) == 1:
    ans = n
elif len(n) == 2:
    ans = 9
elif len(n) == 3:
    n = int(n)
    ans = ((n-100)+1)+9
elif len(n) == 4:
    ans = 9+900
elif len(n) == 5:
    n = int(n)
    ans = ((n-10000)+1)+900+9
else:
    ans = 90000+900+9

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  int n;
  string cha,str;
 
  cin >> cha >> n;
 
  int count = 0;
 
  for(int q=0;q<n;q++) {
    cin >> str;
    int m = str.size();
 
    int flg = count;
    for(int i=0;i<m;i++) {
      for(int j=0;j<cha.size();j++){
    if(str[(j+i)%m] != cha[j]) break;
    if(j == cha.size()-1) count++;
      }
      if(count != flg) break;
    }
 
  }
 
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 1204
S = list(input())
flagx = 0
flagy = 0
if S[0] == "A":
  S.pop(0)
else:
  flagx = 1
  
for i in range(1,len(S)-1):
  if S[i] == "C":
    S.pop(i)
    flagy = 0
    break
  else:
    flagy = 1
    
if str(S).islower() and flagx == 0 and flagy == 0:
  print("AC")
else:
  print("WA")
  

Measured memory_bytes: 3060
object Main {
  def main (args: Array[String]) {
    val input =  scala.io.StdIn.readLine().split(" ").map(_.toInt)

    (input(0),input(1),input(2)) match{
      case (n1, n2, n3 ) if (n1 < n2) && (n2 < n3) => println("Yes")
      case _ => println("No")
    }
  }
}

Measured memory_bytes: 43852
n=int(input())
l=list(map(int, input().split()))
#l=list(l)
count=0
for i in range(n-2):
    for j in range(i+1,n-1):
        #print(i)
        if l[j]!=l[i]:
            #print(i)
            for k in range(j+1,n):
                a,b,c=[l[i],l[j],l[k]]
                if a!=c and b!=c:
                    if a+b>c and b+c>a and c+a>b:
                        count+=1
                    #print(i+1,j+1,k+1)
print(count)

Measured memory_bytes: 9168
#include <bits/stdc++.h>
        using namespace std;
        using ll = long long;
        using ull = unsigned long long;
        using pii = pair<int, int>;
        using pll = pair<ll, ll>;

        const int MAXN = 1e5 + 5;
        const int MOD = 1e9 + 7;
        const int INF = 0x3f3f3f3f;
        const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
        const double EPS = 1e-9;
        #define NMAX 100005
        #define LAST 1000000000002


        int main(){
            char a;
            cin>>a;
            if(a<'a'){
                cout<<'A'<<endl;
            }
            else{
                cout<<'a'<<endl;
            }
           return 0;

        }


Measured memory_bytes: 3628
using System;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string S = Console.ReadLine();
        int K = int.Parse(Console.ReadLine());
        char key = S[K - 1];
        for(int i = 0; i < N; i++)
        {
            Console.Write(S[i] == key ? key : '*');
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
    int n; cin>>n;
    int a[n+1]; rep(i,n) cin>>a[i];
    sort(a,a+n);
    a[n]=0;

    bool b[n+1];
    long long sum=0;
    rep(i,n){
        sum+=a[i];
        if(sum*2>=a[i+1]) b[i]=1;
        else b[i]=0;
    }
    int ans=0;
    rep(i,n){
        if(b[n-1-i]) ans++;
        else break;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 768
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a = inp()
x = a//500
y = a - x*500
y //= 5
print(x*1000 + y*5)

Measured memory_bytes: 65004
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;
vector<char> alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  string w;
  cin >> w;
  int N = w.size();
  vector<int> alpha(26);
  rep(i,N)
  {
    rep(j,26)
    {
      if(alphabet[j]==w[i])
      {
        alpha[j] ++;
      }
    }
  }
  rep(i,26)
  {
    if(alpha[i]%2==1)
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

int main() {
  int n;
  ll p;

  cin >> n;

  if ((n/100==7)||((n%100)/10==7)||(n%10==7))  cout << "Yes" << endl;
  else cout << "No" <<endl;
  return 0;
  
  }

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

//マスに色を塗った回数の多いプレイヤーの勝ち、同数の場合は後手の勝ちというゲームを
//考えることにする。元のゲームでどちらかのプレイヤーが敗北したあとも色を塗ることが
//可能であると考えると新しいゲームの勝敗と元のゲームの勝敗が一致することがわかる
//この時二人の目的は自分が色を塗る回数を最大化し相手が色を塗る回数を最小化することである
//与えられてるグラフが木であることから二人の最善戦略はマス１からNへのパス上に色が塗られていない
//マスが存在するならば色を塗るであることが示される。これらをふまえて探索する
int N;
vector<vector<int>>G;
bool visited1[100100];
bool visited2[100100];
int key1[100100];//フェネックから見た距離
int key2[100100];//すぬけから見た距離
int main() {
	cin >> N;
	G.resize(N);
	REP(i, N) {
		visited1[i] = false;
		visited2[i] = false;
		key1[i] = 0;
		key2[i] = 0;
	}
	for (int i = 0; i < N-1; ++i) {
		int a, b; cin >> a >> b;
		a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	//0からとN-1からの両方からbfsを行う。同じ距離なら黒く塗る。どちらかに近いなら近いほうの色で塗る
	queue<int>Q1, Q2;
	Q1.push(0);
	Q2.push(N-1);
	visited1[0] = true;
	visited2[N - 1] = true;
	while (!Q1.empty()) {
	    int p = Q1.front();
		Q1.pop();
		for (int a : G[p]) {
			if (!visited1[a]) {
				key1[a] = key1[p] + 1;
				visited1[a] = true;
				Q1.push(a);
			}
		}
	}
	while (!Q2.empty()) {
		int p = Q2.front();
		Q2.pop();
		for (int a : G[p]) {
			if (!visited2[a]) {
				key2[a] = key2[p] + 1;
				visited2[a] = true;
				Q2.push(a);
			}
		}
	}
	int cntF = 0;
	int cntS = 0;
	for (int i = 0; i < N; ++i) {
		if (key1[i] <= key2[i]) {
			cntF++;
		}
		else {
			cntS++;
		}
	}
	if (cntF <= cntS)cout << "Snuke" << endl;
	else cout << "Fennec" << endl;
	return 0;
}

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

int main() {
    string s, t;
    cin >> s >> t;
    map<char, char> a, b;
    bool ok = true;
    rep(i, s.size()){
        if(a.count(s[i])) if(a[s[i]]!=t[i]) ok = false;
        if(b.count(t[i])) if(b[t[i]]!=s[i]) ok = false;
        a[s[i]] = t[i];
        b[t[i]] = s[i];
    }
    if(!ok) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 776
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(N)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, left, right):
        """
        [left, right)のsegfuncしたものを得る
        left: index(0-index)
        right: index(0-index)
        """
        res = self.ide_ele
        left += self.num
        right += self.num
        while left < right:
            if left & 1:
                res = self.segfunc(res, self.tree[left])
                left += 1
            if right & 1:
                res = self.segfunc(res, self.tree[right - 1])
            left >>= 1
            right >>= 1
        return res


def resolve():
    n, k = map(int, input().split())
    A = list(int(input()) for _ in range(n))
    MAX = max(A) + 1
    seg = SegTree([0 for _ in range(MAX)], lambda x, y: max(x, y), -f_inf)
    res = [0] * MAX
    for a in A:
        left = max(0, a - k)
        right = min(MAX + 1, a + k + 1)
        ma = seg.query(left, right)
        seg.update(a, ma + 1)
        res[a - 1] = ma + 1

    print(max(res))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 123440
#include <bits/stdc++.h>
using namespace std;
main()
{
    string s,t;
    cin>>s;
    cin>>t;
    int ans=t.size();
    for(int i=0;i<=s.size()-t.size();++i)
    {
        int c=0;
        for(int j=0;j<t.size();++j){
            c+=s[j+i]!=t[j];
        }
        ans=min(ans,c);
    }
    cout<<ans<<endl;
}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?a:b;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?b:a;}

namespace ae86
{
	const int bufl = 1<<15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 100007 , mo = 1000000007;

inline lint powa(lint a,lint t)
{
	lint b=1;
	while(t){if(t&1)b=b*a%mo;a=a*a%mo,t>>=1;}
	return b;
}

inline lint inva(lint a)
{
	return powa(a,mo-2);
}

int n;
lint val[_],sinv[_];

int main()
{
	n=ty();
	for(int i=1;i<=n;i++)val[i]=ty();
	sinv[0]=0;
	for(int i=1;i<=n;i++)sinv[i]=(sinv[i-1]+inva(i))%mo;

	lint ans=0;
	for(int i=1;i<=n;i++)
		ans=(ans+(sinv[i]+sinv[n-i+1]-sinv[1]+mo)%mo*val[i]%mo)%mo;
	for(int i=1;i<=n;i++)ans=ans*i%mo;
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

void solve(int) {
  cin >> n;
  map<string, int> mp;
  int mx = 0;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    mx = max(mx, ++mp[s]);
  }
  vector<string> a;
  for (const auto& pr : mp) {
    if (pr.second == mx) {
      a.push_back(pr.first);
    }
  }
  sort(begin(a), end(a));
  for (const auto& s : a) {
    cout << s << '\n';
  }
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}



Measured memory_bytes: 25584
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#define size 500010
#define debug(x) cerr<<#x<<"="<<x
#define gc getchar()
#define db double
#define ll long long
#define rep(i,s,n) for (register int i=s;i<=n;i++)
#define drep(i,n,s) for (register int i=n;i>=s;i--)
#define il inline
using namespace std;

il ll r()
{
	char c; ll x,f=1;
	for (c=gc;!isdigit(c);c=gc) if (c=='-') f=-1; x=c-'0';
	for (c=gc;isdigit(c);c=gc) x=(x<<1)+(x<<3)+c-'0';
	return f*x;
}

int m[220]={0};
int n,cnt=0;


int main()
{
	n=r(); char c[10];
	rep(i,1,n)
	{
		scanf("%s",c);
		m[(int)c[0]]++;
		if (m[(int)c[0]]==1) cnt++;
	}
	if (cnt==3) cout<<"Three"<<endl;
	else cout<<"Four"<<endl;
	return 0;
}


















Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int h = Integer.parseInt(str[0]);
		int w = Integer.parseInt(str[1]);

		int n = Integer.parseInt(br.readLine());

		ArrayList<Integer> list = new ArrayList<>();

		str = br.readLine().split(" ");

		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(str[i]);
			for (int j = 0; j < a; j++) {
				list.add(i + 1);
			}
		}

		int dx = 1;

		int x = 0;
		int y = 0;

		int matrix[][] = new int[h][w];

		for (int i = 0; i < list.size(); i++) {
			matrix[y][x] = list.get(i);
			if (x + dx < 0) {
				dx = 1;
				y++;
			} else if (x + dx > w - 1) {
				dx = -1;
				y++;
			} else {
				x += dx;
			}
		}
		for (int i = 0; i < h; i++) {
			System.out.print(matrix[i][0]);
			for (int j = 1; j < w; j++) {
				System.out.print(" " + matrix[i][j]);
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 38848
//by achhhy
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
inline LL in()
{
	char ch=getchar();
	LL f=1,x=0;
	while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return f*x;
}
//need changing
const int inf=(1<<30);
const int mod=1e9+7;
const int N=100010;

int n,m,o;
LL A,B,C,a,b,c;

int main()
{
	A=in(),B=in(),C=in();
	LL k=in();
	if(k&1) printf("%lld\n",B-A);
	else printf("%lld\n",A-B);
	return 0;
}




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

using namespace std;

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<vector<pair<int, int> > > g(n);
  for (int i = 0; i < n - 1; i++) {
    int s, e, w;
    cin >> s >> e >> w;
    s--;
    e--;
    g[s].push_back({e, w});
    g[e].push_back({s, w});
  }
  vector<int> dist (n, INT_MAX);
  queue<int> q;
  q.push(0);
  dist[0] = 0;
  while (!q.empty()) {
    int at = q.front();
    q.pop();
    for (auto to : g[at]) {
      int cost = dist[at] + to.second;
      if (dist[to.first] > cost) {
        dist[to.first] = cost;
        q.push(to.first);
      }
    }
  }
  for (auto it : dist) {
    cout << (it % 2 != 0) << '\n';
  }
}

Measured memory_bytes: 6784
S = input()
T = input()

S_dic={}
T_dic={}

for i in range(len(S)):

    if S[i] in S_dic:
        S_dic[S[i]].append(i)
    else:
        S_dic[S[i]] = [i]

for i in range(len(T)):

    if T[i] in T_dic:
        T_dic[T[i]].append(i)
    else:
        T_dic[T[i]] = [i]


#print (S_dic)
#print (T_dic)

T_dicR = {}

for i in T_dic:
    T_dicR[ str(T_dic[i]) ] = 1

ans = True

for i in S_dic:

    if str(S_dic[i]) not in T_dicR:
        ans = False
        break

#print (T_dicR)

if ans:
    print ("Yes")

else:
    print ("No")

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

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    string a,b;
    cin >> a >> b;
    string ans = "LESS";
    if(a.size()==b.size()){
    	int f = 1;
    	for(int i=0;i<a.size();i++){
    		if(a[i]<b[i]){
    			f = 0;
    			break;
			}else if(a[i]>b[i]){
				f = 0;
				ans = "GREATER";
				break;
			}
		}
		if(f) ans = "EQUAL";
	}else if(a.size()>b.size()){
		ans = "GREATER";
	}
	cout << ans << "\n";
    
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  long long n;
  scanf("%lld",&n);
  int a[12];
  
  long long b[12];
  
  b[0]=1;
  
  int k;
  
  for(int i=1;i<=11;i++){
    b[i]=b[i-1]*26;
  }
  
  long long m=n;
  
  for(int i=1;i<=11;i++){
    m-=b[i];
    if(m<=0){k=i;break;}
  }
  
  n=m+b[k]-1;
  
  
  for(int i=k-1;i>=0;i--){
    a[i]=(n-n%b[i])/b[i];
    n=n%b[i];
  }
  
  for(int i=k-1;i>=0;i--){
    if(a[i]==0){printf("a");}
    if(a[i]==1){printf("b");}
    if(a[i]==2){printf("c");}
    if(a[i]==3){printf("d");}
    if(a[i]==4){printf("e");}
    if(a[i]==5){printf("f");}
    if(a[i]==6){printf("g");}
    if(a[i]==7){printf("h");}
    if(a[i]==8){printf("i");}
    if(a[i]==9){printf("j");}
    if(a[i]==10){printf("k");}
    if(a[i]==11){printf("l");}
    if(a[i]==12){printf("m");}
    if(a[i]==13){printf("n");}
    if(a[i]==14){printf("o");}
    if(a[i]==15){printf("p");}
    if(a[i]==16){printf("q");}
    if(a[i]==17){printf("r");}
    if(a[i]==18){printf("s");}
    if(a[i]==19){printf("t");}
    if(a[i]==20){printf("u");}
    if(a[i]==21){printf("v");}
    if(a[i]==22){printf("w");}
    if(a[i]==23){printf("x");}
    if(a[i]==24){printf("y");}
    if(a[i]==25){printf("z");}
  }
  
  return 0;
}

Measured memory_bytes: 1664
#find set of numbers iroha like
tmp = raw_input("").split(' ')
n = int(tmp[0])
k = int(tmp[1])
tmp = raw_input("")
exclude_set = map(int, tmp.split(' '))

def binarySearch(arr, target):
  l = 0
  r  = len(arr) - 1
  while l <= r:
    m = (l + r)//2
    if arr[m] == target:
      return True
    elif arr[m] > target:
      r = m - 1
    elif arr[m] < target:
      l = m + 1
  return False

def check(n_digits, exclude_set):
  for i in range(0, len(n_digits)):
    if binarySearch(exclude_set, n_digits[i]) == True:
      return False
  return True
for i in range(n, 10**5):
  tmp = i
  n_digits = []
  while tmp > 0:
    n_digits.append(tmp%10)
    tmp = int(tmp/10)
  #print n_digits
  if check(n_digits, exclude_set) == True:
    print i
    break

Measured memory_bytes: 5764
a,b,c,d=map(int,input().split())
gcdc=[]
gcdd=[]
for i in range(1,int(c**(1/2))+1):
  if c%i==0:
    gcdc.append(i)
    if i!=c//i:
      gcdc.append(c//i)
for i in range(1,int(d**(1/2))+1):
  if d%i==0:
    gcdd.append(i)
    if i!=d//i:
      gcdd.append(d//i)
E=[]
for i in range(len(gcdc)):
  if gcdc[i] in gcdd:
    E.append(gcdc[i])
e=max(E)
f=c*d//e
if a%c==0:
  g=b//c-a//c+1
else:
  g=b//c-a//c
if a%d==0:
  h=b//d-a//d+1
else:
  h=b//d-a//d
if a%f==0:
  i=b//f-a//f+1
else:
  i=b//f-a//f
print(b-a+1-g-h+i)

Measured memory_bytes: 3188
import sys
sys.setrecursionlimit(3000*3000)

A = input()
B = input()

# dp = [[None] * (len(B) + 1) for _ in range(len(A) + 1)]
# def dfs(a=0, b=0):
#     if dp[a][b] is not None:
#         return dp[a][b]
#
#     if a >= len(A) or b >= len(B):
#         dp[a][b] = 0
#         return 0
#
#     match = A[a] == B[b]
#     if match:
#         r = dfs(a + 1, b + 1) + 1
#     else:
#         r = max(dfs(a + 1, b), dfs(a, b + 1))
#     dp[a][b] = r
#     return r
# dfs()
# print(dfs())

dp = [[None] * (len(B) + 1) for _ in range(len(A) + 1)]
for a in reversed(range(len(A) + 1)):
    for b in reversed(range(len(B) + 1)):
        if a >= len(A) or b >= len(B):
            dp[a][b] = 0
            continue

        match = A[a] == B[b]
        if match:
            r = dp[a + 1][b + 1] + 1
        else:
            r = max(dp[a + 1][b], dp[a][b + 1])
        dp[a][b] = r

# print("---")
# for v in dp:
#     print(*map(lambda x: x if x is not None else "*", v))

def or_inf(v):
    return float('inf') if v is None else v

def reconst(a=0, b=0):
    if a >= len(A) or b >= len(B):
        return ''

    match = A[a] == B[b]
    if match:
        return reconst(a + 1, b + 1) + A[a]
    else:
        if or_inf(dp[a + 1][b]) >= or_inf(dp[a][b + 1]):
            return reconst(a + 1, b)
        else:
            return reconst(a, b + 1)
print(reconst()[::-1])


Measured memory_bytes: 238984
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    cin >> n;
    cout << 0 << endl;
    string s;
    cin >> s;
    if(s == "Vacant") return 0;
    int l = 0, r = n;
    int i = 18;
    while(--i){
        int mid = (l+r)/2;
        cout << mid << endl;
        string x;
        cin >> x;
        if(x == "Vacant") return 0;
        if(((mid-l)%2) ^(s == x)) l = mid, s = x;
        else r = mid;
    }
    return 0;
}


Measured memory_bytes: 852
// AOJ 2586 Wish upon a shooting star
// 2018.3.31 bal4u

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

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

double dbl()
{
	int minus = 0;
	double x, y;
	int n = 0, c = getchar_unlocked();
	if (c == '-') minus = 1, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');

	if (c == '.') {
		x = 0;
		y = 1, c = getchar_unlocked();
		do y *= 0.1, x += y * (c & 0xf), c = getchar_unlocked(); while (c >= '0');
		x += n;
	} else x = n;
	if (minus) x = -x;
	return x;
}

#define EPS 1e-9
int dcmp(double x) { if (fabs(x) < EPS) return 0; return x <= 0 ? -1 : 1; }
#define EQ(a,b)		(fabs((a)-(b))<EPS)

typedef struct { double x, y, z, vx, vy, vz, r, vr; } T;
T t[202];
typedef struct { int id1, id2; double t; } E;
E e[30000]; int sz;
double tm[202]; char f[202];

void quadratic(int *n, double *x, double a, double b, double c)
{
	int t;
	double d;

	if (EQ(a, 0)) { *n = 0; return; } 
	d = b*b - 4*a*c, t = dcmp(d), a *= 2;
	if (t < 0)  *n = 0;
	else if (t == 0) *n = 1, x[0] = -b/a;
	else d = sqrt(d), *n = 2, x[0] = (-b+d)/a, x[1] = (-b-d)/a;
}

int cmp(E *a, E *b) { return dcmp(a->t - b->t); }

int main()
{
	int n, i, j, k;
	double x[2], a, b, c;		// ax^2 + bx + c = 0

	while (n = in()) {
		sz = 0;
		for (i = 0; i < n; i++) {
			t[i].x = dbl(), t[i].y = dbl(), t[i].z = dbl();
			t[i].vx = dbl(), t[i].vy = dbl(), t[i].vz = dbl();
			t[i].r = dbl(), t[i].vr = dbl();
			e[sz].id1 = e[sz].id2 = i, e[sz++].t = t[i].r/t[i].vr;
		}

		for (i = 0; i < n; i++) for (j = i+1; j < n; j++) {
			a = (t[i].vx-t[j].vx)*(t[i].vx-t[j].vx) +
				(t[i].vy-t[j].vy)*(t[i].vy-t[j].vy) +
				(t[i].vz-t[j].vz)*(t[i].vz-t[j].vz) -
				(t[i].vr+t[j].vr)*(t[i].vr+t[j].vr);
			b = (t[i].x-t[j].x)*(t[i].vx-t[j].vx) +
				(t[i].y-t[j].y)*(t[i].vy-t[j].vy) +
				(t[i].z-t[j].z)*(t[i].vz-t[j].vz) +
				(t[i].r+t[j].r)*(t[i].vr+t[j].vr);
			b *= 2;
			c = (t[i].x-t[j].x)*(t[i].x-t[j].x) +
				(t[i].y-t[j].y)*(t[i].y-t[j].y) +
				(t[i].z-t[j].z)*(t[i].z-t[j].z) -
				(t[i].r+t[j].r)*(t[i].r+t[j].r);

			quadratic(&k, x, a, b, c);
			while (k--) if (dcmp(x[k]) > 0) {
				e[sz].id1 = i, e[sz].id2 = j, e[sz++].t = x[k];
			}
		}
		qsort(e, sz, sizeof(E), cmp);
		memset(f, 0, sizeof(f));
		for (i = 0; i < sz; i++) {
			j = e[i].id1, k = e[i].id2;
			if (!f[j] && !f[k]) {
				f[j] = f[k] = 1;
				tm[j] = tm[k] = e[i].t;
			}
		}
		for (i = 0; i < n; i++) printf("%.10lf\n", tm[i]);
	}
	return 0;
}


Measured memory_bytes: 2584
#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

typedef pair<int,int> s;
typedef long long int ll;

int abs(int x){
  return x > 0 ? x : -x;
}

int length(char c[]){
  int cnt=0;
  for(cnt=0;c[cnt]!='\0';cnt++){
  }
  return cnt;
}
char S[1000000];
int a[27];

int main(){
  scanf("%s",S);
  for(int i=0;S[i]!='\0';i++){
    a[S[i]-'a']++;
  }
  REP(i,26){
    if(a[i]==0){
      printf("%c\n",'a'+i);
      return 0;
    }
  }
  printf("None\n");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    int n;
    cin>>n;
    vector<string> a(n);
    REP(i,n) cin>>a[i];
    REP(i,n-1){
        if(a[i][a[i].size()-1]!=a[i+1][0]){
            cout<<"No";
            return 0;
        }
    }
    sort(a.begin(),a.end());
    REP(i,n-1){
        if(a[i]==a[i+1]){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp
{
	char name[100];
	int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x)
{
	Q[tail]=x;
	tail=(tail+1)%LEN;
}

P dequeue()
{
	P x=Q[head];
	head = (head +1)%LEN;
	return x;
}

int min(int a, int b)
{
	return a < b ? a : b;
}

int main()
{
	int elaps = 0,c;
	int i,q;
	P u;
	scanf("%d %d",&n,&q);
	
	for(i=1;i<=n;i++)
	{
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	head=1; tail=n+1;
	
	while(head != tail)
	{
		u=dequeue();
		c=min(q,u.t);
		u.t-=c;
		elaps+=c;
		if(u.t>0)
		{
			enqueue(u);
		}
		else
		{
			printf("%s %d\n",u.name,elaps);
		}
	}
	
	return 0;
}

Measured memory_bytes: 12732
//abc055_b.cpp
//Sat Oct 27 20:34:00 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	ll ans = 1;
	for (int i=1;i<=n;i++){
		ans = (ans*i)%1000000007;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <algorithm>
#include <iomanip>
static const double PI = 3.14159265359;
int main()
{
	int N;
	std::cin >> N;
	std::vector<int> A;
	for (int i = 0; i < N; ++i) {
		A.push_back(0);
	}
	for (int i = 1; i < N; ++i) {
		int a;
		std::cin >> a;
		A[a - 1] += 1;
	}
	for (int i = 0; i < N; ++i) {
		std::cout << A[i] << std::endl;
	}
	return 0;
}

Measured memory_bytes: 4304
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		StringBuilder sb = new StringBuilder();

		int p = 0;
		for (int i=0; i < s.length(); i++) {
			if(s.charAt(i) != 'B') {
				sb.append(s.charAt(i));
				p++;
			}else{
				if(sb.length() != 0){
				//	System.out.println(sb);
				sb.deleteCharAt(p-1);
				p--;
				}
			}

		}



		System.out.println(sb);

		sc.close();
	}

}


Measured memory_bytes: 9548
#include<bits/stdc++.h>
using namespace std;
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define pb push_back
#define newline cout<<endl
//template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
//template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
//const int MAX = (1 << 20);
#define w(x) int x; cin>>x; while(x--)
int case_no=1;
int main()
{
	int a, b;
	cin>>a>>b;
	cout<<a*b<<endl;

	return 0;
}

Measured memory_bytes: 3636
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

var H, W int
var s []string
var u [][]int

type pos struct {
	x, y int
	c    bool
}

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

func bsf(sx, sy, c int) (int, int) {
	q := make([]pos, 0)
	q = append(q, pos{sx, sy, true})
	u[sy][sx] = c
	b := 1
	w := 0
	for len(q) != 0 {
		cx := q[0].x
		cy := q[0].y
		black := q[0].c
		q = q[1:]
		for i := 0; i < 4; i++ {
			x := cx + dx[i]
			y := cy + dy[i]
			if x < 0 || x >= W || y < 0 || y >= H {
				continue
			}
			if black == true && s[y][x] == '#' {
				continue
			}
			if black == false && s[y][x] == '.' {
				continue
			}
			if u[y][x] != 0 {
				continue
			}
			u[y][x] = c
			if s[y][x] == '#' {
				b++
			} else {
				w++
			}
			q = append(q, pos{x, y, !black})
		}
	}
	return b, w
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	H, W = getInt(), getInt()
	s = make([]string, H)
	u = make([][]int, H)
	for i := 0; i < H; i++ {
		s[i] = getString()
		u[i] = make([]int, W)
	}

	cnt := 1
	ans := 0
	for y := 0; y < H; y++ {
		for x := 0; x < W; x++ {
			if s[y][x] == '#' && u[y][x] == 0 {
				b, w := bsf(x, y, cnt)
				ans += b * w
				cnt++
			}
		}
	}

	// for i := 0; i < H; i++ {
	// 	out(u[i])
	// }
	out(ans)
}


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

using namespace std;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int a=0, b=0;
	
	cin >> a >> b;
	
	( (a>12)? b*=1 : ( (a>5)? b*=0.5 : b*=0) );
	
	cout << b;

	return 0;
}


Measured memory_bytes: 256
/*   LazyBones
*
*/

#include <bits/stdc++.h>
#include<cctype>
#include <sstream>
#include<ctime>
using namespace std;
#define rep(i,b) for(int i=0;i<b;i++)
#define getarr(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define disparr(a,n) for(int i=0;i<n;i++){cout<<a[i];}cout<<"\n";
#define disparrs(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";
#define disparrl(a,n) for(int i=0;i<n;i++){cout<<a[i]<<"\n";}cout<<"\n";
#define mem0(a) memset(a,0,sizeof(a));
#define ull unsigned long long int
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define pob pop_back
#define pof pop_front
#define pf push_front
#define mp make_pair
#define F first
#define S second
//#define nu 100001
#define M 1000000007
#define mul(x,y) ((ll)(x)*(y))%M
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define INF 0x3f3f3f3f
int MOD(int a, int b)
{
    if(a>b)
    return a-b;
    else
    return b-a;
}
ll max3(ll a,ll b,ll c)
{
    return max(c,max(a,b));
}
ll power(ll x,ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll max(ll a,ll b)
{
    return (a>b)?a:b;
}
ll min(ll a,ll b)
{
    return (a<b)?a:b;
}
ll gcd(ll a,ll b)
{
    if(b==1)
    return 1;
    else if(a%b==0)
    return b;
    else
    return gcd(b,a%b);
}
ll mod(ll x){
    if(x>=0)
    return x;
    else
    return -x;
}
int x=8;
int main()
{
    fastio;
    ll n,m;
    cin>>m>>n;
    if(n%m==0)
    cout<<n+m;
    else
    cout<<n-m;
    return 0;
}


Measured memory_bytes: 256
// Author: πα

#include <bits/stdc++.h>
using namespace std;

#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long int64_t
const long INF = 1LL << 60;

const int N = 1e5 + 1005;
long dp[N];

int main()
{
    FastIO;
    int n, i, j, m, w, v, ans;
    fill(dp+1, dp+N, INF);
    cin >> n >> m;
    for(i = 1; i <= n; ++i)
    {
        cin >> w >> v;
        for(j = N-v; j >= 0; --j)
            dp[j+v] = min(dp[j+v], dp[j]+w);
    }
    for(i = 0; i < N; ++i)
        if(dp[i] <= m)
            ans = i;
    cout << ans;
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    string s;
    cin >> s;
    bool flag = true;
    if(s[2] != s[3]) flag = false;
    if(s[4] != s[5]) flag = false;

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

#define REP(i,n,m) for( long long int i = (n); i < (m); i++ )
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define SORT(v) sort( ALL(v) );
#define LAST(v) v[v.size()-1]
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,-1,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pi pair<int, int>
#define MP make_pair
#define PB push_back
#define IIN(a) int a; cin >> a;
#define LIN(a) ll a; cin >> a;
#define SIN(a) string a; cin >> a;
#define EPS (1e-10)
#define INF 1000000000000LL

int MOD=1000000007;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
//I ASCII code: '0' = 48; 'A' = 65; 'a' = 97


signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    LIN( n )
    ll ans = 0;
    vector< ll > len( 2 * n );
    for( ll i = 0; i < 2 * n; i++){
      cin >> len[i];
    }

    SORT( len );

    for( ll i = 2 * n  - 2; i >= 0 ; i -= 2 ){
      ans += len[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  int array[1000];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>array[i];
  }
  
  sort(array,array+n);
  reverse(array,array+n);
  int a=0,b=0;
  for(int i=0;i<n;i++){
    if(i%2==0){
      a+=array[i];
    }else{
      b+=array[i];
    }
  }
  cout<<a-b<<endl;
  return(0);
}


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

using namespace std;

#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()

const int MX = (int)1e5 + 10;
// const int mod = (int)1e9 + 7;

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

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

    int n, m;
    cin >> n >> m;

    vector<pair<int, int>> a(n);
    set<int> st;
    for(int i = 0; i < m; ++i) st.insert(i);
    for(int i = 0; i < n; ++i){
        cin >> a[i].Y >> a[i].X;
    }

    sort(all(a), [&](pair<int, int> x, pair<int, int> y){
        if(x.X != y.X) return x.X > y.X;
        else return x.Y > y.Y;
    });

    ll res = 0;

    for(int i = 0; i < n; ++i){
        if(st.empty()) break;
        auto it = st.lower_bound(m - a[i].Y);
        if(it == st.end() || *it > m - a[i].Y) it--;
        if(it != st.end() && *it <= m - a[i].Y){
            res += a[i].X;
            st.erase(it);
        }
    }

    cout << res << endl;
 
    return 0;
}

Measured memory_bytes: 5760
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
#include <math.h>

using namespace std;
typedef long long ll;
template<typename T>
struct lca{
	int n, root, l;
  	vector<vector<int>> to;
  	vector<vector<T>> co;
  	vector<int> dep;
  	vector<T> costs;
  	vector<vector<int>> par;
  	lca(int n):n(n), to(n), co(n), dep(n), costs(n) {
    	l = 0;
      	while((1<<l) < n) ++l;
      	par = vector<vector<int>>(n+1, vector<int>(l, n));
    }
  	void addEdge(int a, int b, T c=0){
    	to[a].push_back(b); co[a].push_back(c);
      	to[b].push_back(a); co[b].push_back(c);
    }
  	void dfs(int v, int d=0, T c=0, int p=-1){
      	if(p != -1) par[v][0] = p;
      	dep[v] = d;
      	costs[v] = c;
      	for(int i = 0; i < to[v].size(); ++i){
        	int u = to[v][i];
          	if(u == p) continue;
          	dfs(u, d+1, c+co[v][i], v);
        }
    }
  	void init(int _root=0){
    	root = _root;
      	dfs(root);
      	for(int i = 0; i < l-1; ++i){
        	for(int v = 0; v < n; ++v){
            	par[v][i+1] = par[par[v][i]][i];
            }
        }
    }
  	int operator()(int a, int b){
    	if(dep[a] > dep[b]) swap(a, b);
      	int gap = dep[b]-dep[a];
      	for(int i = l-1; i >= 0; --i){
        	int len = 1<<i;
          	if(gap>=len){
            	gap -= len;
              	b = par[b][i];
            }
        }
      	if(a == b) return a;
      	for(int i = l-1; i >= 0; --i){
        	int na = par[a][i];
          	int nb = par[b][i];
          	if(na != nb) a=na, b = nb;
        }
      	return par[a][0];
    }
  	int length(int a, int b){
    	int c = lca(a,b);
      	return costs[a] + costs[b]-costs[c]*2;
    }
};

const int MX = 100005;
struct Edge{
	int to, co, col;
	Edge(int to, int co, int col):to(to), co(co), col(col){};
};
vector<Edge> es[MX];

vector<ll> ans;
struct Query{
	int col, qid, coeff, y;
  	Query(int col, int qid, int coeff, int y):col(col),qid(qid),coeff(coeff),y(y){};
};
vector<Query> qs[MX];
int cnt[MX];
ll sum[MX];

void dfs2(int v, int p = -1){
	for(auto q: qs[v]){
    	ll x = -sum[q.col];
      	x += (ll)q.y*cnt[q.col];
      	ans[q.qid] += x*q.coeff;
    }
  	for(auto e: es[v]){
    	if(e.to == p) continue;
      	cnt[e.col]++; sum[e.col] += e.co;
      	dfs2(e.to, v);
      	cnt[e.col]--; sum[e.col] -= e.co;
    }
}


int main(){
	int n,q;
  	cin >> n >> q;
  	lca<ll> g(n);
  	for(int i = 0; i < n-1; i++){
      	int a,b,c,d;
      	cin >> a >> b >> c >> d;
      	a--;
      	b--;
		es[a].emplace_back(b, d, c);
      	es[b].emplace_back(a, d, c);
      	g.addEdge(a, b, d);
    }
  	g.init();
  	ans = vector<ll>(q);
  	for(int i = 0; i < q; ++i){
    	int x, y, a, b;
      	cin >> x >> y >> a >> b;
      	a--; b--;
      	int c = g(a,b);
      	ans[i] = g.costs[a] + g.costs[b]-g.costs[c]*2;
      	qs[a].emplace_back(x,i,1,y);
      	qs[b].emplace_back(x,i,1,y);
    	qs[c].emplace_back(x,i,-2,y);
    }
  	dfs2(0);
  	for(int i = 0; i < q; ++i){
    	printf("%lld\n", ans[i]);
    }
  	return 0;
}

Measured memory_bytes: 44660
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
const i64 MOD = 1e9+7;
const i64 INF = 1e18+7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto& x : a)
        cin >> x;
    vector<int> pos;
    for(int i = 0; i < n; ++i)
        if(a[i] == 0)
            pos.emplace_back(i);
    vector<int> group(n, -1);
    vector<vector<int>> rev(n);
    for(int i = 0; i < n; ++i)
        if(a[i])
            rev[i + a[i]].emplace_back(i);

    function<void(int,int)> f = [&](int x, int idx){
        for(auto& y : rev[x]){
            if(group[y] == -1){
                group[y] = idx;
                f(y, idx);
            }
        }
    };

    for(int i = 0; i < pos.size(); ++i){
        int val = pos[i];
        group[val] = i;
        f(val, i);
    }
    int m = pos.size();
    vector<vector<int>> edges(m);
    for(int i = 0; i < m; ++i){
        for(int j = 1; j <= 6; ++j)
            if(pos[i] + j < n && group[pos[i] + j] != -1){
                edges[i].emplace_back(group[pos[i] + j]);
            }
    }
    queue<int> que;
    vector<int> range(m, MOD);
    range[0] = 0;
    que.emplace(0);
    while(!que.empty()){
        int to = que.front();
        que.pop();
        for(auto& x : edges[to])
            if(chmin(range[x], range[to] + 1)){
                que.emplace(x);
            }
    }
    cout << range.back() << endl;
}


signed main(){
    solve();
}



Measured memory_bytes: 15176
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//const ll INF = 1e18;
//const ll MOD = 1e9+7;
//const double pi = 3.14159265358979;
using vl = vector<ll>;
# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((ll)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((ll)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()
 
ll a,b,c,k;
ll Main() {
    // ao >> midori >> aka
    cin >> a >> b >> c >> k;
    rep(i, k) {
        if (b <= a) {
            b *= 2;
        } else if (c <= b) {
            c *= 2;
        } else {
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    if (a < b && b < c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}
 
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3632
def main():
    N, M, X = map(int, input().split())

    bk = []
    for _ in range(N):
        c, *a = map(int, input().split())
        bk.append((c, a))

    ans = -1
    for bit in range(1 << N):
        cost = 0
        t = [0] * M
        for j in range(N):
            if (bit >> j) & 1:
                c, a = bk[j]
                cost += c
                for k in range(M):
                    t[k] += a[k]
            if all(x >= X for x in t):
                if (not ~ans) or (ans > cost):
                    ans = cost
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9224
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	N := readInt()
	K := readInt()

	m := make(map[int]int)
	for i := 0; i < N; i++ {
		a := readInt()
		m[a]++
	}
	x := make([]int, 0, N)
	for _, v := range m {
		x = append(x, v)
	}
	sort.Ints(x)
	var ans int
	for i, n := 0, len(x); i < len(x) && n > K; i++ {
		n--
		ans += x[i]
	}
	println(ans)
}


Measured memory_bytes: 12672