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

int main(void)
{
    int x[5];
    for (int i = 0; i < 5; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < 5; i++) {
        if (x[i] == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int INF=-2000000000;
int main() {
  int n;
  cin >> n;
  vector<int> a(n),b(n),c(n);
  rep(i,n){
    cin >> a[i] >> b[i] >> c[i];
  }
  vector<vector<int>> dp(n+1,vector<int>(3,INF));
  dp[0][0]=0;
  dp[0][1]=0;
  dp[0][2]=0;
  for(int i=1; i<n+1; i++){
    dp[i][0]=max({dp[i][0],dp[i-1][1]+a[i-1],dp[i-1][2]+a[i-1]});
    dp[i][1]=max({dp[i][1],dp[i-1][0]+b[i-1],dp[i-1][2]+b[i-1]});
    dp[i][2]=max({dp[i][2],dp[i-1][0]+c[i-1],dp[i-1][1]+c[i-1]});
  }
  cout << max({dp[n][0],dp[n][1],dp[n][2]}) << endl;
}

Measured memory_bytes: 6912
#include <iostream>    
#include <vector>
#include <queue>
#include <functional>
#include <utility>
using namespace std;

template<class T>
vector<T> dijkstra(vector<vector<int>> E, vector<vector<T>> W, int s, T inf)
{
    int n = (int)E.size();

    vector<T> D(n, inf);
    typedef pair<T,int> P;
    priority_queue<P,vector<P>,greater<P>> Q;

    D[s] = T();
    Q.push(make_pair(D[s], s));

    while (!Q.empty())
    {
        int d = Q.top().first;
        int p = Q.top().second;
        Q.pop();
        if (d > D[p])
            continue;
        for (int i=0; i<(int)E[p].size(); i++)
        {
            int t = E[p][i];
            if (d+W[p][i] < D[t])
                D[t] = d+W[p][i],
                Q.push(make_pair(D[t], t));
        }
    }
    return D;
}

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

    vector<vector<int>> E(K+1);
    vector<vector<int>> W(K+1);
    for (int k=0; k<=K; k++)
        for (int i=0; i<10; i++)
        {
            int t = k+K*i;
            E[k].push_back(t/10);
            W[k].push_back(t%10);
        }
    int ans = K;
    for (int i=1; i<10; i++)
        ans = min(ans, dijkstra(E, W, K*i/10, K)[0] + K*i%10);
    cout<<ans<<endl;
}


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

int main() {
  string s;
  cin >> s;
  cout << s[0] << s.size()-2 << s[s.size()-1] << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		int a = Integer.parseInt(str.substring(0, 1));
		int b = Integer.parseInt(str.substring(1, 2));
		int c = Integer.parseInt(str.substring(2, 3));
		int d = Integer.parseInt(str.substring(3, 4));

		if (a+b+c+d == 7) {System.out.println(a+"+"+b+"+"+c+"+"+d+"=7"); return;}
		if (a+b+c-d == 7) {System.out.println(a+"+"+b+"+"+c+"-"+d+"=7"); return;}
		if (a+b-c+d == 7) {System.out.println(a+"+"+b+"-"+c+"+"+d+"=7"); return;}
		if (a+b-c-d == 7) {System.out.println(a+"+"+b+"-"+c+"-"+d+"=7"); return;}
		if (a-b+c+d == 7) {System.out.println(a+"-"+b+"+"+c+"+"+d+"=7"); return;}
		if (a-b+c-d == 7) {System.out.println(a+"-"+b+"+"+c+"-"+d+"=7"); return;}
		if (a-b-c+d == 7) {System.out.println(a+"-"+b+"-"+c+"+"+d+"=7"); return;}
		if (a-b-c-d == 7) {System.out.println(a+"-"+b+"-"+c+"-"+d+"=7"); return;}

	}

}

Measured memory_bytes: 22228
//ビット演算
/**ヒント
StringBuilder/setLength(int newLength):引数に0を渡すと実質配列の中身を全消去できる
Long/parseLong(String s):sを10進数long型にして返す
各要素にある桁の数字を格納したchar配列を文字列にしてから数字に直す方法
char[]としてではなく、StrintBuliderとして宣言しないとsetLength()とか使えない
a={'1', '2', '3'}のときstring.valueOf(a)により"123"となる
Long.parseLong(String.valueOf(a))
*/
import java.util.*;

public class Main{
  public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		//char[] Sary = new char[S.length()];
		StringBuilder Sary = new StringBuilder();
		long sum = 0;//'+'を入れる各パターン数だけsumがある.
		long Allsum = 0;//各sumを足し合わせて結果をおいとく、1つだけ.

		for(long i = 0; i < Math.pow(2, S.length()-1); i++){
			sum = 0;
			int k = 0;//Sのidx
			Sary.append(S.charAt(k));
			for(long j = 0; j < S.length()-1; j++){
				k++;
				//Saryの中身を取り出して数字にして足す場合
				if((1 & i>>j) == 1){
					sum += Long.parseLong(String.valueOf(Sary));
					Sary.setLength(0);
				}
				Sary.append(S.charAt(k));
			}
			sum += Long.parseLong(String.valueOf(Sary));
			//出した合計を全体の合計に足す
			Allsum += sum;
      Sary.setLength(0);
		}

		System.out.println(Allsum);
  }
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int N;
  cin >> N;
  vector<char> V(N);
  
  int max_count = 0;

  for (int i = 0; i < N; i++) {
    cin >> V.at(i);
  }
  
  for (int i = 0; i < N; i++) {//ある場所で切った時の左右に含まれている文字の種類
    int count = 0;
    set<char> S,T;
    for (int j = 0; j < i; j++) {
       S.insert(V.at(j));
    }
    for (int j = i; j < N; j++) {
      T.insert(V.at(j));
    }
    
    for (auto itr = S.begin(); itr != S.end(); ++itr) {
    	for (auto itt = T.begin(); itt != T.end(); ++itt) {
          	if(*itr == *itt)
              count++;
        }
    }
    max_count = max(max_count,count);
  }
  
  cout << max_count << endl;
  
 
}

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

int main() {
    int a, b;
    scanf("%d%d", &a, &b);
    if ((a + b) % 2 == 0) {
        printf("%d", (a + b) / 2);
    } else {
        printf("IMPOSSIBLE");
    }
    return 0;
}

Measured memory_bytes: 256
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	let _ = stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec_char() -> Vec<char> {
    read::<String>().chars().collect()
}


#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    let n = read::<usize>();
    let mut ans = vec!['?'; 2 * n];
    print!("? {}", n + 1);
    for i in 1..n {
        print!(" {}", n + 1 + i);
    }
    println!("");
    let resr = read_vec_char();
    let mut l = 1;
    let mut r = n + 1;
    while l + 1 < r {
        let m = (l + r) / 2;
        print!("? {}", m);
        for i in 1..n {
            print!(" {}", m + i);
        }
        println!("");
        let res = read_vec_char();
        if resr == res {
            r = m;
        } else {
            l = m;
        }
    }
    ans[l - 1] = if resr[0] == 'B' {'R'} else {'B'};
    ans[l + n - 1] = resr[0];
    for i in 1..l {
        print!("? {}", i);
        for j in 1..n {
            print!(" {}", l + j);
        }
        println!("");
        let res = read_vec_char();
        ans[i - 1] = res[0];
    }
    for i in l + n + 1..2 * n + 1 {
        print!("? {}", i);
        for j in 1..n {
            print!(" {}", l + j);
        }
        println!("");
        let res = read_vec_char();
        ans[i - 1] = res[0];
    }
    let mut bs = vec![];
    let mut rs = vec![];
    for i in 1..2 * n + 1 {
        if ans[i - 1] == 'B' && bs.len() < n / 2 {
            bs.push(i);
        }
        if ans[i - 1] == 'R' && rs.len() < n / 2 {
            rs.push(i);
        }
    }
    for i in l + 1..l + n {
        print!("? {}", i);
        for &bi in &bs {
            print!(" {}", bi);
        }
        for &ri in &rs {
            print!(" {}", ri);
        }
        println!("");
        let res = read_vec_char();
        ans[i - 1] = res[0];
    }
    println!("! {}", ans.iter().cloned().collect::<String>());
}


Measured memory_bytes: 4820
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
char s[107][107];
int vis[107][107];
struct node{
    int x,y,dis;
};
int direction[4][2]={{1,0},{0,1}};
void bfs(int x,int y){
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
            vis[i][j]=1e9;
    queue<node>q;
    if(s[x][y]=='#')
        q.push((node){x,y,1}),vis[x][y]=1;
    else
        q.push((node){x,y,0}),vis[x][y]=0;
    ans=1e9;
    while(!q.empty()){
        node now=q.front();
        q.pop();
        if(now.x==n&&now.y==m)
            ans=min(ans,now.dis);
        for(int i=0;i<2;++i){
            int temp_x=now.x+direction[i][0],temp_y=now.y+direction[i][1];
            if(temp_x<=0||temp_x>n||temp_y<=0||temp_y>m)
                continue;
            int temp_dis=now.dis;
            if(s[now.x][now.y]=='.'&&s[temp_x][temp_y]=='#')
                ++temp_dis;
            if(temp_dis<vis[temp_x][temp_y]){
                vis[temp_x][temp_y]=temp_dis;
                q.push({temp_x,temp_y,temp_dis});
            }
        }
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m;
    for(int i=1;i<=n;++i)
        cin>>s[i]+1;
    bfs(1,1);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
// 整数の入力
int a = sc.nextInt();
// スペース区切りの整数の入力
  double length1 = (double)a/3;
//int b = sc.nextInt();
//int c = sc.nextInt();
// 文字列の入力
//String s = sc.next();
// 出力
System.out.println(Math.pow(length1,3));
}
}


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

using namespace std;

typedef pair<int,int> P;
vector<P> vec;

bool check(){
  for(int i = 0 ; i < (int)vec.size() ; i++){
    if(vec[i].first != -1) return true;
  }

  vec.clear();
  return false;
}

void change(int p, int S, int l){
  vector<P> tmp;
  int Next = vec[p].second - S;

  for(int i = 0 ; i < p ; i++){
    tmp.push_back(vec[i]);
  }

  tmp.push_back(P(l, S));
  tmp.push_back(P(-1,Next));

  for(int i = p+1 ; i < (int)vec.size() ; i++){
    tmp.push_back(vec[i]);
  }

  vec = tmp;
}

void Wri(){
  int len = (int)vec.size(), l, S;

  cin >> l >> S;

  if(len == 0 || !check()){
    vec.push_back(P(l,S));
    return;
  }

  for(int i = 0 ; i < len ; i++){
    if(vec[i].first == -1){
      if(S - vec[i].second >= 0){
        vec[i].first = l;
        S -= vec[i].second;
      }else{
        change(i, S, l);
        return;
      }
    }
  }

  if(S > 0){
    vec.push_back(P(l,S));
  }
}

void Del(){
  int len = (int)vec.size(), l;

  cin >> l;
  if(len == 0){
    return;
  }

  for(int i = 0 ; i < len ; i++){
    if(vec[i].first == l){
      vec[i].first = -1;
    }
  }
}

int Ref(){
  long long cnt = 0;
  int len = (int)vec.size(), l, num = vec[0].first;

  cin >> l;
  if(len == 0){
    return -1;
  }

  for(int i = 0 ; i < len ; i++){
    cnt += vec[i].second;
    num = vec[i].first;
    
    if(cnt > l){
      return num;
    }
  }

  if(cnt <= l){
    return -1;
  }else{
    return vec[len-1].first;
  }
}

int main(){
  int N;
  char ch;

  while(cin >> N, N){
    vec.clear();
    for(int i = 0 ; i < N ; i++){
      cin >> ch;

      switch(ch){
      case 'W':
        Wri();
        break;
      case 'D':
        Del();
        break;
      default:
        cout << Ref() << endl;
        break;
      }
    }

    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

double x[8],y[8];
int main() {
	double n;
	cin>>n;
	for(ll i=0;i<n;i++){
		double X,Y;
		cin>>X>>Y;
		x[i]=X;
		y[i]=Y;
	}
	ll kai=1;
	for(ll i=n;i>=1;i--){
		kai*=i;
	}
	double cnt=kai/n;
	//cout <<kai<<endl;
	//cout <<cnt;
	double sum=0;
	for(ll i=0;i<n;i++){
		double nowx=x[i];
		double nowy=y[i];
		for(ll j=0;j<n;j++){
			if(i==j){
				continue;
			}
			double nex=x[j];
			double ney=y[j];
			sum+=sqrt((nowx-nex)*(nowx-nex)+(nowy-ney)*(nowy-ney))*cnt;
		}
	}
	printf("%.11f",sum/kai);
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(),x.end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

ll n,d;
ll solve(){
   ll ans=0;
   rep(i,n){
       ll x,y;
       cin>>x>>y;
       if(x*x+y*y<=d*d)ans++;
   }

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

    cin>>n>>d;
    cout<<solve()<<endl;
    return 0;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

signed main(){
    double R;
    cin >> R;
    cout << fixed << setprecision(10) << M_PI * 2 * R << endl;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define vc vector<int>
#define um unordered_map<int,int>
#define ll long long 
#define rep(i,a,b) for(__typeof(a) i=a; i<b; i++)
#define si(a) a.size()
#define all(a) a.begin(),a.end()
#define ss(a) a.second
#define ff(a) a.first
#define M 1000000
#define pb push_back
#define repit(i,a) for(auto i=a.begin(); i!=a.end(); i++)
#define take(arr,n) for(int i=0;i<n;i++)cin>>arr[i]
#define out(arr,n) for(int i=0;i<n;i++)cout<<arr[i]<<' '
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define reprev(i,b,a) for(__typeof(b) i=b; i>=a; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define doublearray vector<vector<int>>
#define mod 998244353 
using namespace std;
ll max(ll a, ll b){ return a>b?a:b; }
ll min(ll a, ll b){ return a<b?a:b; }
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}
int binaryS(ll x, ll sb[], int m){
    int l = 0, r=m;
    int mid = (l+r)/2;
    while(l<r){
        mid = (l+r)/2;
        if(sb[mid]<x) l= mid+1;
        else if(sb[mid]>x) r = mid-1;
        else return mid;
    }
    return l;
}
int main(){
    fastio;
    int n; cin>>n;
    ll a[n+1];
    a[1]=1;
    rep(i,2,n+1) a[i]=2;
    rep(i,2,n/2+1){
        for(int j=2*i; j<=n; j+=i){
            a[j]++;
        }
     }ll ans=0;
    rep(i,1,n+1){
        ans += i*a[i];
    }
    cout<<ans<<endl;
    return 0;
}





Measured memory_bytes: 81732
#include<cstdio>
int N,Q[210],D[210];
bool vis[210];
char S[210][210];
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++)scanf("%s",S[i]);
	int ans=0;
	for(int o=0;o<N;o++){
		for(int i=0;i<N;i++)vis[i]=0;
		int*h=Q,*t=Q;vis[*t++=o]=1;D[o]=0;
		for(;h<t;h++){
			for(int j=0;j<N;j++)if(j!=*h&&S[*h][j]=='1'){
				if(!vis[j])vis[*t++=j]=1,D[j]=D[*h]+1,D[j]>ans?ans=D[j]:1;
				else if(D[j]==D[*h])return puts("-1"),0;
			}
		}
	}
	printf("%d\n",ans+1);
}

Measured memory_bytes: 256
import sys

N = int(input())
W = [input()]

for i in range(1, N):
    c = input()
    W.append(c)
    if W[i - 1][-1] == W[i][0]:
        continue
    print("No")
    sys.exit()

if len(W) != len(set(W)):
    print("No")
    sys.exit()

print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3116
#include <stdio.h>

int main(void){

  int n,a,b;
  scanf("%d %d %d", &n, &a, &b);
  long sum = 0;
  int digit_sum;
  int number;
  for (int i = 1; i <= n; i++) {
    number = i;
    digit_sum = 0;
    for (int j = 0; j < 5; j++) {
      digit_sum += number%10;
      number /= 10;
    }
    if (digit_sum >= a && digit_sum <= b) {
      sum += i;
    }
  }
  printf("%ld\n", sum);

  return 0;
}

Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left 

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

def main():
    n = INT()

    print(n*(n+1)//2 - n)

if  __name__=='__main__':
    main()


Measured memory_bytes: 5148
use std::io::{self, BufRead, BufWriter, Write};

fn solve<R, W>(reader: R, mut writer: W)
where
    R: BufRead,
    W: Write,
{
    let mut lines = reader.lines();
    let n: i64 = lines.next().unwrap().unwrap().parse().unwrap();
    // let mut factrized = prime_factorization(n);

    // let mut x: i64 = 1;
    // let mut y: i64 = 1;
    // for (i, n) in factrized {
    //     for _ in 0..n {
    //         if x < y {
    //             x *= i;
    //         } else {
    //             y *= i;
    //         }
    //     }
    // }
    // let ans: i64 = x - 1 + y - 1;

    let mut ans = 0;
    let s: i64 = (n as f64).sqrt() as i64;
    for i in 0..s {
        if n % (s - i) == 0 {
            ans = (s - i) + n / (s - i) - 2;
            break;
        }
    }

    writeln!(&mut writer, "{}", ans).unwrap();
}

fn main() {
    let stdio = io::stdin();
    let input = stdio.lock();

    let stdout = io::stdout();
    let output = BufWriter::new(stdout.lock());

    solve(input, output);
}

fn prime_factorization(mut n: i64) -> Vec<(i64, i64)> {
    let s: i64 = (n as f64).sqrt() as i64;
    let mut result = vec![];
    for i in 2..s + 1 {
        if (n % i) == 0 {
            let mut r = 0;
            loop {
                r += 1;
                n = n / i;
                if !((n % i) == 0) {
                    break;
                }
            }
            result.push((i, r));
        }
    }
    if n > s {
        result.push((n, 1));
    }
    result
}

#[cfg(test)]
mod tests {
    use super::*;

    const TESTS: &'static [(&'static [u8], &'static [u8])] = &[
        (
            br"10", br"5
",
        ),
        (
            br"50", br"13
",
        ),
        (
            br"10000000019",
            br"10000000018
",
        ),
        (
            br"4", br"2
",
        ),
        (
            br"1", br"0
",
        ),
        (
            br"15241383936",
            br"246910
",
        ),
        (
            br"852770983936",
            br"1846910
",
        ),
        (
            br"29524500",
            br"14578
",
        ),
        (
            br"3804953495641",
            br"3901256
",
        ),
        (
            br"1565912117761",
            br"2509568
",
        ),
        (
            br"549755813888",
            br"1572862
",
        ),
    ];

    #[test]
    fn test_c() {
        for &(input, expected) in TESTS {
            let mut output = Vec::new();
            solve(input, &mut output);
            let expected_str = String::from_utf8(expected.to_vec()).unwrap();
            let output_str = String::from_utf8(output).unwrap();
            assert_eq!(expected_str, output_str);
        }
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    string s;
    cin>>s;
    string t="2019/04/30";
    cout<<(s<=t?"Heisei":"TBD");
    return 0;
}


Measured memory_bytes: 256
N = int(input())
XL = list(map(int, input().split()))

PP = sum(XL) / len(XL)
P = sum(XL) // len(XL)
R0= sum([(x - P - 1) ** 2 for x in XL])
R1= sum([(x - P) ** 2 for x in XL])
R2= sum([(x - P + 1) ** 2 for x in XL])

print(min(R0, R1, R2))


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;
using ld = long double;

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

void solve(ll N, vector<ll> p) {
  cout << accumulate(ALL(p),0ll) - *max_element(ALL(p))/2 << endl;
}

int main() {
  ll N;
  cin >> N;
  vector<ll> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  solve(N, move(p));
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int H,W,num = 0;
  cin >> H >> W;
  char str[H * W];
  for(int i = 0; H * W > i; i++){
    cin >> str[i];
  }
   //W+2
   for(int i = -2; W > i; i++){
     cout << "#";
   }
   cout << endl;

  for(int i = 0; H > i; i++){
    for(int j = -1; W + 1 > j; j++){
      if(j == -1 || j == W){
        cout << "#";
      } else {
        cout << str[num];
        num++;
      }
    }
    cout << endl;
  }
   for(int i = -2; W > i; i++){
     cout << "#";
   }
   cout << endl;

}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
using namespace std;
#define MOD 1000000007

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

int main() {
  long long N, K;
  cin >> N >> K;
  
  long long count = modpow(K, N);
  long long sum[K];
  for (int i = 0; i < K; i++) sum[i] = 1;
  
  for (int i = 2; i <= K; i++){
    count += (i - sum[i - 1]) * modpow(K / i, N);
    count %= MOD;
    for (int j = 2; j <= K / i; j++){
      sum[j * i - 1] += i - sum[i - 1];
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 4316
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val aa = readLine()!!.split(" ").map { it.toInt() }

    var sum = 1

    aa.forEach {
        sum *= if (it % 2 == 0) 2 else 1
    }

    println((Math.pow(3.0, n.toDouble()) - sum).toInt())
}

Measured memory_bytes: 37972
n,k = map(int,input().split())
v = list(map(int,input().split()))
 
m=[]
for i in range(min(k,n)+1):
    for j in range(min(k,n)-i+1):

        t=sorted(v[:i]+v[:~j:-1])
 
        while t and(k-i-j)*t[0]<0:
            t.pop(0)
            j+=1
        m.append(sum(t))
print(max(m))

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
    int S,h,m,s;
    
    scanf("%d",&S);
    
    h=S/3600;
    m=S/60-h*60;
    s=S-h*3600-m*60;
    
    printf("%d:%d:%d\n",h,m,s);
    
    return 0;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) cout << (x) << endl;
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INF = 1<<29;
const int MOD = 1000000007;
 
void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};



int main(void){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string s,t;
    cin >> s >> t;
    int n = sz(s), m = sz(t);
    vector<vector<int>> is(26);
    rep(i,n) is[s[i] - 'a'].push_back(i);
    rep(i,n) is[s[i] - 'a'].push_back(i+n);
    ll ans = 0;
    int p = 0;
    rep(i,m){
        int c = t[i] - 'a';
        if(sz(is[c]) == 0){
            print("-1");
            return 0;
        }
        p = *lower_bound(is[c].begin(), is[c].end(), p)+1;
        if(p >= n){
            p -= n;
            ans += n;
        }
    }
    ans += p;
    print(ans);
}

Measured memory_bytes: 1736
#include "bits/stdc++.h"

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ll long long
#define li long int
#define ld long double
#define lld long long double

#define pb push_back
#define mk make_pair
#define F first
#define S second

#define all(v) (v).begin(),(v).end()
#define fill(a) memset(a, 0, sizeof(a))

const int MX = 1e6;
const int MI = -1e6;
const int MOD = 1e9 + 7;
const string ALPHA = "abcdefghijklmnopqrstuvwxyz";
const double PI = 3.1415926535;

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

const int mod=1e9+7;
inline int add(int x,int y)
{
  x+=y;
  if (x>=mod)
    return x-mod;
  return x;
}
inline int sub(int x,int y)
{
  x-=y;
  if (x<0)
    return x+mod;
  return x;
}
inline int mul(int x,int y)
{
  return (x*1ll*y)%mod;
}
inline int power(int x,int y)
{
  int ans=1;
  while(y)
    {
      if (y&1) ans=mul(ans,x);
      x=mul(x,x);
      y>>=1;
    }
  return ans;
}
inline int inv(int x)
{
  return power(x,mod-2);
}
inline int gcd(int x, int y)
{
  return(y!=0)?gcd(y, x%y):x;
}

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

int main()
{
  IOS;
  int s, w;
  cin >> s >> w;
  if (w>s || w==s)
    cout << "unsafe" << endl;
  else
    cout << "safe" << endl;
  return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m;
int t;
int res;
int main()
{
	cin >>n>>m;
	for (int i=0;i<n;i++) t+=m+i;
	for (int i=0;i<n;i++)
	{
		int tt=0;
		for (int j=0;j<n;j++)
		{
			if (i==j) continue;
			tt+=m+j;
		}
		if (abs(t-tt)<abs(t-res)) res=tt;
	}
	cout <<res;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  vll a(3*n);
  multiset<ll> l;
  multiset<ll, greater<ll>>r;
  vll ls(n+1), rs(n+1);
  re(i, 3*n) std::cin >> a[i];
  re(i, n) l.insert(a[i]), ls[0]+=a[i];
  rep(i, 2*n, 3*n) r.insert(a[i]), rs[0]+=a[i];
  for(int i=1;i<=n;i++){
    ls[i] = ls[i-1] + a[i-1+n];
    l.insert(a[i-1+n]);
    ls[i] -= (*l.begin());
    l.erase(l.begin());
  }
  for(int i=1;i<=n;i++){
    rs[i] = rs[i-1] + a[2*n-i];
    r.insert(a[2*n-i]);
    rs[i] -= (*r.begin());
    r.erase(r.begin());
  }
  ll ans = -1000000000000000000;
  for(int i=0;i<=n;i++){
    ans = max(ans, ls[i] - rs[n-i]);
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
  int main(){
    int n,m;
    cin>>n>>m;
    int x=0;
    vector<int>vec(m);
    for(int i=0;i<m; i++){
      cin>>vec.at(i);
      x+=vec.at(i);
    }
    if(x>n){cout<<"-1"<<endl;}
    else {cout<<n-x<<endl;}
  }
    


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

#define range 524289
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef  long long int ll;
typedef vector <ll> vi;
typedef vector<vi> vvi;
typedef pair <ll, ll> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;



int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	int t = 1;
	// cin>>t;
	while(t--){

        int n, k;
        cin>>n>>k;
        if(k==0){
            cout<<1<<endl;
            return 0;
        }
        vi a(n+1);
        vvi dp(k+1, vi(n+1, 1));
        ll temp = 0;
        for (int i = 1; i <= n; ++i){
            /* code */
            cin>>a[i];
            temp += a[i];
        }
        if(temp==k){
            cout<<1<<endl;
            return 0;
        }
        if(temp<k){
            cout<<0<<endl;
            return 0;
        }
        sort(a.begin(), a.end());
        ll ans =0;

        for (int i = 1; i <=k ; ++i)
        {
            /* code */
            ll sum = 0;
            for(int j=1;j<=n;j++){
                sum += a[j];
                if(sum<i){
                    dp[i][j] = dp[i-1][j];
                }
                else{
                    ll res = 0;
                    if(a[j]>=i){
                        res = dp[i][j-1];
                        dp[i][j] = (dp[i-1][j] + res)%mod;
                    }
                    else{
                        dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
                        dp[i][j] = (dp[i][j] - dp[i-a[j]-1][j-1])%mod;
                        if(dp[i][j]<0){
                            dp[i][j] += mod;
                        }
                    }
                    // cout<<res<<" "<<i<<" "<<j<<endl;
                }
            }

        }
        cout<<(dp[k][n]-dp[k-1][n]+mod)%mod<<endl;





	}

    return 0;
}


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

template<class T>
void merge(vector<T>& a,int left,int right){
  vector<T> tmp(right-left);
  int mid= (left+right)/2;
  int tl = left;
  int tr = mid;
  for(int idx=0;idx<(right-left);++idx){
    if(tl>=mid)tmp[idx]=a[tr++];
    else if(tr>=right)tmp[idx]=a[tl++];
    else tmp[idx] = (a[tl]<a[tr]?a[tl++]:a[tr++]);
  }
  for(int i=0;i<(right-left);++i){
    a[left+i] = tmp[i];
  }
}

template<class T>
void split(vector<T>& a,int left,int right){
  if(right-left>1){
    split(a,left,(left+right)/2);
    split(a,(left+right)/2,right);
  }
  merge(a,left,right);
}

template<class T>
void merge_sort(vector<T>& a){
  split(a,0,a.size());
}


int main(){

  ll n,t;
  cin>>n>>t;
  vector<pair<ll,ll>> a(n);
  for(auto& ai:a)cin>>ai.first>>ai.second;

  merge_sort(a);

  vector<vector<ll>> dp(6060,vector<ll>(6060));
  rep(i,n){
    rep(w,t){
      dp[i+1][w] = max(dp[i+1][w],dp[i][w]);
      dp[i][w+1] = max(dp[i][w+1],dp[i][w]);
      dp[i+1][w+1] = max(dp[i+1][w+1],dp[i][w]);
      dp[i+1][w+a[i].first] = max(dp[i+1][w+a[i].first],dp[i][w]+a[i].second);
    }
  }

  ll ans = 0;
  for(auto y:dp)for(auto x:y)ans=max(ans,x);

  cout<<(ans)<<endl;

}

Measured memory_bytes: 287488
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
 
/*** Template Begins ***/
 
typedef long long    ll;
typedef pair<ll,ll>  pll;
typedef pair<ll, pair<int, int> > plll;
typedef vector<long long>  vll;
typedef vector<pll>  vp;
typedef long double ld;
#define pb           push_back
#define INF          INT_MAX/10
#define F            first
#define S            second
#define mp           make_pair
// #define ios          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define hell         1000000007
// #define h 998244353
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p)
{
  ll res = 1;
  x = x % p;
  while (y > 0)
  { 
    if (y & 1) 
      res = (res*x) % p;
    y = y>>1;
    x = (x*x) % p;
  } 
  return res; 
} 
const int MAXN = 1e5+7;

// Debug //
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
// #define trace6(a, n,i;b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

// Constants //
 
/*** Template Ends ***/
ll bit[26][500005];
ll n;
void update(ll i,ll index,ll val)
{
  while(index<=n)
  {
    bit[i][index]+=val;
    index += (index & (-index));
  }
}
ll query(ll i,ll index)
{
  ll ans=0;
  while(index>0)
  {
    ans += bit[i][index];
    index -= (index & (-index));
  }
  return ans;
}
void solve()
{
  // ll n;
  ll i,index,l,r;
  char c;
  cin>>n;
  string s;
  cin>>s;
  memset(bit,0,sizeof(bit));
  for(i=0;i<n;i++)
    update(s[i]-'a',i+1,1);
  ll q;
  cin>>q;
  while(q--)
  {
    ll t;
    cin>>t;
    if(t==1)
    {
      cin>>index>>c;
      update(s[index-1]-'a',index,-1);
      update(c-'a',index,1);
      s[index-1] = c;
    }
    else
    {
      cin>>l>>r;
      ll count=0;
      for(i=0;i<26;i++)
      {
        if(query(i,r)-query(i,l-1))
          count++;
      }
      cout<<count<<endl;
    }
  }
}
int main()
{ 
  // ios;
  // fxreopen("inputt.txt", "w", stdout);
  ll t;
  // cin >> t;
  t=1;
  while(t--)
    solve();
  return 0;
}

Measured memory_bytes: 102532
#include<bits/stdc++.h>
using namespace std;
int N, M;
int main() {
    cin >> N >> M;
    long long a[N];
    for (int i = 0; i < N; i++)
    {
        long long x; cin >> x;
        a[i] = x;
    }
    sort(a, a + N);

    pair<long long, long long> cb[M];
    for (int i = 0; i < M; i++)
    {
        long long first, second;
        cin >> first >> second;
        cb[i].first = second;
        cb[i].second = first;
    }
    sort(cb, cb + M);
    reverse(cb, cb + M);

    int i = 0, j = 0;
    for (int st = 0; st < N; st++)
    {
        if(a[st] < cb[i].first) {
            a[st] = cb[i].first;
            j++;
        }
        else break;

        if(j == cb[i].second){
            i++;
            j = 0;
        }
        if(i == M) break;
    }


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

    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T = ll> constexpr T TEN(int n) {return (n==0)?1:10*TEN<T>(n-1);}


template<class T>
T pow(T x, ll n) {
    T r = 1;
    while (n) {
        if (n & 1) r *= x;
        x *= x;
        n >>= 1;
    }
    return r;
}

template<uint MD>
struct ModInt {
    uint v;
    ModInt() : v{0} {}
    ModInt(ll v) : v{normS(v%MD+MD)} {}
    static uint normS(const uint &x) {return (x<MD)?x:x-MD;};
    static ModInt make(const uint &x) {ModInt m; m.v = x; return m;}
    ModInt operator+(const ModInt &r) const {return make(normS(v+r.v));}
    ModInt operator-(const ModInt &r) const {return make(normS(v+MD-r.v));}
    ModInt operator*(const ModInt &r) const {return make(ull(v)*r.v%MD);}
    ModInt& operator+=(const ModInt &r) {return *this=*this+r;}
    ModInt& operator-=(const ModInt &r) {return *this=*this-r;}
    ModInt& operator*=(const ModInt &r) {return *this=*this*r;}
    static ModInt inv(const ModInt &x) {
        return pow(ModInt(x), MD-2);
    }
};

using Mint = ModInt<TEN(9)+7>;
const int MN = 900900;
Mint fact[MN], iFac[MN], p3[MN];
void first() {
    fact[0] = 1;
    for (int i = 1; i < MN; i++) {
        fact[i] = fact[i-1]*i;
    }
    for (int i = 0; i < MN; i++) {
        iFac[i] = Mint::inv(fact[i]);
    }
    p3[0] = 1;
    for (int i = 1; i < MN; i++) {
        p3[i] = p3[i-1]*3;
    }
}

Mint C(int n, int k) {
    if (n < k || k < 0) return 0;
    return fact[n]*iFac[k]*iFac[n-k];
}

Mint buf[MN];
int main() {
    first();
    int n, m, k;
    scanf("%d %d %d", &n, &m, &k); n--;

    buf[0] = 1;
    for (int i = 1; i <= m+k; i++) {
        buf[i] = buf[i-1]*2;
        if (i-1 >= m) {
            buf[i] -= C(i-1, m);
        }
        if (i-1 >= k) {
            buf[i] -= C(i-1, k);
        }
    }
    Mint ans = 0;
    for (int i = 0; i <= m+k; i++) {
        Mint res = p3[m+k-i];
        res *= C(n+i, n);
        res *= buf[i];
        ans += res;
    }
    printf("%d\n", ans.v);
    return 0;
}

Measured memory_bytes: 14336
def input_n(inputfile,outputfile):
	while True:
		n = inputfile.readline()
		n = int(n)
		if n == 0:
			break
		battle(inputfile,outputfile,n)

def battle(inputfile,outputfile,n):
	apoint = 0
	bpoint = 0
	for i in range(n):
		a , b = inputfile.readline().split()
		a = int(a)
		b = int(b)
		if a > b:
			apoint += (a + b)
		elif b > a:
			bpoint += (a + b)
		else:
			apoint += a
			bpoint += b
	print >> outputfile, apoint, bpoint

if __name__ == "__main__":
	import sys
	input_n(sys.stdin,sys.stdout)

Measured memory_bytes: 4524
require 'mathn'
gets
a = gets.split.map(&:to_i).sort
p [
    a[-4..-1].permutation(4).map {|x, y, z, w| (x + y) / (z - w)}.max,
    (a[-1] + a[-2]) / a[0..-3].each_cons(2).map{|x, y| y - x}.min
].max.to_f


Measured memory_bytes: 9420
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
R, S, P = lr()
T = list(sr())
answer = 0
for i, t in enumerate(T):
    if i >= K and t == T[i-K]:
        T[i] = '_'
        continue
    dic = {'r': P, 's': R, 'p': S}
    answer += dic[t]

print(answer)
# 51

Measured memory_bytes: 4084
anss=[]
while True:
    try:
        ans=0
        goal=int(input())
        for a in range(10):
            for b in range(10):
                for c in range(10):
                    for d in range(10):
                        if a+b+c+d==goal:
                            ans+=1
        anss.append(ans)
    except:
        break
for ans in anss:
    print(ans)

Measured memory_bytes: 7688
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

signed main(){
	ll N,M;
	cin >> N >> M;
	vl A(M);
	FOR(i,0,M)cin >> A[i];
	sort(ALL(A));
	ll m[] = {0,2,5,5,4,5,6,3,7,6};
	ll DP[N+1] = {0};
	ll used[N+1] = {0};
	FOR(i,0,N+1){
		for(auto x:A){
			if(i - m[x] >= 0){
				if(DP[i] <= DP[i-m[x]]+1){
					if(DP[i-m[x]] == 0 && i-m[x] != 0)continue;
					used[i] = x;
					DP[i] = DP[i-m[x]]+1;
				}
			}
		}
	}
	DEBUG(DP)
	while(N){
		if(DP[N-m[used[N]]] == 0)break;
		cout << used[N];
		N -= m[used[N]];
	}
	sort(ALL(A),greater<ll>());
	for(auto x:A){
		if(N == m[x]){
			cout << x << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+5;
int n,s,x[N];long long p[N],ans;
int main(){
	scanf("%d%d",&n,&s);
	for(int i=1;i<=n;++i)scanf("%d%lld",&x[i],&p[i]);
	for(int l=1,r=n,las=0;;){
		if(s<x[l]){ans+=x[r]-s;break;}
		if(x[r]<s){ans+=s-x[l];break;}
		if(p[l]>=p[r]){
			if(las!=1)las=1,ans+=x[r]-x[l];
			p[l]+=p[r];--r;
		}else{
			if(las!=2)las=2,ans+=x[r]-x[l];
			p[r]+=p[l];++l;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
using namespace std;
int main() {
    int A,B,M; scanf("%d%d%d",&A,&B,&M);
    int a[A],b[B];
    int am,bm,m;
    am = bm = m = 1000000;
    for (int i=0; i<A; i++) {
        scanf("%d",&a[i]);
        am = min(am,a[i]);
    }
    for (int i=0; i<B; i++) {
        scanf("%d",&b[i]);
        bm = min(bm,b[i]);
    }
    m = am + bm;
    int x,y,c;
    for (int i=0; i<M; i++) {
        scanf("%d%d%d",&x,&y,&c);
        m = min(m, a[x-1]+b[y-1]-c);
    }
    printf("%d\n",m);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    int a, b;
    cin >> a >> b;
    cout << max({a+b, a-b, a*b}) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define int long long
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9+7;
int n,m,k,ok;

int a[maxn];

signed main()
{
    //freopen("data.in", "r", stdin);
    cin>>n>>m;
    int sum = 0;
    for(int i = 1; i <= n; i++) 
    {
        cin>>a[i];
        sum += a[i];
    }
    sort(a+1,a+1+n,greater<int>());
    if(a[m]*4*m < sum) puts("No");
    else puts("Yes");
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int[] x = new int[5];
		for(int i = 0;i<5;i++) {
			x[i]=scn.nextInt();
		}
		int y = scn.nextInt();
		Arrays.sort(x);
		if(x[4]-x[0]>y) {
			System.out.println(":(");
		}else {
			System.out.println("Yay!");
		}
		scn.close();
	}
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define mem(a) memset(a, 0, sizeof(a))
#define sqr(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int mn = 1e5 + 5;
const int mod = 1e9 + 7;
#define P mod

int n,q;

int main() {
#ifdef LOCAL
    freopen("../1.txt", "r", stdin);
#endif
    scanf("%d%d",&n,&q);

    if (n%2) n++;
    if (q<=n/2) puts("YES");
    else puts("NO");

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  long long n,r,b;
  cin>>n>>b>>r;
  if(n%(r+b)==0){
      
      cout<<(n/(r+b))*b<<endl;
    }
    else{
      if(n%(b+r)>=b){
        
        cout<<n/(b+r)*b+b<<endl;
      }
      else if(n%(b+r)<b){
        cout<<n/(b+r)*b+n%(b+r)<<endl;
      }

      
    }
}


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

using namespace std;

int main(){
  int a, b, c, ans = 1;
  while(cin >> a >> b){
    c = a + b;
    ans = 1;
    while(c >= 10){
      ++ans;
      c /= 10;
    }
    cout << ans << "\n";
  }
}

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



int main(){
    int n,m;
    cin>>n>>m;
    vector<int> h(n);
    vector<int> ok(n,0);
    rep(i,n)cin>>h[i];
    vector<pair<int,int>> ab(m);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        ab[i]=make_pair(a-1,b-1);
        if(h[a-1]<h[b-1]){
            ok[a-1]=1;
        }else if(h[a-1]==h[b-1]){
            ok[a-1]=1;ok[b-1]=1;
        }else{
            ok[b-1]=1;
        }
    }
    int ans=0;
    rep(i,n){
        if(ok[i]==0)ans++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4844
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}

string sa;

bool check(int n){
    for(int i=0;i<n/2;i++){
        if(sa[i]!=sa[i+n/2])return false;
    }
    return true;
}

int main(){
    int n,m;
    int i,j,k;
    int a,b,c;
    bool flag=false;
    cin>>sa;
    for(i=sa.size()-1;i>=0;i--){
        if(i%2!=0)continue;
        if(check(i))break;
    }
    cout<<i<<endl;
}

Measured memory_bytes: 256
from heapq import heappush, heappop

INF = 10**15

def dijkstra(s, edges):
    n = len(edges)
    que = []
    d = [INF] * n
    prev = [-1] * n
    d[s] = 0
    heappush(que, (0, s))

    while len(que) > 0:
        (c, v) = heappop(que)
        if d[v] < c:
            continue
        for (cc, w) in edges[v]:
            if d[w] > d[v] + cc:
                d[w] = d[v] + cc
                prev[w] = v
                heappush(que, (d[w], w))

    return d, prev

n = int(input())
edge = [[] for i in range(n)]
for i in range(n-1):
    ai, bi, ci = map(int, input().split())
    ai, bi = ai-1, bi-1
    edge[ai].append((ci, bi))
    edge[bi].append((ci, ai))

q, k = map(int, input().split())
x, y = [], []
for i in range(q):
    xi, yi = map(int, input().split())
    xi, yi = xi-1, yi-1
    x.append(xi)
    y.append(yi)

dist, prev = dijkstra(k-1, edge)

for i in range(q):
    print(dist[x[i]]+dist[y[i]])

Measured memory_bytes: 104224