akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int n;
	int o=0;
	int total=0;

	cin>>n;

	for(int i=1; i<n+1; i+=2){
		o=0;
		for(int j=1; j<n+1; j++){
			if(i%j==0){
				o+=1;
			}
		}
		if(o==8){
			total+=1;
		}
	}
	cout<<total<<endl;


	return 0;
}


Measured memory_bytes: 256
n = int(input())

towns = []
count = 0
lenSum = 0

for i in range(n) :
    tmp = list(map(int, input().split()))
    towns.append(tmp)

for p in range(len(towns)-1) :
    for q in range(p+1, len(towns)) :
        lenSum += ((towns[p][0] - towns[q][0]) ** 2 + (towns[p][1] - towns[q][1]) ** 2) ** 0.5
        count += 1

print(lenSum / count * (n - 1))

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int N = scanner.nextInt();
        long[] list = new long[N];
        for (int i = 0; i < N; i++) {
            list[i] = scanner.nextLong();
        }


        long min =-1000000000;
        long max = 1000000000;

        long v = 0;
        while (true) {
            long mid = (min + max) /2;
            long v1 = search(mid - 1, list);
            long v2 = search(mid, list);
            long v3 = search(mid + 1, list);
            if (v1 < v2) {
                max = mid;
            } else if (v3 < v2) {
                min = mid;
            } else {
                v = mid;
                break;
            }
        }

        long ans = 0;
        for (int i = 0; i < N; i++) {
            ans += Math.abs(v - list[i]);
            v++;
        }

        System.out.println(ans);
    }

    private long search(long v, long[] list) {
        long ans = 0;
        for (int i = 0; i < list.length; i++) {
            ans += Math.abs(v - list[i]);
            v++;
        }
        return ans;
    }

    private class MyScanner {
        String[] s;int i;BufferedReader br;String reg = " ";
        MyScanner () { s = new String[0];i = 0;br = new BufferedReader(new InputStreamReader(System.in)); }
        public String next() {
            try {
                if (i < s.length) return s[i++]; String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0); i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


Measured memory_bytes: 49876
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#define line cout << endl
using namespace std;
int n, k, p[1005];
int main () {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
	}
	sort (p + 1, p + n + 1);
	int ans = 0;
	for (int i = 1; i <= k; i++) {
		ans += p[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;

int main(void) {

  int n, k; cin >> n >> k;
  string s; cin >> s;
  char c = s[k-1];
  s[k-1] = c - 'A' + 'a';
  cout << s << endl;


  return 0;
}



// EOF


Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			ArrayList<Integer> list = new ArrayList<Integer>();
			int[] b = new int[n];
			int count = 0;
			int p;
			
			for(int i=1;i<n;i++){
				p = (i*i)%n;
				if(list.contains(p)==false){
					list.add(p);
					b[count] = p;
					count++;
				}
			}

			int[] ans = new int[(n-1)/2+1];
			
			for(int i=0;i<count;i++){
				for(int j=0;j<count;j++){
					if(i==j) continue;
					p = b[i]-b[j];
					if(p<0) p = p+n;
					if(p>(n-1)/2) p = n-p;
					ans[p]++;
				}
			}

			for(int i=1;i<=(n-1)/2;i++) System.out.println(ans[i]);
		}	
	}	
}

Measured memory_bytes: 27840
import java.io.PrintWriter

fun main(args : Array<String>) {
//    for (i in 1..100000) print("1 ")
//    if (true) return
    val printWriter = PrintWriter(System.out)
    fun println(s : String) = printWriter.println(s)
    fun println(i : Int) = printWriter.println(i)
    val (n, l) = readLine()!!.split(' ').map(String::toInt)
    val a = readLine()!!.split(' ').map(String::toInt)
    var q = -1
    for (i in 0..n - 2) {
        if (a[i] + a[i + 1] >= l) q = i;
    }
    if (q == -1) println("Impossible") else {
        println("Possible")
        for (i in 0..q - 1) println(i + 1)
        for (i in n - 2 downTo q) println(i + 1)
    }
    printWriter.close()
}

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

using ll = long long;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}

// 最大公約数
ll gcd(ll a, ll b) {
   if(b == 0) return a;
   return(gcd(b, a % b));
}

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

int main() {
  int N;  cin >> N;
    ll T, ans = 1LL;
    for(int i=0; i<N; i++){
        cin >> T;
        ans = lcm(ans, T);
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 256
$r=0..8
def f
a=yield$m
b=yield$c
$r.map{|i|l=a[i];(?1..?9).map{|d|(l-[d]).size<8&&$r.map{|j|l[j]==d&&b[i][j]=?*}}}
$m=yield a
$c=yield b
end
puts ("1\n"..gets).map{$c=$r.map{[" "]*9};$m=$r.map{|i|gets.chop.split}
f{|a|a}
f &:transpose
f{|a|a.map{|l|l.each_slice 3}.each_slice(3).flat_map{|i,*j|i.zip(*j).map &:flatten}}
$r.map{|i|$c[i].zip($m[i])<<?\n}*""}*?\n

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

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;

main(){
    int x, a ,b;
    scanf("%d %d %d",&x,&a,&b);
    int value = a -b;
    if(value >= 0) printf("delicious");
    else if(value < 0){
        value *= -1;
        if(value > x) printf("dangerous");
        else printf("safe");
    }
}

Measured memory_bytes: 256
import Control.Monad

main :: IO ()
main = do
  [n,a,b] <- map read . words <$> getLine
  s <- getLine
  forM_ (solve s a b 0 0) $ \t -> putStrLn $ case t of
    True -> "Yes"
    False -> "No"

solve :: [Char] -> Int -> Int -> Int -> Int -> [Bool]
solve [] _ _ _ _ = []
solve (c:cs) a b po fo = case c of
  'a' -> if po < a+b
    then True : solve cs a b (po+1) fo
    else False : solve cs a b po fo
  'b' -> if po < a+b && fo < b
    then True : solve cs a b (po+1) (fo+1)
    else False : solve cs a b po fo
  'c' -> False : solve cs a b po fo

Measured memory_bytes: 5372
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const ll MOD2=998244353;
const double PI=acos(-1);
const ll INF=1e18;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n,m;
  cin >> n >> m;
  vl x(n),K(m),M(m,0);
  rep(i,n){
    cin >> x[i];
    K[x[i]%m]++;
  }
  sort(x.begin(),x.end());
  ll cnt=1;
  rep(i,n-1){
    if(x[i]==x[i+1]){
      cnt++;
    }
    else{
      M[x[i]%m]+=cnt/2;
      cnt=1;
    }
  }
  M[x[n-1]%m]+=cnt/2;
  ll ans=0;
  rep(i,m){
    if(i!=0&&2*i!=m){
    ll z=min(K[i],K[(m-i)%m]);
    ans+=z;
    M[i]=min(M[i],K[i]-z);
    K[i]-=z;
    K[(m-i)%m]-=z;
    }
    if(i==0||2*i==m){
      ans+=K[i]/2;
      K[i]-=(K[i]/2)*2;
    }
  }
  rep(i,m){
    M[i]=min(M[i],K[i]/2);
  }
  rep(i,m){
    if(M[i]>=1){
      ans+=M[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[1000000];
int main(){
    int n; cin >> n;
    ll ans = 0;
    for(int i = 0; i < n; ++i){
        int x; cin >> x;
        ans += x;
        a[x]++;
    }
    int q; cin >> q;
    for(int i = 0; i < q; ++i){
        int x, y; cin >> x >> y;
        ans = ans - x * a[x];
        ans = ans + y * a[x];
        a[y] += a[x];
        a[x] = 0;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4304
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
typedef long long ll;
 
int main() {
    int N,Q;cin >> N >> Q;
    string s;cin >> s;
    int l,r;
    vector<int>t(N);
    t[0]=0;
    for(int i=0;i<N;i++){
        t[i+1]=t[i];
        if(s[i]=='A' && s[i+1]=='C')t[i+1]+=1;
    }
    
    for(int i=0;i<Q;i++){
        cin >> l >> r;
        cout << t[r-1]-t[l-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
s = int(input())

if s <= 10 ** 9:
    print(0,0,0,1,s,0)
    exit()
elif s == 10 ** 18:
    print(0,0,10**9,0,0,10**9)
    exit()

x2 = 10 ** 9
y2 = 1

x3 = x2 - (s % x2)
y3 = s // x2 + 1

print(0, 0, x2, y2, x3, y3)


Measured memory_bytes: 3060
H,W = map(int, input().split())
fields = [list(input()) for i in range(H)]
# print(fields)

# seen = [False] * (H*W+1)
seen = [[False] * W for i in range(H)]
mv = [(0,1),(0,-1),(1,0),(-1,0)]
from collections import deque
from collections import defaultdict
ans  = 0
for i in range(H):
    for j in range(W):
        if seen[i][j]: continue
        # print("i,j",i,j)
        d = defaultdict(int)
        q = deque()
        q.append((i,j))
        # d[fields[i][j]] += 1
        while len(q) > 0:
            h,w = q.popleft()
            s = fields[h][w] #そこの文字列
            for dh, dw in mv:
                if 0 <= h + dh < H and 0 <= w + dw < W:
                    if seen[h+dh][w+dw]:continue
                    t = fields[h+dh][w+dw] #隣接セルの文字
                    if t == s:continue #同じ場合は加算せず
                    # print(s,t,h,w,h+dh,w+dw,"debug")
                    d[s] += 1
                    q.append((h+dh,w+dw))
                    seen[h+dh][w+dw] = True
        ans += d["#"]*d["."]
# print(seen)
print(ans)

Measured memory_bytes: 6128
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
int px[]={1,1,-1,-1};
int py[]={1,-1,1,-1};
struct edge{
	int from,to,next,id;
	ll v;
}e[100];
int head[10],q[10],tot;
int from[10],vis[10];
ll dis[10],ans;
void add(int x,int y,int id,ll v){
	e[++tot]=(edge){x,y,head[x],id,v};
	head[x]=tot;
}
void SSSP(){
	For(i,1,6){
		dis[i]=-(1ll<<60);
		vis[i]=0;
	}
	int h=0,t=1;
	q[1]=1; dis[1]=0;
	while (h!=t){
		int x=q[++h]; vis[x]=0;
		for (int i=head[x];i;i=e[i].next)
			if (dis[e[i].to]<dis[x]+e[i].v){
				dis[e[i].to]=dis[x]+e[i].v;
				from[e[i].to]=i;
				if (!vis[e[i].to]){
					vis[e[i].to]=1;
					q[++t]=e[i].to;
				}
			}
	}
}
const int N=2005;
int x[N],y[N],v[N],n;
int S1[N],S2[N][4];
struct SEG{
	int t[N*4];
	ll v[N*4];
	int nn;
	int Mx(int x,int y){
		return v[x]>v[y]?x:y;
	}
	void init(int n){
		for (nn=1;nn<=n+1;nn<<=1);
		For(i,0,nn-1) v[i]=-(1ll<<60),t[i+nn]=i;
		Rep(i,nn-1,1) t[i]=Mx(t[i*2],t[i*2+1]);
	}
	void change(int x,ll val){
		v[x]=val; x+=nn;
		for (x>>=1;x;x>>=1)
			t[x]=Mx(t[x*2],t[x*2+1]);
	}
	pll ask(){
		return pll(t[1],v[t[1]]);
	}
};
SEG T0[4],T1[4];
SEG T2[4][4];
bool check(){
	tot=0;
	memset(head,0,sizeof(head));
	For(i,0,3){
		pll tmp;
		tmp=T0[i].ask();
		add(1,i+2,tmp.fi,tmp.se);
		tmp=T1[i].ask();
		add(i+2,6,tmp.fi,tmp.se);
	}
	For(i,0,3) For(j,0,3) if (i!=j){
		pll tmp;
		tmp=T2[i][j].ask();
		add(i+2,j+2,tmp.fi,tmp.se);
	}
	SSSP();
	return dis[6]>-(1ll<<60);
}
void rebuild(int id){
	For(i,0,3)
		if (id<=n) T0[i].change(id,S1[id]?px[i]*x[id]+py[i]*y[id]:-(1ll<<60));
		else	   T1[i].change(id-n,S1[id]?px[i]*x[id]+py[i]*y[id]:-(1ll<<60));
	For(i,0,3) For(j,0,3) if (i!=j)
		if (id<=n) T2[i][j].change(id,S2[id][i]?1ll*(px[j]-px[i])*x[id]+1ll*(py[j]-py[i])*y[id]:-(1ll<<60)); 
		else       T2[j][i].change(id,S2[id][i]?1ll*(px[j]-px[i])*x[id]+1ll*(py[j]-py[i])*y[id]:-(1ll<<60)); 
}
void del(){
	ans+=dis[6];
	for (int i=from[6];i;i=from[e[i].from]){
		int x=e[i].from,y=e[i].to,id=e[i].id;
		if (x==1){
			--S1[id];
			++S2[id][y-2];
			rebuild(id);
		}
		else if (y==6){
			--S1[id+n];
			++S2[id+n][x-2];
			rebuild(id+n);
		}
		else{
			if (id<=n){
				--S2[id][x-2];
				++S2[id][y-2];
			}
			else{
				--S2[id][y-2];
				++S2[id][x-2];
			}
			rebuild(id);
		}
	}
	For(i,1,n*2){
		assert(S1[i]>=0);
		For(j,0,3)
			assert(S2[i][j]>=0);
	}
}
int main(){
	scanf("%d",&n);
	For(i,0,3){
		T0[i].init(n);
		T1[i].init(n);
	}
	For(i,0,3) For(j,0,3)
		T2[i][j].init(n*2);
	For(i,1,n) scanf("%d%d%d",&x[i],&y[i],&S1[i]);
	For(i,1,n) scanf("%d%d%d",&x[i+n],&y[i+n],&S1[i+n]);
	For(i,1,n){
		x[i+n]*=-1; y[i+n]*=-1;
		For(j,0,3){
			T0[j].change(i,px[j]*x[i]+py[j]*y[i]);
			T1[j].change(i,px[j]*x[i+n]+py[j]*y[i+n]);
		}
	}
	for (;check();del());
	printf("%lld\n",ans);
}


Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC137
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            List<string> s = new List<string>();
            for (int i = 0; i < n; i++)
            {
                var p = String.Concat(Console.ReadLine().OrderBy(c=>c));
                s.Add(p);

            }
            var tmp = s.GroupBy(x => x).Select(x => new { x, Count = x.LongCount() }).Where(x=>x.Count>1);
            long allcount = tmp.Sum(x => x.Count*(x.Count-1)/2);
            Console.WriteLine(allcount);
            
        }
    }
}


Measured memory_bytes: 36976
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000],arr1[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    long long i,j,k,n,x,y;
    cin>>n;
    for (i=0;i<n;i++)
    {
    	cin>>arr[i]>>arr1[i];
	}
	for (i=2;i<n;i++)
	{
		if (arr[i]==arr1[i] && arr[i-2]==arr1[i-2] && arr[i-1]==arr1[i-1])
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}

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

public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn = null;
		int count = 0;
		
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			while( stdIn.hasNext() ){
				String str = stdIn.next();
				StringBuilder sb = new StringBuilder(str);
				sb.reverse();
				if( str.contentEquals(sb) ){
					count++;
				}
			}
			System.out.println(count);
		} finally {
			if( stdIn != null ){
				stdIn.close();
			}
		}
	}
}

Measured memory_bytes: 12000
import itertools as it

n = input()
ans = 0
nums = ['3', '7', '5']

for j in range(1, len(n) + 1):
    for i in it.product(nums, repeat=j):
        if int(n) >= int("".join(i)) and '3' in i and '5' in i and '7' in i:
            ans += 1

print(ans)


Measured memory_bytes: 3060
while True:
    H,W = map(int, input().split())
    
    if H == 0 and W == 0:
        break
    
    for h in range(H):
        for w in range(W):
            if h == 0 or h == H - 1 or w == 0 or w == W - 1:
                print("#",end="")
            else:
                print(".",end="")
        print("")
    print("")


Measured memory_bytes: 7012
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する


int main() {
    string s;
    string inp;
    REP(i,0,3){
        cin >> inp;
        s += inp[0];
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a;i<n;i++)
#define ve vector
#define ss second 
#define ff first
#define pf pop_front
#define pob pop_back
#define psf push_front
#define res(x) cout<<x<<'\n'
#define read(t) ll t;cin>>t

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    read(n);
    ll a[n];
    bool ans=true;
    f(i,0,n){
        cin>>a[i];
    }
    f(i,0,n){
        if(a[i]%2==0){
            if(a[i]%3==0||a[i]%5==0){

            }
            else{
                ans=false;
                break;
            }
        }
    }

    if(ans){
        cout<<"APPROVED"<<endl;
    }
    else{
        cout<<"DENIED"<<endl;
    }
    
    
    


   

}

Measured memory_bytes: 256
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
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);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
using namespace std;
signed main()
{
	fastio;
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(a+b<k)	
	{
		k-=(a+b);
		cout<<a-k;
	}
	else
		cout<<min(a,k)<<endl;
	
}












Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
	int M, D;

	cin >> M >> D;

	int count = 0;

	for (int d10 = 2; d10 <= D / 10; d10++)
	{
		int d1_end;

		if (d10 == D / 10)
		{
			d1_end = D % 10;
		}
		else
		{
			d1_end = 9;
		}

		for (int d1 = 2; d1 <= d1_end; d1++)
		{
			if (d1 * d10 <= M)
			{
				count++;
			}
		}
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
i = [a,b,c,d,e]
x = 0
for num1 in range(5):
	for num2 in range(5):
		if num2 > num1:
			ans = i[num2] - i[num1]
			if ans > k:
				x += 1

if x == 0:
	print("Yay!")
elif x != 0:
	print(":(") 


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep for(int s,i=lk[x];i;i=hd[i])\
if(i^y&&!del[s=to[i]])
const int N=100005;
using namespace std;
int n,to[N*2],hd[N*2],lk[N],deg[N],cnt=1,
q[N],f[N],g[N],h,t,ans,ini;
bool del[N];
inline void add(int u,int v){
	to[++cnt]=v,hd[cnt]=lk[u],lk[u]=cnt,deg[u]++;
}int u,v;
char a[N];
void dfs(int x,int y){
	rep dfs(s,i^1),f[x]=max(f[x],f[s]);
	f[x]+=a[x];
}
void dfss(int x,int y){
	int mx=g[x],se=0;
	rep{
		if(f[s]>mx)se=mx,mx=f[s];
		else if(f[s]>se)se=f[s];
	}
	ans=max(ans,mx+=a[x]),se+=a[x];
	rep g[s]=f[s]+a[x]<mx?mx:se,dfss(s,i^1);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	scanf("%d%d",&u,&v),
	add(u,v),add(v,u);
	scanf("%s",a+1);
	u=0,ini=n-1<<1;
	for(int i=1;i<=n;i++){
		u+=(a[i]=a[i]=='W');
		if(deg[i]==1)q[t++]=i;
	}
	if(u<2)return printf("%d",u),0;
	for(;h<t;){
		if(a[u=q[h++]])continue;
		del[u]=1,ini-=2;
		for(int i=lk[u];i;i=hd[i])
		if(--deg[v=to[i]]==1)q[t++]=v;
	}
	for(int i=1;i<=n;i++)
	if(!del[i])
	ini+=(a[i]^=deg[i]&1);
	for(int i=1;i<=n;i++)
	if(!del[i]){
		dfs(i,0),dfss(i,0);
		return printf("%d\n",ini-2*ans),0;
	}
}

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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    int N; cin >> N;
    //まあ貪欲にやりましょう
    vector<int> nodes[N];
    vector<int> use(N, 0);
    string S[N];
    rep(i, N){
        cin >> S[i];
        rep(j, N){
            if(S[i][j] == '1'){
                nodes[i].push_back(j);
            }
        }
    }

    int ans = -1;
    rep(i, N){
        //cout << i << endl;
        //V_0 = {i}とする
        vector<vector<int>> st;
        vector<int> zero(1); zero[0] = i;
        st.push_back(zero);
        vector<int> one;
        rep(j, nodes[i].size()) {one.push_back(nodes[i][j]); use[nodes[i][j]] = 1;}
        st.push_back(one);

        rep(j, one.size()){
            rep(k, one.size()){
                if(S[one[j]][one[k]] == '1'){
                    cout << -1 << endl;
                    return 0;
                }
            }
        }

        //rep(j, one.size()) cout << one[j] << " "; cout << endl;

        use[i] = 1;
        int cnt = 2;
        bool cont = false;
        rep(j, N){
            if(use[j] == 0){
                cont = true;
                break;
            }
        }

        while(cont){
            //operation
            vector<int> temp;
            rep(j, st[cnt-1].size()){
                rep(k, nodes[st[cnt-1][j]].size()) temp.push_back(nodes[st[cnt-1][j]][k]);
            }

            sort(temp.begin(), temp.end());
            int temp_judge[N] = {};
            vector<int> kakutei;
            rep(j, st[cnt-2].size()) temp_judge[st[cnt-2][j]] = 1;
            rep(j, temp.size()){
                if(j < temp.size()-1 && temp[j] == temp[j+1]) continue;
                if(temp_judge[temp[j]] == 0) kakutei.push_back(temp[j]);
            }
            // temp = temp - st[cnt-2];
            rep(j, kakutei.size()) use[kakutei[j]] = 1;

            //集合内の辺が存在したら強制終了
            for(int j = 0; j < kakutei.size(); j++){
                for(int k = 0; k < kakutei.size(); k++){
                    if(S[kakutei[j]][kakutei[k]] == '1'){
                        cout << -1 << endl;
                        return 0;
                    }
                }
            }

            //judge cont
            cont = false;
            rep(i, N){
                if(use[i] == 0){
                    cont = true;
                    break;
                }
            }

            st.push_back(kakutei);
            cnt++;
        }
        
        bool ok = true;
        //judge ok
        vector<int> temp;
        //st[cnt-1]の要素から伸びてる辺を全部入れたものはst[cnt-2]に含まれる
        rep(j, st[cnt-1].size()){
            rep(k, nodes[st[cnt-1][j]].size()) temp.push_back(nodes[st[cnt-1][j]][k]);
        }

        int work_judge[N] = {};
        rep(j, st[cnt-2].size()) work_judge[st[cnt-2][j]] = 1;
        rep(j, temp.size()) if(work_judge[temp[j]] == 0) ok = false;

        if(ok){
            if(cnt > ans) ans = cnt;
        }
        rep(i, N) use[i] = 0;
    }
    cout << ans << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 512
k,a,b = gets.strip.split(" ").map(&:to_i)

if a <= b
  if k <= a
    puts 1
  else
    puts "-1"
  end
else
  t = k - a
  if t <= 0
    puts 1
  else
    if t % (a - b) == 0
      f = t  / (a - b)
    else
      f = t / (a - b) + 1
    end
    puts f * 2 + 1
  end
end

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

hako=[0]*n
for i in range(n):
    # print(n-i-1, sum(hako[n-i-1:n:n-i]))
    if (sum(hako[n-i-1:n:n-i])%2)!=a[n-i-1]:
        hako[n-i-1]+=1
# print(hako)

ans=[]
for i in range(n):
    if hako[i]==1:
        ans.append(str(i+1))

print(len(ans))
if len(ans)!=0:
    print(' '.join(ans))


Measured memory_bytes: 17208
periods = [
  ["heisei",    1989, 1, 8],
  ["showa",     1926, 12, 25],
  ["taisho",    1912, 7, 30],
  ["meiji",     1868, 9, 8],
]

while (line = gets)
  y, m, d = line.chomp.split(" ").map{|s| s.to_i}

  era = "pre-meiji"

  for p in periods
    if y > p[1] ||
        y == p[1]&& (m > p[2] || m == p[2] && d >= p[3])
      era = [p[0], y - p[1] + 1, m, d].join(" ")
      break
    end
  end

  puts era
end

Measured memory_bytes: 6100
def is_same(s1, s2):
  sp1 = s1.split("\"")
  sp2 = s2.split("\"")
  if len(sp1) != len(sp2):
    return 2
  
  count = 0
  for i in range(len(sp1)):
    if i % 2 == 0:
      if sp1[i] != sp2[i]:
        return 2
    else:
      if sp1[i] != sp2[i]:
        count += 1
        if count >= 2:
          return 2
  return count

while True:
  s1 = input()
  if s1 == ".":
    break
  s2 = input()
  result = is_same(s1, s2)
  if result == 0:
    print("IDENTICAL")
  elif result == 1:
    print("CLOSE")
  else:
    print("DIFFERENT")



Measured memory_bytes: 5588
//Love and Freedom.
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 20021225
#define M 510
using namespace std;
int read()
{
	int s=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return f*s;
}
int in[M],out[M],fa[M],n,h,a,b,c,d; bool vis[M];
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);} 
int main()
{
	n=read(),h=read();
	for(int i=0;i<=2*h;i++)	fa[i]=i;
	for(int i=1;i<=n;i++)
	{
		a=read(),b=read(),c=read(),d=read();
		int l=c>0?c:-a,r=d>0?-d:b; l+=h,r+=h;
		if(find(l)!=find(r))	fa[find(l)]=find(r);
		out[l]++; in[r]++;
	}
	for(int i=-h;i<0;i++)	if(in[i+h]>out[i+h])	return puts("NO"),0;
	for(int i=1;i<=h;i++)	if(out[i+h]>in[i+h])	return puts("NO"),0;
	for(int i=0;i<=h*2;i++)	if(in[i]!=out[i])	vis[find(i)]=1;
	for(int i=0;i<=h*2;i++)	if((in[i]||out[i])&&!vis[find(i)])	return puts("NO"),0;
	return puts("YES"),0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
  int a,b,c,d,e,f;
  while(cin >> a >> b >> c >> d >> e >> f){
    double x,y;
    x = (double)(c*e-f*b)/(a*e-d*b);
    y = (double)(c*d-f*a)/(b*d-e*a);
    if(x==0) x=0;
    if(y==0) y=0;
    printf("%.3f %.3f\n", x,y);
  }
  return 0;
}

Measured memory_bytes: 1192
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()    
    #define bit(n) (1LL<<(n))
    template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
#pragma endregion library

int main(){
    int n, k; cin >> n >> k;
    vi a(n); rep(i,n) cin >> a[i];
    int ng = 0, ok = INF;
    while(ng+1<ok){
        int c = (ng+ok)/2;
        int cut = 0;
        rep(i,n){
            cut += (a[i]-1)/c;
        }
        if(cut>k) ng = c;
        else ok = c;
    }
    cout << ok << '\n';
    
    
}


Measured memory_bytes: 3952
import java.util.*

fun main(args: Array<String>) {
        val k = Integer.parseInt(readNext())
        var hashMap = HashMap<String, Long>()
        var result: Long = 0
        for (i in 1..k) {
            val input    = readNext().split("")
            var str = ""
            input.sorted().map {
                str += it
            }
            hashMap.contains(str).let {

                var c: Long
                if (it) {
                    c = hashMap.get(str)!!.plus(1)
                    result += c
                    hashMap.put(str, hashMap.get(str)!!.plus(1))
                }else {
                    hashMap.put(str, 0)
                }
            }
        }
        println(result)
    }


    fun readNext(): String {
        return readLine()!!
    }


Measured memory_bytes: 116048
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
 
int main(void)
{
    char num[1001] = {0} ;
    int i=0 ;
    int number=0 ;
    int mem=0 ;
 
    while (1){
 
        scanf("%s",num);
 
        if (num[0]=='0' && num[1]=='\0') break;
 
        for (i=0 ;i<1001 ;i++){
 
            if (num[i]=='\0') break;
 
            number=number+(num[i]-'0');
 
        }
 
        printf("%d\n",number);
        memset(num ,'\0' ,sizeof num);
        number=0;
 
    }
 
    return 0;
}


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

using namespace std;
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

long long  gcd(long long  a, long long b) {
	if (a < b) return gcd(b, a);
	long long  r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

int main() {
	int H,N,sum=0;
	cin >>H>> N;
	vector<int> A(N);
	for (size_t i = 0; i < N; i++)
	{
		cin >> A.at(i);
		sum += A.at(i);
	}
	if (H <= sum)
	{
		cout << "Yes";
	}
	else cout << "No";
}

Measured memory_bytes: 640
// B - Voting Judges
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	long long n, m, v, p;
	cin >> n >> m >> v >> p;
	vector<long long> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end(), greater<int>());
	int l = p, r = n;
	while (l < r) {
		int c = (l + r) / 2;
		long long s = p * m + (n - c - 1) * m;
		bool ok = true;
		for (int i = p - 1; i < c; i++) {
			if (a[c] + m - a[i] < 0) ok = false;
			s += max(a[c] + m - a[i], 0LL);
		}
		if (s >= m * v && ok) l = c + 1;
		else r = c;
	}
	cout << l << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#define N 10000

int main(){
int i,j,s,n1,t,n2,teto[N],teto2[N],count=0;
scanf("%d",&n1);
for(i=0;i<n1;i++){
scanf("%d",&teto[i]);
}
scanf("%d",&n2);
for(i=0;i<n2;i++){
scanf("%d",&teto2[i]);
}
for(i=0;i<n2;i++){
for(j=0;j<n1;j++){
if(teto2[i]==teto[j]){
count++;
break;
}
}
}
printf("%d\n",count);


return 0;
}

Measured memory_bytes: 644
solve :: Int -> Int -> Int -> String
solve _ _ 0 = "IMPOSSIBLE"
solve a b k = if isSolved
              then show k
              else solve a b $ k - 1
  where isSolved = abs (a - k) == abs (b - k)

main :: IO ()
main = do
  [a, b] <- map read . words <$> getLine
  putStrLn . solve a b $ max a b

Measured memory_bytes: 508
N = int(input())
A = list(map(int, input().split()))

cusum = [0]
for a in A:
  tmp = cusum[-1] + a
  cusum.append(tmp)

ans = 5e9
for i in range(1, N):
  p1 = cusum[i]
  p2 = cusum[-1] - cusum[i]
  diff = abs(p1 - p2)
  ans = min(diff, ans)

print(ans)

Measured memory_bytes: 23788
#include <iostream>
#include <algorithm>
#include <functional>

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

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

    std::sort(a, a + n, std::greater<int>());

    int alice = 0;
    int bob = 0;
    for(int i = 0; i < n; i++) {
        i % 2 == 0 ? alice += a[i] : bob += a[i];
    }

    std::cout << alice - bob << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define EPS 1e-9
#define MOD 1000000007
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define range 200010
#pragma GCC optimize ("Ofast")
#define endl '\n'
signed main(){

	//freopen("test.txt","r",stdin);
	ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s;
	int n;
	cin>>n;
	cout<<n*n*n<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int R,G,B,N; cin >> R >> G >> B >> N;
    ll ans=0;
    for (int i=0;R*i<=N;++i){
        for (int j=0;R*i+G*j<=N;++j){
            if ((N-R*i-G*j)%B==0) ++ans;
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int MAXN = 1e3+5;
const ll mod = 1e9+7;
char s[MAXN][MAXN];
ll dp[MAXN][MAXN];
inline ll max(ll a,ll b){
    return a>b?a:b;
}
inline ll sum(int x,int y){
    ll cnt=0;
    if(x)cnt+=dp[x-1][y];
    if(y)cnt+=dp[x][y-1];
    return cnt;
}
int main(){
    int N,M;
    scanf("%d%d",&N,&M);
    for(int i=0;i<N;++i){
        scanf("%s",s[i]);
    }
    if(s[0][0]=='.')dp[0][0]=1;
    for(int i=0;i<N;++i){
        for(int j=0;j<M;++j){
            if(i==0&&j==0)continue;
            if(s[i][j]=='.')dp[i][j]=sum(i,j)%mod;
        }
    }
    printf("%lld\n",dp[N-1][M-1]%mod);
    return 0;
}

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

using namespace std;

int main() {
  int n, k;
  cin >> n >>k;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) cin >> p[i];
  sort(p.begin(), p.end());

  int  ans = 0;
  for (int i = 0; i < k; ++i) ans += p[i];
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 3628
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

ll r,D,x;

int main(){
    cin>>r>>D>>x;
    rep(i,10){
        x=r*x-D;
        out(x);
    }
    
    
}


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

int cmp(const void *a,const void *b)
{
   return *(int*)a-*(int*)b;
}



int main(void)
{
   int n, i, a[100000][2];
   long k;

   scanf("%d%ld",&n,&k);
   for(i=0;i<n;i++)
      scanf("%d%d",&a[i][0],&a[i][1]);

   qsort(a,n,sizeof(int)*2,cmp);

   for(i=0;i<n;i++){
      k-=a[i][1];
      if(k<=0){
         printf("%d\n",a[i][0]);
         return 0;
      }
   }
}


Measured memory_bytes: 3076
#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 A, B, C, K;
  cin >> A >> B >> C >> K;
  if (K % 2 == 0) {
    cout << A - B << endl;
  } else {
    cout << B - A << endl;
  }
  return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<long long> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];
  sort(A.begin(), A.end(), greater<long long>());
  long long res = 0;
  for (int i = 0; i < K; ++i) res += A[i];
  cout << res << endl;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int W, H;
  cin >> W >> H;

  vector<pair<ll, ll>> p;

  rep(i, W){
    ll tmp;
    cin >> tmp;
    p.emplace_back(tmp, 0LL);
  }

  rep(i, H){
    ll tmp;
    cin >> tmp;
    p.emplace_back(tmp, 1);
  }

  int cnt_w = 0;
  int cnt_h = 0;

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

  ll ans = 0;
  ll num_e = 0;
  rep(i, W+H){

    auto q = p[i];

    if(q.second==0){
      
      ans += q.first * (H-cnt_h+1);
      cnt_w++;
      num_e += (H-cnt_h+1);

    }else{

      ans += q.first * (W-cnt_w+1);
      cnt_h++;
      num_e += (W-cnt_w+1);
    }
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 6384
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9+5;
int main(){
		int n;
		cin>>n;
		int a[n];
		for(int i=0;i<n;i++)
		cin>>a[i];
	    vector<int>dp(n,INF);
	    dp[0]=0;
	    for(int i=0;i<n;++i){
	    	for(int j:{i+1,i+2}){
	    		if(j<n){
	    			dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
				}
			}
		}
		cout<<dp[n-1]<<endl;
  return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long

int main() {
  int N;
  cin >> N;
  vector<pair<ll, ll>> AB(N);
  rep(i, 0 , N) {
    cin >> AB[i].second >> AB[i].first;
  }
  sort(AB.begin(), AB.end());
  ll cntA = 0;
  ll deadline = 0;
  bool success = true;
  rep(i, 0, N) {
    cntA += AB[i].second;
    deadline = AB[i].first;
    if (cntA > deadline) {
      success = false;
      break;
    }
  }
  if (success) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
};


Measured memory_bytes: 3328
i = list(map(int, input().split()))
N = i[0]
M = i[1]
A  = list(map(int, input().split()))
S=sum(A)
A_sorted=sorted(A,reverse=True)
if A_sorted[M-1] >= S*1/(4*M):
    print('Yes')
else:
    print('No')




Measured memory_bytes: 3060
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let mut iter = buf.split_whitespace();
	let a:i32 = match iter.next().unwrap().parse() {
		Ok(n) => n,
		_ => panic!(""),
	};
	let b:i32 = match iter.next().unwrap().parse() {
		Ok(n) => n,
		_ => panic!(""),
	};
	let c:i32 = match iter.next().unwrap().parse() {
		Ok(n) => n,
		_ => panic!(""),
	};
	
	if a-b >= c {
		println!("0");
	}else{
		println!("{}", c - (a-b));
	}
}

Measured memory_bytes: 4352
sx, sy, tx, ty = map(int, input().split())
x = tx - sx
y = ty - sy

print('U'*y+'R'*x+'D'*y+'L'*x+
      'L'+'U'*(y+1)+'R'*(x+1)+'D'+'R'+'D'*(y+1)+'L'*(x+1)+'U')


Measured memory_bytes: 3064
#include <iostream>
typedef long long ll;
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int A, B;
  cin >> A >> B;
  for (int i=1; i<=20000; i++) {
    double a = (double)i * 0.08;
    double b = (double)i * 0.10;
    if (A == (int)a && B == (int)b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <map>
#include <unordered_map>
using namespace std;


using vc = vector<char>;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void process(const string& t) {
}

int main() {
  int t, n;
  string s;
  int x, y;
  int ans = 0;
  while (cin >> n) {
    vector<int> v(n);
    unordered_map<int, int> m;
    long long sum = 0;
    for (int i = 0; i < n; ++i) {
      cin >>v[i];
      sum += v[i];
      ++m[v[i]];
    }
    int q, x, y;
    cin >> q;
    while (q--) {
      cin >> x >> y;
      if (m.count(x) == 0) {
        cout << sum << endl;
        continue;
      }
      int cnt = m[x];
      sum += cnt * (y - x);
      cout << sum << endl;
      m.erase(x);
      m[y] += cnt;
    }
  }
  return 0;
}


Measured memory_bytes: 7036
(* O(2^|s|) *)
let s = read_line ()
let ds = Array.to_list @@ Array.init (String.length s) @@ fun i -> Char.code s.[i] - 48
let rec f sum n = function
| [] -> sum + n
| d :: r -> f (sum + n) d r + f sum (10 * n + d) r
let _ = f 0 (List.hd ds) (List.tl ds) |> Printf.printf "%d\n"

Measured memory_bytes: 384
//Heaplax
//别让自己后悔
#include<bits/stdc++.h>
#define N 100001
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
int n,a[N],f[N];
int cnt,head[N],nxt[N],to[N];
void dfs(int u)
{
	vector<int> que;
	for(int i=head[u],v;i;i=nxt[i])
		dfs(v=to[i]),que.push_back(f[v]);
	sort(que.begin(),que.end(),greater<int>());
	for(int i=0;i<que.size();++i)
		f[u]=max(f[u],i+1+que[i]);
}
int main()
{
	re(n);
	for(int i=2;i<=n;++i)
		re(a[i]),add_edge(a[i],i);
	dfs(1);
	printf("%d\n",f[1]);
}


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

#define reps(i,j,n) for(int i = (j) ; i < (int)(n) ; ++i)    
#define rep(i,n) reps(i,0,n)  
#define each(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)  
  
#define all(v) (v).begin(), (v).end()  
#define pb(x) push_back(x)  
#define sz(x) (int)((x).size())  
#define UNQ(s) {sort(ALL(s));(s).erase(unique(ALL(s)),(s).end());}   
#define fr first  
#define sc second  
  
typedef pair< int , int > Pi;  
typedef pair< int , Pi > Pii;

  
typedef long long int64;  
const int INF = 1 << 30;  
  
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is>>a.first>>a.second; }  
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os<<a.first<<" "<<a.second; }  
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ rep(i,sz(vc)) is >> vc[i]; return is;}  
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ rep(i,sz(vc)) os << vc[i] << endl; return os; }  

main(){

  int X, Y, Z;
  vector< int > V; //ルーレット

  vector< int > next; //先へ進む
  vector< int > price; //金額を得る
  vector< int > send; //金額を払う

  vector< vector < double > > dp;

  while( cin >> X >> Y >> Z, X){

    V = vector< int >(X);
    next = vector< int >(Y + 1, 0);
    price = vector< int >(Y + 1, 0);
    send = vector< int >(Y + 1, 0);


    cin >> V;
    for(int i = 0; i < Z; i++){
      int N, E, A;
      cin >> N >> E >> A;
      if(E == 1) next[N] = A;
      else if(E == 2) price[N] = A;
      else send[N] = A;
    }

    dp = vector< vector< double > >( Y + 1, vector< double >( Y * 100 + 1, 0));

    dp[0][0] = 1.0;
    for(int i = 0; i < Y; i++){ //マス
      for(int j = Y * 100; j >= 0; j--){ //カネ
        if(dp[i][j] == 0) continue;

        for(int k = 0; k < V.size(); k++){ //ルーレットの目
          
          int push = min( Y, i + V[k]);
          int money = max( 0, j + price[push] - send[push]);
          if(push < Y) push = min( Y, push + next[push]);
          
          dp[push][money] += (double)dp[i][j] / V.size();
        }
      }
    }

    double ret = 0;
    for(int i = 0; i <= Y * 100; i++){
      ret += dp[Y][i] * i;
    }
    cout << (int)ret << endl;
  }

  return(0);
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    string sub1 = "KIH", sub2 = "B", sub3 = "R";
    for (int i = 0; i < (1 << 4); i++) {
        string a1 = "", a2 = "", a3 = "", a4 = "";
        if (i & 1) a1 = "A";
        if ((i >> 1) & 1) a2 = "A";
        if ((i >> 2) & 1) a3 = "A";
        if ((i >> 3) & 1) a4 = "A";
        string all = a1 + sub1 + a2 + sub2 + a3 + sub3 + a4;
        if (all == S) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256