akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
char S[100002];
int main(){
  int i;
  int res;
  N = rd(S);
  res = N / 2;
  for(i=(0);i<(N);i++){
    if(S[i]=='p'){
      res--;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190921-1

// --- original code ---
// int N; char S[100002];
// {
//   int res;
//   rd(S@N);
//   res = N / 2;
//   rep(i,N) if(S[i]=='p') res--;
//   wt(res);
// }


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){
    cin>>a>>b;
    if(a<b);
    else{
        c=a;
        a=b;
        b=c;
    }
    for(int i=0;i<b;i++)cout<<a;
    cout<<endl;
}


Measured memory_bytes: 256
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 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
}

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

	r := getInt()

	out(r * r)
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int l = sc.nextInt();
    String s[] = new String[n];
    for(int i = 0 ; i < n ; ++i){
      s[i] = sc.next();
    }
    Arrays.sort(s);
    
    String ans = "";

    for(int i = 0 ; i < n ; ++i){
      ans += s[i];
    }
    System.out.println(ans);    
  }
}

Measured memory_bytes: 40476
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll n;
map<string, ll> m;
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    F0R(i, n)
    {
        string str; cin >> str;
        sort(str.begin(), str.end());
        m[str]++;   
    }
    ll res = 0;
    for(auto i : m)
    {
        res += max(0LL, (i.s * (i.s - 1))/2);
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 11264
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}

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

func main() {
	n := nextInt()
	mm := map[string]int64{}
	for i := 0; i < n; i++ {
		s := nextLine()
		ss := strings.Split(s, "")
		sort.Sort(sort.StringSlice(ss))
		v := strings.Join(ss, "")
		mm[v]++
	}

	var re int64
	for _, v := range mm {
		if v > 1 {
			re += nCr(v, 2)
		}
	}

	fmt.Println(re)
}

func nCr(n, r int64) int64 {
	if r == 0 {
		return 0
	}

	var a int64 = 1
	for i := 0; i < int(r); i++ {
		a *= (n - int64(i))
	}

	var b int64 = 1
	for i := 1; i <= int(r); i++ {
		b *= int64(i)
	}

	return a / b
}


Measured memory_bytes: 11776
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
#include<set>
#define fre(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
using namespace std;

inline int read(){
	int sum=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
	return f*sum;
}

const int N=2000005;
struct edge{int to,next,c;}e[N];
int n,m,d[N],v[N];
int head[N],cnt=0;
//map < pair<int,int>,int >mp;
set<int>se[N];
queue <int> que;

inline void add(int x,int y,int w){
	e[++cnt]=(edge){head[x],y,w};head[x]=cnt;
}

signed main(){
	n=read();m=read();
	for(int i=1;i<=m;i++){
		int x=read(),y=read(),w=read();
		add(x,y,w);add(y,x,w);
	}
	memset(d,0x3f,sizeof(d));d[1]=0;
	que.push(1);
	while(!que.empty()){
		int x=que.front();que.pop();
//		cout<<"x="<<x<<endl;
		v[x]=0;
		for(int i=head[x];i;i=e[i].to){
			int k=e[i].next;
			int w=se[x].count(e[i].c)^1;
			if(d[k]>d[x]+w){
				d[k]=d[x]+w;se[k].clear();
// 				mp[make_pair(k,e[i].c)]=1;
				se[k].insert(e[i].c);
				if(!v[k]) que.push(k),v[k]=1;
			}
			if(d[k]==d[x]+w){
				if(se[k].find(e[i].c)==se[k].end()){
					if(!v[k]) que.push(k),v[k]=1;
				}
				se[k].insert(e[i].c);
			}
		}	
	}
	if(d[n]==1061109567) puts("-1");
	else printf("%d\n",d[n]);
	return 0;
}


Measured memory_bytes: 120448
import sys
a=input()
a0=a.split()
x=int(a0[0])
y=int(a0[1])
if y%2==1:
    print("No")
    sys.exit()
if y/2<x:
    print("No")
    sys.exit()
if y/4>x:
    print("No")
    sys.exit()
print("Yes")

Measured memory_bytes: 9188
import java.util.Arrays;
import java.util.BitSet;
import java.util.Scanner;
import java.util.function.Predicate;

class Solver {
	static final Solver INSTANCE = new Solver();
	private int[] P;
	private int[] Q;
	private int a;
	private int b;

	void permutation(int[] seed){
		int[] perm = new int[seed.length];
		buildPerm(seed, perm, new BitSet(seed.length), 0);
	}

	int idx;
	void buildPerm(int[] seed, int[] permutation, BitSet used, int index){
		if (index == seed.length) {
			idx++;
			if (Arrays.equals(permutation, P)) {
				a = idx;
			}
			if (Arrays.equals(permutation, Q)) {
				b = idx;
			}
			return;
		}

		for (int i = 0; i < seed.length; ++i) {
			if (used.get(i)) continue;
			permutation[index] = seed[i];
			used.set(i);
			buildPerm(seed, permutation, used, index + 1);
			used.flip(i);
		}
	}

	void solve(Scanner sc) {
		int N = sc.nextInt();
		P = new int[N];
		Q = new int[N];
		for (int i = 0; i < N; i++) {
			P[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			Q[i] = sc.nextInt();
		}

		int[] R = new int[N];
		Arrays.setAll(R, i -> i + 1);
		permutation(R);
		System.out.println(Math.abs(a - b));
	}
}

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 28532
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
 
#define INF (1e9)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

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

int N,M;
int c[50][50];
int visited[50];

void dfs(int v){
	visited[v] = true;
	for (int v2 = 0; v2 < N;v2++){
		if(c[v][v2]==0)
			continue;
		if(visited[v2]==1){
			continue;
		}
		dfs(v2);
	}
}
int main()
{
	cin >> N >> M;
	int a[M], b[M];
	REP(i, M)
	{

		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		c[a[i]][b[i]] = 1;
		c[b[i]][a[i]] = 1;
	}

	int ans = 0;

	REP(i,M){
		c[a[i]][b[i]] = 0;
		c[b[i]][a[i]] = 0;
		REP(j,N){
			visited[j] = 0;
		}
		dfs(0);
		bool bridge = false;
		REP(j,N){
			if(visited[j]==0){
				bridge = true;
			}
		}
		if(bridge){
			ans++;
		}
		c[a[i]][b[i]] = 1;
		c[b[i]][a[i]] = 1;
	}

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() 
{ 
    int c; 
    int cflag=0; 
    int fflag=0; 
    string s; 
    cin>>s; 
    c=s.size();
    for(int i=0;i<c;i++)
    {
        if(s[i]=='C') 
        {
            cflag=1;
            for(int j=i+1;j<c;j++)
            { 
                if(s[j]=='F') 
                { 
                    cout<<"Yes";
                    return 0; 
                    
                } 
            }
        }
    }
    cout<<"No";
    cout<<endl;
    return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);

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


    cout << (n * (n - 1)) / 2 + (m * (m - 1)) / 2 << "\n"; 
    return 0;
}

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

typedef long long int ll;
typedef unsigned long long int ull;

#define test(t)		int t; cin>>t; while(t--)
#define all(a)		a.begin(), a.end()
#define f(i, a, b)	for(int i = a; i < b; ++i)
#define endl 		"\n"
#define deb(x)		cout << #x << "--" << x << "--" << endl;
#define deb2(x,y)	cout << #x << "--" << x << "--" << endl <<  #y << "--" << y << "--" << endl;
#define fast 		ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define mx9		1000000007
#define mx7		10000007
#define mx6		1000006
#define mx5		200005
#define inf		1<<30                                 
#define eps		1e-9
#define mod		1000000007

void solve()
{
  string s, t;
  cin >> s;
  cin >> t;
  if(s.length() > t.length())
  {
   	cout << "NO" << endl;
    return;
  }
  
  f(i, 0, s.length())
    if(s[i] != t[i])
    {
      cout << "No" << endl;
      return;
    }
  cout << "Yes" << endl;
         
}

int main()
{
     fast;
     //test(t)
          solve();
     return 0;
}


Measured memory_bytes: 3052
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, *A = map(int, read().split())

A = sorted(A)[::-1]

idx = 1
ans = A[0]
flag = False
for i in range(N - 2):
    ans += A[idx]
    if not flag:
        flag = True
        continue
    if flag:
        flag = False
        idx += 1
print(ans)


Measured memory_bytes: 46024
import sys
input=sys.stdin.readline
n,m = map(int, input().split())
link = []
for i in range(m):
    tmp = list(map(int,input().split()))
    link.append(tmp)

ans=0
for bri in range(m):
    wf=[[10**10 for i in range(n)] for j in range(n)]
    for i in range(m):
        if i==bri:
            continue
        a=link[i][0]
        b=link[i][1]
        wf[a-1][b-1] = 1
        wf[b-1][a-1] = 1

    for i in range(n):
        wf[i][i]=0

    for k in range(n):
        for i in range(n):
            for j in range(n):
                wf[i][j] = min(wf[i][j],wf[i][k]+wf[k][j])

    is_b=True
    for i in range(n):
        for j in range(n):
            if wf[i][j] == 10**10:
                is_b=False
                break
    if not is_b:
        ans+=1

print(ans)

Measured memory_bytes: 45532
local n, m = io.read("*n", "*n")
local t = {}
for i = 1, n do
  t[i] = io.read("*n")
end
table.sort(t)
local tsum = {t[1]}
for i = 2, n do
  tsum[i] = tsum[i - 1] + t[i]
end

local function solve(x)
  local cnt = 0
  local pos = 1
  for i = n, 1, -1 do
    while pos <= n and t[pos] + t[i] < x do
      pos = pos + 1
    end
    if n < pos then break end
    cnt = cnt + n + 1 - pos
  end
  return m <= cnt
end

local min, max = 0, 200001
while 1 < max - min do
  local mid = (min + max) // 2
  if solve(mid) then
    min = mid
  else
    max = mid
  end
end
do
  local score = 0
  local cnt = 0
  local pos = 1
  for i = n, 1, -1 do
    while pos <= n and t[pos] + t[i] < min do
      pos = pos + 1
    end
    if n < pos then break end
    cnt = cnt + n + 1 - pos
    score = score + (n + 1 - pos) * t[i] + tsum[n]
    if 1 < pos then
      score = score - tsum[pos - 1]
    end
  end
  score = score - min * (cnt - m)
  print(score)
end


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    int D, E;
    while (cin >> D >> E, D || E) {
        double ans = INF;
        for (int y=0; y<1000; y++) {
            for (int x=0; x<1000; x++) {
                if (x + y == D) {
                    ans = min(ans, fabs(sqrt(x*x + y*y) - E));
                }
            }
        }
        cout << fixed << setprecision(10) << ans << endl;
    }
}

Measured memory_bytes: 3232
import sys
import math
from collections import deque
from collections import defaultdict

def main():
    INF = 10**9
    n, m = list(map(int,sys.stdin.readline().split()))
    rank = [False] * (n + 1)
    next_room = [None] * n
    next_room[0] = 0
    group = [[] for _ in range(n)]
    
    for _ in range(m):
        a, b = list(map(int,sys.stdin.readline().split()))
        a -= 1
        b -= 1
        group[a].append(b)
        group[b].append(a)
    #print(group)

    #幅優先探索
    queue = deque([0])
    while(queue != deque([])):
        now = queue.popleft()
        now_group = group[now]
        for mem in now_group:
            if rank[mem] or mem == 0:
                continue
            rank[mem] = True
            next_room[mem] = now
            queue.append(mem)

    if None in next_room:
        print("No")
        return 0
    print("Yes")
    for i in range(1,n):
        print(next_room[i] + 1)
    return 0

if __name__ == "__main__":
    main()

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

int main()
{
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  vector<long long> s(n+1);
  vector<int> x(n+1);
  for(int i=0;i<n;i++)
  {
   x[i+1]=x[i]^a[i];
   s[i+1]=s[i]+a[i];
   }
  long long  ans=0;
  for(int l=0;l<n;l++)
  {
   int lb=l+1,ub=n+1;
   while(ub-lb>1)
   {
    int mid=(lb+ub)/2;
    if((x[mid]^x[l])==(s[mid]-s[l])) lb=mid;
    else ub=mid;
	}
   ans+=lb-l;
   }
   cout<<ans<<endl;
 return 0;
 } 

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount

int ar[100005];
map<int,int> odd;
map<int,int> even;

int32_t main(){
	int n;	
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>ar[i];
		if(i&1){
			odd[ar[i]]++;
		}
		else {
			even[ar[i]]++;
		}
	}
	int oddmx1t = 0, oddmx2t = 0, oddmx1 = -1, oddmx2 = -1;
	for(auto x: odd){
		if(x.second>oddmx1t){
			oddmx2 = oddmx1;
			oddmx1 = x.first;
			oddmx2t = oddmx1t;
			oddmx1t = x.second;
		}
		else if(x.second > oddmx2t){
			oddmx2 = x.first;
			oddmx2t = x.second;
		}
	}
	int evenmx1t = 0, evenmx2t = 0, evenmx1 = -1, evenmx2 = -1;
	for(auto x: even){
		if(x.second>evenmx1t){
			evenmx2 = evenmx1;
			evenmx1 = x.first;
			evenmx2t = evenmx1t;
			evenmx1t = x.second;
		}
		else if(x.second > evenmx2t){
			evenmx2 = x.first;
			evenmx2t = x.second;
		}
	}
	if(evenmx1 != oddmx1){
		cout<<n-evenmx1t-oddmx1t;
	}
	else {
		cout<<min(n-evenmx2t-oddmx1t,n-evenmx1t-oddmx2t);
	}
}


Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    string a[] = {"a", "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};

    string s;
    cin >> s;

    int res = 0;
    for (int i = 0; i < 8; i++)
        if (s == a[i])
        {
            cout << i << endl;
            return 0;
        }

    return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main()
{
	int n;
	map<string,int> mp;
	string s;
	cin>>n;
	while(n--)
	{
		cin>>s;
		mp[s]++;
	}
	cout<<"AC"<<" x "<<mp["AC"]<<endl;
	cout<<"WA"<<" x "<<mp["WA"]<<endl;
	cout<<"TLE"<<" x "<<mp["TLE"]<<endl;
	cout<<"RE"<<" x "<<mp["RE"]<<endl; 
	return 0;
}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    
    if (A - B == 0) cout << C;
    else if (A-B > C) cout << 0;
    else cout << C - A+B;
    cout << endl;
}

Measured memory_bytes: 256
// Oh boi here we go again
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

#define all(s) s.begin(), s.end()
#define ok puts("ok")
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >
#define pii pair < int, pi >
#define next next123
#define left left123

const int N = 2e5 + 7;
const int INF = 1e9 + 7;

int n, k, s;

main(){
    cin >> n >> k >> s;
    for (int i = 1; i <= n; i++){
        if (k){
            printf("%d ", s);
            k--;
        }
        else if (s == int(1e9))
            printf("1 ");
        else
            printf("%d ", int(1e9));
    }

}


Measured memory_bytes: 1280
function Main(input) {
	input = input.split(" ").map(Number);
	var n = -input[0]+input[1]+input[2];
	if(n<=0) n=0;
	console.log(Math.min(input[1],input[2])+" "+n);

}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define fastIO                        \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
// g++ -std=c++11 -O2 -Wall *.cpp -o *
#define eps 1e-9
#define MAX 10002
#define MOD 1000000007
#define PI 3.14159265358979323846
#define Fi first
#define Se second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> pr_int;


int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	string s;
	cin >> s;
	if (s[2]==s[3] && s[4]==s[5]) cout << "Yes\n";
	else cout << "No\n";
	
	cout << "\n";
}


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

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll X;
    cin >> X;
    ll r = X%500;
    ll ans = (X-r)*2;
    cout << ans+r-(r%5) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
using namespace std;

int main(){
    string X;
    cin >> X;
    int ers = 0;
    int cnt = 0;
    rep(i, X.len){   
        if(X.at(i) == 'S'){
            cnt++;
        }
        if(X.at(i) == 'T'){
            if(cnt > 0){
                ers += 2;
                cnt--;
            }
        }
        
    }
    cout << X.len - ers << endl;
    return 0;
}

Measured memory_bytes: 640
var nodes = [];
var restrictions = [];
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    var tmp = input[0].split(" ");
    var hp = tmp[0];

    var waza = input[1].split(" ");
    var total = 0;
    for (var i = 0; i < waza.length; i++) {
        total += parseInt(waza[i]);
    }
    if (total >= hp) {
        console.log("Yes");
    } else {
        console.log("No");

    }

}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

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

    vector<ll> a(n);
    int cnt = 0;

    cin >> a.at(0);
    if (a.at(0) % 2 == 1)
        cnt++;

    rep(i, n) {
        //cout << "1" << endl;
        cin >> a.at(i);
        if (i % 2 == 1) {
            //cout << "2" << endl;
            if (a.at(i) % 2 == 1) {
                //cout << "3" << endl;
                cnt++;
            }
        }
    }
    //cout << "4" << endl;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3628
n=int(input())
a=list(map(int,input().split()))
li_a=[]
for i in range(n):
  li_a.append([a[i],i+1])
li_a.sort()
ans=[]
for i in range(n):
  ans.append(str(li_a[i][1]))

print(' '.join(ans))

Measured memory_bytes: 28412
from copy import copy
N = int(input())
X = [int(i) for i in input().split()]
X2 = copy(X)
X2.sort()
n = [X2[N//2-1], X2[N//2]]
for x in X:
    if x <= n[0]:
        print(n[1])
    else:
        print(n[0])


Measured memory_bytes: 93128
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n;
int cnt;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    int x, y;
    bool flag = false;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        if (x == y) cnt++;
        else cnt = 0;
        if (cnt >= 3) flag = true;
    }
    if (flag) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3648
N = int(input())
count = [0]*4

for _ in range(N):
    S = input()
    if S == "AC":
        count[0] += 1
    elif S == "WA":
        count[1] += 1
    elif S == "TLE":
        count[2] += 1
    else:
        count[3] += 1

print("AC x", count[0])
print("WA x", count[1])
print("TLE x", count[2])
print("RE x", count[3])   

Measured memory_bytes: 9212
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

var ans;
console.log(main());
function main(){
  var n = o.a();
  if(n === 2)return -1;
  ans = Array(n).fill().map(a=>Array(n).fill("."));
  var flag = 1;
  while(flag){
    flag = 0;
    if(n % 3 === 0)solve3(0,n,0,n);
    else if(n % 4 === 0)solve4(0,n,0,n);
    else if(n % 5 === 0)solve5(n);
    else if(n % 7 === 0)solve7(n);
    else solve(n),n-=6,flag = 1;
  }
  return ans.map(a=>a.join("")).join("\n");
}

function solve3(yi,yn,xi,xn){
  for(var y = yi; y < yn; y+=3)for(var x = xi; x < xn; x+= 3){
    ans[y][x] = ans[y][x+1] = "a";
    ans[y+1][x+2] = ans[y+2][x+2] = "b";
  }
}
function solve4(yi,yn,xi,xn){
  for(var y = yi; y < yn-1; y+=4){
    ans[y][y] = ans[y][y+1] = "i";
    ans[y+1][y] = ans[y+1][y+1] = "j";
    ans[y+2][y+2] = ans[y+2][y+3] = "i";
    ans[y+3][y+2] = ans[y+3][y+3] = "j";
    ans[y][y+2] = ans[y+1][y+2] = "k";
    ans[y][y+3] = ans[y+1][y+3] = "l";
    ans[y+2][y] = ans[y+3][y] = "k";
    ans[y+2][y+1] = ans[y+3][y+1] = "l";
  }
}
function solve5(n){
  for(var x = 0; x < n;x += 5){
    ans[x][x] = ans[x][x+1] = "c";
    ans[x][x+2] = ans[x][x+3] = "d";
    ans[x+4][x+4] = ans[x+4][x+3] = "c";
    ans[x+4][x+2] = ans[x+4][x+1] = "d";
    ans[x][x+4] = ans[x+1][x+4] = "f";
    ans[x+2][x+4] = ans[x+3][x+4] = "g";
    ans[x+4][x] = ans[x+3][x] = "f";
    ans[x+2][x] = ans[x+1][x] = "g";
    solve3(x+1,x+4,x+1,x+4);
  }
}
function solve7(n){
  for(var x = 0; x < n;x += 7){
    ans[x][x] = ans[x][x+1] = "c";
    ans[x][x+2] = ans[x][x+3] = "d";
    ans[x][x+4] = ans[x][x+5] = "e";
    ans[1+x][x+6] = ans[2+x][x+6] = "c";
    ans[3+x][x+6] = ans[4+x][x+6] = "d";
    ans[5+x][x+6] = ans[6+x][x+6] = "e";
    solve3(x+1,x+7,x,x+6);
  }
}
function solve(n){
  solve3(n-6,n,n-6,n);
  ans[n-6][n-1] = ans[n-6][n-2] = "w";
  ans[n-6][n-3] = ans[n-5][n-3] = "x";
  ans[n-4][n-3] = ans[n-4][n-2] = "y";
  ans[n-4][n-1] = ans[n-5][n-1] = "z";
  ans[n-3][n-4] = ans[n-3][n-5] = "w";
  ans[n-3][n-6] = ans[n-2][n-6] = "x";
  ans[n-1][n-6] = ans[n-1][n-5] = "y";
  ans[n-1][n-4] = ans[n-2][n-4] = "z";
}

Measured memory_bytes: 33308
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  string s;
  cin >> s;
  int N = len(s);

  int ans = 0;
  int l = 0, r = N - 1;
  while (l < r) {
    int xl = 0;
    while (s[l] == 'x') {
      xl++;
      l++;
    }

    int xr = 0;
    while (s[r] == 'x') {
      xr++;
      r--;
    }

    if (s[l] != s[r]) {
      cout << -1 << '\n';
      return 0;
    }

    ans += abs(xr - xl);
    l++, r--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
int gcd(int i, int j){
    if (i < j){
        swap(i, j);
    }
    if (i % j == 0){
        return j;
    }
    else{
        return gcd(j, i % j);
    }
}

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> x(N);
    for (int i = 0; i < N; i++){
        cin >> x[i];
        x[i] = abs(x[i] - X);
    }
    sort(x.begin(), x.end());
    if (N == 1) {
        cout << x[0] << endl;
        return 0;
    }
    int ans = gcd(x[0], x[1]);
    for (int i = 2; i < N; i++){
        ans = gcd(ans, x[i]);
        if (ans == 1){
            cout << 1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
from collections import defaultdict
N=int(input())
A=[int(i) for i in input().split()]
dd=defaultdict(int)
for a in A:
    dd[a]+=1
num=0
s=0
for p,n in dd.items():
    num+=1
    if n%2==0:
        s+=1
        s%=2
print(num-s)
#print(num,s,dd)

Measured memory_bytes: 18656
def main():
    K = [int(input()) for _ in range(5)]
    ans = []
    A = [0]
    for k in K:
        a = k % 10
        if a == 0:
            ans.append(k)
        else:
            ans.append(k + (10 - a))
            A.append(10 - a)
    print(sum(ans) - max(A))


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  int mat[n][m];
  REP(i,n){
    REP(j,m){
      cin >> mat[i][j];
    }
  }
  int b[m];
  REP(i,m){
    cin >> b[i];
  }
  int ans=0;
  REP(i,n){
    REP(j,m){
      ans+= mat[i][j]*b[j];
    }
    cout << ans << endl;
    ans =0;
  }
  }

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

int main(){
  int n, m, e, j;

  while(1){
    cin >> n;
    if(n == 0) break;
    for(int i = 1; i <= n; i++){
      cin >> m >> e >> j;

      if(m == 100 || e == 100 || j == 100){
        cout << "A" << endl;
      }
      else if((m + e) / 2 >= 90 || (m + e + j) / 3 >= 80){
        cout << "A" << endl;
      }
      else if((m + e + j) / 3 >= 70 || (m + e + j) / 3 >= 50 && m >= 80 || e >= 80){
        cout << "B" << endl;
      }
      else cout << "C" << endl;
    }

  }
}

Measured memory_bytes: 3012
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
using namespace std;

//ABC141 B
int main() {
	string s;
	cin >> s;

	for (int i=0; i < s.size(); i++) {
		if ((i%2 == 0 && s[i]=='L') || (i%2 == 1 && s[i]=='R')) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
void main() {
	auto N = readAs!long;
	if(N.to!real.sqrt.to!ulong ^^ 2 == N) {
		writeln(N.to!real.sqrt.to!ulong * 2 - 2);
		return;
	}
	auto div = getDivisors(N);
	debug div.writeln;
	writeln(div[$ / 2 - 1] + div[$ / 2] - 2);
}

ulong[] getDivisors(ulong N) {
	if(N == 0) return [];
	if(N == 1) return [1];
	ulong[] lower_part, upper_part;
	foreach(i; 1..N.to!real.sqrt.ceil.to!ulong) {
		if(N % i == 0) {
			lower_part ~= i;
			upper_part ~= N / i;
		}
	}
	upper_part.reverse();
	if(N.to!real.sqrt.to!ulong ^^ 2 == N) return lower_part ~ N.to!real.sqrt.to!ulong ~ upper_part;
	else return lower_part ~ upper_part;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vt<int>>;

int main(){

  /*
    writer Torisuto 2020/5/31
    AとBの掛け算を出力
    1 <= A,B <= 100
  */

  int A, B;
  cin >> A >> B;

  cout << A*B << endl;
  return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
    #define REP(i, n) for(int i = 0;i < n;i++)
    #define REPR(i, n) for(int i = n;i >= 0;i--)
    #define FOR(i, m, n) for(int i = m;i < n;i++)
    #define FORR(i, m, n) for(int i = m;i >= n;i--)
    #define SORT(v, n) sort(v, v+n);
    #define VSORT(v) sort(v.begin(), v.end());
    #define llong long long
    #define pb(a) push_back(a)
    #define INF 999999999
    using namespace std;
    typedef pair<int, int> P;
    typedef pair<llong, llong> LP;
    typedef pair<int, P> PP;
    typedef pair<llong, LP> LPP;

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

    int main()
    {
       llong n;
       cin>>n;
       vector<llong> a(5,0);
       REP(i,5)cin>>a[i];
       sort(a.begin(),a.end());
       if(n%a[0]!=0) {cout<<4+1+n/a[0]<<endl;}
       else cout<<4+n/a[0]<<endl;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll, ll>
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define vvi vector<vector<int> >
#define vvl vector<vector<long long> >
ll mod = 1e9 + 7;
const double pi = acos(-1.0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed;
    cout.precision(12);
    int x;
    cin>>x;
    if(x==0)
        cout<<1<<endl;
    else
        cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
using namespace std;
int main(){
	int N,i,j,flag=0,k;
	int arr[3][3];
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
			cin>>arr[i][j];
		}
	}
	cin>>N;
	int num[N];
	for(i=0;i<N;i++){
		cin>>num[i];
	}
	for(i=0;i<N;i++){
		for(k=0;k<3;k++){
			for(j=0;j<3;j++){
				if(num[i]==arr[k][j]){
					arr[k][j]=0;
				}
			}
		}
	}
	for(i=0;i<3;i++){
		if(arr[i][0]==0 && arr[i][1]==0 && arr[i][2]==0){
			flag = 1;
			break;
		}
		else if(arr[0][i]==0 && arr[1][i]==0 && arr[2][i]==0){
			flag =1;
			break;
		}
		else if(arr[0][0]==0 && arr[1][1]==0 && arr[2][2]==0){
			flag =1;
			break;
		}
		else if(arr[2][0]==0 && arr[1][1]==0 && arr[0][2]==0){
			flag =1;
			break;
		}
	}
	if(flag ==1){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <atcoder/dsu>
#include <cstdio>
#include <vector>

using namespace std;
using namespace atcoder;

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    dsu d(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        d.merge(a - 1, b - 1);
    }
    size_t size = d.groups().size();
    printf("%d", size - 1);
    return 0;
}

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

using namespace std;


int main() {
    int n,k;
    cin>>n>>k;
    int len[n];
    for (int i = 0; i < n; ++i) {
        cin>>len[i];
    }
    sort(len,len+n,greater<int>());
    int re=0;
    for (int j = 0; j < k; ++j) {
        re+=len[j];
    }
    cout<<re<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<queue>
using namespace std;
struct P{int x,y;P(int x,int y):x(x),y(y){}P(){}};
struct S
{
	int x,y,t,c;
	S(int x,int y,int t,int c):x(x),y(y),t(t),c(c){}
	S(){}
	bool operator<(const S&rhv)const{return c>rhv.c;}
};
const int dx[]={0,1,1,0,-1,-1,  0};
//dy[x%2][angle]
const int dy[][7]={
	{1,0,-1,-1,-1,0,  0},
	{1,1,0,-1,0,1,  0}
};
const int OFFSET=128;
bool obj[256][256];
int lx,ly;
int Solve(P ps,P pg)
{
	bool visited[256][256][6]={};
	priority_queue<S>q;
	q.push(S(ps.x,ps.y,0,0));
	while(!q.empty())
	{
		S s=q.top(); q.pop();
		if(visited[s.y][s.x][s.t]++)
			continue;
		else if(s.x==pg.x&&s.y==pg.y)
			return s.c;
		for(int i=0;i<7;++i)
		{
			P p(s.x+dx[i],s.y+dy[s.x%2][i]);
			if(obj[p.y][p.x] || lx<abs(p.x-OFFSET) || ly<abs(p.y-OFFSET))
				continue;
			S s2(p.x,p.y,(s.t+1)%6,s.c+ (i!=abs((s.x-OFFSET)*(s.y-OFFSET)*s.t)%6));
			if(visited[s2.y][s2.x][s2.t])
				continue;
			q.push(s2);
		}
	}
	return -1;
}
int main()
{
	int n,x,y;
	P s,g;
	scanf("%d%d%d%d",&s.x,&s.y,&g.x,&g.y);
	s.x+=OFFSET;
	s.y+=OFFSET;
	g.x+=OFFSET;
	g.y+=OFFSET;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d%d",&x,&y);
		obj[OFFSET+y][OFFSET+x]=true;
	}
	scanf("%d%d",&lx,&ly);
	printf("%d\n",Solve(s,g));
	return 0;
}

Measured memory_bytes: 1956
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

string solve(const vector<int>& P) {
  string res = "";
  vector<int> stk;
  int sum = 0;
  for (int x : P) {
    while (sum < x) {
      res += '(';
      stk.push_back(++sum);
    }
    if (!stk.empty() && stk.back() == x) {
      stk.pop_back();
      res += ')';
    } else {
      return ":(";
    }
  }
  return res;
}

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int N;
  while (cin >> N) {
    vector<int> P(N);
    for (int& x : P) cin >> x;
    cout << solve(P) << endl;
  }
  return 0;
}



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

int main(){
    string s;
    cin >> s;
    int i, m = (int)s.length(), n = m;
    for(i=0; i<n-1; i++){
        if(s[i] != s[i+1]){
            m = min(m, max(i+1, n-i-1));
        }
    }
    cout << m;
    return 0;
}

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

int main() {
    int n, q, a, b; 
    scanf("%d%d%d%d", &n, &q, &a, &b);
    a--, b--;
    vector<int> x(q);
    for (int i = 0; i < q; ++i) {
        scanf("%d", &x[i]);
        x[i]--;
    }
    constexpr int64_t kInf = 1'000'000'000'000'000'000;
    vector<int64_t> dp(n, kInf);
    vector<int64_t> pref(n + 1, kInf), suff(n + 1, kInf);

    auto Modify = [&](int p, int64_t v, vector<int64_t> &fw) {
        for (int i = p + 1; i <= n; i += i & -i) fw[i] = min(fw[i], v); 
    };

    auto Query = [&](int p, const vector<int64_t> &fw) {
        int64_t res = kInf;
        for (int i = p + 1; i > 0; i -= i & -i) res = min(res, fw[i]);
        return res;
    };

    int64_t sum = 0;
    dp[a] = 0;
    Modify(a, -a, pref);
    Modify(n - 1 - a, a, suff);
    for (int i = 0, v = b; i < q; ++i) {
        int64_t res = min(Query(x[i], pref) + x[i], Query(n - 1 - x[i], suff) - x[i]) + sum;
        sum += abs(x[i] - v);
        dp[v] = min(dp[v], res - sum);
        Modify(v, dp[v] - v, pref);
        Modify(n - 1 - v, dp[v] + v, suff);
        v = x[i];
    }
    int64_t ans = *min_element(dp.begin(), dp.end()) + sum;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n, m;
    cin >> n >> m;
    vint a(m);
    rep(i, m) cin >> a[i];

    int ans = n;
    rep(i, m) ans -= a[i];

    if (ans < 0) puts("-1");
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <queue>

int f(std::vector<int> a) {
    int alice = 0;
    int bob = 0;
    std::priority_queue<int> p;
    for (int i = 0; i < a.size(); i++) {
        p.push(a[i]);
    }
    while (!p.empty()) {
        alice += p.top();
        p.pop();
        if (p.empty()) {
            break;
        }
        bob += p.top();
        p.pop();
    }
    return alice - bob;
}

int main() {

    int n;
    std::cin >> n;

    std::vector<int> a;
    for (int i = 0; i < n; i++) {
        int tmp;
        std::cin >> tmp;
        a.push_back(tmp);
    }

    int result = f(a);
    std::cout << result << std::endl;

    return 0;
}


Measured memory_bytes: 384
import sys
from collections import deque

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def bfs(N, v0, edge):

    search = [-1] * N
    search[v0] = 0
    q = deque()
    q.append(v0)

    while q:
        v = q.popleft()
        for nv in edge[v]:
            if search[nv] == -1:
                q.append(nv)
                search[nv] = search[v] + 1

    return search


def bfs2(N, v0, edge, dis):

    q = deque()
    q.append(v0)

    max_dis = dis[v0]
    while q:
        v = q.popleft()
        for nv in edge[v]:
            if dis[v] < dis[nv]:
                q.append(nv)
                max_dis = max(max_dis, dis[nv])

    return max_dis


def main():

    N, taka, aoki = in_nn()
    taka, aoki = taka - 1, aoki - 1

    edge = [[] for _ in range(N)]
    for i in range(N - 1):
        x, y = in_nn()
        x, y = x - 1, y - 1
        edge[x].append(y)
        edge[y].append(x)

    dis = bfs(N, aoki, edge)

    if dis[taka] > 2:
        x = (dis[taka] + 1) // 2 - 1
        for _ in range(x):
            for v in edge[taka]:
                if dis[v] < dis[taka]:
                    taka = v
                    break

    ans = bfs2(N, taka, edge, dis) - 1
    print(ans)


if __name__ == '__main__':
    main()


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

using u64 = unsigned long long;

const u64 B = 13131;
const int N = 500000 + 7;

int n;
char s[N];
u64 f[N];
int g[N];
std::map<u64, u64> map;
u64 cnt;

u64 pow(u64 a, u64 k) {
	if (k < 0) k += (1llu << 63) - 1;
	u64 t = 1;
	for (; k; a = a * a, k >>= 1)
		if (k & 1) t = t * a;
	return t;
}

int main() {
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);

	scanf("%d%s", &n, s + 1);
	for (int i = 1; i <= n; ++i)
		if (s[i] == '+' || s[i] == '-')
			f[i] = f[i - 1] + (s[i] == '+' ? 1 : -1) * pow(B, g[i] = g[i - 1]);
		else
			f[i] = f[i - 1], g[i] = g[i - 1] + (s[i] == '<' ? -1 : 1);
	for (int i = n; i; --i)
		++map[f[i]], cnt += map[f[n] * pow(B, g[i - 1]) + f[i - 1]];
	printf("%lld\n", cnt);

	return 0;
}


Measured memory_bytes: 38200
n = int(input())
a = input().split()
b = input().split()
c = input().split()
result = 0
for i in range(n):
    order = int(a[i]) - 1
    result += int(b[order])
    if int(a[i]) - int(a[i-1]) == 1 and i is not 0:
        result += int(c[order-1])
print(result)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
     
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
     
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll, ll>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


int main () {
  int n, i;
  cin >> n;
  vector<pii> xsyu(2*n);
  for (i = 0; i < n; i++) {
    cin >> xsyu[i].first;
    xsyu[i].second = 0;
  }
  for (i = 0; i < n; i++) {
    cin >> xsyu[i + n].first;
    xsyu[i + n].second = 1;
  }
  sort(xsyu.begin(), xsyu.end());
  int cnt0 = 0, cnt1 = 0;
  ll ans = 1;
  for (i = 0; i < 2 * n; i++) {
    //DEBUG(cnt0);
    //DEBUG(cnt1);
    if (xsyu[i].second == 0) {
      if (cnt1 != 0) {
	ans = ans * cnt1 % MOD;
	cnt1--;
      }
      else {
	cnt0++;
      }
    }
    else {
      if (cnt0 != 0) {
	ans = ans * cnt0 % MOD;
	cnt0--;
      }
      else {
	cnt1++;
      }
    }
  }
  cout << ans << endl;
      
}


Measured memory_bytes: 1792