akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

import javax.swing.plaf.basic.BasicInternalFrameTitlePane.SystemMenuBar;
public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}
		return ans;
	}
	static long[] splitL() throws IOException
	{
		String[] cmd=br.readLine().split(" ");
		long[] ans=new long[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Long.valueOf(cmd[i]);
		}
		return ans;
	}
	static long[][]dp;
	static long[]arr;
	static long solve(int l,int r)
	{
		if(l>=r)
			return 0;
		if(dp[l][r]!=-1)
			return dp[l][r];
		long res=(long)Math.pow(10, 18);
		long sum=0;
		for(int i=l;i<=r;i++)
		{
			sum+=arr[i];
		}
		for(int i=l;i<=r-1;i++)
		{
			res=Math.min(res,solve(l,i)+solve(i+1,r)+sum);
		}
		dp[l][r]=res;
		return res;
	}
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		br=new BufferedReader(new InputStreamReader(System.in));
		int n=cin();
		arr=splitL();
		dp=new long[n+1][n+1];
		for(int i=0;i<=n;i++)
		{
			Arrays.fill(dp[i], -1);
		}
		System.out.println(solve(0,n-1));
	}
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int a, b;
    cin >> a >> b;

    string x, y;

    if (a < b)
    {
        rep(i, b)
        {
            cout << a;
        }
        cout << endl;
    }
    else
    {
        rep(i, a)
        {
            cout << b;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n = int(input())
c = None
res = 0
for i in range(1, len(str(n))+1):
    c = '9' * i
    if int(c) <= n:
        continue
    else:
        for j in range(9, -1, -1):
            if int(str(j) + str(c)[1:]) <= n:
                c = str(j) + str(c)[1:]
                break
        break
for i in range(len(c)):
    res += int(c[i])
print(res)

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

int main() {
    std::string S;
    std::cin >> S;
    uint32_t c = 0; 

    for (size_t i = 0; i < S.size(); ++i) {
        const int a = S[i] - 'a';
        if ((c >> a) & 1) {
            std::cout << "no\n";
            return 0;
        } else {
            c |= (1u << a);
        }
    }

    std::cout << "yes\n";

    return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left

a, b, q = map(int, input().split())
INF = 10**12
s = [-INF] + [int(input()) for i in range(a)] + [INF]
t = [-INF] + [int(input()) for i in range(b)] + [INF]


for _ in range(q):
    x = int(input())
    k = bisect_left(s, x)
    l = bisect_left(t, x)
    sm = x - s[k - 1]
    sM = s[k] - x
    tm = x - t[l - 1]
    tM = t[l] - x
    ans = min(2 * sm + tM, 2 * sM + tm, 2 * tm + sM, 2 * tM + sm, max(sm, tm), max(sM, tM))
    print(ans)


Measured memory_bytes: 107220
#include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <map>
    #include <set>
    using namespace std;
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos(-1.0)
    #define ei exp(1)
    #define PI 3.141592653589793238462
    #define ios() ios::sync_with_stdio(false)
    #define INF 1044266558
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    int a,b,c,x,n;
    int main()
    {
    	while(scanf("%d",&n)!=EOF)
    	{
    		a=b=c=0;
    		for(int i=0;i<n;i++)
    		{
    			scanf("%d",&x);
    			if(!(x%4)) a++;
    			else if(x&1) b++;
    			else c++;
    		}
    		if(!c) b--;
    		puts(a>=b?"Yes":"No");
    	}
    	return 0;
    }

Measured memory_bytes: 256
public class Main {

	public static void main(String[] args) {

		java.util.Scanner sc = new java.util.Scanner(System.in);

		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();

		if (x - r < 0 || x + r > W) {
			System.out.println("No");
		}else if (y - r < 0 || y + r > H) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 26168
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//  ABC130
//
//

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
//#define __DBG__




void solve(void){
  
  double W, H, X, Y;
    
  cin >> W >> H >> X >> Y;
  
  bool multi;
  if(X*2==W && Y*2==H){multi=true;}else{multi=false;}
  double ans = W*H/2;
  
  cout << fixed << setprecision(15);
  cout << ans << " " << (multi?"1":"0") << endl;
  
  return;
}

#define TESTCASES 1

int main(int argc, const char * argv[]) {

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

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}



Measured memory_bytes: 256
/* 探索するとTLE */

#include <stdio.h>
#include <limits.h>
#define N_MAX 1000
#define TH_MAX 1000

int W[N_MAX], V[N_MAX], N;

int dp[TH_MAX+1], t[TH_MAX+1];

int main(int argc, char *argv[]){
     int i, c=1, th, n, w, v;

     while(scanf("%d",&th), th!=0){

	  for(i=0; i<=th; i++) dp[i]=0;

	  scanf("%d",&n);
	  while(n--){
	       scanf("%d,%d",&v,&w);
	  
	       for(i=0; i<=th; i++) t[i]=dp[i]+v;
	  
	       for(i=0; i<=th-w; i++)
		    if(dp[i+w] < t[i]) dp[i+w]=t[i];
	  }

	  v = 0, w = 0;
	  for(i=0; i<=th; i++)
	       if(dp[i] > v) v=dp[i], w=i;

	  printf("Case %d:\n%d\n%d\n",c++,v,w);
     }

     return 0;
}

Measured memory_bytes: 0
H, W = map(int, input().split())

x = []
for _ in range(H):
    a = [c for c in input()]
    if '#' in a:
        x.append(a)

ans = []
for a in list(zip(*x)):
    if '#' in a:
        ans.append(a)

for a in list(zip(*ans)):
    print(''.join(a))

Measured memory_bytes: 9336
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<string> vs;
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);

int main() {
    int N;
    cin >> N;
    if (N % 1000 == 0) cout << 0 << endl;
    else cout << 1000 - (N % 1000) << endl;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int K = s.nextInt();
        int gcd = 0;

        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                for (int k = 1; k <= K; k++) {
                    int tmp = gcd(j, k);
                    gcd += gcd(tmp, i);
                }
            }
        }

        System.out.println(gcd);
        s.close();
    }

    public static int gcd(int p, int q) {
        if (p % q == 0) {
            return q;
        }
        return gcd(q, p % q);
    }
}

Measured memory_bytes: 35748
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int x[10000000]; int n, sum2; long long sum;
int main() {
	while (true) {
		memset(x, 0, sizeof(x));
		cin >> n;
		if (!n) { break; }
		for (int i = 0; i < n; i++) {
			cin >> x[i];
		}
		sort(x, x + n);
		sum2 = 0;
		sum = 0;
		for (int i = 0; i < n; i++) {
			sum += sum2;
			sum2 += x[i];
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 40236
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

#define FOR(i, l, r) for (i = (l); i < r; i++ )

using namespace std;
typedef long long ll;

typedef pair<int, char> Card;
#define MAX_N (100010)

int n;
Card A[MAX_N];

#define INF (0x7FFFFFFF)

Card B[MAX_N];
Card L[(MAX_N >> 1)];
Card R[(MAX_N >> 1)];

// merges two arraies. Those are already sorted.
void merge(Card A[], int left, int mid, int right ) {
    // returns when the number of element is 1 or less.
    if ( right - left <= 1 ) return;
    int i;
    int n1 = mid - left;
    int n2 = right - mid;
    int n = right - left;

    FOR( i, 0, n1 ) {
	L[i] = A[left + i];
    }

    FOR( i, 0, n2 ) {
	R[i] = A[mid + i];
    }

    L[n1].first = R[n2].first = INF;

    int i_l = 0;
    int i_r = 0;

    FOR( i, left, right ) {
	if ( L[i_l].first <= R[i_r].first ) {
	    A[i] = L[i_l];
	    i_l++;
	}
	else {
	    A[i] = R[i_r];
	    i_r++;
	}
    }

    return;
}

void merge_sort( Card A[], int left, int right ) {
    // proceeds when the number of element is greater than 1.
    if ( right - left > 1 ) {
	int mid = (right + left) >> 1;
	merge_sort( A, left, mid );
	merge_sort( A, mid, right );
	merge( A, left, mid, right );
    }
}


int partition(Card A[], int p, int r) {
    Card x = A[r];		// pivot
    int i = p - 1;
    int j;

    FOR(j, p, r) {
	if (A[j].first <= x.first) {
	    i++;
	    swap(A[i], A[j]);
	}
    }

    swap(A[i+1], A[r]);

    return i + 1;
}

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


int main()
{
    int i;
    scanf("%d", &n);
    FOR(i, 0, n) {
	scanf(" %c %d", &A[i].second, &A[i].first);
	B[i] = A[i];
    }
    
    merge_sort(B, 0, n);
    quick_sort(A, 0, n-1);

    bool is_stable = true;
    FOR(i, 0, n) {
	if ( A[i].first != B[i].first || A[i].second != B[i].second ) {
	    is_stable = false;
	    break;
	}
    }

    printf("%s\n", (is_stable) ? "Stable" : "Not stable");

    FOR(i, 0, n) {
	printf("%c %d\n", A[i].second, A[i].first);
    }

    return 0;
}

Measured memory_bytes: 5564
let m = 1000000007
let ( *^ ) x y = (x * y) mod m

let () = Scanf.scanf "%d\n" @@ fun n ->
  let ts = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun t -> t in
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun t -> t in
  let dp = Array.make n `Undefined in
  Printf.printf "%d\n" @@
  try
    if ts.(n - 1) <> as_.(0) then raise Not_found;
    dp.(0) <- `Defined ts.(0);
    for i = 0 to n - 2 do
      dp.(i + 1) <-
        if ts.(i) = ts.(i + 1)
        then `Under ts.(i)
        else `Defined ts.(i + 1)
    done;
    begin match dp.(n - 1) with
    | `Defined h ->
        if h <> as_.(n - 1) then raise Not_found
    | `Under h ->
        if h < as_.(n - 1) then raise Not_found
        else dp.(n - 1) <- `Defined as_.(n - 1)
    end;
    for i = n - 2 downto 0 do
      match dp.(i), as_.(i) = as_.(i + 1) with
      | `Under h, true ->
          dp.(i) <- `Under (min h as_.(i))
      | `Defined h, true ->
          if as_.(i) < h then raise Not_found
      | `Under h, false ->
          if h < as_.(i) then raise Not_found
          else dp.(i) <- `Defined as_.(i)
      | `Defined h, false ->
          if as_.(i) <> h then raise Not_found
    done;
    Array.fold_left (fun acc -> function
      | `Under h -> acc *^ h
      | _ -> acc) 1 dp
  with Not_found -> 0


Measured memory_bytes: 10496
///
// File:  2197.cpp
// Author: ymiyamoto
//
// Created on Fri Nov 10 06:14:48 2017
//

#include <cstdint>
#include <iostream>

using namespace std;

int32_t main()
{
  while (true) {
    uint32_t N;
    cin >> N;
    if (N == 0) break;
    uint32_t count = 0;
    for (uint32_t i = 1; i < N; i++) {
      uint32_t cur = i;
      uint32_t num = cur;
      do {
        cur++;
        num += cur;
      } while (num < N);
      if (num == N) {
        count++;
      }
    }
    cout << count << endl;
  }

  return 0;
}

Measured memory_bytes: 3084
import math
n , h = map(int,input().split())
max = 0
b = []
c = 0
for i in range(n):
    a , b1 = map(int,input().split())
    if a > max:
        max = a
    b.append(b1)
b.sort(reverse = True)
b.append(0)
i=0
while h > 0 and b[i]>max:
    h-=b[i]
    i+=1
    c+=1
if h > 0:
    c += math.ceil(h/max)
print(c)


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

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

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

const ll INF = 1e10;

int main() {

    ll n, W;
    cin >> n >> W;
    vector<ll> w(n+5);
    vector<ll> v(n+5);
    rep(i,n){
        cin >> w[i];
        cin >> v[i];
    }

    ll max_val = 100*1e3+500;
    vector<vector<ll>> dp(n+5, vector<ll>(max_val, INF));
    dp[0][0]= 0;

    rep(j,max_val)rep(i,n){
        if(j - v[i]>=0){
            chmin(dp[i+1][j],dp[i][j - v[i]] + w[i]);
        }
        chmin(dp[i+1][j], dp[i][j]);
    }

    ll ans = INF;
    rep(i,max_val){
        if(dp[n][i] > W){
            continue;
        }else{
            ans = i;
        }
    }
    cout << ans << endl;


}

Measured memory_bytes: 83712
#include <bits/stdc++.h>
#define N (long long)(1e9 + 7)
#define fin 61
using namespace std;

long long l, r;
long long dp[70][2][2];

long long solve();
long long cnt(long long nowl, long long nowr,
              long long dig);
bool ch(long long x, long long d);

int main() {
  cin >> l >> r;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0;
  for(int i = 0; i < fin; ++i) {
    long long nbase = 1LL << i, nmax = (1LL << (i + 1)) - 1;
    if(nmax < l || nbase > r) continue;
    ans +=
        cnt(max(nbase, l) - nbase, min(r, nmax) - nbase, i);
    ans %= N;
  }
  return ans;
}

long long cnt(long long nowl, long long nowr,
              long long dig) {
  for(int i = 0; i <= dig; ++i)
    for(int j = 0; j < 2; ++j)
      for(int k = 0; k < 2; ++k) dp[i][j][k] = 0;
  long long ans = 0;
  // i l r
  dp[0][0][0] = 1;
  for(int i = 0; i < dig; ++i) {
    bool flagr = ch(nowr, dig - 1 - i),
         flagl = ch(nowl, dig - 1 - i);
    if(flagr && flagl) {
      // use 1 1
      for(int j = 0; j < 2; ++j)
        for(int k = 0; k < 2; ++k)
          dp[i + 1][j][k] = dp[i][j][k];
      // use 0 1
      for(int j = 0; j < 2; ++j) {
        dp[i + 1][1][j] += dp[i][1][j];
        dp[i + 1][1][j] %= N;
      }
      // use 0 0
      dp[i + 1][1][1] += (dp[i][1][0] + dp[i][1][1]) % N;
      dp[i + 1][1][1] %= N;
    }
    else if(flagr) {
      // use 1 1
      for(int j = 0; j < 2; ++j)
        dp[i + 1][1][j] = (dp[i][0][j] + dp[i][1][j]) % N;
      // use 0 1
      for(int j = 0; j < 2; ++j)
        for(int k = 0; k < 2; ++k) {
          dp[i + 1][j][k] += dp[i][j][k];
          dp[i + 1][j][k] %= N;
        }
      // use 0 0
      for(int j = 0; j < 2; ++j) {
        dp[i + 1][j][1] += (dp[i][j][1] + dp[i][j][0]) % N;
        dp[i + 1][j][1] %= N;
      }
    }
    else if(flagl) {
      // use 1 1
      for(int j = 0; j < 2; ++j)
        dp[i + 1][j][1] = dp[i][j][1];
      // use 0 1
      dp[i + 1][1][1] += dp[i][1][1];
      dp[i + 1][1][1] %= N;
      // use 0 0
      for(int j = 0; j < 2; ++j) {
        dp[i + 1][1][j] += dp[i][1][j];
        dp[i + 1][1][j] %= N;
      }
    }
    else {
      // use 1 1
      dp[i + 1][1][1] = (dp[i][1][1] + dp[i][0][1]) % N;
      // use 0 1
      for(int j = 0; j < 2; ++j) {
        dp[i + 1][j][1] += dp[i][j][1];
        dp[i + 1][j][1] %= N;
      }
      // use 0 0
      for(int j = 0; j < 2; ++j)
        for(int k = 0; k < 2; ++k) {
          dp[i + 1][j][k] += dp[i][j][k];
          dp[i + 1][j][k] %= N;
        }
    }
  }
  for(int i = 0; i < 2; ++i)
    for(int j = 0; j < 2; ++j) {
      ans += dp[dig][i][j];
      ans %= N;
    }
  return ans;
}

bool ch(long long x, long long d) { return (x >> d) & 1; }

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){
	int N,n2=1;
	
	cin>>N;
	
	n2=(N%10)*100;
	n2+=N%100-N%10;
	n2+=(N-N%100)/100;
	
	if(N==n2){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	
	return 0;
}

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

class C
{
	static List<int> Read() => Console.ReadLine().Split().Select(int.Parse).ToList();
	static void Main()
	{
		var h = Read();
		int k = h[0], n = h[1];
		var a = Read();
		a.Add(k + a[0]);
		Console.WriteLine(k - Enumerable.Range(0, n).Max(i => a[i + 1] - a[i]));
	}
}


Measured memory_bytes: 44696
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	int n;
	cin>>n;
	vector<int> a(n),b(n);
	for(int i=0;i<n;++i) {
		cin>>a[i]>>b[i];
	}
	sort(all(a));
	sort(all(b));
	if(n&1) {
		cout<<(b[n/2]-a[n/2]+1)<<"\n";
	}else {
		cout<<(b[n/2]+b[n/2-1])-(a[n/2]+a[n/2-1])+1<<"\n";
	}
	return 0;
}


Measured memory_bytes: 4776
#include<stdio.h>
#define INFTY 1000000

int min(int,int);

int main(){
  int l,i,j,k,n,p[100],m[101][101],q;
  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }

  for(i=1;i<=n;i++){
    m[i][i]=0;
  }

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=INFTY;
      for(k=i;k<=j-1;k++){
	q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	m[i][j]=min(m[i][j],q);
      }
    }
  }

  printf("%d\n",m[1][n]);
  return 0;
}

int min(int a,int b){
  if(a<b)return a;
  else return b;
}
	

  

  



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;

int N;
double ans,ans1;
int main(){
  cin>>N;
  rep(i,N){
    double x;
    string u;
    cin>>x>>u;
    if(u=="JPY")ans+=x;
    else ans1+=x*380000;
  }
  cout<<fixed<<setprecision(10)<<ans+ans1<<endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

int main(){

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    int x,n;
    vector<int> arr;
    
    cin>>x>>n;
    int max=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        arr.push_back(a);
        if(a>max)
            max=a;
    }
    int min=10000;
    int flag=0;
    int ans=0;
    if(n==0){
        cout<<x;
    }
    else{
        for(int i=0;i<=150;i++){
                int tmp=abs(x-i);
                for(int j=0;j<arr.size();j++){
                    if(i==arr[j]){flag++;}
                }
                if(tmp<min){
                    if(flag==0){
                            min = abs(x-i);
                            ans = i;
                    }
                }
                flag = 0;
        }
        cout<<ans;
    }
    

}


Measured memory_bytes: 3648
N, M = map(int, input().split())
S = []
for i in range(N):
  a, b = map(int, input().split())
  S.append([a, b])

S.sort(key=lambda x: x[0])
price = 0
count = 0
for s in S:
  if count + s[1] < M:
    price += s[0] * s[1]
    count += s[1]
  else:
    price += s[0] * (M - count)
    break

print(price)

Measured memory_bytes: 21204
#include <algorithm>
#include <numeric>
#include <map>
#include <vector>
#include <cmath>
#include <complex>
#include <iostream>
#include <iomanip>

using namespace std;

typedef long double D;
typedef complex<D> P,Vec;

#define X real()
#define Y imag()

template<typename D> D EPS(){return 1e-9;}

struct L : public vector<P> {
  Vec vec;
  L(const P &a, const P &b):vec(b-a) {
	push_back(a); push_back(b);
  }
};

int sig(D a, D b=0){return a<b-EPS<D>()?-1:a>b+EPS<D>()?1:0;}
D norm(D a) {return a*a;}

istream& operator >> (istream& is, complex<D>& p) {
  D x,y; is >> x >> y;p=P(x,y); return is;
}
bool eq(const P& a, const P& b) {return sig(a.real(), b.real())== 0 && sig(a.imag(), b.imag())==0;}
bool compY (const P& a, const P& b) {return a.Y != b.Y ? a.Y < b.Y : a.X < b.X;}
bool compX (const P& a, const P& b) {return a.X != b.X ? a.X < b.X : a.Y < b.Y;}

D dot(const Vec& a, const Vec& b) { return real(conj(a)*b);}

bool isIntersectSP(const L &s, const P &p) {
  return sig(abs(s[0]-p)+ abs(s[1]-p), abs(s[1]-s[0])) <= 0;
}

P projection(const L &l, const P &p) {
  D t = dot(p-l[0], l.vec) / norm(l.vec);
  return l[0] + t * l.vec;
}

D distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (isIntersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}

int main() {
  int n1;
  cin >> n1;
  D x1[n1+2], y1[n1+2];
  x1[0] = 0.0; y1[0] = 0.0;
  for (int i = 1; i <= n1; i++) {
	cin >> x1[i] >> y1[i];
  }
  x1[n1+1] = 1000.0; y1[n1+1] = 0.0;
  int n2;
  cin >> n2;
  D x2[n2+2], y2[n2+2];
  x2[0] = 0.0; y2[0] = 1000.0;
  for (int i = 1; i <= n2; i++) {
	cin >> x2[i] >> y2[i];
  }
  x2[n2+1] = 1000.0; y2[n2+1] = 1000.0;
  n1 += 2; n2 += 2;
  D res = 1e9;
  for (int i = 0; i < n1; i++) {
	for (int j = 0; j < n2-1; j++) {
	  res = min(res, distanceSP(L(P(x2[j],y2[j]), P(x2[j+1],y2[j+1])), P(x1[i],y1[i])));
	}
  }
  for (int i = 0; i < n2; i++) {
	for (int j = 0; j < n1-1; j++) {
	  res = min(res, distanceSP(L(P(x1[j],y1[j]),P(x1[j+1],y1[j+1])), P(x2[i],y2[i])));
	}
  }
  cout << fixed << setprecision(20) << res <<endl;
  //  printf("%.10lf\n", res);
}

Measured memory_bytes: 1316
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

string s, t;

int main() {
    cin >> s >> t;
    
    vector<vector<int>> length(s.length() + 1, vector<int>(t.length() + 1));
    for (int i = 0; i < s.length(); i++) {
        for (int j = 0; j < t.length(); j++) {
            if (s[i] == t[j]) {
                length[i + 1][j + 1] = length[i][j] + 1;
            } else {
                length[i + 1][j + 1] = length[i + 1][j] > length[i][j + 1]? length[i + 1][j] : length[i][j + 1];
            }
        }
    }
    
    string ans = "";
    int i = (int) s.length(), j = (int) t.length();
    while (i > 0 && j > 0) {
        if (length[i][j] == length[i - 1][j]) {
            i--;
        } else if (length[i][j] == length[i][j - 1]) {
            j--;
        } else {
            ans = s[i - 1] + ans;
            i--; j--;
        }
    }
    
    cout << ans << endl;
}



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

public class Main{

	public static void main(String[] args) throws IOException {
		int N = readInt();
		HashSet<String> set = new HashSet<>();
		String t = read();
		char c = t.charAt(t.length()-1);
		set.add(t);
		for(int i = 2; i<=N; i++) {
			String s = read();
			if((s.charAt(0) != c) ){
				println("No"); exit();
			}
			c = s.charAt(s.length()-1);
			set.add(s);
			if(set.size() != i) {
				println("No");
				exit();
			}
		}
		println("Yes");
		exit();
	}

	final private static int BUFFER_SIZE = 1 << 16;
	private static DataInputStream din = new DataInputStream(System.in);
	private static byte[] buffer = new byte[BUFFER_SIZE];
	private static int bufferPointer = 0, bytesRead = 0;
	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	public static String readLine() throws IOException {
		byte[] buf = new byte[64]; // line length
		int cnt = 0, c;
		while ((c = Read()) != -1) {
			if (c == '\n')
				break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	public static String read() throws IOException {
		byte[] ret = new byte[1024];
		int idx = 0;
		byte c = Read();
		while (c <= ' ') {
			c = Read();
		}
		do {
			ret[idx++] = c;
			c = Read();
		} while (c != -1 && c != ' ' && c != '\n' && c != '\r');
		return new String(ret, 0, idx);
	}

	public static int readInt() throws IOException {
		int ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static long readLong() throws IOException {
		long ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}

	public static double readDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();

		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (c == '.') {
			while ((c = Read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}

		if (neg)
			return -ret;
		return ret;
	}

	private static void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if (bytesRead == -1)
			buffer[0] = -1;
	}

	private static byte Read() throws IOException {
		if (bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		din.close();
		pr.close();
		System.exit(0);
	}
}


Measured memory_bytes: 21972
import fractions
x = input().split()
a,b,c,d = int(x[0]),int(x[1]),int(x[2]),int(x[3])

cd = int(c*d/fractions.gcd(c,d))

cn = b // c - (a-1) // c
dn = b // d - (a-1) // d
cdn = b // cd - (a-1) // cd

print((b-a+1)-(cn+dn-cdn))

Measured memory_bytes: 5048
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: r

    read*, r
    if (r < 1200) then
        print'(a)', 'ABC'
    else if (r < 2800) then
        print'(a)', 'ARC'
    else
        print'(a)', 'AGC'
    end if
end program main

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	long long d[4000],x,y,z;
	int s[4000],n,i,j;
	while(scanf("%d",&n)&&n!=0)
	{
		memset(d,0,sizeof(d));
		for(i=0,j=0;i<n;i++)
		{
			scanf("%lld%lld%lld",&x,&y,&z);
			if(d[x]==0)
				d[x]=1000000;
			if(d[x]!=-1)
			{
				if(d[x]<=y*z)
				{
					s[j++]=x;
					d[x]=-1;
				}
				else
					d[x]-=y*z;
			}
		}
		if(j==0)
			printf("NA\n");
		else
			for(i=0;i<j;i++)
				printf("%d\n",s[i]);
	}
	return 0;
}

Measured memory_bytes: 660
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
const int mod=1e9+7; 
const int maxn=2e6+3;
int r1,c1,r2,c2;
ll Finv[maxn+5],jc[maxn+5],ans;
ll modpow(ll x,ll n,ll mod)
{
	ll res=1;
	for(;n;x=x*x%mod,n/=2)
	if(n&1)res=res*x%mod;
	return res;
}
void init()
{
	jc[0]=Finv[0]=1;
	for(int i=1;i<=maxn;++i)
	{
	 jc[i]=jc[i-1]*i;
	 if(jc[i]>=mod)jc[i]%=mod;
    }
	Finv[maxn]=modpow(jc[maxn],mod-2,mod);
	for(int i=maxn-1;i>=1;--i)
	{
	 Finv[i]=Finv[i+1]*(i+1);
	 if(Finv[i]>=mod)Finv[i]%=mod;
    }
}
ll C(ll n,ll m)
{
	if(m<0||m>n)return 0;
	return jc[n]*Finv[n-m]%mod*Finv[m]%mod;
}
int main()
{
	init();
	scanf("%d%d%d%d",&r1,&c1,&r2,&c2);
	for(int i=r1;i<=r2;++i)
		ans=(ans+C(i+c2+1,i+1)-C(i+c1,i+1)+mod)%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 31488
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
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; }
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;    
    vector<vector<int>> g(n);

    rep(i,m){
        int a,b;
        cin>>a>>b;
        --a;--b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> dist(n,-1);
    queue<int> que;
    vector<int> pre(n);
    que.push(0);
    dist[0] = 0;

    while(!que.empty()){
        int v = que.front();
        que.pop();

        for(auto nv : g[v]){
            if(dist[nv] != -1) continue;
            dist[nv] = dist[v] + 1;
            pre[nv] = v;
            que.push(nv);
        }
    }
    
    cout<<"Yes"<<endl;
    for(int i=1; i<n; i++){
        cout<<++pre[i]<<endl;
    }

}

Measured memory_bytes: 10588
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    auto abc = make_v(N, 3, 0LL);
    REP(i, 0, N) {
        REP(j, 0, 3) {
            cin >> abc[i][j];
        }
    }
    auto dp = make_v(N + 1, 3, 0LL);
    REP(i, 0, N) {
        REP(j, 0, 3) {
            REP(k, 0, 3) {
                if (j == k) continue;
                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + abc[i][k]);
            }
        }
    }

    ll ans = 0;
    REP(i, 0, 3) {
        ans = max(ans, dp[N][i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11264
#include<stdio.h>
#include<math.h>
int main(void){
    int i,j,K,N,m,s;
    int l=1;
    double ans;
    
    scanf("%d",&N);
    scanf("%d",&K);

    while(l<=N){
        s=l;
        m=0;
        while(s<K){
            m++;
            s=s*2;
        }
        ans = ans + (1.0/(double)N)*pow(0.5,(double)m);
        l++;
        if(N>K&&l>K) break;
    }

  
    if(N>K) ans = ans + ((double)(N-K)/(double)N);

    printf("%.12f\n",ans);
    
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
 
class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
         
        while (true) {
            int h = sc.nextInt(); int w = sc.nextInt();
            if (h==0 && w==0) return;
             
            for (int i=0; i<h; i++) {
                StringBuilder sb = new StringBuilder();
                for (int j=0; j<w; j++) {
                    if (i%2==0) {
                        if (j%2==0) sb.append("#");
                        else sb.append(".");
                    }
                    else {
                        if (j%2==0) sb.append(".");
                        else sb.append("#");
                    }
                }
                System.out.println(sb);
            }
             
            System.out.println();
        }
         
    }
}


Measured memory_bytes: 28856
function Main(input){
  const s = parseInt(input);
  var arr = [s];
  
  var flag = true;
  var idx = -1;
  do{
    var _f = f(arr[arr.length - 1]);
    idx = arr.findIndex(elem => elem === _f);
    if(idx < 0){
      arr.push(_f);
    }else{
      flag = false;
    }
  }while(flag)
  
  console.log(arr.length + 1);
}

function f(num) {
  if(num % 2 == 0){
    return num / 2;
  }else{
    return 3 * num + 1;
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void) {
    int n;string s;cin>>n>>s;
    vector<vector<int>>dp(n+1,vector<int>(n+1,0));
    rep(i,n){
        for(int j=i+1;j<n;j++){
            if(s[i]==s[j])dp[i+1][j+1]=min(j-i,dp[i][j]+1);
        }
    }
    int ans=0;
    rep(i,n)rep(j,n)ans=max(ans,dp[i+1][j+1]);
    cout<<ans<<endl;
    
    
}

Measured memory_bytes: 195840
def datesOfTheYear(year):
    if year % 3 == 0:
        return 200
    return 195


def datesOfTheMonth(year, month):
    if year % 3 == 0:
        return 20
    if month % 2 == 0:
        return 19
    else:
        return  20


def datesFromBorn(birthyear, birthmonth, birthdate):
    result = 0
    for y in range(birthyear + 1, 1000):
        result += datesOfTheYear(y)
    for m in range(birthmonth + 1, 11):
        result += datesOfTheMonth(birthyear, m)
    result += datesOfTheMonth(birthyear, birthmonth) - birthdate + 1
    return result

if __name__ == "__main__":
    import sys
    import fileinput

    fin = fileinput.input()
    numberofcandidate = int(fin.next().strip())

    for _ in range(numberofcandidate):
        year, month, date = [int(i) for i in fin.next().strip().split()]
        print datesFromBorn(year, month, date)

    sys.exit(0)

Measured memory_bytes: 4288
#include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<iostream>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<climits>
#include<complex>
#define sz(x) (int)((x).size())
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define clr(x) memset((x),0,sizeof(x))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
int a[111][111],s[111];
int main()
{
	int i,j,k,n,m;
	while (scanf("%d%d",&n,&m)!=EOF,n*n+m*m)
	{
		rep(i,m)scanf("%d",s+i);
		rep(i,n)rep(j,m)scanf("%d",a[i]+j);
		for (i=0;i<m;i++)
		{
			for (j=0;j<n;j++)
			{
				s[i]-=a[j][i];
			}
			if (s[i]<0)break;
		}
		puts(i==m?"Yes":"No");			
	}
	return 0;
}

Measured memory_bytes: 0
/*input
7
1 1 1 1 1 1 1
*/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>

using namespace std; 

int GCD(int x,int y){return y?GCD(y,x%y):x;}
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,a,b) for(int i=(a);i<(b);i++)
#define repm(i,a,b) for(int i=(a);i>(b);i--)
#define rept(v) for(auto it=v.begin();it<v.end();it++)
#define all(v) v.begin(),v.end()
const int INF = 1<<30;
typedef long long ll;
typedef pair<int,int> pii;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	sort(all(a));
	reverse(all(a));
	ll ans=a[0];
	repl(i, 1, n/2) {
		ans+=2*a[i];
	}
	if(n%2) ans+=a[n/2];
	cout << ans;
	return 0;
}


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

const int N = 2e5 + 10;
#define ll long long

struct edge {
    int to, nxt;
    ll v;
}e[N<<1];
int head[N], cnt, n;

void ins(int u, int v, ll w) {
    e[++cnt] = (edge) {v, head[u], w};
    head[u] = cnt;
}

int ans[N];

void dfs(int u, int fa) {
    for(int i = head[u]; i; i = e[i].nxt) {
        int v = e[i].to;
        if(v == fa) continue;
        if(e[i].v % 2) ans[v] = ans[u] ^ 1;
        else ans[v] = ans[u];
        dfs(v, u);
    }
}

int main() {
    scanf("%d", &n);
    for(int i = 1; i < n; ++i) {
        int u, v; ll w;
        scanf("%d%d%lld", &u, &v, &w);
        ins(u, v, w); ins(v, u, w);
    }
    dfs(1, 0);
    for(int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;



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

    vector<plint> A(N), B(N);
    vector<lint> C(N);
    lint ans = 0;

    lint ansA = 0, ansB = 0;

    priority_queue<plint, vector<plint>, greater<plint>> pq;
    priority_queue<plint, vector<plint>, greater<plint>> greaters;
    REP(i, N)
    {
        cin >> A[i].first >> B[i].first;
        ansA += A[i].first;
        ansB += B[i].first;
        A[i].second = B[i].second = i;
        greaters.push(plint(max(B[i].first, A[i].first), i));
    }

    

    REP(i, N) pq.push(B[i]);
    REP(i, N) pq.push(A[i]);

    set<int> num;
    plint pa;
    REP(i, N)
    {
        pa = pq.top();
        pq.pop();
        num.insert(pa.second);
        ans += pa.first;
    }

    cerr << num.size() << endl;

    lint tmp_sum = ans;
    if (num.size() == N)
    {
        ans = 10000000000000000;
        REP(i, N)
        {
            plint pa_taihi = greaters.top();
            bool flg_taihi = false;
            
            if (greaters.top().second == i)
            {
                flg_taihi = true;
                greaters.pop();
            }

            ans = min(ans, tmp_sum - min(A[i].first, B[i].first) + greaters.top().first);

            if (flg_taihi) greaters.push(pa_taihi);

        }
    }

    cout << min(ans, min(ansA, ansB)) << endl;
}


Measured memory_bytes: 14444
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N=int(input())
from collections import defaultdict
dic=defaultdict(int)
for i in range(1,N+1):
  arr=factorization(i)
  for a in arr:
    dic[a[0]]+=a[1]
    
# これら素因数の集まりに対して、
# 2,4,4
# 74
# 2,24
# 4,14
# 個選択できるペアをいくつ作れるかを数える
items=dic.items()

def c(items,p):
  return len(list(filter(lambda x:x[1]>=p,items)))

ans=0
ans+=c(items,74)
ans+=(c(items,4)*(c(items,4)-1)*(c(items,2)-2))//2
ans+=c(items,24)*(c(items,2)-1)
ans+=c(items,14)*(c(items,4)-1)
print(ans)

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s, t;
  int a, b;
  cin >> s >> t >> a >> b;
  string u;
  cin >> u;
  if (s == u) a--;
  if (t == u) b--;
  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const stc& lhs, const stc& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N;
    vd X(N), Y(N);
    vector<pair<double, pair<double, double>>> args;
    rep(i, N){
        cin >> X[i] >> Y[i];
        args.pb({atan2(Y[i], X[i]), {X[i], Y[i]}});
    }
    sort(ALL(args));
    
    double ans = 0.0;
    rep(st, N){
        rep(ed, st+N+1){
            double tx = 0.0, ty = 0.0;
            FOR(k, st, ed){
                ll kk = k%N;
                tx += args[kk].ss.ff; ty += args[kk].ss.ss;
            }
            chmax(ans, sqrt(tx*tx+ty*ty));
        }
    }
    cout << fixed << setprecision(20) << ans << endstr;
    return 0;
}


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

int main(void)
{
    int timeLength;
    cin >> timeLength;

    int *dollar = new int[timeLength];
    for (int i = 0; i < timeLength; i++) cin >> dollar[i];

    int maxProfit = dollar[1] - dollar[0];
    int minDollar = dollar[0];
    for (int i = 1; i < timeLength; i++) {
        maxProfit = max(maxProfit, dollar[i] - minDollar);
        minDollar = min(minDollar, dollar[i]);
    }

    cout << maxProfit << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
  char S[2222222];
  cin >> S;
  ll sum = 0;
  ll i;
  ll N = 0;
  while(S[N]) N++;
  for(i=0;i<=N-1;i++)
    sum += (S[i] - '0');
  if(sum%9) cout << "No";
  else cout << "Yes";
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    int N = s.size();
    int res = 0;
    for(int i = 0;i < N/2;i++) {
        if(s[i] != s[N - i - 1]) {
            res++;
        }
    }
    cout << res << endl;
    return 0;
}



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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int d, n;
  cin >> d >> n;
  if(n==100) n++;
  int ans;
  if(d==0) ans = n;
  else if(d==1) ans = n*100;
  else ans = n*10000;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N=0;
  int K=0;
  int A=0;
  cin >> N >> K;
  vector<int> H(N);
  
  for(int i=0; i<N; i++){
    cin >> H.at(i);
  }
  
  for(int j=0; j<N; j++){
    if(H.at(j)>=K){
      A+=1;
    }
  }
  
  cout << A << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,m;
  cin >> n >> m;
  int k,a;
  vector<int> list(m+1);
  for(int i=0; i<n; i++) {
    cin >> k;
    for(int j=0; j<k; j++) {
      cin >> a;
      list.at(a) += 1;
    }
  }
  int ans = 0;
  for(int i=1; i<=m; i++) {
    if(list.at(i) == n) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> H(n);
    copy_n(istream_iterator<int>(cin), n, H.begin());
    vector<vector<int>> E(n);
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        E[a].push_back(b);
        E[b].push_back(a);
    }

    int ans = 0;
    for (int i = 0; i < n; i++){
        bool flag = true;
        for (const auto &e: E[i])
            flag &= H[i] > H[e];
        if (flag)
            ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 8804