akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
 

int main(){
	long long N; cin >> N;
	long long A[N+10]={},count=1,ans=0;
	for(long long i=0; i<N; i++){
		cin >> A[i];
	}sort(A,A+N);
	for(long long i=1; i<N; i++){
		if(A[i]==A[i-1]) count+=1;
		else{
			if(count%2!=0)
			ans+=1;
			count=1;
		}
	}if(count%2!=0)
	ans+=1;
	cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;
//b?£?f??????r???????????¨?±????v??????????????§??\?±???????????????????

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner kb=new Scanner(System.in);
		int nowLives[][][]=new int[5][4][10];
		for(int i=0;i<5;i++){
			for(int j=0;j<4;j++){
				for(int k=0;k<10;k++){
					nowLives[i][j][k]=0;
				}	
			}
		}
		
		int n=kb.nextInt();
		int b,f,r,v;
		for(int i=0;i<n;i++){
		//b?£?f??????r???????????¨?±????v??????????????§??\?±???????
		    b=kb.nextInt();f=kb.nextInt();
            r=kb.nextInt();v=kb.nextInt();
			nowLives[b-1][f-1][r-1]+=v;
		}
		
		
		//System.out.println();
		for(int k=0;k<4;k++){
		for(int i=0;i<3;i++){
			for(int j=0;j<10;j++){
System.out.printf(" %d",nowLives[k][i][j]);
/*if(j!=9){
	System.out.print(" ");
}*/
			}
			System.out.println();
		}
		if(k!=3){
		System.out.println("####################");
		}
		}
	}
/*3
1 1 3 8
3 2 2 7
4 3 8 1*/

}

Measured memory_bytes: 30516
#include <iostream>

using namespace std;

int main()
{
  int i=1;
  int n;
  int a[100]={0};
  
  cin >> n;
  for(i=0;i<n;i++)
  {
    cin >> a[i];
  }
  
  for(i=0;i<n;i++)
  {
    cout << a[n-i-1];
    if(i<(n-1))
    {
      cout << " ";
    }
  }
  cout <<"\n";
}

Measured memory_bytes: 1168
X,Y=map(int,input().split())
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7
N = 10**6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
if (X+Y)%3!=0:
  print(0)
else:
  n=2*Y-X
  m=2*X-Y
  if n<0 or m<0:
    print(0)
  else:
    n=int(n/3)
    m=int(m/3)
    print(cmb(n+m,m,mod))

Measured memory_bytes: 122048
require 'pp'

def gets_num
  $stdin.gets.chomp.to_i
end

loop do
  n = gets_num
  break if n == 0
  list = n.times.map {gets_num}
  max = 0
  result = list.reduce(0) {|accum, x|
    max = accum if (max < accum)
    if (x + accum < 0) then 0
    else x + accum end
  }
  max = result if result > max
  if result == 0 then
    puts list.reduce {|x, accm| accm > x ? accm : x}
  else
    puts max
  end
end

Measured memory_bytes: 6244
def resolve():
    n = int(input())
    h = list(map(int, input().split()))
    flag = 0
    for i in range(n-1):
        if h[i] == h[i+1]:
            continue
        else:
            h[i+1] -= 1
            if h[i] <= h[i+1]:
                continue
            else:
                print("No")
                exit()
    print("Yes")
resolve()

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

int main() {
  int a;
  cin>>a;
  int m;
  
  while(a>0){
  for(int i=0;i<10000;i++){
    if((i*(i+1))/2>=a){
      m=i;
      break;
    }
  }
  
  cout<<m<<endl;
    a-=m;
  }
    
      
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define rv(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define SZ(x) (x.size())
#define pb(x) push_back(x)
#define P pair<int,int>
using namespace std;
const int M = 210000;
const ll inf = 9e18;
int n,m,k;
void solve() {
    int a,b,c;
    cin >> a >> b >> c;
    cout << (b*c>=a?"Yes":"No") << endl;
}
int main()
{ 
    int t;
    //cin >> t;
    t = 1;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;

int main(){
	ll n,h;
	cin>>n>>h;
	vector<ll>a(n),b(n);
	vector<P>mp2(n);
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		mp2[i]=P(b[i],a[i]);
	}
	sort(a.begin(),a.end());
	sort(mp2.begin(),mp2.end());
	ll num=a[n-1];
	ll tmp=0,ans=0;
	for(int i=n-1;i>=0;i--){
		if(mp2[i].first>num){
			tmp+=mp2[i].first;
			ans++;
		}
		if(tmp>=h){
			cout<<ans<<endl;
			return 0;
		}
	}
	ll res=(h-tmp)/num;
	if((h-tmp)%num)cout<<res+1+ans<<endl;
	else cout<<res+ans<<endl;
	return 0;
}


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

long long f(long long s,long long t){
if(s==-1)return 0;
else    return s/t+1;
}
int main(){
long long a,b,x;
cin >> a >> b >> x; 
cout << f(b,x)-f(a-1,x) << endl;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
















int main(){
    char a, b;
    cin >> a >> b;
    string s(b - '0', a), t(a - '0', b);
    cout << ((s < t)? s : t) << endl;
}

Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() int {
	a, b, c, x := scanInt(sc), scanInt(sc), scanInt(sc), scanInt(sc)
	rests := map[int]struct{}{}
	for i := 0; i <= a; i++ {
		rests[x-500*i] = struct{}{}
	}
	count := 0
	for i := 0; i <= b; i++ {
		for j := 0; j <= c; j++ {
			if _, ok := rests[100*i+50*j]; ok {
				count++
			}
		}
	}
	return count
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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

int main() {
  int n;
  std::cin >> n;
  std::set<char> h;
  for (int i = 0; i < n; i++) {
    char t;
    std::cin >> t;
    h.insert(t);
  }

  if (h.size() == 3) {
    std::cout << "Three" << std::endl;
  } else {
    std::cout << "Four" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for i in range(M)]
es = [[] for _ in range(N)]

for a, b in AB:
  a, b = a-1, b-1
  es[a].append(b)
  es[b].append(a)

from collections import deque
q = deque([0])

INF = float('inf')
dist = [INF] * N
dist[0] = 0
back = [-1] * N

while q:
  v = q.popleft()
  for to in es[v]:
    #ここのロジックの意味がまだわかっていない
    if dist[v] + 1 >= dist[to]: continue
    dist[to] = dist[v]
    back[to] = v+1
    q.append(to)

print("Yes")
print(*back[1:], sep='\n')

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

int main(){
    //input
    long long N;
    cin >> N;
    long long a[3*N+1];
    long long i;
    for(i=1; i<=3*N; i++){
        cin >> a[i];
    }

    //calc
    priority_queue<long long> que_zen, que_kou;
    long long zen[3*N+1], kou[3*N+1];
    zen[N]=0;
    for(i=1; i<=N; i++){
        que_zen.push(-a[i]);
        zen[N]+=a[i];   
    }
    for(i=N+1; i<=2*N; i++){
        que_zen.push(-a[i]);
        zen[i]=zen[i-1]+a[i]-(-que_zen.top());
        que_zen.pop();
    }
    kou[2*N+1]=0;
    for(i=2*N+1; i<=3*N; i++){
        que_kou.push(a[i]);
        kou[2*N+1]+=a[i];
    }
    for(i=2*N; i>=N+1; i--){
        que_kou.push(a[i]);
        kou[i]=kou[i+1]+a[i]-que_kou.top();
        que_kou.pop();
    }
    long long ans=-10000000000000000;
    for(i=N; i<=2*N; i++){
        ans=max(ans,zen[i]-kou[i+1]);
    }

    //output
    cout << ans << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 9008
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main(void){
    int n;
    std::cin >> n;
    std::set<std::string> s;
    for(int i = 0; i < n; ++i){
        std::string tmp;
        std::cin >> tmp;
        s.insert(tmp);
    }
    std::cout << s.size() << std::endl;

    return 0;
}

Measured memory_bytes: 19280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14 100兆
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

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

Measured memory_bytes: 3636
//AOJ Drowng Lots

#include <iostream>
#include <cstdio>
using namespace std;

int main() {
	int w, n;
	int a[30], b[30];
	int x[30];
	cin >> w;
	cin >> n;
	for(int i = 0; i < w; i++) {
		x[i] = i+1;
	}
	for(int i = 0; i < n; i++) {
		scanf("%d,%d", &a[i], &b[i]);
		a[i]--;
		b[i]--;
		swap(x[a[i]], x[b[i]]);
	}
	for(int i = 0; i < w; i++) {
		cout << x[i] << endl;
	}
	return 0;
}

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

int main(){
    ll N;
    cin >> N;
    ll x = 800 * N;
    ll y = (ll)(N / 15) * 200;
    cout << x - y << endl;
    return 0;
}

Measured memory_bytes: 256
// =====================================================================================
// 
//       Filename:  D.cpp
//        Created:  2017년 09월 30일 21시 06분 27초
//       Compiler:  g++ -O2 -std=c++14
//         Author:  baactree ,  bsj0206@naver.com
//        Company:  Chonnam National University
// 
// =====================================================================================

#include <bits/stdc++.h>
using namespace std;
int n, k;
pair<int, int> arr[100005];
typedef long long ll;
int main(){
	scanf("%d%d", &n, &k);
	for(int i=0;i<n;i++){
		scanf("%d%d", &arr[i].first, &arr[i].second);
	}
	ll ans=0;
	for(int i=30;i>=0;i--){
		ll now=0;
		int g=0;
		for(int j=0;j<n;j++){
			if((arr[j].first|g)<=k){
				if(arr[j].first<(1<<i)||!((1<<i)&arr[j].first)){
					g|=arr[j].first;
					now+=arr[j].second;
				}
			}
		}
		ans=max(ans,now);
	}
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 1152
import java.util.*;
class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        HashSet <String> hs = new HashSet<>();
        int n = sc.nextInt();
        for(int i = 0; i<n; i++)
        {
            String cmd = sc.next();
           if(cmd.compareTo("insert")==0)
           {
               hs.add(sc.next());
           }
           else 
           {
              if(hs.contains(sc.next())) System.out.println("yes");
              else System.out.println("no");
           }
        }
    }
}



Measured memory_bytes: 259308
x = int(input())
if 400 <= x <= 599: print("8")
elif 600 <= x <= 799: print("7")
elif 800 <= x <= 999: print("6")
elif 1000 <= x <= 1199: print("5")
elif 1200 <= x <= 1399: print("4")
elif 1400 <= x <= 1599: print("3")
elif 1600 <= x <= 1799: print("2")
elif 1800 <= x <= 1999: print("1")


Measured memory_bytes: 9120
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

int H,W;
vector<string> A;
bool used[1010][1010];
int ans;

int main ()
{
    cin >> H >> W;
    A.resize(H);
    REP(i,A.size()) cin >> A[i];

    queue < tuple<int,int,int> > que;
    REP(x,H)REP(y,W) {
        if (A[x][y] == '#') {
            que.emplace(x, y, 0);
        }
    }

    ans = 0;
    const int dx[4] = {0, 1, 0, -1};
    const int dy[4] = {1, 0, -1, 0};
    while (!que.empty()) {
        int x,y,dep;
        tie(x,y,dep) = que.front();
        que.pop();
        if (used[x][y]) continue;
        used[x][y] = true;
        ans = max(ans, dep);
        REP(i,4) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (nx < 0 || ny < 0 || nx >= H || ny >= W) {
                continue;
            }
            que.emplace(nx, ny, dep + 1);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 51912
import sys
input = sys.stdin.readline
 
n, m = map(int, input().split())
s = set(map(int, [input() for _ in range(m)]))
MOD = 10 ** 9 + 7
a = 1 if not 0 in s else 0
b = 1 if not 1 in s else 0
for i in range(2, n + 1):
    if i in s:
        a, b = b, 0
    else:
        a, b = b, (a + b) % MOD
print(b)

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

a_new=[]
for i in range(n):
    a_new.append(a[i]%2)
even=a_new.count(0)
odd=a_new.count(1)

if odd==0 and p==0:
    print(2**n)
elif odd==0 and p==1:
    print(0)
else:
    print(2**(n-1))


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

class Card {
public:
  int num; string mark; int index;
};

void BubbleSort(vector<Card> &C, int N) {
  for (ll i = 0; i < N; i++) {
    for (int j = N - 1; j >= i + 1; j--) {
      if (C[j].num < C[j - 1].num) swap( C[j], C[j - 1]);
    }
  }
}

void SelectionSort(vector<Card> &C, int N) {
  for (ll i = 0; i < N; i++) {
    ll minj = i;
    for (ll j = i; j < N; j++) {
      if (C[j].num < C[minj].num) minj = j;
    }
    swap(C[i], C[minj]);
  }
}

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

  ll N; cin >> N;
  vector<Card> A(N);
  for (ll i = 0; i < N; i++) {
    string S; cin >> S;
    Card c;
    c.num = S[1] - '0';
    c.mark = S[0];
    c.index = i;
    A[i] = c;
  }

  vector<Card> B(N);

  string Stable;
  Stable = "Stable";
  B = A;
  BubbleSort(B, N);

  cout << B[0].mark << B[0].num;
  for (ll i = 1; i < N; i++) {
    cout << ' ' << B[i].mark << B[i].num;
    if (B[i - 1].num == B[i].num && B[i - 1].index > B[i].index) Stable = "Not stable";
  }
  cout << '\n' << Stable << '\n';


  Stable = "Stable";
  B = A;
  SelectionSort(B, N);

  cout << B[0].mark << B[0].num;
  for (ll i = 1; i < N; i++) {
    cout << ' ' << B[i].mark << B[i].num;
    if (B[i - 1].num == B[i].num && B[i - 1].index > B[i].index) Stable = "Not stable";
  }
  cout << '\n' << Stable << '\n';

  return 0;
}


Measured memory_bytes: 3236
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>

using namespace std;

int main() {
    
    
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> v(n);
    int c = 0;
    
    if (s[0] == '0')
    {
        c++;
        v[0] = c;
    }
    
    for (int i = 1; i < n; ++i)
    {
        if (s[i - 1] == '1' && s[i] == '0')
        {
            c++;
        }
        v[i] = c;
    }
    
    int ret = 0;
    
    for (int i = 0; i < n; ++i)
    {
        int pos = 0;
        if (s[i] == '0')
        {
            auto itr = upper_bound(v.begin(), v.end(), v[i] + k - 1);
            pos = itr - v.begin();
        }
        else
        {
            auto itr = upper_bound(v.begin(), v.end(), v[i] + k);
            pos = itr - v.begin();
        }
        ret = max(ret, pos - i);
    }
    
    
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 896
#include<iostream>
using namespace std;
string s,m[10];
int h,w,cnt;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
bool f(int x,int y,int r,int now)
{
	if(now==cnt)
	{
		cout<<s<<endl;
		return true;
	}
	for(int dr=0;dr<4;dr++)
	{
		if(dr==2)continue;
		int nr=(r+dr)%4;
		int tx=x,ty=y;
		while(tx>=0&&ty>=0&&tx<h&&ty<w&&m[tx][ty]!='o')tx+=dx[nr],ty+=dy[nr];
		if(tx>=0&&ty>=0&&tx<h&&ty<w&&m[tx][ty]=='o')
		{
			m[tx][ty]='.';
			s[now]="RDLU"[nr];
			if(f(tx,ty,nr,now+1))return true;
			m[tx][ty]='o';
		}
	}
	return false;
}
main()
{
	cin>>h>>w;
	int x,y,r;
	for(int i=0;i<h;i++)
	{
		cin>>m[i];
		for(int j=0;j<w;j++)
		{
			cnt+=m[i][j]=='o';
			if(m[i][j]!='.'&&m[i][j]!='o')
			{
				x=i;
				y=j;
				r=m[i][j]=='R'?0:m[i][j]=='D'?1:m[i][j]=='L'?2:3;
			}
		}
	}
	m[x][y]='.';
	s=string(cnt,'A');
	f(x,y,r,0);
}


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

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			int[] height = new int[numN];
			for (int i = 0; i < numN; i++) {
				height[i] = scanner.nextInt();
			}

			int[] costArray = new int[numN];
			Arrays.fill(costArray, Integer.MAX_VALUE);
			costArray[0] = 0;
			for (int i = 0; i < height.length; i++) {
				for (int j = 1; j <= 2 && j + i < numN; j++) {
					int cost = Math.min(Math.abs(height[i + j] - height[i]) + costArray[i], costArray[i + j]);
					costArray[i + j] = cost;
				}
			}

			System.out.println(costArray[numN - 1]);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			numK = scanner.nextInt();

			int[] height = new int[numN];
			for (int i = 0; i < numN; i++) {
				height[i] = scanner.nextInt();
			}

			int[] costArray = new int[numN];
			Arrays.fill(costArray, Integer.MAX_VALUE);
			costArray[0] = 0;
			for (int i = 0; i < height.length; i++) {
				for (int j = 1; j <= numK && j + i < numN; j++) {
					int cost = Math.min(Math.abs(height[i + j] - height[i]) + costArray[i], costArray[i + j]);
					costArray[i + j] = cost;
				}
			}

			System.out.println(costArray[numN - 1]);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 52016
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main() {
	ll N, S;
	cin >> N >> S;

	vll X(N + 1), P(N + 1);
	repn(i, N)cin >> X[i] >> P[i];

	auto itr = lower_bound(++X.begin(), X.end(), S);
	ll t = distance(X.begin(), itr);

	ll l = 1;
	ll r = N;

	vll path;

	repn(i, N) {
		if (l >= t) {
			path.push_back(r);
			r--;
			continue;
		}
		if (r < t) {
			path.push_back(l);
			l++;
			continue;
		}

		ll a = P[l];
		ll b = P[r];

		if (a >= b) {
			path.push_back(r);
			P[l] += b;
			r--;
		}
		else {
			path.push_back(l);
			P[r] += a;
			l++;
		}
	}

	reverse(path.begin(), path.end());
	//rep(i, N)cout << path[i] << endl;

	ll ans = abs(S - X[path[0]]);
	repn(i, N - 1) {
		ans += abs(X[path[i]] - X[path[i - 1]]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 5868
#define ll long long
    #define pub push_back
    #define pob pop_back
    #define puf push_front
    #define pof pop_front
    #define mp make_pair
    #define fo(i , n) for(ll i = 0 ; i < n ; i++)
    //#include<bits/stdc++.h>
    #include<iomanip>
    #include<cmath>
    #include<cstdio>
    #include<utility>
    #include<iostream>
    #include<vector>
    #include<string>
    #include<algorithm>
    #include<map>
    #include<queue>
    #include<set>
    #include<stack>
    ll pi = acos(-1) ;
    ll z =  998244353 ;
    ll inf = 100000000000000000 ;
    ll p1 = 37 ;
    ll p2 = 53 ;
    ll mod1 =  202976689 ;
    ll mod2 =  203034253 ;
    ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
    ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;}
    ll inverse(ll a ,ll n){return power(a , n-2 , n) ;}
    ll max(ll a , ll b){if(a > b) return a ; return b ;}
    ll min(ll a , ll b){if(a < b) return a ; return b ;}
    ll left(ll i){return ((2*i)) ;}
    ll right(ll i){return ((2*i) + 1) ;}
    void swap(ll&a , ll&b){ll c = a ; a = b ; b = c ; return ;}
    //ios_base::sync_with_stdio(0);
    //cin.tie(0); cout.tie(0);
    using namespace std ;
    #include <ext/pb_ds/assoc_container.hpp> 
    #include <ext/pb_ds/tree_policy.hpp> 
    using namespace __gnu_pbds; 
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    // ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
    // s.find_by_order(i)  itertor to ith element (0 indexed)
    ll cnt = 1 ;

    void solve()
    {
        ll n,  k ;
        cin >> n >> k ;
        cout << min(n%k , k - n%k) << endl ;
        return ;

    }

    int main()
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);
        /*#ifndef ONLINE_JUDGE
        freopen("inputf.txt" , "r" , stdin) ;
        freopen("outputf.txt" , "w" , stdout) ;
        freopen("error.txt" , "w" , stderr) ;
        #endif*/
        
        ll t ;
        //cin >> t ;
        t = 1 ;
        while(t--)
        {
            solve() ;
        }
        //cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";*/

        return 0;
    }

Measured memory_bytes: 256
n,m = gets.split.map(&:to_i)

class UnionFind
  def initialize(size)
    @rank = Array.new(size,0)
    @parent = Array.new(size,&:itself)
  end
  def getRoot(x)
    @parent[x] == x ? x : (@parent[x] = getRoot(@parent[x]))
  end
  def unite(x,y)
    xp = getRoot(x)
    yp = getRoot(y)
    if xp == yp
      return
    elsif @rank[xp] > @rank[yp]
      @parent[yp] = xp
    else
      @parent[xp] = yp
      @rank[yp] += 1 if @rank[xp] = @rank[yp]
    end
  end
  def same?(x,y)
    getRoot(x) == getRoot(y)
  end
  def size
    @parent.map{|x| getRoot(x)}.uniq.size
  end
  def sizeOfTree
    data = Array.new(@parent.size,0)
    for i in 0..(@parent.size-1)
        data[getRoot(i)] += 1
    end
    data
  end
end

friends = UnionFind.new(n)

m.times do
  a,b = gets.split.map(&:to_i)
  friends.unite(a-1,b-1)
end
p friends.sizeOfTree.max


Measured memory_bytes: 19012
#include<stdio.h>
int main()
{
long long int n,m,i,sum=0,h;
scanf("%lld%lld",&n,&m);
long long int a[m];
for(i=0;i<m;i++)
{
    scanf("%lld",&a[i]);
    sum=sum+a[i];
}
if(sum>n)
printf("-1");
else
printf("%lld",n-sum);
}


Measured memory_bytes: 1748
N = int(input())

if N <= 2:
    print(0)
else:
    L = list(map(int,input().split()))
    L.sort()
    ans = 0
    for i in range(N):
        for j in range(i+1,N):
            if L[i] == L[j]:
                continue
            else:
                for k in range(j+1,N):
                    if L[i] == L[k] or L[j]==L[k]:
                        continue
                    else:
                        if L[k] < L[i] + L[j]:
                            ans += 1
    
    print(ans)


Measured memory_bytes: 70468
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    K = input_number()
    print(-(-K // 2) * (K // 2))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9116
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
#define INF 2147483647
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;



int main(){
	string s;
	cin>>s;
	ll ans=0,co=-1,co2=0;;
	for(int i=s.size()-1;i>=0;i--){
		co++;
		if(s[i]=='B'){
			ans+=co;
			ans-=co2;
			co2++;
		}
	}
	cout<<ans<<endl;
	
}

Measured memory_bytes: 640
max1=0; max2=0; max3=0
for i in range(10):
    x=int(input())
    if max1<x:
        max3=max2
        max2=max1
        max1=x
    elif max2<x:
        max3=max2
        max2=x
    elif max3<x:
        max3=x
print(max1)
print(max2)
print(max3)


Measured memory_bytes: 5588
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n, d, x, y;
    cin >> n >> d;
    ll cnt = 0;
    while(n--){
        cin >> x >> y;
        if(d*d >= x*x + y*y) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3620
n,m=map(int,input().split())
a=[]
for i in range(m):
    x=int(input())
    if a:
        if x!=a[-1]:
            a.append(x)
    else:
        a.append(x)
count=[0]*(n+2)
count[1]=2
count[0]=1
i=0
s=0
if a:
    s=a.pop(0)
if s==1:
    count[1]=1
    count[0]=0
    if a:
        s=a.pop(0)
if s==2:
    count[1]=0
    if a:
        s=a.pop(0)

while i<n:        
    if (i+2==s-1):
        i=i+1
        if a:
            s=a.pop(0)
    else:
        count[i+2]=(count[i]+count[i+1])%1000000007
        i=i+1
#print(count)
print(count[n-1])

Measured memory_bytes: 7844
#include<iostream>
#include<cstdio>
#include<cstring>
typedef long long ll;
int main()
{
	ll a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	if(a%2==0 || b%2==0 || c%2==0){printf("0\n");return 0;}
	if(a>b)std::swap(a,b);
	if(a>c)std::swap(a,c);
	if(b>c)std::swap(b,c);
	printf("%lld\n",a*b);
	return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) = abc158d()

fun abc158d() {
    val s = readLine()!!
    val q = readLine()!!.toInt()

    val stack = ArrayDeque(s.toList())
    var reversed = false

    for (i in 1..q) {
        val t = readLine()!!.split(' ')
        when (t[0].toInt()) {
            1 -> reversed = !reversed
            else -> {
                val f = t[1].toInt()
                val c = t[2][0]
                val addFirst = if (f == 1) !reversed else reversed
                if (addFirst) stack.addFirst(c) else stack.addLast(c)
            }
        }
    }

    val answer = (if (reversed) stack.reversed() else stack).joinToString("")

    println(answer)
}


Measured memory_bytes: 74472
using static System.Math;
using System;

public class Hello
{
	public static void Main()
	{
		string[] line = Console.ReadLine().Trim().Split(' ');
		var n = int.Parse(line[0]);
		var d = int.Parse(line[1]);
		var a = new int[n, d];
		for (int i = 0; i < n; i++)
		{
			line = Console.ReadLine().Trim().Split(' ');
			for (int j = 0; j < d; j++) a[i, j] = int.Parse(line[j]);
		}
		getAns(a, n, d);
	}
	static void getAns(int[,] a, int n, int d)
	{
		var count = 0;
		for (int i = 0; i < n - 1; i++)
			for (int j = i + 1; j < n; j++)
			{
				var sum = 0;
				for (int k = 0; k < d; k++)
					sum += (a[i, k] - a[j, k]) * (a[i, k] - a[j, k]);
				if (check(sum)) count++;
			}
		Console.WriteLine(count);
	}
	static bool check(int a)
	{
		var b = (int)Sqrt(a);
		return b * b == a;
	}
}

Measured memory_bytes: 13140
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>  
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<ll> v32;
typedef vector<vector<ll> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 1e9+7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define vvv64 vector<vv32>
#define vvvv64 vector<vvv32>
int LIM=1e5+100;
v64 parent(LIM);
vv64 adj(LIM);
v64 level(LIM);
v64 depth(LIM);
int v;	
void dfs(int n,int par)
{
	// cout<<n<<"a"<<endl;
	parent[n]=par;
	if (n!=v)
		level[n]=level[par]+1;
	// cout<<n<<" "<<level[n]<<endl;
	for (int i=0; i<adj[n].size(); i++)
	{
		if (adj[n][i]!=par)
		{
			dfs(adj[n][i],n);
			depth[n]=max(depth[n],depth[adj[n][i]]+1);

		}
	}
	// cout<<n<<" "<<depth[n]<<endl;
}
void solve()
{
	int n;
	cin>>n;
	int u;
	cin>>u>>v;
	for (int i=1; i<n; i++)
	{
		int a,b;
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	dfs(v,v);
	int d=level[u];
	int up=d-(d/2+1);
	// cout<<up<<endl;
	int root=u;
	for (int i=1; i<=up; i++)
		root=parent[root];
	// cout<<depth[root]<<" "<<level[root]<<endl;
	cout<<depth[root]+level[root]-1<<endl;
}   
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}

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

struct union_find_tree {
    std::vector<int> par, rank;
    union_find_tree(){}
    union_find_tree(int size)
    {
        par=std::vector<int>(size);
        rank=std::vector<int>(size);
        for(int i=0; i<size; ++i) par[i]=i;
    }
    int root(int x)
    {
        if (x==par[x]) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x, int y)
    {
        x=root(x);
        y=root(y);
        if (x==y) return;
        if (rank[x]<rank[y]) {
            par[x]=y;
        }
        else {
            par[y]=x;
            if (rank[x]==rank[y]) ++rank[x];
        }
    }
    bool same(int x, int y)
    {
        return root(x)==root(y);
    }
};


int main()
{
	int n; cin>>n;
	vector<tuple<int, int, int>> p;
	for(int i=0; i<n; ++i) {
		int x, y; cin>>x>>y;
		p.emplace_back(i, x, y);
	}

	vector<tuple<int, int, int>> edges;

	sort(begin(p), end(p), [](auto& a, auto& b){ return get<1>(a)<get<1>(b);});
	for(int i=0; i<n-1; ++i) {
		int a, x, y; tie(a, x, y)=p[i];
		int b, s, t; tie(b, s, t)=p[i+1];
		edges.emplace_back(min(abs(x-s), abs(y-t)), a, b);
	}
	sort(begin(p), end(p), [](auto& a, auto& b){ return get<2>(a)<get<2>(b);});
	for(int i=0; i<n-1; ++i) {
		int a, x, y; tie(a, x, y)=p[i];
		int b, s, t; tie(b, s, t)=p[i+1];
		edges.emplace_back(min(abs(x-s), abs(y-t)), a, b);
	}
 
	sort(begin(edges), end(edges));
	union_find_tree uf(n);
	long res=0;
	for(auto& e: edges) {
		int c, u, v; tie(c, u, v)=e;
		if (uf.same(u, v)) continue;
		uf.unite(u, v);
		res+=c;
	}
	cout<<res<<endl;
}

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

// Begin {{{
using namespace std;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (i64 i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (i64 i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<>>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
inline i64 sigma(i64 n) { return n * (1 + n) >> 1; }
inline i64 updiv(i64 n, i64 d) { return (n + d - 1) / d; }
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;
#ifndef DEBUG
#define dump(...)
#endif

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

inline void outs() { cout << "\n"; }
template <class Head, class... Tail>
inline void outs(Head&& head, Tail&&... tail) {
    cout << head << (sizeof...(tail) ? " " : "");
    outs(forward<Tail>(tail)...);
}

template <class T>
inline void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e == &vec.back()]; }

template <class T>
inline void outs(vector<vector<T>> &df) { for (auto &vec : df) outs(vec); }

inline void outl() { cout << "\n"; }
template <class Head, class... Tail>
inline void outl(Head&& head, Tail&&... tail) {
    cout << head << (sizeof...(tail) ? "\n" : "");
    outl(forward<Tail>(tail)...);
}

template <class T>
inline void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

inline void outn() {}
template <class Head, class... Tail>
inline void outn(Head&& head, Tail&&... tail) {
    cout << head;
    outn(forward<Tail>(tail)...);
}

template <class T>
inline void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}
// }}} End

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    var(int, N);
    i64 num4 = 0, num2 = 0, num1 = 0;
    rep(i, N) {
        var(i64, a);
        if (!(a % 4)) num4++;
        else if (!(a % 2)) num2++;
        else num1++;
    }
    dump(num1, num2, num4);
    bool yes = true;
    if (!num2) {
        if (num1 > num4 + 1) yes = false;
    } else {
        if (num1 > num4) yes = false;
    }
    outl((yes) ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,q,suma[200001],ans,pw10[200001];
const ll mod=998244353;
set<ll> s;
map<ll,ll> dig;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>q;
    s.insert(1);
    s.insert(n+1);
    dig[1]=1;
    pw10[0]=1;
    for(ll i=1;i<=n;i++)
    {
        suma[i]=(suma[i-1]*10+1)%mod;
        pw10[i]=(pw10[i-1]*10)%mod;
    }
    ans=suma[n];
    while(q--)
    {
        ll l,r,d;
        cin>>l>>r>>d;
        auto it=s.lower_bound(l);
        if((*it)>l)
            it--;
        ll poz=(*it);
        vector<ll> toerase;
        ll valnxt;
        while(poz<=r)
        {
            it++;
            ll pozfin=(*it)-1;
            if(poz>=l)
                toerase.push_back(poz);
            if(pozfin>r)
                valnxt=dig[poz];
            ll st=max(l,poz);
            ll dr=min(r,pozfin);
            ll dg=dig[poz];
            ans-=(((dg*suma[dr-st+1])%mod)*pw10[n-dr])%mod;
            if(ans<0)
                ans+=mod;
            ans=(ans+(((d*suma[dr-st+1])%mod)*pw10[n-dr])%mod)%mod;
            poz=(*it);
        }
        for(auto i:toerase)
        {
            s.erase(i);
            dig[i]=0;
        }
        s.insert(l);
        dig[l]=d;
        if(s.find(r+1)==s.end())
        {
            dig[r+1]=valnxt;
            s.insert(r+1);
        }
        cout<<ans<<'\n';
    }
    return 0;
}


Measured memory_bytes: 28600
// う　し　た　ぷ　に　き　あ　く　ん　笑
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

constexpr int ceil(int a, int b) { return (a + b - 1) / b; }

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

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.rbegin(), a.rend());

    int ans = 0;
    for (int i = 0; i < ceil(n, 2); i++) {
        ans += a[i];
    }
    for (int i = 1; i < n/2; i++) {
        ans += a[i];
    }

    cout << ans << endl;
}



Measured memory_bytes: 4792
#include <iostream>

using namespace std;

class B {
	int a, b;
public:
	void solve()
	{
		cin >> a >> b;

		cout << ((1 + b - a) * (b - a) / 2 - b) << endl;
	}
};


int main()
{
	B solution;
	solution.solve();

	return 0;
}

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

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

using namespace std;

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using pint = pair<int,int>;

const int INF = ~(1 << 31);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a;
    cin >> n;
    cin >> a;
    int n2 = n*n;
    cout << n2 - a << endl;

    return 0;
}

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

using namespace std;
    void leftrotate(string &s , int d);
    void rightrotate(string &s, int d);

int main()
{   string S,T; bool test=0;;
    cin >> S >> T ;
    if(S==T){cout<<"Yes"; test=true;}
    else {for(int i=0 ;i<S.size();i++)
    {
        rightrotate(S,1);
        if(S==T){cout << "Yes"; test=true; break;}
    }}

    if(test==false){cout<<"No";}

    return 0;
}

   void leftrotate(string &s , int d)
   {

    reverse(s.begin(), s.begin()+d);
    reverse(s.begin()+d, s.end());
    reverse(s.begin(), s.end());

    }

    void rightrotate(string &s, int d)
{
   leftrotate(s, s.length()-d);
}


Measured memory_bytes: 256
A,B,C = map(int,input().split())

if B > C:
  print(B + C)
elif (A + B) > C:
  print(B + C)
elif (A + B) < C:
  print(B*2 + A + 1)
elif B == C:
  print(B + C)
elif (A + B) == C:
  print(B + C)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

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

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

//////////////////////////////////////////////////

int main() {
    int n; cin >> n;
    vector<int> a(n), b(n);
    ll asum = 0, bsum = 0;
    rep(i,n) cin >> a[i], asum+=a[i];
    rep(i,n) cin >> b[i], bsum+=b[i];

    // 操作の度にasumは2,bsumは1増えるので
    // 以下の場合は、成立しない
    if (bsum < asum) {
        cout << "No" << endl;
        return 0;
    }

    // 変更回数は一意
    ll change = bsum-asum;

    // aの最低変更回数を調べる
    // bの最低変更回数を調べる
    ll cnt_a = 0, cnt_b = 0;
    rep(i,n) {
        if (a[i]<b[i]) {
            cnt_a += (b[i]-a[i]+1)/2;
            cnt_b += (b[i]-a[i])%2;
        } else {
            cnt_b += a[i]-b[i];
        }
    }

    // cout << cnt_a << endl;
    if (cnt_a > change || cnt_b > change) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 384
s = input()
t = input()

ans = {c:[] for c in 'abcdefghijklmnopqrstuvwxyz'}
res = {c:[] for c in 'abcdefghijklmnopqrstuvwxyz'}
for a,b in zip(s,t):
    ans[b].append(a)
    res[a].append(b)

aa = [0 for v in ans.values() if len(set(v)) > 1]
bb = [0 for v in res.values() if len(set(v)) > 1]

if len(aa) == 0 and len(bb) == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 8112
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI 3.14159265358979323846264338327950L

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

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

bool isPalindrome(string s){
    REP(i, s.length() / 2){
        if(s[i] != s[(s.length() - 1) - i]){
            return false;
        }
    }
    return true;
}

//scanf("%lld", &);
//cin >> ;
//cout << ans << endl;

 ll N, M, K, Q, i, j, k, l, tmp, ans;
int ac, wa, tle, re;

int main(){

    cin >> N;
    REP(i, N){
        string s;
        cin >> s;
        switch (s[0])
        {
        case 'A':
            ac++;
            break;
        case 'W':
            wa++;
            break;
        case 'T':
            tle++;
            break;
        case 'R':
            re++;
            break;
        default:
            break;
        }
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;

     return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
char ss[110];
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
   	scanf("%s",ss+1);int n=strlen(ss+1);
   	bool bk=true;
   	for(int i=1;i<=n;i++)if(ss[i]!=ss[n-i+1])bk=false;
   	for(int i=1;i<=n/2;i++)if(ss[i]!=ss[n/2-i+1])bk=false;
   	for(int i=n/2+2;i<=n;i++)if(ss[i]!=ss[n+n/2+2-i])bk=false;
   	if(bk==true)puts("Yes");
   	else puts("No");
    return 0;
}

Measured memory_bytes: 128
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int x;
   cin >> x;
   if(x >= 30){
      cout << "Yes\n";
   }else{
      cout << "No\n";
   }
   return 0;
} 


Measured memory_bytes: 3620