akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main () {
  int N;
  cin >> N;
  vector<int> a(N*2);
  for (int i=0; i<N*2; i++) 
    cin >> a[i];
  
  sort(a.begin(), a.end());
  int b = 0;
  for (int i=0; i<N; i++) {
    b += a[i*2];
  }
  cout << b << endl;
  
  return 0;
}


Measured memory_bytes: 256
(X, Y, Z, K), As, Bs, Cs = readlines.map{|l| l.split.map(&:to_i)}

as, bs, cs = [As, Bs, Cs].map{|xs| [nil] + xs.sort.reverse}
ds = []
(1 .. X).each do |i|
  (1 .. Y).each do |j|
    (1 .. Z).each do |k|
      if i*j*k <= K
        ds << as[i] + bs[j] + cs[k] if i*j*k <= K
      else
        break
      end
    end
  end
end
puts ds.sort.reverse.take(K)

Measured memory_bytes: 4916
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
int main(){
    int n;
    cin >> n;
    vector<int> v(n, 0);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }

   int min_v = v[0];
   int max_v = v[1] - v[0];
   for(int i = 1; i < n; i++){
       max_v = max(max_v, v[i] - min_v);
       min_v = min(min_v, v[i]);
   }
   cout << max_v << endl;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    i32 n,h,w; cin >> n >> h >> w;
    i32 a, b, Cnt = 0;
    rep(i,n) {
        cin >> a >> b;
        if(a >= h && b >= w) ++Cnt;
    }

    cout << Cnt << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


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

class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int a = int.Parse(input[0]);
		int b = int.Parse(input[1]);
		int c = int.Parse(input[2]);
		int d = int.Parse(input[3]);
		long mod = 998244353;

		long[][] dp = new long[c+1][];
		for(int i=0; i<=c; i++) dp[i] = new long[d+1];
		dp[a][b] = 1;

		for(int col = b; col <= d; col++)
		{
			for(int row = a; row <= c; row++)
			{
				if(col == b && row == a) continue;
				long dpTmp = (dp[row-1][col] * (long)col) % mod;
				dpTmp = (dpTmp + (dp[row][col-1] * (long)row) % mod) % mod;
				dpTmp = (dpTmp + mod - ((dp[row-1][col-1] * ((long)row - 1) * ((long)col - 1)) % mod)) % mod;
				dp[row][col] = dpTmp;
			}
		}
		Console.WriteLine(dp[c][d]);
	}
}


Measured memory_bytes: 98344
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int h = Integer.parseInt(sc.next());
    int a = Integer.parseInt(sc.next());

    int cnt = 0;
    while (h >= 0) {
      h -= a;
      ++cnt;
    }
    if (h % a == 0) {
      System.out.println(cnt - 1);
    } else {
      System.out.println(cnt);
    }
  }
}


Measured memory_bytes: 21716
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<string> 
#include<cstring>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

#define int long long

int a[2002][2002];
int b[2002][2002];
int c[2002][2002];
int dp[2002][2002];

signed main(){
    int h,w,m;
    cin >> h >> w >> m;
    vector<string> s(h);
    rep(i,h){
        cin >> s[i];
    }
    dp[1][1] = 1;
    rep(i,h){
        rep(j,w){
            if(i==0&&j==0)continue;
            dp[i+1][j+1] = dp[i][j+1]+ dp[i+1][j];
            dp[i+1][j+1] %= m;
        }
    }
    rep(i,h){
        int p = i+1;
        rep(j,w){
            int q = j+1;
            if(isdigit(s[i][j])){
                int k = s[i][j]-'0';
                if(i==0&j==0){
                    b[p][q] = 1;
                    c[p][q] = k;
                }else{
                    a[p][q] = (a[p-1][q]+a[p][q-1])%m;
                    b[p][q] = (b[p-1][q]+b[p][q-1])%m;
                    c[p][q] = (10*c[p-1][q]+10*c[p][q-1]+b[p][q]*k)%m;
                }
            }else if(s[i][j]=='+'){
                a[p][q] = (a[p-1][q]+a[p][q-1]+c[p-1][q]+c[p][q-1])%m;
                b[p][q] = dp[p][q];
            }else{
                a[p][q] = (a[p-1][q]+a[p][q-1])%m;
                b[p][q] = (c[p-1][q]+c[p][q-1])%m;
            }
            //cerr << i << " " << j << " " << a[p][q] << " " << b[p][q] << " " << c[p][q] << "  "<< a[p][q]+c[p][q] << endl;
        }
        
    }
    cout << (a[h][w]+c[h][w])%m << endl;
    return 0;
}


Measured memory_bytes: 131904
#include <iostream>
using namespace std;
//C - GeT AC
int main(void){
    int N,Q;
    char txt[100001];
    std::cin >> N >> Q >>txt;
    int X[100001];
    for(int i=1;i<N;i++){
        if(txt[i]=='C' && txt[i-1]=='A'){
            X[i]++;
        }
        X[i]+=X[i-1];
    }
    for(int i=0;i<Q;i++){
        int l,r;
        std::cin >> l >> r;

        std::cout <<X[r-1]-X[l-1] << std::endl;
    }
    return 0;
}


Measured memory_bytes: 1280
import scala.io.StdIn

object Main {

  val stack: Array[Int] = new Array[Int](1000)
  var top: Int = 0

  def main(args: Array[String]): Unit = {
    val probArray = StdIn.readLine().split(" ")
    println(calc(probArray))
  }

  def calc(array: Array[String]): Int = {
    array.foreach( t => {
      t match {
        case "+" => push(pop() + pop())
        case "-" =>
          val num1 = pop()
          val num2 = pop()
          push(num2 - num1)
        case "*" => push(pop() * pop())
        case "/" =>
          val num1 = pop()
          val num2 = pop()
          push(num2 / num1)
        case _ => push(t.toInt)
      }
    })
    pop()
  }

  def push(value: Int): Unit = {
    stack(top) = value
    top += 1
  }

  def pop(): Int = {
    top -= 1
    val result = stack(top)
    stack(top) = 0
    result
  }

  def isEmpty(): Boolean = if (top == 0) true else false

  def isFull(): Boolean = if (stack.length == top) true else false
}

Measured memory_bytes: 43780
n,m=map(int,input().split())
l=list(map(int,input().split()))
from collections import deque
d=deque([0])
li=[0]*n
c=1
lis=[]
for i in range(n+1):
  now=d.pop()
  ne=l[now]
  li[now]=c
  lis.append(now)
  if li[ne-1]!=0:
    z=ne-1
    break
  else:
    d.append(ne-1)
x=lis.index(z)
if m<x+1:
  print(lis[m]+1)
else:
  print(lis[(m-x)%(len(lis)-x)+x]+1)

Measured memory_bytes: 32300
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
string s;

int main(){
	cin >> s;
	
	REP(i,0,s.size()-1){
		REP(j,i+1,s.size()){
			if(s[i]=='C'&&s[j]=='F'){cout << "Yes" << endl; return 0;}
		}
	}
	
	cout << "No" << endl;
	return 0;
}


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



int main(){
	int n;
	cin >> n;
	map<int,int> have;
	rep(i,n){
		int input;
		cin >> input;
		have[input]++;
	}	
	int m;
	cin >> m;
	map<int,int> prob;
	rep(i,m){
		int input;
		cin >> input;
		have[input]--;
	}
	for(auto a:have){
		if(a.second<0){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}


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

using namespace std;

int main() {
  int N, D, look = 0, ans = 0;
  
  cin >> N >> D;
  
  while (look < N) {
    look += 2 * D + 1;
    ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}

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

typedef long long ll;

int N;
ll ans = 0;
bool flag;
ll MIN = 1001001001;

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)
    {
        ll a,b;
        scanf("%lld%lld",&a,&b);
        if(a != b)flag = true;
        ans += a;
        if(a > b)MIN = min(MIN,b);
    }

    if(!flag)printf("0\n");
    else printf("%lld\n",ans - MIN);
    return 0;
}


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

string f(string s1,int n1,string s2,int n2,vector<vector<int> > &dp)
{
    for (int i=1;i<=n1;i++)
        for (int j=1;j<=n2;j++)
            if(s1[i-1]==s2[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);

    string r="";
    r.resize(dp[n1][n2]);
    int i=n1,j=n2,k=dp[n1][n2]-1;
    while(k>=0)
    {
        if(s1[i-1]==s2[j-1] && dp[i][j]==dp[i-1][j-1]+1)
        {
            r[k--]=s1[i-1];
            i--;
            j--;
        }
        else if(dp[i][j]==dp[i][j-1])
            j--;
        else i--;
    }
    return r;
}

int main()
{
    int n1,n2;
    string s1,s2;
    cin >> s1 >> s2;
    n1=s1.size();
    n2=s2.size();
    vector<vector<int> > dp(n1+1,vector<int> (n2+1,0));
    cout << f(s1,n1,s2,n2,dp);
}


Measured memory_bytes: 35584
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

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

long long int INF = 2147483647;
int const TREE_SIZE = 1 << 20;
long long int seg_tree[TREE_SIZE];
bool is_a[TREE_SIZE];

int find(int a, int b, int index, int l, int r){
	
	// 外からは query(a, b, 1, 0, TREE_SIZE / 2) のように呼ぶ
	if(r <= a || b <= l){
		return INF;
	}
	if(a <= l && r <= b){
		return seg_tree[index];
	}
	if(is_a[index]){
		return seg_tree[index];
	}
	int ret = INF;
	ret = min(ret, find(a, b, index * 2, l, (l + r) / 2));
	ret = min(ret, find(a, b, index * 2 + 1, (l + r) / 2, r));
	return ret;
}

int update(int a, int b, int index, int num, int l, int r){
	
	// 外からは query(a, b, 1, 0, TREE_SIZE / 2) のように呼ぶ
	
	if(r <= a || b <= l){
		return seg_tree[index];
	}
	if(a <= l && r <= b){
		seg_tree[index] = num;
		is_a[index] = true;
		return num;
	}
	int ret = INF;
	if(is_a[index]){
		is_a[index * 2] = true;
		seg_tree[index * 2] = seg_tree[index];
		is_a[index * 2 + 1] = true;
		seg_tree[index * 2 + 1] = seg_tree[index];
		is_a[index] = false;
		ret = seg_tree[index];
	}
	ret = min(ret, update(a, b, index * 2, num, l, (l + r) / 2));
	ret = min(ret, update(a, b, index * 2 + 1, num, (l + r) / 2, r));
	return seg_tree[index] = ret;
}

int main(){
	
	int n, q;
	cin >> n >> q;
	
	for(int i = 0; i < TREE_SIZE; i++){
		seg_tree[i] = INF;
		is_a[i] = false;
	}
	is_a[1] = true;
	
	for(int i = 0; i < q; i++){
		long long int num, a, b, c;
		cin >> num;
		if(num == 0){
			cin >> a >> b >> c;
			update(a, b + 1, 1, c, 0, TREE_SIZE / 2);
		}else{
			cin >> a >> b;
			cout << find(a, b + 1, 1, 0, TREE_SIZE / 2) << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 12340
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
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;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    // char ;
    ll n,ans=0;
    scanf("%lld",&n);
    ll s[n];
    rep(i,0,n){
        scanf("%lld",&s[i]);
        ans+=s[i];
    }
    if(ans%10!=0){
        printf("%lld\n",ans);
        return 0;
    }else{
        sortup(s,n);
        rep(i,0,n){
            if(s[i]%10!=0){
                printf("%lld\n",ans-s[i]);
                return 0;
            }
        }
        printf("0\n");
    }
    // printf("\n");
    return 0;
}


Measured memory_bytes: 128
import bisect

INF = 10 ** 18

def main():
    A, B, Q = list(map(int, input().split()))
    s = []
    t = []
    for i in range(A):
        s.append(input())
    for i in range(B):
        t.append(input())
    s = [-INF] + sorted(list(map(int, s))) + [INF]
    t = [-INF] + sorted(list(map(int, t))) + [INF]

    for i in range(Q):
        x = int(input())
        a = bisect.bisect_right(s, x)
        b = bisect.bisect_right(t, x)
        ret = INF
        for j in [s[a-1], s[a]]:
            for k in [t[b-1], t[b]]:
                ret = min(ret, abs(x-j)+abs(j-k), abs(x-k)+abs(j-k))
        print(ret)

if __name__ == "__main__":
    main()

Measured memory_bytes: 22188
import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def isOK(i, A, K):
    if i == 0:
        return False
    return K >= sum((a-1)//i for a in A)

def b_serach(A, K):
    ng = -1
    ok = 10**9+1

    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if isOK(mid, A, K):
            ok = mid
        else:
            ng = mid

    return ok


def main():
    N, K = mi()
    A = list(mi())
    print(b_serach(A, K))


if __name__ == '__main__':
    main()

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

class Dice {
public:
    int upside() {
        return faces[0];
    }

    void E() {
        int tmp = faces[0];
        faces[0] = faces[3];
        faces[3] = faces[5];
        faces[5] = faces[2];
        faces[2] = tmp;
    }

    void N() {
        int tmp = faces[0];
        faces[0] = faces[1];
        faces[1] = faces[5];
        faces[5] = faces[4];
        faces[4] = tmp;
    }

    void S() {
        int tmp = faces[0];
        faces[0] = faces[4];
        faces[4] = faces[5];
        faces[5] = faces[1];
        faces[1] = tmp;
    }

    void W() {
        int tmp = faces[0];
        faces[0] = faces[2];
        faces[2] = faces[5];
        faces[5] = faces[3];
        faces[3] = tmp;
    }

private:
    int faces[6] = {0, 1, 2, 3, 4, 5};
};

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

    string str;
    cin >> str;

    Dice dice;
    for (int i = 0; i < str.size(); i++) {
        char ch = str[i];
        if (ch == 'E') {
            dice.E();
        } else if (ch == 'N') {
            dice.N();
        } else if (ch == 'S') {
            dice.S();
        } else if (ch == 'W') {
            dice.W();
        }
    }

    cout << a[dice.upside()] << endl;

    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define endl "\n" 
#define ll long long
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define umap unordered_map
#define uset unordered_set 
#define mod 1000000007
#define imax INT_MAX
#define imin INT_MIN
#define exp 1e9
#define sz(x) (int((x).size()))
#define int long long

void clear(int dp[][3], int n) {
    for(int i = 0; i < n; i++) {
        dp[i][0] = dp[i][1] = dp[i][2] = -1;
    }
    return ;
}

int helper(int arr[][3], int n, int col, int index, int dp[][3]) {
    if(index == n-1) {
        return arr[n-1][col];
    }
    if(dp[index][col] != -1) return dp[index][col];
    int ans = imin;
    if(col != 0)
        ans = max(ans, helper(arr, n, 0, index + 1, dp));
    if (col != 1)
        ans = max(ans, helper(arr, n, 1, index + 1, dp));
    if (col != 2)
        ans = max(ans, helper(arr, n, 2, index + 1, dp));

    return dp[index][col] = ans + arr[index][col];
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    int arr[n][3];
    for(int i = 0; i < n; i++) {
        cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
    }
    int ans = imin;
    int dp[n][3];
    clear(dp, n);
    ans = max(ans, helper(arr, n, 0, 0, dp));
    clear(dp, n);
    ans = max(ans, helper(arr, n, 1, 0, dp));
    clear(dp, n);
    ans = max(ans, helper(arr, n, 2, 0, dp));

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 16092
#include "bits/stdc++.h"
#include <boost/range/irange.hpp>
using namespace std;
using boost::irange;

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for (ll i = m ; i < (ll)n ; ++i)
#define VL                vector<ll>
#define VLL               vector<vector<ll>>
#define VLLL              vector<vector<vector<ll>>>
#define INF               2e9;
#define INF_LL            1LL<<60;
#define MOD               1000000007;

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// 処理
void Solve()
{
	double A, B, H, M;
	cin >> A >> B >> H >> M;

	double radM = (M / 60);
	double radH = (H / 12) + (M / 60) / 12;
	radM *= 2 * M_PI;
	radH *= 2 * M_PI;
	double ang = radM > radH ? radM - radH : radH - radM;
	if (ang > 180) ang = 360 - ang;
	double area = A * A + B * B - 2 * A * B * cos(ang);

	cout << sqrt(area) << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


Measured memory_bytes: 4248
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>

using namespace std;
#define ll long long


int main(void){
    ll N;
    cin>>N;
    cout<<180*(N-2)<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define st first
#define nd second
#define turbo ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define qi queue<int>
#define ld long double

using namespace std;

/*---------------------------------------------------------///CODE///---------------------------------------------------------*/

const int N = 2e5;
pii T[N + 10];
ll dp[N + 10];

const int MAX = 1 << 18;
ll Tree[2*MAX + 10];

void Update(int p, ll v)
{
    p += MAX;

    Tree[p] = v;
    p /= 2;

    while(p >= 1)
    {
        Tree[p] = max(Tree[2*p], Tree[2*p + 1]);
        p /= 2;        
    }
}
ll Query(int a, int b)
{
    a += MAX, b += MAX;

    ll res = (a == b ? Tree[a] : max(Tree[a], Tree[b]));

    while(a / 2 != b / 2)
    {
        if(a % 2 == 0) res = max(res, Tree[a + 1]);
        if(b % 2 == 1) res = max(res, Tree[b - 1]);
        a /= 2, b /= 2;
    }
    return res;
}
int main()
{
    turbo

    int n; cin >> n;

    for(int i = 1; i <= n; i++)
        cin >> T[i].st;
    for(int i = 1; i <= n; i++)
        cin >> T[i].nd;

    for(int i = 1; i <= n; i++)
    {
        ll curr = Query(1, T[i].st);
        dp[T[i].st] = curr + T[i].nd;
        Update(T[i].st, dp[T[i].st]); 
    }
    
    return cout << *max_element(dp, dp + n + 1), 0;
}

Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;
ll INF=1000000000000000;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
int main()
{
	ll n,k;
	cin>>n>>k;
	ll a[n+1];
	for(ll i=1;i<=n;i++)
	cin>>a[i];
	ll dp[n+1];
	dp[1]=0;
	for(ll i=2;i<=n;i++)
	dp[i]=INF;
	for(ll i=2;i<=n;i++)
	{
		for(ll j=1;j<=k && (i-j)>0;j++)
		{
			dp[i]=min(dp[i],(dp[i-j]+abs(a[i]-a[i-j])));
		}
//cout<<dp[i]<<' ';
	}
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

#define N 100

int main() {
	static int ll[N], dd[N + 1];
	int n, x, i, cnt;

	scanf("%d%d", &n, &x);
	for (i = 0; i < n; i++)
		scanf("%d", &ll[i]);
	dd[0] = 0;
	cnt = 1;
	for (i = 1; i <= n; i++)
		if ((dd[i] = dd[i - 1] + ll[i - 1]) <= x)
			cnt++;
	printf("%d\n", cnt);
	return 0;
}


Measured memory_bytes: 128
//2020-06-21 06:58:21
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
const int INF = 1e9;
int dp[1001][1<<12];
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n, m; cin >> n >> m;
   vector<pair<int, int>> keys;
   rep(i,m){
      int a, b; cin >> a >> b;
      int state = 0;
      rep(j,b){
         int c; cin >> c;
         state += (1<<(c-1));
      }
      keys.push_back(make_pair(a, state));
   }
   rep(i,1001)rep(j,1<<12)dp[i][j] = INF;
   dp[0][0] = 0;
   rep(i,keys.size()){
      rep(j,1<<n){
         if (dp[i][j] != -1){
            dp[i+1][j] = min(dp[i][j], dp[i+1][j]);
            dp[i+1][j | keys[i].second] = min(dp[i+1][j | keys[i].second], dp[i][j]+keys[i].first);
         }
      }
   }
   cout << (dp[m][(1<<n)-1]==INF ? -1 : dp[m][(1<<n)-1]) << endl;
}

Measured memory_bytes: 19596
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

def main():
    N = int(input())
    T, A = map(int, input().split())
    H = [v for v in map(int, input().split())] # N
    result = sys.float_info.max
    for i in range(0, N):
        tmp = abs(A - (T - H[i] * 0.006))
        if  tmp < result:
            result = tmp
            answer = i + 1

    print(answer)


if __name__ == "__main__":
    main()


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

int main()
{
    char a,b;
    cin>>a>>b;
    if(a=='H' && b=='H'){
        cout<<"H"<<endl;
    }else if(a=='D'&&b=='D'){
        cout<<"H"<<endl;
    }else{
        cout<<"D"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define ALL(a) (a).begin(), (a).end()
#define p(a, b) printf(a, b);
#define c(s) cout << (s) << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define cyn(c) cout << (c ? "Yes" : "No") << endl;
#define cYN(c) cout << (c ? "YES" : "NO") << endl;
#define pyn(c) printf("%s\n", c ? "Yes" : "No");
#define pYN(c) printf("%s\n", c ? "YES" : "NO");
#define INF 1e18
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
template <class T>
bool contain(const std::string &s, const T &v)
{
  return s.find(v) != std::string::npos;
}
ULL mod = 1e9 + 7;

unsigned long long gcd(unsigned long long a, unsigned long long b)
{
  while (1)
  {
    if (a < b)
      swap(a, b);
    if (!b)
      break;
    a %= b;
  }
  return a;
}

int main()
{
  int R, G, B, N, ans = 0;
  cin >> R >> G >> B >> N;
  for (int r = 0; r <= N / R; r++)
  {
    for (int g = 0; g <= N / G; g++)
    {
      if ((N - (r * R + g * G)) >= 0 && ((N - (r * R + g * G)) <= N) && ((N - (r * R + g * G)) % B == 0))
      {
        // cout << "r: " << r << " g: " << g << " b: " << (N - (r * R + g * G)) / B << endl;
        ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B = MAP()
C = gcd(A, B)
print(A*B//C)

Measured memory_bytes: 5148
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>

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

using namespace std;

int main()
{
    string s;
    while(true)
    {
        getline(cin,s);
        if(s == ".") break;
        
        stack<char> st;
        bool flag = true;
        rep(i,s.size()) {
            if(!flag) break;

            if(s[i] == '(') {
                st.push(s[i]);
            }
            if(s[i] == ')') {
                if(st.size() == 0) flag = false;
                else {
                    if(st.top() == '(') st.pop();
                    else flag = false;
                }
            }
            if(s[i] == '[') {
                st.push(s[i]);
            }
            if(s[i] == ']') {
                if(st.size() == 0) flag = false;
                else {
                    if(st.top() == '[') st.pop();
                    else flag = false;
                }
            }
        }

        if(flag && st.size() == 0) cout << "yes" << endl;
        else cout << "no" << endl;
        
    }

    return 0;
}

Measured memory_bytes: 1176
n=int(input())
S=input()
A=[0]*n
for i in range(n):
  if S[i]=='(':
    A[i]=1
  else:
    A[i]=-1
A=[0]+A
for i in range(1,n+1):
  A[i]=A[i]+A[i-1]
#print(A)
m=min(A)
T='('*(A[0]-m)+S+')'*(A[-1]-m)
print(T)

Measured memory_bytes: 3060
#include <iostream>
#include <iterator>
#include <list>
#include <string>

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

    std::list<int> intList;
    std::string command;
    int         element;
    for (int i = 0; i < commandNum; i++)
    {
        std::cin >> command;

        if (command == "insert")
        {
            std::cin >> element;
            intList.push_front(element);
        }
        else if (command == "delete")
        {
            std::cin >> element;

            for (auto it = intList.begin(); it != intList.end(); it++)
            {
                if (*it == element)
                {
                    intList.erase(it);
                    break;
                }
            }
        }
        else if (command == "deleteFirst")
        {
            intList.pop_front();
        }
        else if (command == "deleteLast")
        {
            intList.pop_back();
        }
    }

    for (auto it = intList.begin(); it != intList.end();)
    {
        std::cout << *it;

        if (++it != intList.end()) std::cout << " ";
        else std::cout << std::endl;
    }
}


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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

int main(){
  int N,H,W;
  cin >> N >> H >> W;
  cout << max(0,(N-H+1)*(N-W+1)) << endl;
}

Measured memory_bytes: 256
#include <cctype>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define LL long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

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

int main(){
	int m;
	cin >> m;
	while(m--){
		string s;
		cin >> s;
		
		map<string, int> mp;
		REP(i, s.size() - 1){
			string left, right;
			REP(j, s.size()){
				if(j < i + 1) left.pb(s[j]);
				else right.pb(s[j]);
			}

			reverse(left.begin(), left.end());
			reverse(right.begin(), right.end());
			string Rleft = left;
			string Rright = right;
			reverse(left.begin(), left.end());
			reverse(right.begin(), right.end());

			mp[left + right] = 1;
			mp[left + Rright] = 1;
			mp[Rleft + right] = 1;
			mp[Rleft + Rright] = 1;
			mp[right + left] = 1;
			mp[right + Rleft] = 1;
			mp[Rright + left] = 1;
			mp[Rright + Rleft] = 1;
		}

		cout << mp.size() << endl;
	}

}

Measured memory_bytes: 3128
import sys

N, T = map(int, input().split())

ans_c = sys.maxsize
ans_t = sys.maxsize

for i in range(N):
    c, t = map(int, input().split())
    if t <= T and c < ans_c:
        ans_c = c
        ans_t = t

if ans_t > T:
    print("TLE")
else:
    print(ans_c)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

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

int N;
vector<string> S;

bool Contain(string S, string T) {
    for(int i = 0; i < T.size(); i++) {
        if(T.substr(i, S.size()) == S) return true;
    }
    return false;
}

int dp[1 << 14][14];
int PreCal[14][14];

int f(string S, string T) {
    for(int sz = min(S.size(), T.size()); sz >= 0; sz--) {
        if(S.substr(S.size() - sz, sz) == T.substr(0, sz)) return sz;
    }
}

void solve() {
    S.resize(N);
    for(int i = 0; i < N; i++) {
        cin >> S[i];
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            if(i == j) continue;
            if(Contain(S[i], S[j])) {
                S.erase(S.begin() + i);
                i--;
                N--;
                break;
            }
        }
    }
    //for(int i = 0; i < N; i++) cerr << S[i] << endl;
    for(int i = 0; i < (1 << N); i++) {
        for(int j = 0; j < N; j++) {
            dp[i][j] = 1e9;
        }
    }
    for(int i = 0; i < N; i++) {
        dp[1 << i][i] = S[i].size();
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            PreCal[i][j] = f(S[i], S[j]);
        }
    }
    for(int bits = 1; bits < (1 << N); bits++) {
        for(int before = 0; before < N; before++) {
            if(!(bits & (1 << before))) continue;
            for(int to = 0; to < N; to++) {
                if(bits & (1 << to)) continue;
                chmin(dp[bits | (1 << to)][to], dp[bits][before] + (int)S[to].size() - PreCal[before][to]);
            }
        }
    }
    int ans = 1e9;
    for(int i = 0; i < N; i++) {
        chmin(ans, dp[(1 << N) - 1][i]);
    }
    cout << ans << endl;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        cin >> N;
        if(N == 0) break;
        solve();
    }
    return 0;
}


Measured memory_bytes: 4084
//Utkarsh-raj

#include<bits/stdc++.h>

#define ll long long int
#define vc vector
#define mod 100000000007
#define mp make_pair
#define pb push_back
#define nl cout<<endl;
#define ff first
#define ss second

using namespace std;

int dp[3010][3010];
string res = "";

void solve(string s, string t){
    int n = s.size(), m = t.size();

    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else{
                dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
            }
        }
    }

    int x = n, y = m;
    while(x >= 0 && y >= 0 && dp[x][y] != 0){
        if(s[x-1] == t[y-1]){
            res += s[x-1];
            x--;
            y--;
        }
        else if(dp[x][y] == dp[x][y-1]){
            y--;
        }
        else{
            x--;
        }
    }
    reverse(res.begin(), res.end());
    cout<<res<<endl;
}

int main()
{
    ifstream myFile("task.in");
    if(!myFile.fail())
    {
        assert(freopen("task.in", "r", stdin));
    }

    string s, t;
    cin>>s>>t;

    solve(s, t);

    return 0;
}


Measured memory_bytes: 35584
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;
import std.ascii;

string solve(string s)
{
    string[] WS = ["the","this","that"];
    immutable char N = 'z'-'a'+1;
    foreach(i;0..N)
    {
        string t = s.map!(c=>cast(immutable char)(isLower(c)?((c+i)-'a')%N+'a':c)).array();
        foreach(w_;t.split())
            foreach(w;w_.split("."))
                foreach(W;WS)
                    if(w==W)
                        return t;
    }
    return "not found";
}

void main()
{
    stdin.byLine().map!(to!string).map!solve().join("\n").writeln();
}

Measured memory_bytes: 1084
#include <algorithm>

#include <stdio.h>
#include <string.h>

int n;

int memo[4 + 1][50 + 1];

int search(int i, int j)
{
  if (memo[i][j] >= 0)
    return memo[i][j];

  if (j > i * 9)
    return memo[i][j] = 0;

  if (i == 1)
    return memo[i][j] = 1;

  int c = 0;

  for (int k = 0; k <= j && k <= 9; k ++)
    c += search(i - 1, j - k);

  return memo[i][j] = c;
}

int main(int argc, char** argv)
{
  while (fscanf(stdin, "%d", &n) == 1) {
    memset(memo, -1, sizeof(memo));
    
    fprintf(stdout, "%d\n", search(4, n));
  }
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();//プレイヤー人数
		int x[][] = new int[N][3];//二重配列　行にプレイヤー、列にゲーム数
		int p[][] = new int[N][3];//暫定ポイント
		int result[] = new int[N];//最終得点
		int i,j,k,a;
		
		for(i = 0; i < N; i++){
			for(j = 0; j < 3; j++){
				x[i][j] = sc.nextInt();//プレイヤーiの書いた数を入力
				p[i][j] = x[i][j];
			}
		}
		
		for(j = 0; j < 3; j++){
			for(i = 0; i < N; i++){//プレイヤーi
				for(k = i+1; k < N; k++){//プレイヤーiの比較対象プレイヤーk+1
					if(x[i][j] == x[k][j]){
						p[i][j] = 0;
						p[k][j] = 0;
						break;//両者のポイントを0にすれば、それ以降でiが増えていっても最初のプレイヤーと比較しなおす必要は無くなる。
					}
				}
			}
		}
		
		for(i = 0; i < N; i++){
			for(j = 0; j < 3; j++){
				result[i] = result[i] + p[i][j];
			}
		System.out.println(result[i]);
		}
	
	
	}	
	

}

Measured memory_bytes: 21036
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];
int32_t main(){_

   cin>>n;

   vector<int> x(n), y(n);
   vector<int> p(n);
   for (int i = 0; i < n; ++i)
   {
      cin >> x[i] >> y[i];
      p[i] = i;
   }

   int fact = 1;
   for (int i = 1; i <= n; ++i)
   {
      fact *= i;  
   }

   double avg = 0;
   do{

      double dist = 0;
      for (int i = 0; i+1 < n; ++i)
      {
         double curr = (x[p[i+1]] - x[p[i]]) * (x[p[i+1]] - x[p[i]]);
         curr += (y[p[i+1]] - y[p[i]]) * (y[p[i+1]] - y[p[i]]);
         curr = sqrt(curr);
         dist += curr;
      }

      avg += dist;
   }while(next_permutation(p.begin(), p.end()));


   cout << fixed << setprecision(18);
   avg /= fact;
   
   cout<<avg;

   return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
  string s;
  cin>>s;
  bool t_f=false;
  if(s[0]==s[1] && s[2]==s[3] && s[0]!=s[2]){
    t_f=true;
  }
  if(s[0]==s[2] && s[1]==s[3] && s[0]!=s[1]){
    t_f=true;
  }
  if(s[0]==s[3] && s[1]==s[2] && s[0]!=s[1]){
    t_f=true;
  }
  if(t_f){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c; cin>>a>>b>>c;
	if((a==b && a!=c)||(a==c && a!=b)||(b==c && a!=b)) cout<<"Yes"<<'\n';
	else cout<<"No"<<'\n';
	return 0;
}

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

using namespace std;

int main(){
  int i;
  int N, K;
  int l[55];

  cin >> N; cin >> K;
  for(i = 0; i < N; i++) cin >> l[i];

  sort(l, l+N, greater<int>());

  int res = 0;
  for(i = 0; i < K; i++) res += l[i];

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
      	long nam[] = new long[N];
      	long memo = 0;
      	long cnt = 0;
      
      nam[0] = in.nextLong();
      
      for(int i = 1;i < N;i++){
       	nam[i] = in.nextLong();
        
       	if(nam[i-1]>=nam[i]){cnt++;}
        else{cnt = 0;}
        memo = Math.max(cnt,memo);
      }
     System.out.print(memo);
	}
}

Measured memory_bytes: 61096
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		if(s.substring(s.length()-1).equals("s")) System.out.println(s + "es");
		else System.out.println(s + "s");
	}
}


Measured memory_bytes: 38396
#include<iostream>
using namespace std;
int main(){
  int r;
  cin >> r;
  if(r<1200) cout << "ABC" << "\n";
  if(1200<=r&&r<2800) cout << "ARC" << "\n";
  if(2800<=r) cout << "AGC" << "\n";

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>

using namespace std;
typedef long long int lli;

int soinsu[100000],soinsui=0;

void soinsu_bunkai(int n){
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){
            soinsu[soinsui++]=i;
            soinsu_bunkai(n/i);
            return;
        }
    }
    soinsu[soinsui++]=n;
}

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

    cin>>n;
    soinsu_bunkai(n);
    cout<<n<<":"<<flush;
    for(int i=0;i<soinsui;i++)cout<<" "<<soinsu[i]<<flush;
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3084
#include <stdio.h>

int main(void)
{
    int apple  = 0;
    int app_div = 0;
    int applepies = 0;

    scanf("%d",&apple);
    scanf("%d", &app_div);

    applepies = (apple*3 + app_div)/2;

    printf("%d", applepies);

}


Measured memory_bytes: 128
import java.util.*;

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

        // using long
        long N = sc.nextLong();
        long A = sc.nextLong();
        long B = sc.nextLong();

        //N/(A+B) finds the number of times red and blue balls repeats
        //multiplying by A finds the number of blue balls
        // adding Math.min(N%(A+B),A) finds the number of
        // blue balls the group of red and  blue that wasn't repeated

        System.out.println(N/(A+B) * A + Math.min(N%(A+B),A));
    }
}


Measured memory_bytes: 22612
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

//約数
void divisor(ll n, vector<ll>& ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
}


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

	ll n;
	cin >> n;

	Array ret;
	divisor(n, ret);
	ll ans = INF;
	for (auto i : ret) {
		chmin(ans, i + n / i - 2);
		if (i * i > n)break;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python3

N = int(input().split()[0])
s = input()
t = input()

for i in range(N):
    if s[i] == t[0]:
        is_ok = True
        for j in range(N - i):
            if s[j + i] != t[j]:
                is_ok = False
                break
        if is_ok:
            start_idx = i
            break
    else:
        is_ok = False

if is_ok:
    l = N + start_idx
else:
    l = N * 2

ans = l
print(ans)


Measured memory_bytes: 3060
#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <iostream>
#include <queue>
#include <set>
#define ll long long
#define sf(a) scanf("%lld",&a)
#define pf(b) printf("%lld",b)
#define sp printf(" ")
#define nw printf("\n")
#define mp make_pair
#define pi pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define fast ios_base::sync_with_stdio(false)
using namespace std;

vector<ll> p,q,a;
int main()
{
   ll n;
   sf(n);
   for(ll i=0;i<n;i++) {
    ll v;
    sf(v);
    p.pb(v);
   }
    for(ll i=0;i<n;i++) {
    ll v;
    sf(v);
    q.pb(v);
   }
   for(ll i=1;i<=n;i++) a.pb(i);
   ll c,d;
   c=d=0;
   for(ll i=1;;i++)
   {
    if(c and d)
    {
      pf(abs(c-d));
      break;
    }
    if(a==p) c=i;
    if(a==q) d=i;
    next_permutation(a.begin(),a.end());
   }
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000009
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;


int check(string s )
{
    //cout<<s<<endl;
    int n =s.size();
    if(n%2==0&&s.substr(0,n/2)==s.substr(n/2))
    return n/2;
    return -1;

}
int main()
{
string s ;
cin>>s;



int n = s.size();
int f;
int index =0;
do
{
     f= check(s.substr(0,n-index-1));
index++;
}while( f==-1);
cout<<2*f<<endl;
 return 0;
}


Measured memory_bytes: 3620
N = int(input())
p = [0]*N
index = -1
max_value = 0
for i in range(N):
    p[i] = int(input())
    if(p[i]>max_value):
        max_value = p[i]
        index = i
p[index] = int(p[index]/2)
print(sum(p))

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

using namespace std;
	
int dp[4005][4005]={};

int main()
{
	string s;
	cin >> s;
	int n=s.size();
	
	int red=0,blue=0;
	
	dp[0][0]=1;

	for(int i=1;i<=2*n;i++)
	{
		if(i<=n)
		{
			blue+=s[i-1]-'0';
			red=i*2-blue;
		}

		for(int j=max(0,i-blue);j<=red;j++)
		{
			dp[i][j]=((j!=0 ? dp[i-1][j-1]:0)+(dp[i-1][j]))%998244353;

		}
	
	}

	cout << dp[2*n][red] << endl;

}

Measured memory_bytes: 60544
#include <iostream>
#include <algorithm>

using namespace std;

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

	long long A[N];

	for (long long i = 0; i < N; i++){
		cin >> A[i];
	}
	sort(A, A + N);

	if (A[0] == 0){
		cout << "0" << endl;
		return 0;
	}

	long long ans = 1;
	for (long long i = 0; i < N; i++){
		long long temp = ans * A[i];
		if(temp > (long long)1e18 || temp < ans){
			cout << "-1" << endl;
			return 0;
		}
		ans = temp;
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4376
import sys

A, B, C, X, Y = map(int, input().split())

a = min(A, 2*C)
b = min(B, 2*C)
ab = min(A+B, 2*C)
cost = 0

if ab < (a + b):
  if X == Y:
    print(ab * X)
    sys.exit()
  elif X > Y:
    cost += ab * Y
    if ab <= a:
      cost += ab * (X - Y)
      print(cost)
      sys.exit()
    else:
      cost += a * (X - Y)
      print(cost)
      sys.exit()
  else:       # (X < Y)
    cost += ab * X
    if ab <= b:
      cost += ab * (Y - X)
      print(cost)
      sys.exit()
    else:
      cost += b * (Y - X)
      print(cost)
      sys.exit()
else:
  print(a*X + b*Y)
  sys.exit()

Measured memory_bytes: 3064
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        int n = Integer.parseInt(scan.nextLine());
        String[] strArr = scan.nextLine().split(" ");
        int arrLen = strArr.length;
        int[] intArr = new int[arrLen];

        for (int i=0; i<arrLen; i++){
            intArr[i] = Integer.parseInt(strArr[i]);
        }

        int swapNum = 0;
        int tmp;

        for (int i=0; i<arrLen; i++){
            for (int j=arrLen-1; j>i; j--){
                if (intArr[j] < intArr[j-1]){
                    tmp = intArr[j];
                    intArr[j] = intArr[j-1];
                    intArr[j-1] = tmp;
                    swapNum += 1;
                }
            }
        }

        for (int i=0; i<arrLen; i++){
            strArr[i] = String.valueOf(intArr[i]);
        }

        System.out.println(String.join(" ", strArr));
        System.out.println(swapNum);
    }
}

Measured memory_bytes: 26104
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int n, m;
vector<int> ng(1e5 + 10, 0);
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    vector<int> ng(n + 1, 0);
    for(int i = 0; i < m; i++)
    {
        int a; cin >> a;
        ng[a] = 1;
    }
    vector<ll> dp(n + 1, 0);
    dp[0] = 1;
    for(int i = 1; i <= n; i++)
    {
        if(ng[i]) continue;
        dp[i] = (dp[i] + dp[i - 1]) % MOD;
        if(i - 2 >= 0) dp[i] = (dp[i] + dp[i - 2]) % MOD;
    }
    cout << dp[n] << endl;
    return 0;
}



Measured memory_bytes: 1792
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    if(n <= k){
        cout << n*x;
    } 
    else
    {
        cout << k*x + (n-k)*y;
    }
    
    cout << endl;
}


Measured memory_bytes: 256