akhauriyash/Code-Regression huggingface dataset:
program pairs
  implicit none
  integer :: n, i
  integer(8) :: k, l = -1e18, r = 1e18, m, c
  integer(8), dimension(200000) :: a = 0, b = 0
  read(*,*) n, k
  read(*,*) a(1:n)
  call quick_sort(a(1:n))
  do while (r-l > 1)
    m = (l+r)/2
    c = 0
    do i = 1, n
      if (a(i) < 0) then
        c = c+count_lower(a(n:i+1:-1),a(i),m)
      else
        c = c+count_lower(a(i+1:n),a(i),m)
      end if
    end do
    if (c < k) then
      l = m
    else
      r = m
    end if
  end do
  write(*,'(i0)') l
contains
  function count_lower(a,b,c) result(r)
    integer(8), intent(in) :: a(:), b, c
    integer :: l, r, m
    l = 0
    r = size(a)+1
    do while (r-l > 1)
      m = (l+r)/2
      if (a(m)*b < c) then
        l = m
      else
        r = m
      end if
    end do
    r = r-1
  end
  recursive subroutine quick_sort(a)
    integer(8), intent(inout) :: a(:)
    integer :: n, l, r, m
    integer(8) :: p
    n = size(a,1)
    l = 1
    r = n
    m = (n+1)/2
    p = a(l)+a(m)+a(r)-max(a(l),a(m),a(r))-min(a(l),a(m),a(r))
    do
      do while (a(l) < p)
        l = l+1
      end do
      do while (a(r) > p)
        r = r-1
      end do
      if (l >= r) exit
      a(l) = xor(a(l),a(r))
      a(r) = xor(a(l),a(r))
      a(l) = xor(a(l),a(r))
      l = l+1
      r = r-1
    end do
    if (l-1 > 1) call quick_sort(a(1:l-1))
    if (n > r+1) call quick_sort(a(r+1:n))
  end
end program pairs

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	string s;
	cin>>s;
	rep(i,s.size()){
		cout<<"x";
	}
	re 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);



template <typename T>
class Seg_Tree{
public: // 0-index
  vector<T> dat;
  T initial,M;
  int n;
  T unite(T a,T b){//
    return a|b;
  }
  //Seg_Tree(int n0_=1,T initial_=1,T M_=1){
  //  initsize(n0_,initial_,M_);
  //}
  void initsize(int n0,T initial_,T M_){
    M = M_;
    initial = initial_;
    int k=1;
    while(1){
      if(n0<=k){
        n=k;
        dat.resize(2*n-1);
        for(int i=0;i<2*n-1;i++)dat[i]=initial;
        break;
      }
      k*=2;
    }
  }
  //i banme wo x nisuru
  void update(int i,T x){
    i += n-1;
    dat[i] = x;
    while(i>0){
      i = (i-1) / 2;
      dat[i] = unite(dat[i*2+1],dat[i*2+2]);
    }
  }
  //[a,b)
  T query0(int a,int b,int k,int l,int r){
    if(r<=a || b<=l)return initial;
    if(a<=l && r<=b)return dat[k];
    else{
      T vl = query0(a,b,k*2+1,l,(l+r)/2);
      T vr = query0(a,b,k*2+2,(l+r)/2,r);
      return unite(vl,vr);
    }
  }
  //return [a,b)
  T query(int a,int b){
    return query0(a,b,0,0,n);
  }
  T get_except(int ind){
    T vl = query(0,ind);
    T vr = query(ind+1,n);
    return unite(vl,vr);
  }
  T get_all(){
    return query(0,n);
  }
};


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  Seg_Tree<ll> sg;

  ll N,Q;
  string S;
  cin >> N >> S >> Q;
  sg.initsize(N+1,0,MOD);
  FOR(i,0,N){
    sg.update(i,(1<<(S[i]-'a')));
  }

  int x,l,r,i;
  char c;
  FOR(q,0,Q){
    cin >> x;
    if(x==1){
      cin >> i >> c;
      i--;
      sg.update(i,(1<<(c-'a')));
    }else{
      cin >> l >> r;
      l--,r--;
      cout << __builtin_popcount(sg.query(l,r+1)) << '\n';
    }
  }
}

Measured memory_bytes: 9116
import itertools
import math
n=int(input())
xy=[list(map(int,input().split())) for i in range(n)]

ans=0
for v in itertools.permutations(xy):
  x=[v[i][0] for i in range(n)]
  y=[v[i][1] for i in range(n)]

  for i in range(n-1):
    ans += ((x[i+1]-x[i])**2 + (y[i+1]-y[i])**2)**0.5

print(ans/(math.factorial(n)))

Measured memory_bytes: 3188
package main

import (
	"fmt"
)

var ar6 = make([]int, 6)
var ar9 = make([]int, 5)

var N int
var ans int

func main() {
	ar6[5] = 6
	for i := 4; i >= 0; i-- {
		ar6[i] = ar6[i+1] * 6
	}
	ar9[4] = 9
	for i := 3; i >= 0; i-- {
		ar9[i] = ar9[i+1] * 9
	}
	fmt.Scan(&N)
	ans = N
	f(0, 0, 0)
	fmt.Println(ans)
}

func f(n, c, sum int) {
	if n == 6 {
		rest := N - sum
		for _, v := range ar9 {
			c += (rest / v)
			rest %= v
		}
		if c+rest < ans {
			ans = c + rest
		}
		return
	}
	for i := 0; i <= 5; i++ {
		if N < sum+ar6[n]*i {
			return
		}
		f(n+1, c+i, sum+ar6[n]*i)
	}
}


Measured memory_bytes: 512
//実装が重そうな問題はある程度考えてから書く
//初期化を忘れずに（特に二分探索とか）
//コーナーケースを考えて（特に場合分けとか）
//不可解すぎるバグは配列外参照（配列の長さ）を検討
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b-1,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB emplace_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int long long
#define zero 0LL
#define pb PB
using namespace std;
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr ,greater<pr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
int dx[] = { 0,1,0,-1,0 }, dy[] = { 1,0,-1,0,0 };
const int SIZE1 =3e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 22;
const int SIZE = SIZE1;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
ut N, M, K, X, L, Y,H,W,Q;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE], nums[SIZE], maps[SIZE3][SIZE3], answer = zero;
LL A[SIZE], B[SIZE];
LL solve() {
	LL a, b;
	cin >> H >> W >> a >> b;
	cout << (H%a)*W + H * (W%b) - (H%a)*(W%b) << endl;
	return 0;
}
signed main() {
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	solve();
	cin >> N;
	return 0;
}


Measured memory_bytes: 10244
import std.stdio, std.conv, std.algorithm, std.range, std.array, std.string, std.uni;

void main() {
  auto a = readln.chomp;
  auto b = readln.chomp;
  auto res = zip(a,b).map!(a => a[0].to!string ~ a[1].to!string).join;
  if (a.length > b.length) res ~= a[$-1];
  writeln(res);
}


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

int main() {
	string s,s0;
	cin >> s;
	s0 = "";
	int len = s.size();
	for (int i = 0; i < len; ++i) {
		if (s.at(i) == 'B') {
			if (s0 != "") {
				s0.pop_back();
			}
		}
		else s0 += s.at(i);
	}

	cout << s0 << endl;
}

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

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define show(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)
#else
#define show(...) 42
#endif


#define f first
#define s second
#define endl "\n"
#define pb push_back
#define  oo 0x3f3f3f3f
#define limit 1000000007
#define int long long int
#define mod(x,m) ((x%m+m)%m)
#define ll long long
#define two pair<int,int>
#define all(v) v.begin(),v.end()
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repb(i,a,b) for(int i=(a);i>=(b);i--)
#define fastio std::ios::sync_with_stdio(false)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define input_from_file  freopen("input.txt", "r", stdin);


const int N = 4e5;  // limit for array size
int t[2 * N];

void modify(int p, int value,int n) {  // set value at position p
  for (t[p += n] = value; p > 1; p >>= 1) t[p>>1] = max(t[p],t[p^1]);
}

int query(int l, int r,int n) {  // sum on interval [l, r]
  int res = 0;
  for (l += n, r += n+1; l < r; l >>= 1, r >>= 1) {
    if (l&1) res = max(res,t[l++]);
    if (r&1) res = max(res,t[--r]);
  }
  return res;
}

signed main(){
 //input_from_file;
 int n; cin>>n;
 int ans = 0;
 vector<int> h(n), a(n);
 for(int i=0;i<n;i++) cin>>h[i];
 for(int i=0;i<n;i++) cin>>a[i];
 memset(t,0,sizeof t);
 for(int i=0;i<n;i++){
   int curr = a[i] + query(0,h[i]-1,n+1);
   ans = max(ans,curr);
   modify(h[i],curr,n+1);
 }
 cout<<ans<<endl;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;

int main()
{
  while (true) {
    int n;
    fscanf(stdin, "%d", &n);
    if (n == 0) { break; }
    vector<int> v(n);
    int sum = 0;
    for (int i = 0; i < n; ++i) {
      fscanf(stdin, "%d", &v[i]);
      sum += v[i];
    }
    double mean = sum * 1.0 / n;
    double alpha = 0;
    for (int i = 0; i < n; ++i) {
      alpha += (v[i] - mean) * (v[i] - mean);
    }
    alpha /= n;
    fprintf(stdout, "%.9f\n", sqrt(alpha));
  }
  return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll x; cin >> x;

    ll n = x / 100;
    ll r = x % 100;

    if(r <= n * 5){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for(int i=a;i<b;i++)
#define repds(i,a,b) for(int i=a+1;i<=b;i++)
#define rep(i,N) repd(i,0,N)
#define reps(i,N) repds(i,0,N)
#define debug(x) if(isDebugMode) cout<<#x<<"="<<x<<","
#define debugarr(arr,N,M){if(isDebugMode) rep(i,N+1){rep(j,M+1)\
	{if(arr[i][j]==INF)printf(" INF");\
		else printf(" %3d",arr[i][j]);} cout<<endl;}}
#define pb push_back
#define pob pop_back
#define cint(a) int a;cin>>a
#define cint2(a,b) int a,b;cin>>a>>b
#define cint3(a,b,c) int a,b,c;cin>>a>>b>>c
typedef long long ll;
typedef pair<int,int> P;
const int INF=100000000;
const int dx[4]={ 0, 1, 0,-1};
const int dy[4]={ 1, 0,-1, 0};

bool isDebugMode=true;
//--------------------------------------//

int main(){
	cint2(a,b);
	if(a+b==15) cout<<"+"<<endl;
	else if(a*b==15) cout<<"*"<<endl;
	else  cout<<"x"<<endl;
	return 0;
}


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

int main()
{
    string S;
    cin >> S;
    int N = S.size(), num = 0;
    bool check = true;

    while (num != N)
    {
        if (S.substr(num, 6) == "eraser")
        {
            num += 6;
        }
        else if (S.substr(num, 5) == "erase")
        {
            num += 5;
        }
        else if (S.substr(num, 7) == "dreamer" && S.substr(num + 5, 5) != "erase")
        {
            num += 7;
        }
        else if (S.substr(num, 5) == "dream")
        {
            num += 5;
        }
        else
        {
            check = false;
            break;
        }
    }
    if (check)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3728
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Map as Map
import Data.Array
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.Set as Set
import qualified Data.Sequence as Sq
import qualified Data.IntMap as IMap
import Data.Sequence (ViewL(..),ViewR(..),(><),(<|),(|>),Seq)

bsreadInt :: BC.ByteString -> Int
bsreadInt = fst . fromJust . BC.readInt

setadj :: [[Int]] -> IMap.IntMap [Int] -> IMap.IntMap [Int]
setadj [] adj = adj
setadj (x:xs) adj = setadj xs (IMap.insert a (b:cs) adj) 
                            where a = x!!0
                                  b = x!!1
                                  cs = if IMap.member a adj == True
                                       then (IMap.!) adj a
                                       else []

nsetadj :: [[Int]] -> IMap.IntMap [Int] -> IMap.IntMap [Int]
nsetadj xs adj = setadj (xs ++ (map reverse xs)) adj

main = do
    [n,m] <- map bsreadInt . BC.words <$> BC.getLine --n頂点，m本の辺
    ab <- map ((map bsreadInt . BC.words)) <$> replicateM m BC.getLine -- a-->b :path のリスト
    let q = Sq.singleton [1]
    let chk = Set.singleton 1
    print $ length $ filter (==False) [connectchk q n (nsetadj (ab \\ [ab!!(k-1)]) IMap.empty) chk | k <-[1..m]]
    --print $ length $ filter (==False) [connectchk q n (delete adjs) chk | k <- [1..m]]
    --print $ length $ filter (==False) [connectchk q n (Set.union (Set.fromList (ab \\ [ab!!(k-1)] ) ) (Set.fromList (map reverse (ab \\ [ab!!(k-1)] )) )) chk | k <- [1..m]]

connectchk :: Sq.Seq [Int] -> Int -> IMap.IntMap [Int] -> Set.Set Int -> Bool
connectchk q n adjs chk = foldr (&&) True [ (bsearch q n g adjs chk) /= [] | g <- [2..n] ]
         
adjset :: Int -> Int  -> IMap.IntMap [Int] -> Set.Set Int -> [Int]
adjset x n adjs chk  = (f adjs x) \\ Set.toList chk
                        where f adj a = if IMap.member a adj == True
                                        then (IMap.!) adj a
                                        else []

bsearch :: Sq.Seq [Int] -> Int -> Int -> (IMap.IntMap [Int]) -> Set.Set Int -> [Int]
bsearch q n g adjs chk = if Sq.length q == 0
                         then []
                         else if head (sqleft q) == g
                              then reverse $ sqleft q
                              else bsearch q2 n g adjs chk2
                                where qa = sqleft q
                                      q2 = (Sq.drop 1 q) >< (Sq.fromList add)
                                      add = [x : qa | x <- adjset (head qa) n adjs chk]
                                      chk2 = Set.union chk (Set.fromList (adjset (head qa) n adjs chk))
                                      
sqleft :: Seq a -> a
sqleft q = sqleft_(Sq.viewl q)
sqleft_ :: ViewL a -> a
sqleft_ (x :< xs) = x
sqright :: Seq a -> a
sqright q = sqright_(Sq.viewr q)
sqright_ :: ViewR a -> a
sqright_ (xs :> x) = x

    


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; }
vector<int> p,a,b,c,d;
ll dfs(int depth, const int n, const int m, const int q, int start){
    ll ans = 0;
    if(depth == n){
        for(int i=0; i<q; i++){
            if(p[b[i]-1]-p[a[i]-1]==c[i]){
                ans+=d[i];
            }
        }
        return ans;
    }else{
        for(int i=start; i<=m; i++){
            p[depth] = i;
            ans = max(ans,dfs(depth+1,n,m,q,i));
        }
    }
    return ans;
}
int main(){
    int n,m,q;
    cin>>n>>m>>q;
    p.resize(n);
    a.resize(q);
    b.resize(q);
    c.resize(q);
    d.resize(q);
    for(int i=0; i<q; i++) cin>>a[i]>>b[i]>>c[i]>>d[i];
    ll ans = 0;
    ans = dfs(0,n,m,q,1);
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3580
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  int n; cin >> n;
  vector<int> A(n);
  int b[n];
  rep(i,n) {
    cin >> A[i]; A[i]--;
    b[A[i]] = i+1;
  }
  rep(i,n) {
    if(i) cout << " ";
    cout << b[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 1664
import java.io.*;
import java.util.*;

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	void solve() throws IOException {
		int a = nextInt();
		int b = nextInt();
		if (a <= 0 && b >= 0) {
			out.println("Zero");
			return;
		}
		
		int cnt = a > 0 ? 0 : (b - a + 1);
		out.println(cnt % 2 == 1 ? "Negative" : "Positive");
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 8020
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


int main()
{
	int N;
	string S;
	cin >> N >> S;

	int count = 0;
	rep( i, N - 1 )
	{
		string x = S.substr( 0, i + 1 );
		string y = S.substr( i + 1 );

		int tmp = 0;
		map<char, int> m;
		rep( j, x.size() )
		{
			if ( ( y.find( x[j] ) != string::npos )
				 && ( m[x[j]] == 0 ) )
			{
				tmp++;
				m[x[j]]++;
			}
		}
		chmax( count, tmp );
	}

	cout << count << endl;

	return ( 0 );
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  int n, t;
  cin >> n >> t;
  vector<int> v;
  for (int i = 0; i < n; ++i) {
    int c, kita;
    cin >> c >> kita;
    if (kita <= t) {
      v.push_back(c);
    }
  }
  sort(v.begin(), v.end());
  if (!v.empty()) {
    cout << v.at(0) << endl;
  } else {
    cout << "TLE" << endl;
  }

}

Measured memory_bytes: 256
def bubble_sort(array):
    n = len(array)

    while True:
        flag = False
        for i in range(1, n)[::-1]:
            if array[i-1][1] > array[i][1]:
                tmp = array[i]
                array[i] = array[i-1]
                array[i-1] = tmp
                flag = True
        if not flag:
            break
    return array

def selection_sort(array):
    n = len(array)

    for i in range(n):
        min_idx = i
        for j in range(i, n):
            if array[j][1] < array[min_idx][1]:
                min_idx = j
        if min_idx != i:
            tmp = array[i]
            array[i] = array[min_idx]
            array[min_idx] = tmp
    return array

def accum_hcsd_order(array):
    hcsd_order = {}
    for item in array:
        if item[1] in hcsd_order:
            hcsd_order[item[1]].append(item[0])
        else:
            hcsd_order[item[1]] = [item[0]]
    return hcsd_order


def check_stable(array, hcsd_order):
    tgt_hcsd_order = accum_hcsd_order(array)

    for no, hcsd in hcsd_order.items():
        if len(hcsd) == 1:
            continue
        tgt_hcsd = tgt_hcsd_order[no]
        for src, tgt in zip(hcsd, tgt_hcsd):
            if src != tgt:
                return False
    return True


def main():
    n = int(input())
    array = [(x[0], int(x[1:])) for x in input().split()]
    str_stable_or_not = {True: "Stable", False: "Not stable"}

    hcsd_order = accum_hcsd_order(array)

    # bubble_sort
    array_b = array[:]
    array_b = bubble_sort(array_b)
    print(" ".join(map(lambda x: "{}{}".format(x[0],x[1]), array_b)))
    print(str_stable_or_not[check_stable(array_b, hcsd_order)])

    # selection_sort
    array_s = array[:]
    array_s = selection_sort(array_s)
    print(" ".join(map(lambda x: "{}{}".format(x[0], x[1]), array_s)))
    print(str_stable_or_not[check_stable(array_s, hcsd_order)])

    return

main()


Measured memory_bytes: 5620
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int x; cin >> x;
    if(x<1200){
        cout << "ABC" << endl;
    }
    else cout << "ARC" << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define pb push_back


int main()
{
    ll N, M, K;
    cin >> N >> M >> K;
    mat GF(N), GB(N);
    ll a, b;
    REP(i,0,M) {
        cin >> a >> b;
        --a; --b;
        GF[a].pb(b);
        GF[b].pb(a);
    }
    REP(i,0,K) {
        cin >> a >> b;
        --a; --b;
        GB[a].pb(b);
        GB[b].pb(a);
    }

    vec A(N), I(N);
    vector<bool> F(N, false);
    stack<ll> S, T;
    ll cnt, id = 0;
    REP(i,0,N) {
        if(!F[i]) {
            cnt = 1;
            S.push(i);
            T.push(i);
            F[i] = true;
            while(!S.empty()) {
                ll v = S.top(); S.pop();
                FORR(nv,GF[v]) {
                    if(!F[nv]) {
                        ++cnt;
                        S.push(nv);
                        T.push(nv);
                        F[nv] = true;
                    }
                }
            }
            while(!T.empty()) {
                ll v = T.top(); T.pop();
                A[v] = cnt;
                I[v] = id;
            }
            ++id;
        }
    }

    ll ans;
    REP(i,0,N) {
        ans = A[i] - 1 - SZ(GF[i]);
        FORR(nv,GB[i]) {
            if(I[i] == I[nv]) --ans;
        }
        PS(ans);
    }
    PR("");

    return 0;
}

/*



*/

Measured memory_bytes: 16116
if 1:
    N,W = map(int, input().split(' '))
    w,v = [],[]
    for i in range(N):
        w_,v_ = map(int, input().split(' '))
        w.append(w_)
        v.append(v_)
else:
    N,W = 4,6
    w = [2,3,4,3]
    v = [1,4,10,4]

w0 = w[0]

idxs = set()
for i in range(N+1):
    for j in range(3*i+1):
        if i*w0+j <= W:
            idxs.add(i*w0+j)
idxs = sorted(list(idxs))
idx_dict = {idx:i for i,idx in enumerate(idxs)}

dp = [[0 for j in range(len(idxs))] for i in range(N+1)]

for i in range(N):
    for j in range(len(idxs)):
        if idxs[j] < w[i]:
            dp[i+1][j] = dp[i][j]
        else:
            try:
                dp[i+1][j] = max([dp[i][j],dp[i][idx_dict[idxs[j]-w[i]]]+v[i]])
            except:
                dp[i+1][j] = dp[i][j]
        
print(max([max(dp_) for dp_ in dp]))

Measured memory_bytes: 45604
import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    a, b = list(map(int,ipti().split()))
    print(math.ceil(((b-1)/(a-1))))

if __name__ == '__main__':
    main()

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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef priority_queue< int, vector< int >, greater< int > >  minHeap;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define sz(v) v.size()
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define sqr(x) x*x
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ten(n) (int)1e##n
#define tenll(n) (lli)1e##n
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}


inline int addmod(int x ,int y){return (x%mod + y%mod)%mod;}
inline int submod(int x ,int y){return (x%mod - y%mod + mod)%mod;}
inline int mulmod(int x ,int y){return (x%mod *1LL* y%mod)%mod;}
inline int nextSubMask(int i , int mask) {return (i-1)&mask;} /// returns next smallest submask

void we_r_done(){cout<<"NO"; exit(0);}

void debug(bool ok , string mssg)
{
    if(ok)return;
    cout<<mssg;
    exit(0);
}

lli dp[66][55];

lli nCr(int n, int r)
{
 if(n==r) return dp[n][r] = 1;
 if(r==0) return dp[n][r] = 1;
 if(r==1) return dp[n][r] = n;
 if(dp[n][r]) return dp[n][r];
 return dp[n][r] = nCr(n-1,r) + nCr(n-1,r-1);
}

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

    //FastIO;

    cout<<setprecision(7)<<fixed;



    int n, A , B;
    cin>>n>>A>>B;
    lli a[n];
    map<lli,int>cnt;
    long double ans = 0;
    lli tot = 0;

    for(int i=0; i<n; i++){
        cin>>a[i];
        cnt[a[i]]++;
    }

    sort(a,a+n);

    map<lli,int>took;
    int AA = A;
    lli l = -1;
    for(int i=n-1; i>=0 && A ; i-- , A--){

        tot += a[i];
        took[a[i]]++;
        l = a[i];
    }

    ans = tot/(double)AA;

    lli ways = nCr(cnt[l] , took[l]);

    if(ans == l) for(int i=took[l]+1; B>=(AA+i-took[l]) &&  i<=cnt[l]; i++) ways += nCr(cnt[l] , i);



    cout<<ans<<endl<<ways;

    return 0;

}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?


Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.141592653289793;
using namespace std;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define lld long double
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> vp;
typedef vector<tuple<ll, ll, ll>> vt;
//vector<vector<ll>> vv(n, vector<ll>(n));

int main()
{
	int dx[] = { 1,0,-1,1,-1,1,0,-1 };
	int dy[] = { 1,1,1,0,0,-1,-1,-1 };
	int h, w;
	cin >> h >> w;
	vs s(h);
	REP(i, h) cin >> s[i];
	vector<vector<ll>> d(h, vector<ll>(w, 0));
	REP(i, h) {
		REP(j, w) {
			if (s[i][j] == '#')
			{
				REP(k, 8)
				{
					int x = i + dx[k], y = j + dy[k];
					if (x < 0 || h <= x) continue;
					if (y < 0 || w <= y) continue;
					d[x][y]++;
				}
			}
		}
	}
	REP(i, h) {
		REP(j, w) {
			if (s[i][j] == '#') cout << '#';
			else cout << d[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int fac[maxn];
int  inv[maxn];
int a[maxn];
int  n;
int  add;
int  fin[maxn];
int  id;
long long pow_mod(long long x)
{
    long long res = 1;
    long long n=mod-2;
    while (n)
    {
        if (n & 1)
            res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
int C(int x, int y)
{
    return ((1ll * fac[x] * inv[y] )% mod * inv[x - y] )% mod;
}
void init()
{
    fac[0] = 1;
    fac[1] = 1;
    for (int i = 2; i <= n; i ++)
        fac[i] = (1ll * fac[i - 1] * i) % mod;
    inv[n] = pow_mod(fac[n]);
    for (int i = n - 1; i >= 0; i --)
        inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
}
int main()
{
    scanf("%d",&n);
    n++;
    for (int i = 1; i <= n; i ++)
        scanf("%d",&a[i]);
        init();
    for (int i = 1; i <= n; i ++)
    {
        if (fin[a[i]]!=0)
        {
            add = i;
            id = a[i];
            break;
        }
        fin[a[i]] = i;
    }
    int com=n-add+fin[id]-1;
    for (int i = 1; i <= n; i ++)
    {
        int ans = C(n, i);
        if (i - 1 <= com)
            ans -= C(com, i - 1);
        printf("%d\n",(ans+mod)%mod);
    }
    return 0;
}


Measured memory_bytes: 2816
// 解き直し.
// ARC 085/ABC 078 解説.
// https://img.atcoder.jp/arc085/editorial.pdf
#include <iostream>

using namespace std;

typedef long long LL;

int main() {
    
    // 1. 入力情報取得.
    int N, M;
    cin >> N >> M;
    
    // 2. 期待値の合計を計算.
    // 2-1. (N - M)ケースの実行にかかる時間.
    // LL X = 100 * (N - M);
    
    // 2-2. Mケースの実行にかかる時間の期待値.
    // iケースの実行にかかる時間の期待値は, 入力例1 を 参考に考えると, 
    // i 回      で 通過 … 〇〇〇〇〇 ... 〇
    // (i + 1)回 で 通過 … ×〇〇〇〇 ... 〇
    // (i + 2)回 で 通過 … ××〇〇〇 ... 〇 or 〇×〇〇〇 ... 〇
    // (i + 3)回 で 通過 … ×××〇〇 ... 〇 or ×〇×〇〇 ... 〇 or 〇〇×〇 ... 〇
    // 
    // のように考えると, 数式的には, 以下のように表せる.
    // (i * 1900) * (1 / 2 の i乗) + 
    // ((i + 1) * 1900) * (1 / 2 の (i + 1)乗) * 1通り(初回間違い) + 
    // ((i + 2) * 1900) * (1 / 2 の (i + 2)乗) * 2通り(初回間違い or 2回目間違い) + 
    // ((i + 3) * 1900) * (1 / 2 の (i + 3)乗) * 3通り(初回間違い or 2回目間違い or 3回目間違い) + ...
    // 
    // 上記を, E[i] と置いた場合, E[i + 1] との間に, 次のような関係式がある.
    // E[i + 1] - E[i] * (1 / 2) = 
    // 1900 * (1 / 2 の (i + 1)乗) + 1900 * (1 / 2 の (i + 2)乗) * 1通り + 1900 * (1 / 2 の (i + 3)乗) * 2通り ...
    // = 1900 * (1 / 2 の (i + 1)乗) * {1 + ((1 / 2) の 1乗) * 1通り + ((1 / 2) の 2乗) * 2通り + ...}
    // = 5700 * (1 / 2 の (i + 1)乗)
    // 
    // よって, E[i] = i * 5700 * (1 / 2 の i乗) と分かる.
    // E[1] = 2850[ms] となり, 3800[ms] と異なるので, 誤答となってしまう.
    // 
    
    // 2-3. 解答参照した.
    // p = 1 / (2 の M乗)
    // y = x / p = (1900M + 100(N − M)) × (2 の M乗)
    LL X = 1900 * M + 100 * (N - M);
    X = X << M;
    
    // 3. 出力 ～ 後処理.
    cout << X << endl;
    return 0;
    
}

Measured memory_bytes: 256
import bisect

N = int(input())
Bs = list(map(int, input().split()))

As = []
while Bs:
  f = 0
  for i in range(len(Bs)-1,-1,-1):
    if Bs[i] == i + 1:
      f = 1
      As.append(Bs.pop(i))
      break
  if f == 0:
    print('-1')
    exit()
    
for a in As[::-1]:
  print(a)

Measured memory_bytes: 63732
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = INT_MAX;
// clang-format on

int N, K;
int x[MAX_N + 1];
int w[MAX_N + 2];

int main(void)
{
  cin >> N >> K;
  REP(i, N) { cin >> x[i]; }
  int ans = INT_MAX;
  for (int l = 0; l < N - K + 1; l++) {
    int r = l + K - 1;
    ans = min(ans, abs(x[l]) + abs(x[r] - x[l]));
    ans = min(ans, abs(x[r]) + abs(x[r] - x[l]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define ALL(i) i.begin(),i.end()
#define SZ(i) ll(i.size())
#define MEM(i,n) memset(i,(n),sizeof(i))
#define X first
#define Y second
#define eb emplace_back
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template <typename T> void _do(T &&x){cerr<<x<<endl;}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define debug(...)
#define endl '\n'
#endif

const ll INF = 0x3f3f3f3f3f3f3f3f;

ll n,k,a[100003];
ll mx[50],pre[50],cnt[50];
int main () {
	IOS();
	cin >> n >> k;
	REP (i,n) {
		cin >> a[i];
	}
	
	REP (i,50) {
		REP (j,n) {
			cnt[i] += (a[j] & (1LL<<i)) > 0;
		}	
		mx[i] = max(cnt[i],n-cnt[i]) * (1LL<<i);
		cnt[i] = cnt[i] * (1LL<<i);
		pre[i] =  mx[i];
		if (i) {
			pre[i] += pre[i-1];
		}
	}
	
	k++;
	ll ans = 0,sum = 0;
	
//	REP (i,50) {
//		cout << cnt[i] << " ";
//	}
//	cout << endl;
//	
//	REP (i,50) {
//		cout << mx[i] << " ";
//	}
//	cout << endl;
	for (ll i=49;i>=0;i--) {
		if (k & (1LL<<i)) {	
			ans = max(ans,sum+cnt[i]+pre[i-1]);
			sum += n*(1LL<<i) - cnt[i];
		} else {
			sum += cnt[i];
		}
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int  N = sc.nextInt();
		Long A[] = new Long[N+2] ;
		Long B[] = new Long[N+1] ;

		for( int i = 1 ; i <= N + 1; i ++ ) {
			A[i] = sc.nextLong();
		}
		for( int i = 1 ; i <= N ; i ++ ) {
			B[i] = sc.nextLong();
		}

		//
		Long yoryoku = 0L ;
		Long mCountSum = 0L ;
		for( int i = 1 ; i <= N ; i ++ ) {
			Long mCount = 0L ;//モンスターを倒してもらえる人数
			if(yoryoku <= A[i]) {//余力より多い場合
				mCount =  yoryoku ;//まず余力分を倒す
				Long nokori = A[i] - yoryoku ;//残りのモンスター数
				if(nokori <= B[i]) {//残りを倒せるなら
					mCount = A[i] ;//全滅させる
					yoryoku = B[i] - nokori ; //余力を更新
				}else {//倒せないなら倒せるだけ
					mCount += B[i] ;
					yoryoku = 0L ;
				}
			}else {//余力より少ないモンスターなら
				mCount = A[i] ; //全滅させる
				yoryoku = B[i] ; //すべてを余力にする
			}
			mCountSum += mCount ;
		}
		//最後の町
		if(0 < yoryoku) {
			if(yoryoku <= A[N+1]) {//余力より多い場合
				mCountSum += yoryoku ;
			}else {
				mCountSum += A[N+1] ; //全滅させる
			}
		}


		System.out.println(mCountSum);
	}
}


Measured memory_bytes: 96436
n = gets.chomp.to_i
card = gets.split(" ").map(&:to_i).sort.reverse

alice = 0
bob = 0
i = 0
n.times do
  alice += card[i] if i%2 == 0
  bob += card[i] if i.odd?
  i += 1
end

puts alice - bob

Measured memory_bytes: 1788
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  set<ll> failed_set;
  set<ll> checked_num;
  for (int i = 0; i < N; i++) {
    for (int j = 2; j * A[i] <= A[N - 1]; j++) {
      failed_set.insert(j * A[i]);
    }
    if (checked_num.find(A[i]) != checked_num.end()) {
      failed_set.insert(A[i]);
    }
    checked_num.insert(A[i]);
  }

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    if (failed_set.find(A[i]) == failed_set.end()) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 58572
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 2e5 + 10;
const int INF = 1e9 + 10;

int main(){
	int n;	scanf("%d", &n);
	int l, r;
	int sum = 0;
	for(int i = 0; i < n; ++i) {
		scanf("%d%d", &l, &r);
		sum += (r - l + 1);
	}
	printf("%d\n", sum);
	return 0;
}	

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,Q;
int A[101010],B[101010];
int D[101010];
int yes[101010];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q;
	FOR(i,N) D[i]=i;
	FOR(i,Q) {
		cin>>A[i]>>B[i];
		A[i]--,B[i]--;
	}
	for(i=Q-1;i>=0;i--) {
		swap(D[A[i]],D[B[i]]);
	}
	int cur=0;
	yes[D[0]]=1;
	if(cur) yes[D[cur-1]]=1;
	if(cur<N-1) yes[D[cur+1]]=1;
	FOR(i,Q) {
		if(A[i]==cur) cur=B[i];
		else if(B[i]==cur) cur=A[i];
		swap(D[A[i]],D[B[i]]);
		if(cur) yes[D[cur-1]]=1;
		if(cur<N-1) yes[D[cur+1]]=1;
	}
	
	
	
	cout<<count(yes,yes+N,1)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 1536
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,p[200111];
ll v[200111];
int ls[200111],rs[200111],sz[200111];
vector<pair<ll,ll> > q[200111],nq,tnq;
void standardize(int x)
{
	tnq.clear();
	for(int i=0;i<nq.size();i++)tnq.PB(MP(nq[i].SS,nq[i].FF));
	sort(tnq.begin(),tnq.end());
	q[x].resize(nq.size()*2);
	merge(nq.begin(),nq.end(),tnq.begin(),tnq.end(),q[x].begin());
//	nq.clear();
//	for(int i=0;i<q[x].size();i++)if(q[x][i].FF>q[
}
bool check(ll lim)
{
//	cerr<<"check:"<<lim<<endl;
	for(int i=n;i>=1;i--)
	{
		q[i].clear();
		if(!ls[i])
		{
			q[i].PB(MP(v[i],v[i]));
//		for(int j=0;j<q[i].size();j++)cerr<<q[i][j].FF<<","<<q[i][j].SS<<" ";cerr<<endl;
			continue;
		}
		if(sz[ls[i]]>sz[rs[i]])swap(ls[i],rs[i]);
		ll clim=lim+2*v[i];
		int it=0;
		ll mn=1ll*mod*mod;
		nq.clear();
		for(int j=0;j<q[ls[i]].size();j++)
		{
			while(it<q[rs[i]].size()&&q[rs[i]][it].FF+q[ls[i]][j].SS<=clim)
			{
				mn=min(mn,q[rs[i]][it].SS);
				it++;
			}
			if(mn<1ll*mod*mod)nq.PB(MP(q[ls[i]][j].FF,mn));
		}
		standardize(i);
//		swap(q[i],nq);
//		for(int j=0;j<q[i].size();j++)cerr<<q[i][j].FF<<","<<q[i][j].SS<<" ";cerr<<endl;
	}
	return q[1].size()>0;
	for(int i=0;i<q[1].size();i++)
	{
		if(q[1][i].FF<=lim&&q[1][i].SS<=lim)return true;
	}
}
int main()
{
	geti(n);
	ll l=0,r=0;
	for(int i=2;i<=n;i++)
	{
		getii(p[i],v[i]);
		v[i]+=v[p[i]];
		if(!ls[p[i]])ls[p[i]]=i;
		else rs[p[i]]=i;
		r=max(r,v[i]*2);
	}
	for(int i=n;i>=1;i--)sz[i]++,sz[p[i]]+=sz[i];
	while(l<=r)
	{
		ll mid=l+r>>1;
		if(check(mid))r=mid-1;
		else l=mid+1;
	}
	cout<<l<<endl;
	return 0;
}


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

long dp[111][10000];
int N, K, a;

int main()
{
    cin >> N;
    cin >> a;
    dp[1][a]++;
    for (int i = 2; i <= N; i++)
    {
        cin >> a;
        for (int j = 0; j <= 20; j++)
            dp[i][j + a] += dp[i - 1][j];
        for (int j = a; j <= 20; j++)
            dp[i][j - a] += dp[i - 1][j];
    }
    cout << dp[N][0] << endl;
}



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

int main() {
    int ans=0;
    for(int i=0;i<4;i++)
    {
        char a;
        cin>>a;
        if(a=='+')ans++;
        else ans--;
    }
    cout<<ans<<"\n";
	// your code goes here
	return 0;
}


Measured memory_bytes: 256
loop do
h,w = gets.split.map {|eee|eee.to_i}
break if h == 0 and w == 0
h.times do |i|
  if i == 0 or i == h-1
    w.times do
      print("#")
    end
    print("\n")
  else
    if w <= 2
      w.times do
        print("#")
      end
      print("\n")
    else
      print("#")
      (w-2).times do
        print(".")
      end
      print("#\n")
    end
  end
end
  print("\n")
end


Measured memory_bytes: 8712
#include <stdio.h>

int main(){
  char buf[3][4];
  int i,j;
  for(i=0;i<3;i++){
    for(j=0;j<4;j++){
      scanf("%c",&buf[i][j]);
    }
  }
  for(int count=0,i=0,j=0;count<3;count++)
    printf("%c",buf[i++][j++]);

  return 0;
}


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

int main()
{
  string O,E;cin>>O>>E;string S;
  for(int i=0;i<(int)E.size();i++){S+=O[i];S+=E[i];}
  if(O.size()>E.size())S+=O[O.size()-1];
  cout<<S; 
}

Measured memory_bytes: 3588
#include <iostream>

int main()
{
	int m, f, rr;
	while (std::cin >> m >> f >> rr && !(m == f && f == rr && rr == -1))
	{
		int r = m + f;
		if (m == -1 || f == -1)
			std::cout << "F\n";
		else
		{
			if (r >= 80)
				std::cout << "A\n";
			else if (r >= 65)
				std::cout << "B\n";
			else if (r >= 50)
				std::cout << "C\n";
			else if (r >= 30 && rr >= 50)
				std::cout << "C\n";
			else if (r >= 30)
				std::cout << "D\n";
			else
				std::cout << "F\n";
		}
	}
	return 0;
}


Measured memory_bytes: 3028
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define forep(i, a, b) for(int64_t i=(a);i<(b);++i)
#define all(obj) (obj).begin(), (obj).end()
#define in(x) cin >> (x)
#define out(y) cout << (y) << "\n"
#define i64 int64_t
#define str string
using namespace std;
void Main() {
	/*----------------------------------------------------------------------------------------------------*/
	str S; in(S);
	cout << S[0] << S[1] << S[2];

	/*----------------------------------------------------------------------------------------------------*/
}
int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	Main();
	return 0;
}

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

int main(){
	int n; cin>>n;
	vector<int> h(n+1, INT_MAX);
	for(int i=0; i<n; i++) cin>>h[i+1];
	vector<int> dp(h.size());
	for(int i=2; i<dp.size(); i++){
		dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
	}
	cout<< dp[n] <<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,x,sum;
  cin>>N>>K;
  sum=0;
  
 for(int i=0;i<N;i++){
 cin>>x;
   if(K-x<x){
   sum+=2*(K-x);
   }else{
   sum+=2*x;
   }
 }
 cout<<sum<<endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	bool distinct = true;
	for (int i = 1; i < n; i++)
		if (a[i-1] == a[i])
			distinct = false;
	if (distinct) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 1024