akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    int ans = 1000;
    for(int a = 1; a < n; a++)
    {
        int b = n - a;
        int ad = 0, bd = 0;
        int c = a;
        while(c / 10 != 0)
        {
            ad += c % 10;
            c /= 10;
        }
        ad += c;
        while(b / 10 != 0)
        {
            bd += b % 10;
            b /= 10;
        }
        bd += b;
        ans = min(ans, ad + bd);
    }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        //命令の回数
        int q = Integer.parseInt(sc.next());
        int order,num;
        List<Integer> list = new ArrayList<>(q);
        for(int i=0; i<q; i++){
            //命令の種類
            order = Integer.parseInt(sc.next());
            //0:pushBack
            if(order == 0){
                num = Integer.parseInt(sc.next());
                list.add(num);
            }
            //1:randomAccess
            else if(order == 1){
                num = Integer.parseInt(sc.next());
                System.out.println(list.get(num));
            }
            //2:popBack
            else if(order == 2){
                list.remove(list.size()-1);
            }
        }
    }
}



Measured memory_bytes: 117204
def bs(k, m):
    i = -1
    pas = 1<<30
    while pas:
        if i+pas < m and u[i+pas] <= k:
            i += pas
        pas //= 2
    return i+1

n, m, k = map(int, input().split())
v = list(map(int, input().split()))
u = list(map(int, input().split()))
for i in range(1, n):
    v[i] += v[i-1]
for i in range(1, m):
    u[i] += u[i-1]
ans = bs(k, m)
for i in range(n):
    if v[i] <= k:
        ans = max(ans, bs(k-v[i], m) + i+1)
print(ans)

Measured memory_bytes: 117396
{-
HOME- ITP1-ITP1_3-C
Discussion Solution Statistics Submit
 
Repetitive Processing - Swapping Two Numbers
????????¶??? : 1 sec, ?????¢?????¶??? : 65536 KB
2 ????????°?????????

???????????´??° x, y ?????????????????????????????????????°?????????????????????????????????°?????????????????????????????????

?????????????????????????????\?????????????????????????????????????????????????????????????????????????????¨?????¨?????????????????????
Input

??\???????????°????????????????????????????§?????????????????????????????????????????????????????????§??????????????????????????´??° x, y ??????????????????????§?????????????????????????

x ??¨ y ?????¨?????? 0 ?????¨?????\?????????????????????????????????????????????????????????????????????????????£????????????????????????
Output

??????????????????????????¨??????x ??¨ y ????°????????????????????????????????????????????????????????????????x ??¨ y ????????????????????????????????\??????????????????
Sample Input

3 2
2 2
5 3
0 0

Sample Output

2 3
2 2
3 5
-}
import Data.List
import Data.List.Split
import Text.Regex.Posix
import Text.Printf
main = prtln
prtln :: IO ()
prtln = do
  s <- getLine
  let t = aux s
  if t == "" then return ()
    else do putStrLn t
            prtln 

aux :: String -> String
aux s = if s =~ "^ *0 +0 *$" :: Bool then ""
        else printf "%d %d" a b :: String
          where f = sort $ map (\x->read x ::Int) $ splitOn " "  s
                a = head f
                b = last f

Measured memory_bytes: 4692
using System;
using System.Collections.Generic;
using System.Linq;

class B
{
    double Solve(long N, long X)
    {
        long r = N;
        long a = Math.Min(X, N - X);
        long b = Math.Max(X, N - X);
        while (true) {
            var n = b / a;
            r += 2 * a * n;
            var pa = a;
            a = b - a * n;
            b = pa;
            if (a == 0) return r - pa;
        }
    }
    
    static void Main() { 
        var NX = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        Console.WriteLine(new B().Solve(NX[0], NX[1]));    
    }
}

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

int main() {
    string s;
    cin >> s;
    int a[11];
    REP(i, s.length()) {
        if(s[i] == 'A') a[i] = 1;
        else if(s[i] == 'T') a[i] = 1;
        else if(s[i] == 'C') a[i] = 1;
        else if(s[i] == 'G') a[i] = 1;
    }
    int m=0,tmp=0;
    REP(i,s.length()) {
        if(a[i]==1) {
            tmp++;
        } else {
            tmp=0;
        }
        m = max(tmp,m);
    }
    cout << m << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
	string str;
	
	cin >> str;
	
	int k;
	
	scanf("%d", &k);

	int i = 0;
	
	while (k){
		if (i == str.length()){
			k %= 26;
			str[str.length() - 1] += k;
			k = 0;
		}
		else if (str[i] + k > 'z' && str[i] != 'a'){
			int n = str[i] - ('z' + 1);
			str[i] = 'a';
			k += n;
		}
		i++;
	}
	
	cout << str << endl;

	return (0);
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#define INF 2000000000
using namespace std;
int c;

void merge(int *A,int l,int m,int r){
  vector<int> L,R;
  for(int i=l;i<m;i++)L.push_back(A[i]);
  for(int i=m;i<r;i++)R.push_back(A[i]);  
  L.push_back(INF);
  R.push_back(INF);
  int i=0,j=0;
  for(int k=l;k<r;k++){
     if(R[j]>L[i])A[k]=L[i++];
     else A[k]=R[j++];
     c++;
  }
}

void mergesort(int *A,int l,int r){
  if(l+1<r){
    int m=(l+r)/2;
    mergesort(A,l,m);
    mergesort(A,m,r);
    merge(A,l,m,r);
  }
}
 
 
int main(){
  int n,S[500000];
  cin>>n;
  for(int i=0;i<n;i++)cin>>S[i];
  mergesort(S,0,n);
  for(int i=0;i<n-1;i++)cout<<S[i]<<" ";
  cout<<S[n-1]<<endl<<c<<endl;
  return 0;
}


Measured memory_bytes: 7460
n = int(input())
s = [input() for _ in range(n)]

c0 = s.count('AC')
c1 = s.count('WA')
c2 = s.count('TLE')
c3 = s.count('RE')

print('AC x '+ str(c0))
print('WA x '+ str(c1))
print('TLE x '+ str(c2))
print('RE x '+ str(c3))


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

int main(){
  int N, K;
  cin >> N >> K;
  
  int count = 0;
  
  vector<int> h(N);
  for(int i = 0; i < N; ++i) {
    cin >> h.at(i);
  }
  
  for(int i = 0; i < N; ++i) {
    if(h.at(i) >= K) {
      count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
struct UnionFind
{
	int parent[N],rnk[N];
	UnionFind(int n)
	{
		for(int i=0;i<=n;i++)
		{
			parent[i]=i;
			rnk[i]=1;
		}
	}
	int root(int x)
	{
		if(parent[x]!=x)
			parent[x]=root(parent[x]);
		return parent[x];
	}
	void connect(int x,int y)
	{
		int rx=root(x),ry=root(y);
		if(rx==ry)
			return;
		if(rx>ry)
		{
			parent[ry]=rx;
			rnk[rx]+=rnk[ry];	
		} 
		if(rx<=ry)
		{
			parent[rx]=ry;
			rnk[ry]+=rnk[rx];
		}
	}
};
set<int>s;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	UnionFind uf(n);
	for(int i=1;i<=m;i++)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		uf.connect(x,y);
	}
	for(int i=1;i<=n;i++)
		s.insert(uf.root(i));
	printf("%d\n",s.size());
	return 0;
}


Measured memory_bytes: 5760
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)

using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

double A, B, H, M;
int main(void){
    cin >> A >> B >> H >> M;

    cout << setprecision(10);
    double s = abs(2*M_PI*(H+M/60)/12-2*M_PI*M/60);
    double res = A*A + B*B -2*A*B*cos(s);
    cout << sqrt(res) << endl;

    return 0;
}



Measured memory_bytes: 4216
import java.util.*;

public class Main{
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        if(a == b){
            System.out.println("Draw");
        }else if(a == 1 && b > 1){
            System.out.println("Alice");
        }else if(a > 1 && b == 1){
            System.out.println("Bob");
        }else if(a > b){
            System.out.println("Alice");
        }else{
            System.out.println("Bob");
        }
    }
}

Measured memory_bytes: 35804
#include <iostream>
#include <utility>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
#define inf (int)(1e9)

struct pos{
  int x;
  int y;
  int t;

  pos(int x, int y, int t) : x(x), y(y), t(t){}
};

int main(){
  int sx, sy, gx, gy, N, lx, ly, i, j;
  scanf("%d%d%d%d", &sx, &sy, &gx, &gy);
  scanf("%d", &N);
  vector<int> x(N), y(N);
  for(i = 0; i < N; i++){
    scanf("%d%d", &x[i], &y[i]);
  }
  scanf("%d%d", &lx, &ly);
  sx += lx;
  sy += ly;
  gx += lx;
  gy += ly;
  vector<vector<int> > kagu(2 * lx + 1, vector<int>(2 * ly + 1, 0));
  for(i = 0; i < N; i++){
    kagu[lx + x[i]][ly + y[i]] = 1;
  }
  lx = 2 * lx + 1;
  ly = 2 * ly + 1;
  vector<vector<vector<int> > > B(lx, vector<vector<int> >(ly, vector<int>(6, inf)));
  deque<pair<pos, int> > dq;
//  printf("(sx, sy) = (%d, %d)\n", sx, sy);
  dq.push_back(pair<pos, int>(pos(sx, sy, 0), 0));
  int dx[2][6] = {{0, 1, 1, 0, -1, -1}, {0, 1, 1, 0, -1, -1}};
  int dy[2][6] = {{1, 0, -1, -1, -1, 0}, {1, 1, 0, -1, 0, 1}};
  while(dq.size() > 0){
    pos p = dq.front().first;
    int v = dq.front().second;
    int x = p.x, y = p.y, t = p.t;
    dq.pop_front();
    if(x < 0 || lx <= x || y < 0 || ly <= y || B[x][y][t] <= v || kagu[x][y] == 1){
      continue;
    }
    B[x][y][t] = v;
    for(int d = 0; d < 6; d++){
      if(d == abs((x - lx / 2) * (y - ly / 2) * t) % 6){
        dq.push_front(pair<pos, int>(pos(x + dx[abs(x - lx / 2) % 2][d], y + dy[abs(x - lx / 2) % 2][d], (t + 1) % 6), v));
      }
      else{
        dq.push_back(pair<pos, int>(pos(x + dx[abs(x - lx / 2) % 2][d], y + dy[abs(x - lx / 2) % 2][d], (t + 1) % 6), v + 1));
      }
    }
    dq.push_back(pair<pos, int>(pos(x, y, (t + 1) % 6), v + 1));
  }
/*  int k;
  for(i = 0; i < lx; i++){
    for(j = 0; j < ly; j++){
      printf("(%d, %d):\n", i, j);
      for(k = 0; k < 6; k++){
        printf("%d ", B[i][j][k]);
      }
      printf("\n");
    }
  }
*/  int ans = inf;
  for(i = 0; i < 6; i++){
    ans = min(ans, B[gx][gy][i]);
  }
  if(ans >= inf){
    printf("-1\n");
  }
  else{
    printf("%d\n", ans);
  }
  return 0;
}



Measured memory_bytes: 5984
#include <stdio.h>

int main(void) {
	int n, m, k;
	int x, y, z;

	scanf("%d %d %d", &n, &m, &k);

	if ((k%n == 0) || (k%m == 0)) {
		printf("Yes\n");
		return 0;
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			x = i;
			y = j;
			z = m*x + n*y - 2 * x*y;
			if (z == k) {
				printf("Yes\n");
				return 0;
			}
		}
	}

	printf("No\n");

	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<long long> vl;

#define F 						first
#define PB 						push_back
#define MP 						make_pair
#define f(i,a,b) 				for(ll i=a; i<b; i++)
#define rep(i,n) 				f(i,0,n)
#define w(t)					ll t; cin>>t; while(t--)
#define epsilon					1e-9

constexpr ll int_pow(ll b, ll e) {
    return (e == 0) ? 1 : b * int_pow(b, e - 1);
}

void doublade() {
	ios::sync_with_stdio(false); cin.tie(0); cout.precision(10);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
}

int main()
{
	doublade();
	// w(t) {
		ll x[5];
		ll ans;
		rep(i, 5) {
			cin>>x[i];
			if(x[i]==0) ans = i+1;
		}
		cout<<ans<<"\n";
	// }
	return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <numeric>
#include <vector>

int main(){
    long long n;
    std::cin >> n;

    std::vector<long long> a(n + 1);
    for(long long i = 0; i < n + 1; ++i){
        std::cin >> a.at(i);
    }

    long long preSum = std::accumulate(a.begin(), a.end(), 0LL);

    long long b;
    for(long long i = 0; i < n; ++i){
        std::cin >> b;
        long long min = std::min(a.at(i), b);
        b -= min;
        a.at(i) -= min;
        a.at(i + 1) -= std::min(a.at(i + 1), b);
    }
    
    std::cout << preSum - std::accumulate(a.begin(), a.end(), 0LL) << std::endl;
    
    return 0;
}

Measured memory_bytes: 1024
import itertools
import math
n = int(input())
positions = []
for i in range(n):
    x, y = map(int, input().split())
    positions.append([x, y])
# print(positions)
ans = 0
for i in itertools.permutations(positions):
    total_distance = 0
    for j in range(1, len(i)):
        x_gap = i[j][0] - i[j - 1][0]
        y_gap = i[j][1] - i[j - 1][1]
        total_distance += math.sqrt(x_gap ** 2 + y_gap ** 2)
    ans += total_distance
ans /= math.factorial(n)
print(ans)

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in(),M=in();
	vector<vector<int>> AB(M);
	REP(i,N){
		int A=in()-1,B=in();
		if(A>=M) continue;
		AB[A].push_back(B);
	}

	priority_queue<int> Q;
	ll sum = 0;
	REP(i,M){
		for(auto& x:AB[i]) Q.push(x);
		if(!Q.empty()){
			auto V = Q.top();
			Q.pop();
			sum += V;
		}
	}
	out(sum);
	return 0;
}


Measured memory_bytes: 5632
#include <stdio.h>

int main(void){
    int N, K;
    int counter = 0;
    scanf("%d %d", &N, &K);
    int h[N];
    for (int i = 0; i < N; i++){
        scanf("%d", &h[i]);
        if (h[i] >= K){
            counter++;
        }
    }
    printf("%d\n", counter);
    return 0;
}

Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
		int countA,countB,sum=0;
		countA = sc.nextInt();
		List<Integer> s=new ArrayList<Integer>(countA);
		for(int i=0; i<countA; i++) {
			s.add(sc.nextInt());
		}

		countB = sc.nextInt();
		List<Integer> t=new ArrayList<Integer>(countB);
		for(int i=0; i<countB; i++) {
			t.add(sc.nextInt());
		}

		for(int tmp:t)
			if(s.contains(tmp))
				sum ++;
		System.out.println(sum);
	}
}





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

int main() {
  int n;
  cin >> n;
  double l = n/3.0;
  printf("%.10f\n", l*l*l);
  }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;
int main() {
  int n;
  cin >> n;
  int xs[101], ys[101], hs[101];

  for (int i = 0; i < n; i++) {
    cin >> xs[i] >> ys[i] >> hs[i];
  }

  int min_h = *min_element(hs, hs + n);

  for (int h = max(min_h, 1); h <= min_h + 200; h++) {
    for (int x = 0; x <= 100; x++) {
      for (int y = 0; y <= 100; y++) {
        int i;
        for (i = 0; i < n; i++) {
          if (max(0, h - abs(x - xs[i]) - abs(y - ys[i])) != hs[i]) {
            goto next;
          }
        }

        cout << x << " " << y << " " << h << endl;
        return 0;
      next:
        ;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 888
# coding: utf-8
# Your code here!
s=list(input())
k=int(input())
cnt=1
cnt2=0
tmp=0
flg=0
flg2=0
flg3=0
for i in range(len(s)):
    if tmp==s[i]:
        cnt+=1
    else:
        cnt2+=cnt//2
        cnt=1
    tmp=s[i]
cnt2+=cnt//2

if len(s)==1:
    flg2=1
elif len(set(s))==1:
    flg3=1

elif s[0]==s[-1]:
    m=0
    cnt3=0
    while s[m]==s[0]:
        cnt3+=1
        m+=1
        if m==len(s)-1:
            cnt3+=1
            break
    n=1
    cnt4=0
    while s[-n]==s[0]:
        cnt4+=1
        n+=1
        if n==len(s):
            cnt4+=1
            break
    if cnt3%2==1 and cnt4%2==1:
        flg=1

if flg==1:
    ans=cnt2*k+k-1
elif flg2==1:
    ans=k//2
elif flg3==1:
    ans=(len(s)*k)//2
else:
    ans=cnt2*k
    
print(ans)
    


Measured memory_bytes: 3064
#include <iostream>
 using namespace std;
 int main(){
 int a,b;
 cin>>a>>b;

 int c=0;
 for(int i=0;i<a;i++){
 int h;
 cin>>h;
 if(h>=b) c++;
 }

 cout<<c<<endl;
 return 0;
 }

Measured memory_bytes: 3592
N, D = map( int, input().split() )
d = list( map( int, input().split() ) )
Q = int( input() )
q = list( map( int, input().split() ) )

dis = [ 0 for i in range( N + 1 ) ]
dis[ 0 ] = D
for i in range( N ):
  dis[ i + 1 ] = min( dis[ i ], abs( dis[ i ] - d[ i ] ) )

dp = [ 0 for i in range( N + 1 ) ]
dp[ N ] = 1
for i in range( N - 1, -1, -1 ):
  if dp[ i + 1 ] <= d[ i ] // 2:
    dp[ i ] = dp[ i + 1 ]
  else:
    dp[ i ] = dp[ i + 1 ] + d[ i ]

for qi in range( Q ):
  print( [ "NO", "YES" ][ dis[ q[ qi ] - 1 ] >= dp[ q[ qi ] ] ] )


Measured memory_bytes: 136824
import sys
readline = sys.stdin.readline

# 全探索
N,M = map(int,readline().split())
G = [[] for i in range(N)]
bridges = [None] * M
for i in range(M):
  a,b = map(int,readline().split())
  G[a - 1].append(b - 1)
  G[b - 1].append(a - 1)
  bridges[i] = (a - 1,b - 1)
  
ans = 0
for i in range(M):
  # 使わない橋を決める
  NG = bridges[i]
  seen = set()
  stack = []
  # 頂点, 親
  stack.append([0, -1])
  while stack:
    v,parent = stack.pop()
    if v in seen:
      continue
    seen.add(v)
    for child in G[v]:
      if child == parent:
        continue
      if (v, child) == NG or (child, v) == NG: # 今回使わない橋
        continue
      stack.append([child, v])
  if len(seen) != N:
    ans += 1

print(ans)

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

#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265
#define oo 1000000007
#define loo 10000000000000007

#define prime 1000000007

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
using namespace std;

ll fib[100100];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    fib[0] = 1;
    fib[1] = 1;
    for (int i = 2; i <= n; ++i){
        fib[i] = (fib[i-1]+fib[i-2])%prime;
        //W(fib[i])
    }
    vi v {0};
    for (int i = 0; i < m; ++i){
        int x; cin >> x;
        v.pb(x);
    }
    v.pb(n+1);
    sort(v.begin(), v.end());
    ll sum = 1;
    for (int i = 1; i < (int)v.size(); ++i){
        //if(i == 1 && v[i] == 1) continue;
        //if(v[i] == n && v[i-1] == v[i]-1) continue;
        if(v[i]-v[i-1]-1 < 0) {
            sum = 0;
            break;
        }
        if(i == 1) {
            sum *= fib[v[i]-v[i-1]-1];
            //W(fib[v[i]-v[i-1]-1])
        }
        else{ 
            sum *= fib[v[i]-v[i-1]-2];
            //W(fib[v[i]-v[i-1]-2])
        }
        //W(sum)
        sum%=prime;
        //W(sum)
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1660
import std.stdio, std.conv, std.string, std.algorithm,
       std.math, std.array, std.container, std.typecons;

void main() {
  auto ab = readln.chomp.split.to!(int[]);
  auto a = ab[0];
  auto b = ab[1];
  if(a<b) {
    for(int i=0; i<b; i++) write(a.to!string);
  }
  else {
    for(int i=0; i<a; i++) write(b.to!string);
  }
  writeln;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define INF I64_MAX
#define MOD 1000000007
#define MEM_SIZE = 1e5+5;

// vector<int> DP[MEM_SIZE]


void solve(void)
{
  int N;
  cin>>N;
  vector<string> str;
  bool ANS = 1;
  for (int i = 0; i < N; i++)
  {
    string str_in;
    cin>>str_in;
    if(i != 0)
    {
      if(str[i-1][str[i-1].size()-1] != str_in[0])
      {
        ANS = 0;
        // cout<<str[i-1][str[i-1].size()-1]<<"test"<<str_in[0]<<endl;
      }

      for (int j = 0; j < i; j++)
      {
        if(str[j] == str_in)
        {
          ANS = 0;
          // cout<<i<<endl;
        }
      }
    }
    str.push_back(str_in);
  }
      if(ANS == 1)
    {
      cout<<"Yes"<<endl;
    }
    else
    {
      cout<<"No"<<endl;
    }
  
  return;
  
}



int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // std::cout << std::fixed;
  // std::cout << std::setprecision(8);

  solve();

 
  return 0;
}

Measured memory_bytes: 384
#include<string>
#include<iostream>

using namespace std;

int main()
{
	int a,b;
	char op;
	
	int i,j=0;
	while(1){
		cin >> a >> op >> b;
		if(op =='?') break;
		if(op =='+') cout << a+b << endl;
		else if(op =='-') cout << a-b << endl;
		else if(op =='*') cout << a*b << endl;
		else if(op =='/') cout << a/b <<endl;	
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 2000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 
bool debug=false;
/*---------------------------------------------------*/
 
map<double,int> t;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  t[a+0.5]+=1;
  t[b+0.5]-=1;
  t[c+0.5]+=1;
  t[d+0.5]-=1;
  for(int i=1;i<205;i++){
    t[i+0.5]+=t[i-0.5];
  }
  int ans=0;
  for(int i=0;i<205;i++)if(t[i+0.5]==2)ans++;
  cout<<ans<<endl;
  return 0;
}

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


const int N = 1e5 + 5;


int n, k, a[N];

int main(){
    cin >> n >> k;
    int ans = 2e9;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(i >= k){
            ans = min(ans, min(abs(0 - a[i - k + 1]) + abs(a[i - k + 1] - a[i]), abs(0 - a[i]) + abs(a[i] - a[i - k + 1])));
        }
    }
    cout << ans;
}


Measured memory_bytes: 768
import std.stdio, std.bigint, std.conv, std.string;

void main(){
    int n = readln.chomp.to!int;
    foreach(i; 0..n){
        auto a = readln.chomp;
        auto b = readln.chomp;
        if(a.length > 80 || b.length > 80){
            "overflow".writeln;
            continue;
        }
        auto res = (a.BigInt + b.BigInt).to!string;
        if(res.length > 80)
            "overflow".writeln;
        else
            res.writeln;
    }
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
bool sortDescByFirst(const pair<int,int>&a, const pair<int,int>&b){
    return a.first>=b.first;
}
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,m;
    while(cin>>n>>m){
        n=n%500;
        if(n<=m)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
INF = float("inf")
n, A, B, C = map(int, input().split())
L = tuple(map(int, (int(input()) for _ in range(n))))
def f(a, b, c, num):
    if num == n:
        return abs(A - a) + abs(B - b) + abs(C - c) if min(a, b, c) > 0 else INF
    return min(
        f(a + L[num], b, c, num + 1) + (10 if a else 0),
        f(a, b + L[num], c, num + 1) + (10 if b else 0),
        f(a, b, c + L[num], num + 1) + (10 if c else 0),
        f(a, b, c, num + 1)
    )
print(f(0, 0, 0, 0))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		int n;
		cin>>n;
		string s;
		cin>>s;
		vector<char> v;
		rep(i,0,sz(s)){
			if(sz(v)==0){
				v.pb(s[i]);
				continue;
			}
			if(v.back()==s[i]){
				continue;
			}
			v.pb(s[i]);
		}
		cout<<sz(v);
	}   
}     

Measured memory_bytes: 592
n = int(input())
l = list(map(int, input().split()))

l.sort()
cnt = 0

for i in range(n):
    for j in range(i+1, n):
        if l[i] == l[j]:
            continue
        for k in range(j+1, n):
            if l[i] == l[k] or l[j] == l[k]:
                continue
            if l[i] + l[j] > l[k]:
                cnt += 1
                
print(cnt)

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

const int N = 2e5 + 10;

int n, k, l, lim;
vector<int> V[N];
vector<int> P[N], Q[N];
int idp[N], idq[N];
int que[N], head, tail;
int set_p[N], set_q[N];

vector<bitset<N> > bs_p, bs_q;
bitset<N> tmp;
bool vis[N];

void bfs(int x, int id, vector<int>* G, int* idx, int* mp, vector<bitset<N> > &bs){
	head = tail = 0;
	que[tail++] = x;
	vis[x] = 1;
	idx[x] = id;
	G[id].clear();
	G[id].push_back(x);
	while(head < tail){
		x = que[head++];
		for(int i=0; i<V[x].size(); i++){
			int j = V[x][i];
            if(!vis[j]){
				vis[j] = 1;
				idx[j] = id;
				que[tail++] = j;
				G[id].push_back(j);
            }
		}
	}

    sort(G[id].begin(), G[id].end());
    if(G[id].size() >= lim){
        tmp.reset();
		for(int i=0; i<G[id].size(); i++){
			int j = G[id][i];
            tmp.set(j);
		}
        mp[id] = bs.size();
		bs.push_back(tmp);
    } else {
        mp[id] = -1;
    }
}

void init(int m, vector<int>* G, int* idx, int* mp, vector<bitset<N> > &bs){
    int x, y;
    for(int i=1; i<=n; i++){
		V[i].clear();
		vis[i] = 0;
    }
    while(m--){
		scanf("%d %d", &x, &y);
		V[x].push_back(y);
		V[y].push_back(x);
    }
    m = 0;
    bs.clear();
    for(int i=1; i<=n; i++){
		if(!vis[i]){
            bfs(i, m, G, idx, mp, bs);
			m++;
		}
    }
}

int solve(int x){
	int px = idp[x];
	int qx = idq[x];
    if(set_p[px]!=-1){
        if(set_q[qx] != -1){
            tmp = bs_p[set_p[px]] & bs_q[set_q[qx]];
            return tmp.count();
        } else {
			int z = set_p[px];
			int ret = 0;
            for(int i=0; i<Q[qx].size(); i++){
                int j = Q[qx][i];
                if(bs_p[z].test(j)){
                    ret++;
                }
            }
            return ret;
        }
    } else {
    	if(set_q[qx] != -1){
			int z = set_q[qx];
			int ret = 0;
            for(int i=0; i<P[px].size(); i++){
                int j = P[px][i];
                if(bs_q[z].test(j)){
                    ret++;
                }
            }
            return ret;
    	} else {
            int n = P[px].size(), m = Q[qx].size();
            int ret = 0;
            int i=0, j=0;
            while(i<n && j<m){
                if(P[px][i] == Q[qx][j]){
                    ret++;
                    i++;
                    j++;
                } else if(P[px][i] < Q[qx][j]){
					i++;
                } else {
					j++;
                }
            }
            return ret;
    	}
    }
}

int main(){
	while(~scanf("%d %d %d", &n, &k, &l)){
		lim = (int)sqrt(n * 1.0);

        init(k, P, idp, set_p, bs_p);
        init(l, Q, idq, set_q, bs_q);

        for(int i=1; i<=n; i++){
			printf("%d%c", solve(i), i==n?'\n':' ');
        }
	}
	return 0;
}


Measured memory_bytes: 30848
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    int n;
    cin>>n;
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    a--;b--;c--;d--;
    string s;
    int i;
    cin>>s;
    bool is = false;
    int lim = MAX2(c, d);
    FOR(i, a, lim)
    {
        if(s[i]=='#'&&s[i+1]=='#') is = true;
    }
    if(is)
    {
        cout<<"No";
        return 0;
    }
    if(d < c)
    {
        is = true;
        FOR(i, b-1, d)
        {
            if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.')
                is = false;
        }
        if(is) 
        {
            cout<<"No";
            return 0 ;
        }
    }
    cout<<"Yes";
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 592
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val A, B, C, K = in.nextInt

  def twice(n: Int, cnt: Int = K): Int = if (cnt == 0) n else twice(n * 2, cnt - 1)
  println((twice(A) + B + C) max (A + twice(B) + C) max (A + B + twice(C)))
}

Measured memory_bytes: 55252
n = int(input())
e = [[int(i) for i in input().split()] for i in range(n)]

ct = 0
cx = 0
cy = 0

result = "Yes"
for e_ in e:
    t = e_[0]
    x = e_[1]
    y = e_[2]

    dt = t - ct
    dxy = abs(cx - x) + abs(cy - y)
    if dxy > dt or (dt - dxy)%2 == 1:
        result = "No"
        break

    ct = t
    cx = x
    cy = y

print(result)

Measured memory_bytes: 21108
# -*- coding: utf-8 -*-

import sys
import os
import math


A = input().strip()
B = input().strip()



if len(A) == len(B):
    for i in range(len(A)):
        print(A[i], end='')
        print(B[i], end='')
else:
    for i in range(len(B)):
        print(A[i], end='')
        print(B[i], end='')
    print(A[-1], end='')



Measured memory_bytes: 3060
//int a = s - '0'; 文字から数字
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define PI 3.14159265358979323846264338327950L
using namespace std;

//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

int main() {
	string S, T;cin >> S >> T;

	ll ans = 100000;
	for(int i = 0; i <= S.size()-T.size(); i++){
		int tmp = 0;
		for(int j = 0; j < T.size(); j++){
			if(T[j] != S[j + i]) tmp++;
		}

		if(tmp <= ans) ans = tmp;
	}

	cout << ans << endl;
}	

Measured memory_bytes: 10972
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	string s;
	cin >> s;
	int a, b, c;
	a = b = c = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'a') {
			a++;
		}
		else if (s[i] == 'b') {
			b++;
		}
		else {
			c++;
		}
	}

	int MIN = min(a, min(b, c));
	a -= MIN;
	b -= MIN;
	c -= MIN;
	if (a > 1 || b > 1 || c > 1) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
	return 0;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.buffer.readline
import numpy as np

def main():
    N,K = map(int,input().split())
    a = list(map(int,input().split()))
    l = max(max(a),K).bit_length()
    a = np.array(a)
    num,ans = 0,0
    for i in reversed(range(l)):
        base = 2**i
        bit = (a>>i)&1
        cnt = np.count_nonzero(bit)
        
        if cnt <= (N-1)//2:
            if num+base <= K:
                num += base
                ans += base*(N-cnt)
            else:
                ans += base*cnt
        else:
            ans += base*cnt
    
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 21548
import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().trim.toInt
  val a = Array(0) ++ StdIn.readLine().split(' ').map(_.toInt)

  def parent(i: Int) = i/2
  def left(i: Int)  = 2*i
  def right(i: Int) = 2*i+1

  def printNodeInfo(i: Int) = {
    val p = parent(i)
    val l = left(i)
    val r = right(i)
    
    println(
    s"node ${i}:" +
    s" key = ${a(i)}, " + 
      (if(0 < p) s"parent key = ${a(p)}, " else "") +
      (if(l <= n) s"left key = ${a(l)}, " else "") +
      (if(r <= n) s"right key = ${a(r)}, " else "")
    )
  }

  (1 to n).foreach{ i =>
    printNodeInfo(i)
  }

}



Measured memory_bytes: 44464
S = gets.chomp.split('')
flag = true
S.each_with_index do |s,i|
    if i%2==0 then
        # 奇数
        flag = false if s == 'L'
    else
        flag = false if s == 'R'
    end
    break unless flag
end
puts flag ? "Yes" : "No"

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string>
using namespace std;

int main(){
    //cout << 1000000000 % 8 << endl;
    int n; 
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    
    sort(a.begin(), a.end());
    for(int i = 1; i < n; i++){
        if(a[i] % a[0] != 0){
            a[i] = (a[i] % a[0]);
            i = 0;
            sort(a.begin(), a.end());
        }
    }

    cout << a[0] << endl;

    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
typedef long long ll;
using namespace std;

#define N 105
int n,maxw;
int v[N],w[N];
int dp[N][10005];


int main(){
    cin>>n>>maxw;
    for(int i=1;i<=n;i++)cin>>v[i]>>w[i];
    for(int i=0;i<=n;i++)for(int j=0;j<=maxw;j++)dp[i][j]=-1;
    for(int j=0;j<=maxw;j++)dp[0][j]=0;
    
    for(int i=1;i<=n;i++){
        for(int j=0;j<=maxw;j++){
            if(j<w[i]){
                dp[i][j]=dp[i-1][j];
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
            }
        }
    }
    cout<<dp[n][maxw]<<endl;
    
    return 0;
}




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

int main()
{
    int a, b[100];
    cin >> a;
    for(int i = 0; i < a; i++)
    {
        cin >> b[i];
    }
    for(int i=0; i < a; i++)
    {
        if(b[i]%2==0)
        {
            if((b[i]%3!=0)&&(b[i]%5!=0))
            {
                cout << "DENIED";
                return 0;
            }
        }
    }
    cout << "APPROVED";
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    S = args[1:]
    D = {}
    for s in S:
        if s not in D:
            D[s] = 1
        else:
            D[s] += 1
    m = max(D.values())
    A = [a[0] for a in sorted(D.items(), key=lambda x: (
        -x[1], x[0])) if a[1] == m]

    return '\n'.join(A)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


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

int main(){
	int n;cin>>n;
	int k;cin>>k;
	vector<int> stone(n);
	int aa;
	for(int i=0;i<n;i++){
		cin>>aa;
		stone[i] = aa;
	}
	vector<int> dp(n,INT_MAX);
	dp[1] = abs(stone[1] - stone[0]);
	dp[0] = 0;
	for(int i=2;i<n;i++){
		for(int j=1;j<=k;j++){
			if(i-j>=0)
			dp[i] = min(dp[i], dp[i-j] + abs(stone[i]- stone[i-j]) );
		}
	}
	cout<<dp[n-1];
	return 0;

}



Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            char[] c = sc.nextLine().toCharArray();
            if(c[0] == '0') break;
            int sum = c[0];
            for(int i = 1,l = c.length;i < l;++i) sum += c[i];
            System.out.println(sum - '0' * c.length);
        }

    }

}

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

using namespace std;
inline int read() {
    int x = 0;
    bool f = 1;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    if (f) return x;
    return 0 - x;
}
typedef long long ll;
const int maxn = 200010;
const int inf = 0x3f3f3f3f;
const ll mod = 1000000000 + 7;
int v[maxn], w[maxn], dp[maxn], h, n;

int main() {
    h = read(), n = read();
    for (int i = 1; i <= n; i++) {
        w[i] = read();
        v[i] = read();
    }
    memset(dp, 0x3f, sizeof(dp));
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = w[i]; j <= 1e4 + 10; j++) {
            if (dp[j - w[i]] != inf)
                dp[j] = min(dp[j], dp[j - w[i]] + v[i]);
        }
    }
    int m = inf;
    for (int i = h; i < maxn; i++)
        m = min(m, dp[i]);
    cout << m << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	// ABC002-D, Expected 1405, 9:50, First AC
	/*int n, m; cin >> n >> m;
	vector<vector<int>> g(n);
	rep(i, m) {
		int x, y; cin >> x >> y;
		x--; y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int ans = 0;
	rep(i, 1 << n) {
		bool ok = true;
		rep(j, n) {
			if (i >> j & 1) {
				rep(k, n) {
					if (i >> k & 1 && j != k) {
						bool ok2 = false;
						rep(l, g[j].size()) {
							if (g[j][l] == k) ok2 = true;
						}
						if (!ok2) {
							ok = false; break;
						}
					}
				}
				if (!ok) break;
			}
		}
		int tmpCount = 0;
		rep(j, n) tmpCount += i >> j & 1;
		if (ok) ans = max(ans, tmpCount);
	}
	cout << ans << endl;
	*/

	// Square869120Contest #4 B, 19:08, First AC
	/*int n, k; cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	ll ans = llINF;
	rep(i, 1 << n) {
		int c = 0;
		rep(j, n) c += i >> j & 1;
		if (c != k) continue;
		ll tmpMax = -1;
		ll tmpAns = 0;
		rep(j, n) {
			if (i >> j & 1) {
				tmpAns += max(0ll, tmpMax - a[j] + 1);
				tmpMax = max(tmpMax + 1, a[j]);
			}
			else {
				tmpMax = max(tmpMax, a[j]);
			}
		}
		ans = min(ans, tmpAns);
	}
	cout << ans << endl;
	*/

	// ABC145-C, 297, 17:15, First AC
	/*int n; cin >> n;
	vector<P> p(n);
	rep(i, n) cin >> p[i].first >> p[i].second;
	sort(ALL(p));
	double ans = 0;
	int num = 0;
	do {
		num++;
		double dist = 0;
		rep(i, n) {
			if (i == 0) continue;
			dist += sqrt((p[i].first - p[i - 1].first) * (p[i].first - p[i - 1].first) + (p[i].second - p[i - 1].second) * (p[i].second - p[i - 1].second));
		}
		ans += dist;
	} while (next_permutation(p.begin(), p.end()));
	cout << setprecision(15) << ans / num << endl;
	*/

	// ABC077-C, 1096, 
	int n; cin >> n;
	vector<int> a(n), b(n), c(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n) cin >> c[i];
	sort(ALL(a));
	sort(ALL(b));
	sort(ALL(c));
	ll ans = 0;
	rep(i, n) {
		if (b[i] <= a[0]) continue;
		if (c[n - 1] <= b[i]) continue;
		int l, r, m, up, down;
		l = -1;
		r = n;
		while (l + 1 < r) {
			m = (l + r) / 2;
			if (a[m] < b[i]) l = m;
			else r = m;
		}
		up = l;

		l = -1;
		r = n;
		while (l + 1 < r) {
			m = (l + r) / 2;
			if (c[m] <= b[i]) l = m;
			else r = m;
		}
		down = r;

		ans += ll(up + 1) * ll(n - down);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4580
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int mod = 1e9+7;
ll gcd(ll a,ll b){
    if(b==0)
    return a;return gcd(b,a%b);
}
ll expo(ll base,ll pow){
    ll ans = 1;
    while(pow!=0){
        if(pow&1==1){
            ans = ans*base;
            ans = ans%mod;
        }
        base *= base;base%=mod;
        pow/=2;
    }return ans;
}
ll inv(ll x){
    return expo(x,mod-2);
}
 
const int M = 2e5 + 5;


int main(){
    int n;
    cin >> n;
    vector <int> vec(n);
    for(int i = 0; i < n; i++) cin >> vec[i];
    sort(vec.begin(), vec.end());
    ll sum = vec[n-1];
    ll cnt = n-2;
     
    for(int i = n-2; i >= 0; i--){
        sum += min(cnt, 2LL)*vec[i];
        cnt -= min(cnt, 2LL);
        if(cnt == 0) break;
    }
    
    cout << sum;
}


Measured memory_bytes: 4060
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Long[] A = new Long[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextLong();
		}
		sc.close();

		// 降順にソート
		Arrays.sort(A, Collections.reverseOrder());
		long ans = 0;
		ans += A[0];
		for (int i = 0; i < N - 2; i++) {
			long next = A[i / 2 + 1];
			ans += next;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 65016
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

using P = pair<int,pii>;

int vv[20][20];
int dp[1<<20][20];
int cost[1<<20];
int n,m;

void mainmain(){
	cin>>n>>m;
	int sum = 0;
	rep(i,m){
		int a,b,c;
		cin>>a>>b>>c;
		a--,b--;
		vv[a][b] = vv[b][a] = c;
		sum += c;
	}
	rep(i,1<<20) rep(j,20) dp[i][j] = -INF;
	rep(i,1<<n){
		rep(j,n){
			rep(k,j){
				if((i&(1<<j))&&(i&(1<<k))){
					cost[i] += vv[j][k];
				}
			}
		}
	}
	dp[1][0] = 0;
	// cout<<cost[7]<<endl;
	rep(i,1<<n){
		rep(j,n){
			if(dp[i][j]==-INF) continue;
			rep(k,n){
				if(i&(1<<k)) continue;
				if(vv[j][k]==0) continue;
				maxs(dp[i|(1<<k)][k], dp[i][j]+vv[j][k]);
			}
			int umask = ((1<<n)-1)^i;
			for(int mask=umask; mask>0; mask=(mask-1)&umask){
				maxs(dp[i|mask][j], dp[i][j]+cost[mask+(1<<j)]);
			} 
		}
	}
	// cout<<dp[7][0]<<endl;
	cout<<sum-dp[(1<<n)-1][n-1]<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 82304
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if abs(a - b) <= k and abs(a - c) <= k and abs(a - d) <= k and abs(a - e) <= k and abs(b - c) <= k and abs(b - d) <= k and abs(b - e) <= k and abs(c - d) <= k and abs(c - e) <= k and abs(d - e) <= k:
  print("Yay!")
else:
  print(":(")

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int D=in(),N=in();
	
	if(N==100) cout << (int)(101*pow(100,D)) << endl;
	else cout << (int)(N*pow(100,D)) << endl;
	return 0;
}


Measured memory_bytes: 256