akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
    char suit;
    int value;
};

struct Card L[MAX/2 + 2], R[MAX/2 + 2];

void Merge(struct Card A[], int left, int mid, int right){
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;

    for (i=0; i<n1; i++) L[i] = A[left + i];
    for (i=0; i<n2; i++) R[i] = A[mid + i];
    L[n1].value = R[n2].value = SENTINEL;

    i = j = 0;
    for (k=left; k<right; k++){
        if (L[i].value <= R[j].value) A[k] = L[i++];
        else                          A[k] = R[j++];
    }
}

void MergeSort(struct Card A[], int left, int right){
    int mid;

    if (left+1 < right){
        mid = (left + right) / 2;
        MergeSort(A, left, mid);
        MergeSort(A, mid, right);
        Merge(A, left, mid, right);
    }
}

int Partition(struct Card A[], int p, int r){
    int i, j;
    struct Card t, x;

    x = A[r];
    i = p-1;
    
    for (j=p; j<r; j++){
        if (A[j].value <= x.value){
            i++;
            t = A[i];
            A[i] = A[j];
            A[j] = t;
        }
    }
    t = A[i+1];
    A[i+1] = A[r];
    A[r] = t;

    return i + 1;
}

void QuickSort(struct Card A[], int p, int r){
    int q;
    if (p<r){
        q = Partition(A, p, r);
        QuickSort(A, p, q-1);
        QuickSort(A, q+1, r);
    }
}

int main(){
    int i, n, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;

    scanf("%d", &n);

    for (i=0; i<n; i++){
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    MergeSort(A, 0, n);
    QuickSort(B, 0, n-1);

    for (i=0; i<n; i++){
        if (A[i].suit != B[i].suit) stable = 0;
    }

    if (stable == 1) printf("Stable\n");
    else            printf("Not stable\n");
    
    for (i=0; i<n; i++){
        printf("%c %d\n", B[i].suit, B[i].value);
    }
    return 0;
}


Measured memory_bytes: 4028
N, Q = map(int, input().split())
S = list(str(input()))

ans_list = []
fa = 0
ans = 0
for index, s in enumerate(S):
    if s == 'A' and fa == 0:
        fa = 1
        ans_list.append(ans)
    elif s == 'A' and fa == 1:
        ans_list.append(ans)
    elif s == 'C' and fa == 1:
        fa = 0
        ans += 1
        ans_list.append(ans)
    else:
        fa = 0
        ans_list.append(ans)
for _ in range(Q):
    l, r = map(int, input().split())
    print(ans_list[r-1] - ans_list[l-1])

Measured memory_bytes: 6800
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    getline(cin,s);
        
        
        for(int i=0;i<s.size(); i++){
            char c=s[i];
            if ('A'<=c && c<='Z'){
                c=c+32;
                
            }
            else if ('a' <=c && c <= 'z'){
                c=c-32;
            }
            cout <<c;
            
        
    }
 
     cout << endl;
}


Measured memory_bytes: 3156
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

ll N, x;
ll a[101010];

int main() {
  cin >> N >> x;
  rep(i, 0, N) { cin >> a[i]; }

  ll ans = max(0LL, a[0] - x);
  a[0] -= ans;
  ll prev = a[0];
  rep(i, 1, N) {
    ll diff = max(0LL, prev + a[i] - x);
    ans += diff;
    a[i] -= diff;
    prev = a[i];
  }

  cout << ans << endl;
}


Measured memory_bytes: 4344
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Comparator;
import java.util.Set;
import java.util.HashMap;
import java.util.Map;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    // 標準入力数値リスト用 int
    static List<Integer> inputIntList() throws Exception {
        List<String> strList = Arrays.asList(br.readLine().trim().split(" "));
        List<Integer> intList = new ArrayList<Integer>();
        for (String elem : strList){
            intList.add(Integer.parseInt(elem));
        }
        return intList;
    }

    // 標準入力数値配列用 integer 降順ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    public static void main(String[] args) throws Exception {
        // write your code here
        int [] nk = inputval();
        int n = nk[0];
        int k = nk[1];
        int [] al = inputval();
        Map<Integer, Integer> map = new HashMap<>();
        int ans = 0;

        for (int i = 0; i<n; i++){
            int a = al[i];
            if (map.containsKey(a)){
                map.replace(a,map.get(a)+1);
            }else{
                map.put(a,1);
            }
        }
        List<Integer> list = new ArrayList<>(map.values());
        Collections.sort(list);
        for (int j = 0; j < list.size()-k; j++){
            ans += list.get(j);
        }
        System.out.println(ans);

    }

}



Measured memory_bytes: 70100
#include<iostream> 
using namespace std; 
typedef long long ll; 
void solve() 
{ 
string s; 
cin>>s; 
  if(s=="ABC") 
    cout<<"ARC"; 
  else
    cout<<"ABC";
}
int main() 
{ 
		ios::sync_with_stdio(false); 
		cin.tie(NULL); 
		solve(); 
		return 0; 
}


Measured memory_bytes: 3656
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from bisect import bisect_left
def resolve():
    n=int(input())
    L=list(map(int,input().split()))
    L.sort()

    ans=0
    for i in range(n):
        a=L[i]
        for j in range(i+1,n):
            b=L[j]
            k=bisect_left(L,a+b)
            ans+=max(0,k-j-1)

    print(ans)
resolve()

Measured memory_bytes: 42716
/*
	written by Pankaj Kumar.
	country:-INDIA
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<pair<ll,ll>> vpl;
typedef vector<string> vs;
typedef map<ll,ll> ml;
typedef set<char>sc;
typedef set<ll> sl;
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
// define values.
#define mod 1000000007
#define phi 1.618
/* Bit-Stuff */
#define get_set_bits(a) (__builtin_popcount(a))
#define get_set_bitsll(a) ( __builtin_popcountll(a))
#define get_trail_zero(a) (__builtin_ctz(a))
#define get_lead_zero(a) (__builtin_clz(a))
#define get_parity(a) (__builtin_parity(a))
/*  Abbrevations  */
#define ff first
#define ss second
#define mp make_pair
#define line cout<<endl;
#define pb push_back
#define Endl "\n"
// loops
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
// Some print
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
#define cc ll test;cin>>test;while(test--)
// sort
#define all(V) (V).begin(),(V).end()
#define srt(V) sort(all(V))
#define srtGreat(V) sort(all(V),greater<ll>())
// function

ll power(ll x,ll y)
{
	ll res=1;
	while(y>0)
	{
		if(y%2==1)res*=x;
		y/=2; x*=x;
	}
	return res;
}
/* ascii value 
A=65,Z=90,a=97,z=122
*/
/*  -----------------------------------------------------------------------------------*/

ll solve()
{
	ll x;
	cin>>x;
	if(x==0)
		cout<<1<<endl;
	else
		cout<<0<<endl;
	return 0;
}

int main()
{
	//freopen("input.txt"a, "r", stdin);
	pan;
	solve();
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    int n,d;
    cin >> n >> d;
    int ans = 0;
    int x[10][10];

    REP(i,n) {
        REP(j,d) {
            cin >> x[i][j];
        }
    }

    FOR(i,0,n-1) {
        FOR(j,i+1,n) {
            int sum = 0;
            REP(k,d) {
                sum += pow(x[i][k] - x[j][k],2);
            }
            int sumq = sqrt(sum);
            sumq = pow(sumq,2);
            if (sum == sumq) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Wed Jan  2 22:49:46 2019
//
package main

import "fmt"

type point struct {
	t, x, y int
}

func (p point) distance() int {
	return abs(p.x) + abs(p.y)
}

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

func main() {
	var N int
	fmt.Scan(&N)

	ps := make([]point, N)
	for i := range ps {
		fmt.Scan(&ps[i].t, &ps[i].x, &ps[i].y)
	}

	for i := range ps {
		p := ps[i]
		if p.distance() > p.t {
			fmt.Println("No")
			return
		}

		if i > 0 {
			pred := ps[i-1]
			dist := abs(p.x-pred.x) + abs(p.y-pred.y)
			if dist > p.t-pred.t {
				fmt.Println("No")
				return
			}
		}

		if (p.t%2 == 0 && p.distance()%2 == 1) || (p.t%2 == 1 && p.distance()%2 == 0) {
			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")
}


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

//テストケースはあんまり見ないほうが良い。デバッグする能力が必要.
int main(){
    string s;
    cin >> s;
    rep(i,s.size()){
        cout << "x";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int N;
    int k = 0;
    string s, t;
    cin >> N >> s >> t;

    for(int i = 1; i <= N; i++) {
        if(t.substr(0, i) == s.substr(N-i, i)) {
            k = i;
        }
    }

    cout << 2*N - k;
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import math
N = int(input())
pf={}
m = N
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1

total = 0
for v in pf.values():
    val = int((-1 + math.sqrt(1 + 8 * v))/2)
    total += val
print(total)


Measured memory_bytes: 63716
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int MN=2e5+5;
const int mod=1e9+7;
int n,Ans,cnt0,cnt1;
#define fi first
#define se second
typedef pair<ll,ll>pll;
map<pll,int>mp,vis;
inline ll Gcd(ll a,ll b){return b?Gcd(b,a%b):a;}
inline ll qpow(ll a,ll b){
	reg ll res=1;
	while(b){
		if(b&1)res=res*a%mod;
		a=a*a%mod;b>>=1;
	}
	return res;
}
int main(){
	scanf("%d",&n);
	for(reg int i=1;i<=n;i++){
		static ll x,y,d;
		scanf("%lld%lld",&x,&y);
		if(!x&&!y)Ans++;
		else if(!x)cnt0++;
		else if(!y)cnt1++;
		else{
			d=Gcd(llabs(x),llabs(y));
			if(x<0)x=-x,y=-y;
			x/=d;y/=d;mp[make_pair(x,y)]++;
		}
	}
	reg int Res=(qpow(2,cnt0)+qpow(2,cnt1)-1)%mod;
	for(auto x:mp){
        if(!x.se)continue;if(vis[x.fi])continue;
		Res=1ll*Res*(qpow(2,x.se)+qpow(2,mp[make_pair(llabs(x.fi.se),(x.fi.se>0?-1:1)*x.fi.fi)])-1)%mod;
        vis[make_pair(llabs(x.fi.se),(x.fi.se>0?-1:1)*x.fi.fi)]=1;
	}
	printf("%d\n",((Res+Ans-1)%mod+mod)%mod);
	return 0;
}

Measured memory_bytes: 53716
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int main(){
    ll n, a, b, h, m;
    while(cin>>a>>b>>h>>m){
        ld ans=0, pi=3.14159265358979323846;
        ld ang1=2.0*pi*(h+m/60.0)/12.0;
        ld ang2=2.0*pi*m/60.0;
        ld ang=abs(ang1-ang2);
        ang=min(ang, 2*pi-ang);
        // cout<<ang1*180/pi<<" "<<ang2*180/pi<<" "<<ang*180/pi<<endl;
        ans=a*a+b*b-2.0*cos(ang)*a*b;
        ans=sqrt(ans);
        cout<<fixed<<setprecision(12)<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 4140
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 1e6+1;
 
typedef long long ll;
typedef long double ld;

ll small[N]; 
void sieve() 
{ 
    for(ll i = 1; i < N; i++) 
        small[i] = i; 
    for(ll i = 4; i < N; i += 2) 
        small[i] = 2; 
    for(ll i = 3; i * i < N; i += 2) 
    { 
        if(small[i] == i) 
        { 
            for(ll j = i * i; j < N; j += i)             
                if(small[j] == j) 
                    small[j] = i; 
        } 
    } 
} 

vector<ll> findfactor(ll x) 
{ 
    vector<ll> ret; 
    while (x != 1) 
    { 
        ret.push_back(small[x]); 
        x = x / small[x]; 
    } 
    return ret; 
} 
void test_case()
{
    ll n;
    cin >> n;
    vector<ll> v(n);
    sieve();
    for(ll i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    vector<bool> done(N, 0);
    bool flag = 0;
    for(ll i = 0; i < n; i++)
    {
        vector<ll> p = findfactor(v[i]);
        for(ll j = 0; j < p.size(); j++)
        {
            if(done[p[j]])
            {
                flag = 1;
                break;
            }
        }
        for(ll j = 0; j < p.size(); j++)
        {
            done[p[j]] = 1;
        }
        if(flag)
            break;
    }
    if(!flag)
    {
        cout << "pairwise coprime\n";
        return;
    }
    ll gg = v[0];
    for(int i = 1; i < n; i++)
    {
        gg = __gcd(gg, v[i]);
    }
    if(gg == 1)
    {
        cout << "setwise coprime\n";
        return; 
    }
    cout << "not coprime\n";


}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}


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

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> V(N);
    for (int i = 0; i < N; i++)
    {
        cin >> V.at(i);
    }

    int res = 0;
    for (int p = 1; p <= K && p <= N; p++)
    {
        for (int pl = 0; pl <= p; pl++)
        {
            int pr = p - pl;
            int s = 0;
            priority_queue<int> q;
            for (int i = 0; i < pl; i++)
            {
                s += V.at(i);
                q.push(-V.at(i));
            }
            for (int i = 0; i < pr; i++)
            {
                s += V.at(N - 1 - i);
                q.push(-V.at(N - 1 - i));
            }

            int mx = s;
            for (int i = 0; i < K - p; i++)
            {
                if (q.empty())
                    break;
                int b = q.top();
                q.pop();
                s += b;
                mx = max(mx, s);
            }
            res = max(res, mx);
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author kessido
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ESortedAndSorted solver = new ESortedAndSorted();
        solver.solve(1, in, out);
        out.close();
    }

    static class ESortedAndSorted {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.NextInt();
            int[] balls = new int[2 * n];
            for (int i = 0; i < 2 * n; i++) {
                if (in.next().charAt(0) == 'W') balls[i] = -in.NextInt();
                else balls[i] = in.NextInt();
            }
            int[][] dp = new int[n + 1][n + 1];
            for (int[] dpp : dp) Arrays.fill(dpp, (2 * n) * (2 * n) * 10);
            int[][][] cost = new int[2][n + 1][n + 1];
            boolean[][] saw = new boolean[2][n];
            dp[0][0] = 0;
            for (int i = 0; i < n * 2; i++) {
                int curr = balls[i];
                int par = balls[i] < 0 ? 0 : 1;
                curr = Math.abs(curr) - 1;
                int sum = 0;
                for (int j = curr + 1; j < n; j++) {
                    if (saw[par][j]) {
                        sum++;
                    }
                }
                cost[par][curr + 1][n] = sum;
                for (int j = n - 1; j >= 0; j--) {
                    if (saw[par ^ 1][j])
                        sum++;
                    cost[par][curr + 1][j] = sum;
                }
                saw[par][curr] = true;
            }
            for (int i = 0; i <= n; i++) {
                for (int j = 0; j <= n; j++) {
                    if (i != 0) dp[i][j] = Math.min(dp[i][j], dp[i - 1][j] + cost[0][i][j]);
                    if (j != 0) dp[i][j] = Math.min(dp[i][j], dp[i][j - 1] + cost[1][j][i]);
                }
            }
            out.println(dp[n][n]);
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine(), " \t\n\r\f,");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int NextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int main(){
  int s,s1,s2,s3;
  cin >> s;
  s1 = s % 10;
  s2 = (s / 10) % 10;
  s3 = (s / 100) % 10;
  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**12
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

#import sys,resource,bisect
import resource
from sys import setrecursionlimit
from resource import getrlimit,setrlimit
from bisect import bisect_left
def setrlim():
  setrecursionlimit(250000)
  soft,hard = getrlimit(resource.RLIMIT_STACK)
  # setrlimit works on ubuntu (and atcoder), but not on WSL
  setrlimit(resource.RLIMIT_STACK, (128*1024*1024,hard))

def dfs(u,j,dp):
    #ddprint(f"dfs {u=} {j=}")
    ans[u] = j
    for v in dst[u]:
        if ans[v]>=0:
            continue
        x = bisect_left(dp,a[v])
        tmp = dp[x]
        dp[x] = a[v]
        #ddprint(f"dfs {u=} {j=} {x=} {tmp=} av {a[v]} {dp=}")
        dfs(v,j+(1 if tmp==BIG else 0),dp)
        dp[x] = tmp

setrlim()
n = inn()
a = inl()
a[0:0] = [0]
dst = [{} for i in range(n+1)]
for i in range(n-1):
    u,v = inm()
    dst[u][v] = dst[v][u] = 1
ans = [-1]*(n+1)
dp = [BIG]*(n+1)
dp[0] = a[1]
dfs(1,1,dp)
for i in range(1,n+1):
    print(ans[i])


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int n, m;
  cin >> n >> m;
  vector< vector<int> > g(n), rg(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    g[u].push_back(v);
    rg[v].push_back(u);
  }

  vector<int> visit(n);
  vector<int> topo;
  function<void(int)> dfs = [&](int u) {
    visit[u] = 1;
    for (auto v : g[u]) {
      if (visit[v] == 0) {
        dfs(v);
      }
    }
    visit[u] = 2;
    topo.push_back(u);
  };

  for (int i = 0; i < n; i++) {
    if (visit[i] == 0) {
      dfs(i);
    }
  }

  vector<int> dp(n);
  int ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    int u = topo[i];
    for (auto v : rg[u]) {
      dp[u] = max(dp[u], dp[v] + 1);
    }
    ans = max(ans, dp[u]);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 14588
// D.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;


int main()
{
    int n, m;

    cin >> n >> m;
    vector<int>a(n), d;
    vector<pair<int,int>>p(m);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < m; i++) {
        int b, c;

        cin >> b >> c;

        p[i] = make_pair(c, b);

    }

    sort(p.begin(), p.end(), std::greater<pair<int,int>>());
    
    int key = 0;
    int i = 0;
    while (d.size() < n && key<m) {

        if (p[key].first <= a[i])break;
        if (p[key].second > 1) {
            if (p[key].first > a[i]) {
                d.push_back(p[key].first);
                p[key].second--;
                i++;
            }

        }
        else if (p[key].second==1){
            if (p[key].first > a[i]) {
                d.push_back(p[key].first);
                p[key].second--;
                i++;
            }
            key++;
        }
    }

    while (i < n) {
        d.push_back(a[i]);
        i++;
    }

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        ans += d[i];
    }

    cout << ans << endl;
}



Measured memory_bytes: 5040
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    odd = ['R', 'U', 'D']
    evn = ['L', 'U', 'D']

    res = YES
    for i, l in enumerate(S):
        if i%2 != 0:
            if not l in evn:
                res = NO
        else:
            if not l in odd:
                res = NO
    print(res)


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1400000;
char cn[CM], * ci = cn, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (72 - dig >> 3);
	return tmp;
}
char* di = cn;
inline void putint(int X) {
	if (X < 10) {
		*di++ = '0' + X;
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

int A[200001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	fread(cn, 1, CM, stdin);
	int N = getint();
	rep(i, N - 1) A[getint()]++;

	rep1(i, N) putint(A[i]);

	fwrite(cn, 1, di - cn, stdout);


	Would you please return 0;
}

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

void printVector(vector<int> A, int N) {
   for(int i=0; i<N; i++) {
      cout << A.at(i);
      if (i != N-1) cout << " ";
   }
   cout << endl;
} 

void insertionSort(vector<int> A, int N) {
   int i, j, v;
   for (i=0; i<N; i++) {
      v = A.at(i);
      j = i-1;
      while (j >= 0 && A.at(j) > v){
         A.at(j+1) = A.at(j);
         j--;
      }
      A.at(j+1) = v;
      printVector(A, N);
   }
}

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

   vector<int> A(N);
   for(int i=0; i<N; i++) cin >> A.at(i);

   insertionSort(A, N);

}


Measured memory_bytes: 3152
A,B,M = map(int,input().split())
a_price = list(map(int,input().split()))
b_price = list(map(int,input().split()))

dis = []
for _ in range(M):
  dis.append(list(map(int,input().split())))

total = min(a_price)+min(b_price)

dis_total = []
for k in range(M):
  dis_total.append(a_price[dis[k][0]-1]+b_price[dis[k][1]-1]-dis[k][2])

if total <= min(dis_total):
  print(total)
else:
  print(min(dis_total))

Measured memory_bytes: 42560
import java.util.Scanner;
public class Main{
 public static void main(String[] args) {
   Scanner kbd = new Scanner(System.in);
   int n =kbd.nextInt();
  double m =kbd.nextInt();
   int[] A= new int[n];
   for(int i=0;i<n;i++){
     A[i]=kbd.nextInt();
}
double s=0;
   for(int i=0;i<n;i++){
     s=s+A[i];
   }
   int c =0;
   double p=s/(4*m);
   for(int i=0;i<n;i++){
     if(A[i]>=p){
   c=c+1;
 }
}
 if(c>=m){
 System.out.println("Yes");
}else{
  System.out.println("No");
}
}
}

Measured memory_bytes: 21844
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long INF = (1LL << 60);
long long N, A[1 << 18];
long long X, Y, Z;
long long dp[55][2][2];

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = 3; i <= N; i++) Z ^= A[i];
	Y = A[1] + A[2]; X = A[1];

	// DP パート
	for (int i = 0; i < 55; i++) {
		dp[i][0][0] = -INF;
		dp[i][0][1] = -INF;
		dp[i][1][0] = -INF;
		dp[i][1][1] = -INF;
	}
	dp[54][1][0] = 0;
	for (int i = 53; i >= 0; i--) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				if (dp[i + 1][j][k] == -INF) continue;

				if ((Z & (1LL << i)) == 0) {
					// (0, 0) にする場合
					int v1 = i, v2 = j, v3 = k;
					int vamari = k * 2 + (long long)(Y / (1LL << i)) % 2LL;
					if ((X & (1LL << i)) != 0 && v2 == 1) v2 = 0;
					if (vamari == 1) v3 = 1;
					if (vamari == 0) v3 = 0;
					if (0 <= vamari && vamari <= 1) {
						dp[v1][v2][v3] = max(dp[v1][v2][v3], dp[i + 1][j][k]);
					}

					// (1, 1) にする場合
					int w1 = i, w2 = j, w3 = k;
					int wamari = k * 2 + (long long)(Y / (1LL << i)) % 2LL; wamari -= 2;
					if ((X & (1LL << i)) == 0 && w2 == 1) w2 = 2;
					if (wamari == 1) w3 = 1;
					if (wamari == 0) w3 = 0;
					if (0 <= wamari && wamari <= 1 && w2 <= 1) {
						dp[w1][w2][w3] = max(dp[w1][w2][w3], dp[i + 1][j][k] + (1LL << i));
					}
				}
				else {
					// (0, 1) にする場合
					int v1 = i, v2 = j, v3 = k;
					int vamari = k * 2 + (long long)(Y / (1LL << i)) % 2LL; vamari -= 1;
					if ((X & (1LL << i)) != 0 && v2 == 1) v2 = 0;
					if (vamari == 1) v3 = 1;
					if (vamari == 0) v3 = 0;
					if (0 <= vamari && vamari <= 1) {
						dp[v1][v2][v3] = max(dp[v1][v2][v3], dp[i + 1][j][k]);
					}

					// (1, 0) にする場合
					int w1 = i, w2 = j, w3 = k;
					int wamari = k * 2 + (long long)(Y / (1LL << i)) % 2LL; wamari -= 1;
					if ((X & (1LL << i)) == 0 && w2 == 1) w2 = 2;
					if (wamari == 1) w3 = 1;
					if (wamari == 0) w3 = 0;
					if (0 <= wamari && wamari <= 1 && w2 <= 1) {
						dp[w1][w2][w3] = max(dp[w1][w2][w3], dp[i + 1][j][k] + (1LL << i));
					}
				}
			}
		}
	}

	// 答え
	long long Answer = max(dp[0][0][0], dp[0][1][0]);
	if (Answer <= 0) cout << "-1" << endl;
	else cout << A[1] - Answer << endl;
	return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
int n,a[100005];
int dp[100005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//    cout<<fixed;
//    cout<<setprecision(10);

    cin>>n;
    for (int i=0;i<n;i++) cin>>a[i];
    //memset(dp,-1,sizeof(dp));
    dp[0]=0;
    for (int i=1;i<n;i++)
    {
        dp[i]=abs(a[i]-a[i-1])+dp[i-1];
        if (i>1)
            dp[i]=min(dp[i],abs(a[i]-a[i-2])+dp[i-2]);
    }
    cout<<dp[n-1]<<endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0 ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
 
}

const int MAXN = 200100;
const int modi = 1e9 + 7;

int ans[MAXN];

int32_t main(){
  fastio;
  int n,k;
  cin>>n>>k;
  int res=0;
  for(ll i=k; i>=1; i--){
        ll qtd = k/i;
        
        ans[i] = exp(qtd, n, modi);

        for(ll j=i+i; j<=k; j+=i){
            ans[i] = (ans[i] - ans[j] + modi)%modi;
        }

        res = (res + ((ans[i]*i)%modi))%modi;
    }
  
  cout<<mod(res,modi)<<endl;
  // Math -> gcd it all // chack MAXN // check ll
  //did you check N=1? Did you mix up N,M?
}

Measured memory_bytes: 4412
ch::String->String
ch c 
    | c == "a" = "vowel"
    | c == "i" = "vowel"
    | c == "u" = "vowel"
    | c == "e" = "vowel"
    | c == "o" = "vowel"
    | otherwise = "consonant"

main::IO ()
main = do
    s <- getLine
    putStrLn $ ch s

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

using namespace std;
#define all(c) begin(c), end(c)
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using ll = long long;
using pii = pair<int, int>;
#define VV(T) vector<vector< T > >

int n;
int a[25];
double dp[25][150000];
double inf = 1e9;

int main() {
    while (cin >> n) {
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
        }
        fill((double*)begin(dp), (double*)end(dp), inf);
        dp[0][1] = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = 1; j < 150000; ++j) {
                for (int k = j; k < 150000; k += j) {
                    double nxt = dp[i][j];
                    nxt = max(nxt, abs((double)(a[i] - k) / a[i]));
                    dp[i + 1][k] = min(dp[i + 1][k], nxt);
                }
            }
        }
        printf("%.10lf\n", *min_element(begin(dp[n]), end(dp[n])));
    }
}

Measured memory_bytes: 32476
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int[] n = {1, 1, 0, 2, 0, 0, 1, 0, 1, 0};
		String a = sc.next();
		int b = Integer.parseInt(a.substring(a.length() - 1));

		System.out.println(n[b] == 0 ? "hon" : n[b] == 1 ? "pon" : "bon");
	}
}

Measured memory_bytes: 35696
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  ll x;
  cin >> x;
  ll sum = 100, y = 0;
  while (x > sum) {
    sum += sum / 100;
    y++;
  }
  cout << y;
}


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

using namespace std;
using ll = long long;

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

    ll ans = 0;
    for (int c = 1; c < n; c++) {
        int nn = n - c;
        for (int a = 1; a * a <= nn; a++) {
            if (nn % a == 0) {
                if (a * a == nn) ans++;
                else ans += 2;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>

int main(){
  int i = 0;
  int num = 0;
  int min = 0;
  int max = 0;
  int *data;

  while(1){
    scanf("%d",&num);
    if(num >= 2 && num <= 200000){
      break;
    }
  }

  data = (int *)malloc(sizeof(int)* num);

  for(i = 0;i < num;i++){
    while(1){
      scanf("%d",&data[i]);
      if(data[i] >= 1 && data[i] <= 1000000000){
        break;
      }
    }
  }

  min = data[0];
  max = data[1] -min;

  for(i = 1;i < num;i++){
    if(max < data[i] - min){
      max = data[i] -min;
    }
    if(min > data[i]){
      min = data[i];
    }
  }
  printf("%d",max);
  printf("\n");
  free(data);
  return 0;
}



Measured memory_bytes: 2320
//TLE

/*
#include <iostream>
using namespace std;

int main(){
	int n = 0, s[5000000000000];
	cin >> n;
	for(int i = 1; i < n / 2; i ++){
		int j = 0;
		if( n % i == 0){
			s[j] = i + (n / i) - 2; //0 origin
			j++;
		}
	}
	
	//error check
	//for(int i = 0; i < n - 1; i++)cout << s[i] << " ";
	
	
	int min = n;
	for(int i = 0; i < n - 1; i++){
		if(s[i] < min && s[i] != 0){
			min = s[i];
		}
		if(s[i] == 0)i = n;
	}
	cout << min << endl;
	return 0;
}
*/



//TLE2

/*

#include <iostream>
using namespace std;

int main(){
	int n = 0, s[5000000000000];
	cin >> n;
	for(int i = 1; i < n / 2; i ++){ //
		if( n % i == 0){
			s[i] = i + (n / i) - 2; //0 origin
			cout << s[i] << " "; //error check
		}
	}
	
	//error check
	//for(int i = 0; i < n - 1; i++)cout << s[i] << " ";
	
	
	int min = n;
	for(int i = 0; i < n - 1; i++){
		if(s[i] < min && s[i] != 0){
			min = s[i];
		}
	}
	cout << min << endl;
	return 0;
}


*/


#include<iostream>
#include<math.h>
using std::cout;
using std::cin;
using std::endl;

int main(){
	long int n; cin >> n; //10桁以上はロング！
	long int i = sqrt(n); //from math.h
	//cout << i << endl;
	while(n % i != 0)i--;
	//cout << i << endl;
	//cout << n << endl;
	cout << n / i + i - 2 << endl; 
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int,input().split()))
q = int(input())
M=[list(map(int,input().split())) for _ in range(q)]
Sum = sum(A)
d={}

for i in range(n):
    if A[i] not in d:
        d[A[i]]=1
    else:
        d[A[i]]+=1

for i in M:
    prev = 0
    a,b=i[0],i[1]
    if a not in d:
        print(Sum)
        continue
    
    elif b in d:
        prev = d[b]*b
        d[b]+=d[a]
    else:
        d[b]=d[a]
    
    Sum += d[b]*b-d[a]*a-prev

    d.pop(a)
    print(Sum)


Measured memory_bytes: 100816
a,b=input().split()

a = int(a)
b = int(b)

wa = a + b
sa = a - b
seki = a * b

if wa >= sa and wa >= seki:
    print(str(wa))
elif sa >= wa and sa >= seki:
    print(str(sa))
else:
    print(str(seki))

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

A, B = map(int, input().split())

def is_prime(n):
    rn = int(n**0.5) + 1 
    for i in range(2, rn):
        if n % i == 0:
            return False
    return True

def divisor(a, b):
    if a < b:
        b, a = a, b
    res = []
    ra = int(a**0.5) + 1 
    for i in range(1, ra):
        if a % i == 0:
            if b % i == 0:
                res.append(i)
                if i != a / i and b % (a/i) == 0:
                    res.append(int(a / i))
            else:
                if i != a / i and b % (a/i) == 0:
                    res.append(int(a / i))
    return sorted(res)

Y = divisor(A, B)

ans = 0
for i in range(len(Y)):
    if is_prime(Y[i]):
        ans += 1

print(ans)

Measured memory_bytes: 41964
N, M, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = [0] + A
B = [0] + B
for i in range(1, N+1):
  A[i] += A[i-1]
for i in range(1, M+1):
  B[i] += B[i-1]
start = 0
end = N+1
while end-start > 1:
  sep = (start+end)//2
  if A[sep] <= K:
    start = sep
  else:
    end = sep
if start==N:
  alim = start
elif A[end]>K:
  alim = start
else:
  alim = end
blim = 0
start = blim
end = M+1
ans = alim
ansalim = -1
ansblim = -1
for _ in range(alim+1):
  Bmax = K-A[alim]
  #print("Bmax" , Bmax)
  while end-start > 1:
    sep = (start+end)//2
    #print(blim,start, end, sep)
    if B[sep] <= Bmax:
      start = sep
    else:
      end = sep
  if start==M:
    blim = start
  elif B[end]>Bmax:
    blim = start
  else:
    blim = end
  
  ans = max(blim + alim, ans)
  start = sep-1
  end = M+1
  alim -= 1
print(ans)

Measured memory_bytes: 41972
import java.util.Scanner;

public class Main {

    static double rate = 380000.0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double ans = 0;
        for (int i = 0; i < n; i++) {
            double x = sc.nextDouble();
            String u = sc.next();
            if(u.equals("JPY")) ans += x;
            else ans += x * rate;
        }

        System.out.println(ans);
        sc.close();
    }

}


Measured memory_bytes: 24656
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll n,m; cin>>n>>m;
    priority_queue<ll>q;
    rep(i,n){
        ll a; cin>>a;
        q.push(a);
    }
    rep(i,m){
        ll t=q.top();
        q.pop();
        q.push(t/2);
    }
    ll sum=0;
    while(!q.empty()){
        sum+=q.top();
        q.pop();
    }
    cout<<sum<<endl;
}





Measured memory_bytes: 1400
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
using namespace std;

int main(){
	int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin >> k;

	cout << a[k-1] << endl;

	return 0;
}



Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

H, W = getNM()
Ch, Cw = getNM()
Dh, Dw = getNM()
maze = [input() for i in range(H)]
Ch -= 1
Cw -= 1
Dh -= 1
Dw -= 1

# ワープを最低で何回使うか
# 上下左右2つ向こうまでの範囲内でワープできる
# 隣接する'.'が領域

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

pos = deque([[Ch, Cw]])
dp = [[-1] * W for i in range(H)]
dp[Ch][Cw] = 0

while len(pos) > 0:
    y, x = pos.popleft()
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        # 歩いて移動
        if 0 <= nx < W and 0 <= ny < H and maze[ny][nx] == "." and (dp[ny][nx] == -1 or dp[y][x] < dp[ny][nx]):
            # 0-1 bfs
            # 先頭に置く
            pos.appendleft([ny, nx])
            dp[ny][nx] = dp[y][x]
    # ワープ
    for i in range(-2, 3):
        for j in range(-2, 3):
            wy = y + i
            wx = x + j
            # 歩いて移動不可能でないと使わない
            if 0 <= wx < W and 0 <= wy < H and maze[wy][wx] == "." and dp[wy][wx] == -1:
                pos.append([wy, wx])
                dp[wy][wx] = dp[y][x] + 1

print(dp[Dh][Dw])

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

int main(void) {
  int N, ans = 0;
  cin >> N;
  for (int i = 1; i <= N; i += 2) {
    int cnt = 0;
    for (int j = 1; j <= i; j++) {
      if (i % j == 0) cnt++;
    }
    if (cnt == 8) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

import static java.lang.Integer.parseInt;

/**
 * Airport Codes
 */
public class Main {

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

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == 0) break;

			String[] ports = new String[n];
			int max = 0;
			for (int i = 0; i < n; i++) {
				ports[i] = genCode(br.readLine());
				max = Math.max(max, ports[i].length());
			}

			int k = 0;
			outer:
			for (int i = max; i >= 0; i--) {
				Set<String> codes = new HashSet<>();
				for (int j = 0; j < ports.length; j++) {
					String code;
					if (ports[j].length() <= i) {
						code = ports[j];
					} else {
						code = ports[j].substring(0, i);
					}
					if (codes.contains(code)) {
						break outer;
					} else {
						codes.add(code);
					}
				}
				k = i;
			}
			System.out.println(k == 0 ? -1 : k);
		} //end while
	} //end main

	static String genCode(String str) {
		StringBuilder sb = new StringBuilder();

		sb.append(str.charAt(0));
		for (int i = 1; i < str.length(); i++) {
			char c = str.charAt(i - 1);
			if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
				sb.append(str.charAt(i));
			}
		}
		return sb.toString();
	}
}

Measured memory_bytes: 27900
#include <cstdio>
#include <cstdlib>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
    while(x->left != NIL)x = x->left;
    return x;

}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){
    while(u != NIL && k != u->key){
        if(k < u->key){
            u = u->left;
        }else{
            u = u-> right;
        }
    }
    return u;

}

Node treeSuccessor(Node x){
    
    if(x->right != NIL)return treeMinimum(x->right);
    
    Node y = x->parent;
    while(y != NIL && x == y->right){
        x = y;
        y = y->parent;
    }
    return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left == NIL ||z->right == NIL)y = z;
  else y = treeSuccessor(z);
  
  if(y->left != NIL)x = y->left;
  else x = y->right;
  
  if(x != NIL)x->parent = y->parent;
  
  if(y->parent == NIL)root = x;
  else if(y == y->parent->left)y->parent->left = x;
  else y->parent->right = x;
  
  if(y != z)z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = (node *)malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL)root = z;
  else if(z->key < y->key)y->left = z;
  else y->right = z;
}

void inorder(Node u){
    if(u == NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(Node u){
    if(u == NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



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

int main() { 
    string n;
    cin >> n;
    
    for (int i = 0; i < 3; i++) {
        if (n[i] != n[2 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
inpl = lambda: list(map(int,input().split()))
N = int(input())
SP = []
for i in range(N):
    S, P = input().split()
    P = int(P)
    SP.append([S,P,i+1])
SP.sort(key=lambda x: x[0]+("%03d" % (100-x[1])))
for S, P, i in SP:
    print(i)

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
const ll INF = 1000000000000007;

using namespace std;

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

    vector <ll> sa(N);
    vector <ll> absa(N,0);

    ll iMin = INF;
    ll iMax = 0;

    REP(i,N)
    {
      cin >> tmp;
      //b = 0のとき
      sa[i] = tmp - (i+1);
    }

    sort(sa.begin(),sa.end());

    ll res = 0;

    if(N % 2 == 1)
    {
      ll b = sa[N/2];
      REP(i,N)
      {
        res += abs(sa[i] - b);
      }
    }
    else
    {
      ll b1 = sa[N/2];
      ll b2 = sa[N/2 - 1];
      REP(i,N)
      {
        res += abs(sa[i] - b1);
      }
      tmp = res;
      REP(i,N)
      {
        res += abs(sa[i] - b2);
      }
      res = min(res,tmp);
    }

    cout << res << endl;

    return 0;

}

Measured memory_bytes: 3328
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(input())
    c = list(input())
    w = c.count("R")
    hidari = c[:w]
    ans = 0
    for i in hidari:
        if i == "W":
            ans += 1
    print(ans)

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 11936