akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class B { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		int K = GetInt();
		var S = GetString();
		if(S.Length <= K)
			WriteLine(S);
		else
			WriteLine($"{S.Substring(0, K)}...");
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


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

int n,a[55],Min,Max,pMin,pMax;

void START()
{
    cin>>n;

    Min=1e7;

    Max=-1e7;

    for(int i=1;i<=n;++i)
    {
        cin>>a[i];

        if(Min>a[i])
        {
            Min=min(Min,a[i]);
            pMin=i;
        }

        if(Max<a[i])
        {
            Max=max(Max,a[i]);
            pMax=i;
        }
    }

    if(Min>=0)
    {
        cout<<n-1<<'\n';

        for(int i=2;i<=n;++i)
            cout<<i-1<<" "<<i<<'\n';

        exit(0);
    }

    if(Max<0)
    {
        cout<<n-1<<'\n';

        for(int i=n-1;i>=1;--i)
            cout<<i+1<<" "<<i<<'\n';

        exit(0);
    }

    if(abs(Min)<=Max)
    {
        cout<<2*n-1<<'\n';

        for(int i=1;i<=n;++i)
            cout<<pMax<<" "<<i<<'\n';

        for(int i=2;i<=n;++i)
            cout<<i-1<<" "<<i<<'\n';

        exit(0);
    }

    if(abs(Min)>Max)
    {
        cout<<2*n-1<<'\n';

        for(int i=1;i<=n;++i)
            cout<<pMin<<" "<<i<<'\n';

        for(int i=n-1;i>=1;--i)
            cout<<i+1<<" "<<i<<'\n';
    }
}

int main()
{
    START();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, s, n) for (ll i = s; i < (n); i++)
#define repr(i, n) for (ll i = n-1; i >= 0; i--)
using namespace std;

ll modPow(ll a, ll n, ll MOD){
  if (n == 0) return 1;
  if (n == 1) return a % MOD;
  if (n % 2 == 1) return (a * modPow(a, n-1, MOD)) % MOD;
  ll t = modPow(a, n/2, MOD);
  return (t * t) % MOD;
}

int main(){
  ll n;
  string x;
  cin >> n;
  cin >> x;
  ll one = 0;
  vector<ll> kt1(n), kt2(n);
  ll sum1 = 0, sum2 = 0;
  rep(i, n) if (x[i] == '1') one++;
  rep(i, n){
    kt1[i] = modPow(2, n-i-1, one+1);
    if (one != 0 && one != 1) kt2[i] = modPow(2, n-i-1, one-1);
    if (x[i] == '1'){
      sum1 = (sum1 + kt1[i]) % (one+1);
      if (one != 0 && one != 1) sum2 = (sum2 + kt2[i]) % (one-1);
    }
  }
  
  rep(i, n){
    ll num;
    ll ans = 1;
    if (x[i] == '0') num = (sum1 + kt1[i]) % (one+1);
    else if (one == 1 && x[i] == '1'){ num = 0; ans = 0;}
    else num = (sum2 - kt2[i] + one-1) % (one-1);
    while(num != 0){
      ans++;
      ll temp = num;
      ll count = 0;
      while(temp != 0){
        if (temp % 2 == 1) count++;
        temp /= 2;
      }
      num %= count;
    }
    cout << ans << endl;
  }
  
  return 0;
}

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

int occ[100005];

int main(){
int m,n;
scanf("%d%d",&m,&n);
for (int x = 0; x<n; x++){
    int a,b;
    scanf("%d%d",&a,&b);
    occ[a]++;occ[b]++;
}
for (int x = 0; x<=n; x++){
    if (occ[x]&1){
        printf("NO");
        return 0;
    }
}
printf("YES");
}


Measured memory_bytes: 640
import java.math.BigInteger;
import java.util.*;

public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int b = sc.nextInt();
			int [] data = new int[n];
			for(int i = 0; i < n; i++){
				data[i] = sc.nextInt();
			}
			long sum = 0;
			int count = 1;
			for(int i = 0; i < n; i++){
				sum += data[i];
				if(sum > b){
					break;
				}
				count++;
			}
			System.out.println(count);
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

}


Measured memory_bytes: 23252
import java.util.*
import kotlin.collections.HashSet

fun main(args: Array<String>) {
    val digitsValuesMap = TreeMap<Int, Set<Int>>()
    (1..readLine()!!.toInt()).mapNotNull { readLine()!!.toInt() }.forEach {
        val value = it
        val digits = value / 10 + 1
        val values: HashSet<Int> = digitsValuesMap[digits] as? HashSet<Int> ?: HashSet()
        values.add(value)
        digitsValuesMap.put(digits, values)
    }
    val possibleValues = HashSet<Int>()
    var i = 0
    for (integers in digitsValuesMap.values) {
        possibleValues.addAll(integers.take(4))
        i += integers.size
        if (i >= 3) {
            continue
        }
    }
    println(possibleValues.flatMap { v -> possibleValues.filter { it != v }.map { "$it$v".toInt() } }.sorted()[2])
}


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

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

int main() {
    int A, B;
    cin >> A >> B;
    if(max(A, B) <= 8) {
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    int X,Y;

    if(C%B==0){
        X=C/B;
    }
    else{
        X=C/B+1;
    }
    if(A%D==0){
        Y=A/D;
    }
    else{
        Y=A/D+1;
    }
    if(X>Y){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
}

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

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

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

    int t = 0;
    for (int i = 0; i < n; ++i) t += a[i];
    t = round((double)t / n);

    int ans = 0;
    for (int i = 0; i < n; ++i) ans += (a[i] - t) * (a[i] - t);

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

Measured memory_bytes: 380
object Main {
  import java.util.Scanner

  def readStrings(n: Int)(implicit sc: Scanner): Array[String] = Array.fill(n) { sc.next() }
  def readInts(n: Int)(implicit sc: Scanner): Array[Int] = Array.fill(n) { sc.nextInt() }
  def readLongs(n: Int)(implicit sc: Scanner): Array[Long] = Array.fill(n) { sc.nextLong() }
  def readLineStrings(implicit sc: Scanner): Array[String] = sc.nextLine().split(' ')
  def readLineInts(implicit sc: Scanner): Array[Int] = readLineStrings.map(_.toInt)
  def readLineLongs(implicit sc: Scanner): Array[Long] = readLineStrings.map(_.toLong)

  def main(args: Array[String]): Unit = solve(new Scanner(System.in))

  def solve(implicit sc: Scanner): Unit = {
    val S = sc.nextLine()
    val target = "keyence"
    val ans = (0 to 7)
      .map(n => { val (a, b) = target.splitAt(n); a + "(.*)" + b })
      .map(S.matches)
      .exists(identity)
    println(if (ans) "YES" else "NO")
  }
}


Measured memory_bytes: 27324
N,L = map(int,input().split())
a = [L+i for i in range(N)]
# print(a)

mn = 10**9
for i in range(N):
  if mn > abs(a[i]):
    mn = abs(a[i])
    agmn = i

sm = 0
for i in range(N):
  if i!=agmn:
    sm += a[i]

# print(mn, agmn)
print(sm)

Measured memory_bytes: 38460
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S,class T>ostream&operator<<(ostream&os,map<S,T>d){bool a=1;for(auto v:d){os<<(a?"":" ")<<v;a=0;}return os;};
template<class S>ostream&operator<<(ostream&os,set<S>d){bool a=1;for(auto v:d){os<<(a?"":" ")<<v;a=0;}return os;};
template<class S>auto&operator<<(ostream&os,vector<S>d){bool a=1;for(auto v:d){os<<(a?"":" ")<<v;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k,q;
    cin>>k>>q;
    vl d(k); cin>>d;
    // partial_sum(all(d),d.begin());
    rep(i,q){
        ll n,x,m; cin>>n>>x>>m;
        vl a(k),c(k,0);
        rep(i,k)a[i]=d[i]%m;
        rep(i,k)c[i]=((n-1)/k)+((n-1)%k>i);
        x%=m;
        // puta(x,",",a);
        // puta("-,",c);
        ll ans=n-1;
        rep(i,k)if(a[i]==0)ans-=c[i];
        ll v=x;
        rep(i,k){
            v+=a[i]*c[i];
        }
        ans-=(v/m-x/m);
        puta(ans);
    }
    return 0;
}

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N,K;
  cin >> N >> K;
  ll l[N];
  rep(i, N) cin >> l[i];
  sort(l, l+N);
  ll sum=0;
  rep(i,K){
    sum += l[N-1-i];
  }
  cout << sum << endl;
  
  return 0;
    

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char c;
int main()
{
    for(int i=0;i<2;++i)
    {
    
        scanf("%c",&c);
        if(c=='9')
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

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

# define pb push_back
# define fr first
# define sc second
# define mk make_pair
# define int long long

using namespace std;

const int inf = 1e9 + 7;
const int N = 305;

typedef long long ll;

int n, a[N][N], f[N][N], u[N][N], ans;

main()
{
      cin >> n;

      for(int i = 1; i <= n; i ++)
            for(int j = 1; j <= n; j ++)
                  cin >> a[i][j], f[i][j] = a[i][j], ans += a[i][j];

      for(int k = 1; k <= n; k ++)
            for(int i = 1; i <= n; i ++)
                  for(int j = 1; j <= n; j ++)
                  {
                        if(f[i][j] >= (f[i][k] + f[j][k]) && i != j && i != k && j != k)
                        {
                              f[i][j] = f[i][k] + f[j][k];
                              u[i][j] = 1;
                        }
                  }

      for(int i = 1; i <= n; i ++)
            for(int j = 1; j <= n; j ++)
            {
                  if(u[i][j]) ans -= a[i][j];
                  if(a[i][j] != f[i][j])
                  {
                        cout << -1 << endl;
                        return 0;
                  }
            }
      cout << ans / 2 << endl;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define cs const 
#define fr first 
#define se second
#define ls (now<<1)
#define mid ((l+r)>>1)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define low(i) (i&(-i))
#define par pair<int,int>
#define cn(x) memset(x, 0, sizeof(x))
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define sep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])

cs int G = 3;
cs int N = 2e5;
cs int ff = 1e6 + 15;
cs int inf = 1e18 + 1;
cs int base = 2333;
cs int M = 998244353;
cs double eps = 1e-14;

struct Node { int x, id; } A[ff];
bool operator < (Node B, Node C) { return B.x < C.x; }
int n, Ans[ff];
void init()
{
	cin >> n;
	rep(i, 1, n) scanf("%lld", &A[i].x), A[i].id = i;
	int md = n / 2;
	sort(A + 1, A + 1 + n);
	rep(i, 1, md) Ans[A[i].id] = A[md + 1].x;
	rep(i, md + 1, n) Ans[A[i].id] = A[md].x;
	rep(i, 1, n) cout << Ans[i] << "\n";
}
signed main()
{
	int Ts = 1;
	while(Ts--)
		init();
}

Measured memory_bytes: 8252
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: i64, m: usize, a: [i64; m]);
    let r = n - a.iter().sum::<i64>();
    let r = if r < 0 { -1 } else { r };
    println!("{}", r);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


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

    int S;
    cin>>S;

    int dp[2010];
    dp[0]=0;
    dp[1]=0;
    dp[2]=0;
    for(int i=3;i<S+5;i++){
        int c=0;
        rep(j,i-2){
            c+=dp[j];
            c%=MOD;
           
        }
        c++;
        
        c%=MOD;
        dp[i]=c;
    }
    cout<<dp[S]<<endl;




}


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

#define mod 1'000'000'007
typedef long long ll;

template<typename T>
void deb(initializer_list<T> l)
{
	for (auto &e : l)
		cout << e << ' ';
	cout << endl;
}

ll multiply(vector<ll>& a, ll l, ll r)
{
	ll prod = 1;
	for ( ; l <= r; ++l)
	{
		prod = (prod * a[l]) % mod;
		if (prod < 0)
			prod += mod;
	}

	return prod;
}

bool comp(ll& a, ll& b)
{
	return abs(a) > abs(b);
}

void solve()
{
	ll n, k;
	cin >> n >> k;
	vector<ll> neg, pos;
	neg.reserve(n);
	pos.reserve(n);

	ll z = 0;
	vector<ll> a;
	a.reserve(n);
	while (n--)
	{
		ll e;
		cin >> e;
		if (e > 0)
			pos.push_back(e);
		else if (e < 0)
			neg.push_back(e);
		else
			++z;

		if (e)
			a.push_back(e);
	}

	sort(pos.begin(), pos.end(), greater<ll>());
	sort(neg.begin(), neg.end());
	sort(a.begin(), a.end(), comp);

	if ((int) pos.size() == 0)
	{
		if (k % 2 == 1)
		{
			if (z)
				cout << 0 << '\n';
			else
			{
				reverse(neg.begin(), neg.end());
				cout << multiply(neg, 0, k - 1) << '\n';
			}
			return;
		}

		if ((int) neg.size() < k)
			cout << 0 << '\n';
		else
			cout << multiply(neg, 0, k - 1) << '\n';
		return;
	}

	if ((int) neg.size() == 0)
	{
		if ((int) pos.size() < k)
			cout << 0;
		else
			cout << multiply(pos, 0, k - 1);
		cout << '\n';
		return;
	}

	if ((int) pos.size() + (int) neg.size() < k)
	{
		cout << 0 << '\n';
		return;
	}

	if ((int) pos.size() + (int) neg.size() == k)
	{
		// if ((int) neg.size() % 2 == 0)
		// {
			ll prod = 1;
			if ((int) neg.size())
				prod = (prod * multiply(neg, 0, (int) neg.size() - 1)) % mod;
			if ((int) pos.size())
				prod = (prod * multiply(pos, 0, (int) pos.size() - 1)) % mod;
			// cout << prod << '\n';
		// 	return;
		// }

		if ((int) neg.size() % 2 == 0)
			cout << prod << '\n';
		else if (z)
			cout << 0 << '\n';
		else
			cout << prod << '\n';
		return;
	}

	// if ((int) pos.size() >= k)
	// {
	// 	cout << multiply(pos, 0, k - 1) << '\n';
	// 	return;
	// }

	ll pi = 0;
	ll ni = 0;
	for (ll i = 0; i < k; ++i)
	{
		if (a[i] < 0)
			++ni;
		else
			++pi;
	}

	if (ni % 2 == 0)
	{
		ll prod = 1;
		if (ni)
			prod = (prod * multiply(neg, 0, ni - 1)) % mod;
		if (pi)
			prod = (prod * multiply(pos, 0, pi - 1)) % mod;

		cout << prod << '\n';
		return;
	}

	ll p1 = -4e18;
	ll p2 = -4e18;

	if (ni < (int) neg.size()) // another negative
	{
		if (pi)
			p2 = (neg[ni] * neg[ni - 1]);// % mod;
		else
		{
			ll prod = multiply(neg, 0, ni - 2);
			prod = (prod * pos[pi]) % mod;
			cout << prod << '\n';
			return;
		}
	}
	else
	{
		ll prod = multiply(neg, 0, ni - 2);
		prod = (prod * pos[pi]) % mod;
		prod = (prod * multiply(pos, 0, pi - 1)) % mod;
		cout << prod << '\n';
		return;
	}

	if (pi < (int) pos.size() && pi)
		p1 = (pos[pi] * pos[pi - 1]);// % mod;

	ll prod = 1;
	if (p1 > p2)
	{
		prod = multiply(pos, 0, pi);
		prod = (prod * multiply(neg, 0, ni - 2)) % mod;
	}
	else
	{
		prod = multiply(neg, 0, ni);
		prod = (prod * multiply(pos, 0, pi - 2)) % mod;
	}
	cout << prod << '\n';
}

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

	int t = 1;
	// cin >> t;
	while (t--)
		solve();

	return 0;
}


Measured memory_bytes: 6372
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<string> vecstr;
typedef vector<char> vecchar;
typedef vector<bool> vecbool;
typedef vector<vector<bool>> vec2bool;
typedef vector<vector<int>> vec2int;
typedef vector<vector<double>> vec2d;
typedef pair<int, int> P;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
vec2int edge;
// vecint par;
vecll ans;
vecll task;
////////////////////////////////////////////////
void dfs(int prev, int v) {
  // cout << prev << " " << v << endl;
  for (auto &e : edge[v]) {
    if (e == prev) continue;
    // cout << e << endl;
    ans[e] = ans[v] + task[e];
    dfs(v, e);
  }
}
////////////////////////////////////////////////
int main() {
  init();
  int n, q;
  cin >> n >> q;
  edge.resize(n);
  ans = vecll(n, 0);
  task = vecll(n, 0);
  REP(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  REP(i, q) {
    int p;
    ll x;
    cin >> p >> x;
    p--;
    task[p] += x;
  }
  // return 0;
  ans[0] = task[0];
  dfs(-1, 0);
  // vecll ans(n, 0);
  REP(i, n - 1) { cout << ans[i] << " "; }
  cout << ans[n - 1] << endl;
}


Measured memory_bytes: 25856
package main

import "fmt"
type node struct {
	key int
	related int
	weight int
}
var q int
var n int
var p []node
func main(){
	fmt.Scanf("%d %d",&n,&q)
	p=make([]node,n)
	for i := 0; i < n; i++ {
		makeSet(i)
	}
	var op,x,y,diff int
	for i := 0; i < q; i++ {
		fmt.Scanf("%d %d %d %d",&op,&x,&y,&diff)
		if 1 == op {
			diff_xy(x,y)
		}else {
			unite(x,y,diff)
		}
	}
}
func makeSet(x int)  {
	p[x]=node{
		key: x,
		related: x,
	}
}
func unite(x,y,diff int){
	temp1:=findSet(x)
	temp2:=findSet(y)
	if temp1 != temp2{
		p[temp2].related=temp1
		p[temp2].weight=p[x].weight - p[y].weight+diff
	}
}
func diff_xy(x,y int) {
	if findSet(x) == findSet(y) {
		fmt.Println(p[y].weight-p[x].weight)
	}else {
		fmt.Println("?")
	}
}
func findSet(x int) int{
	if x == p[x].related {
		return x
	}else {
		temp:=p[x].related
		p[x].related = findSet(p[x].related)
		p[x].weight += p[temp].weight
		return p[x].related
	}
}


Measured memory_bytes: 6476
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    vector<double> p(6), q(6);
    cin >> p; cin >> q;
    REP(i, 6){
        p[i] /= 100.0;
        q[i] /= 100.0;
    }

    double ans = 1.0;
    double a0 = 0.0, a1 = 1.0;
    while(true){
        double A0 = a0 + (a1 - a0) / 3, A1 = a0 + (a1 - a0) * 2 / 3;
        double val0 = 0.0, val1 = 0.0;
        REP(i, 6){
            val0 += max(A0 * p[i], (1.0 - A0) * q[i]);
            val1 += max(A1 * p[i], (1.0 - A1) * q[i]);
        }

        if(val0 > val1) a0 = A0;
        else a1 = A1;

        if(a1 - a0 < 1.0e-11){
            Out((val0 + val1) / 2.0);
            return 0;
        }
    }
    //Out(ans);

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   int a = sc.nextInt();
   int b = sc.nextInt();
   int c = sc.nextInt();
   int d = sc.nextInt();

   int min =0;
   if(a<b) min+= a;
   else min +=b;
   if(c<d) min+=c;
   else min+= d;
   System.out.println(min);
 }
}

Measured memory_bytes: 22100
import math
def li():
    return list(map(int, input().split()))
def mi():
    return map(int, input().split())
def ii():
    return int(input())

x1, y1, x2, y2 = mi()

l = 0
# x = Cの場合
if (x2 - x1) == 0:
    l = abs(y2 - y1)
    if y2 > y1:
        x3 = x1 - l
    else:
        x3 = x1 + l
    y3 = y2
    x4 = x3
    y4 = y1
# y = Cの場合
elif (y2 - y1) == 0:
    l = abs(x2 - x1)
    x3 = x2
    if x2 > x1:
        y3 = y2 + l
    else:
        y3 = y2 - l
    x4 = x1
    y4 = y3
# y = ax + bの場合
else:
    x3 = x2 - (y2 - y1)
    y3 = y2 + (x2 - x1)
    x4 = x1 - (y2 - y1)
    y4 = y1 + (x2 - x1)

print(x3, y3, x4, y4)

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

namespace ABC098A
{
	class Program
	{
		static void Main(string[] args)
		{
			int A, B, max;

			var word = Console.ReadLine().Split(' ');

			A = int.Parse(word[0]);
			B = int.Parse(word[1]);
			if (A + B > A * B && A + B > A - B)
			 max = A + B;
			
			else if (A * B > A + B && A * B > A - B) 
			
				max = A * B;
			 
			else
			max = A - B; 
			
			Console.WriteLine(max);
			Console.ReadKey();
		}
	}
}


Measured memory_bytes: 13140
#include<iostream>
#include<cstdio>
#include<algorithm>
#define P 1000000007
#define ll long long
using namespace std;
ll n,a[100005];
int main()
{
	scanf("%lld",&n);
	for (ll i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	ll Ans=1,sum=0;
	for (ll i=1;i<=n;i++)
	{
	//	cout<<Ans<<' '<<sum<<endl;
		if (sum*2+1>a[i]+1)
			Ans=Ans*sum%P;
		else
		if (sum*2+1==a[i]+1) Ans=Ans*(sum+1)%P;
		else sum++;
	//cout<<Ans<<' '<<sum<<endl;
	}
	while(sum) Ans=Ans*(sum--)%P;
	printf("%lld\n",Ans);
}

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

int main(){
  string s,t;
  cin>>s>>t;
  int a,b;
  cin>>a>>b;
  string u;
  cin>>u;
  if(u==s) cout<<a-1<<" "<<b<<endl;
  else cout<<a<<" "<<b-1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
typedef long long int ll;
using namespace std;
std::vector<int> lis;
std::vector<int> lis2;
std::vector<int> lis3;

void dfs(int e, int num){
  if(num!=0) lis.push_back(num);
  if(num >= 333333333) return;
  dfs(e * 10, num + e * 3);
  dfs(e * 10, num + e * 5);
  dfs(e * 10, num + e * 7);
}
void dfs2(int e, int num){
  if(num!=0) lis2.push_back(num);
  if(num >= 333333333) return;
  dfs2(e * 10, num + e * 3);
  dfs2(e * 10, num + e * 5);
}
void dfs4(int e, int num){
  if(num!=0) lis2.push_back(num);
  if(num >= 333333333) return;
  dfs4(e * 10, num + e * 3);
  dfs4(e * 10, num + e * 7);
}
void dfs5(int e, int num){
  if(num!=0) lis2.push_back(num);
  if(num >= 333333333) return;
  dfs5(e * 10, num + e * 7);
  dfs5(e * 10, num + e * 5);
}
void dfs3(int e, int num){
  if(num!=0) lis3.push_back(num);
  if(num >= 333333333) return;
  dfs3(e * 10, num + e * 3);
}
void dfs6(int e, int num){
  if(num!=0) lis3.push_back(num);
  if(num >= 333333333) return;
  dfs6(e * 10, num + e * 5);
}
void dfs7(int e, int num){
  if(num!=0) lis3.push_back(num);
  if(num >= 333333333) return;
  dfs7(e * 10, num + e * 7);
}

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  dfs(1, 0);
  dfs2(1, 0);
  dfs3(1, 0);
  dfs4(1, 0);
  dfs5(1, 0);
  dfs6(1, 0);
  dfs7(1, 0);
  sort(lis.begin(), lis.end());
  sort(lis2.begin(), lis2.end());
  sort(lis3.begin(), lis3.end());
  int maxx = upper_bound(lis.begin(), lis.end(), N) - lis.begin();
  int maxx2 = upper_bound(lis2.begin(), lis2.end(), N) - lis2.begin();
  int maxx3= upper_bound(lis3.begin(), lis3.end(), N) - lis3.begin();
  std::cout << maxx - maxx2 + maxx3<< '\n';
  return 0;
}


Measured memory_bytes: 512
// abc109_b
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void) {
	int N;
	cin >> N;
	vector<string> vec;
	vec.resize(N);
	cin >> vec[0];

	for (int i = 1; i < N; i++) {
		cin >> vec[i];
		int length = vec[i - 1].length();
		char a = vec[i - 1][length-1];
		char b = vec[i][0];
		if (a != b) {
			cout << "No" << endl;
			return 0;
		}
		for (int j = 0; j < i; j++) {
			if (vec[i] == vec[j]) {
				cout << "No" << endl;
				return 0;
			}
		}

	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define inf 1e9
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (ll i = (ll)(x); i < (ll)(n); i++)
#define repfr(i, x, n) for (ll i = (ll)(x)-1; i >= (ll)(n); i--)
using ll = int64_t;

void Main() {
  int n;
  std::cin >> n;
  array<ll, 87> r;
  r[0] = 2;
  r[1] = 1;
  repf(i, 2, 87) { r[i] = r[i - 1] + r[i - 2]; }

  std::cout << r[n] << '\n';

  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
<?php

while (true) {
    $stdin = preg_split('/ /', trim(fgets(STDIN)));
    $h = intval($stdin[0]);
    $w = intval($stdin[1]);
    
    if ($h === 0 && $w === 0) {
        return;
    }
    
    for ($i = 1; $i <= $h; $i++) {
        for ($j = 1; $j <= $w; $j++) {
            if ($i == 1 || $i == $h) {
                print '#';
            } elseif ($j == 1 || $j == $w) {
                print '#';
            } else {
                print '.';
            }
        }
        print "\n";
    }
    print "\n";
}

Measured memory_bytes: 6640
import java.util.*;
 
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int K = sc.nextInt();
        int[][] cake = new int[H][W];
        int num  = 0;
        for (int i = 0; i < H; i++) {
            boolean found = false;
            String s = sc.next();
            for (int j = 0; j < W; j++) {
                if (s.charAt(j) == '#') {
                    cake[i][j] = ++num;
                    if (!found) {
                        for (int k = j; k >=0; k--) {
                            cake[i][k] = num;
                        }
                        found = true;
                    }
                } else {
                    if (found) {
                        cake[i][j] = num;
                    }
                }
            }
        }
        for (int i = 1; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (cake[i][j] == 0) {
                    cake[i][j] = cake[i-1][j];
                }
            }
        }
        for (int i = H-2; i >= 0; i--) {
            for (int j = 0; j < W; j++) {
                if (cake[i][j] == 0) {
                    cake[i][j] = cake[i+1][j];
                }
            }
        }
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                ans.append(cake[i][j]).append(" ");
            }
            ans.append("\n");
        }
        System.out.print(ans);
    }
}



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

int main()
{
    int n,i;
    cin>>n;
    int arr[n], a[n];
    for(i=0;i<n;i++){
        cin>>arr[i];
        a[arr[i]-1]=i+1;

    }
    for(i=0;i<n;i++){
        cout<<a[i]<<" ";
    }
	return 0;
}

Measured memory_bytes: 1536
N,X=map(int,input().split())
x=list(map(int,input().split()))
x=[abs(i-X) for i in x]

def gcm(a,b):
    if a<b:a,b=b,a
    c=a%b
    while c>0:
        a,b=b,c
        c=a%b
    return b

D=x[0]
for i in range(N):
       D=gcm(D,x[i])
print(D)

Measured memory_bytes: 14252
#define _USE_MATH_DEFINES
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long ull;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef priority_queue<int> maxPq;
typedef priority_queue<ll, vector<ll>, greater<ll> > minPq;
typedef deque<int> dq;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define forVar(type, var, init, till, increment) for (type var = init; var < till; var += increment)
#define deb(x) cout << x << endl;
#define MAX 5 * 10000 + 1
#define INF 10000000000

// Knapsack 1: Atcoder Educational DP contest
int n, peso, wi;
ll v;
vi wes;
vector<ll> utils;
ll dpUtility[101][100001];


ll knapsack()
{
    for(int i = 0; i <= n; ++i)
    {
        for (int w = 0; w <= peso; ++w)
        {
            if (i == 0 || w == 0) dpUtility[i][w] = 0;
            else if (wes[i-1] <= w) dpUtility[i][w] = max(dpUtility[i-1][w], dpUtility[i-1][w-wes[i-1]] + utils[i-1]);
            else dpUtility[i][w] = dpUtility[i-1][w];
        }
    }
    return dpUtility[n][peso];
}



int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n >> peso;

    for(int i = 0; i < n; ++i)
    {
        cin >> wi >> v;
        wes.push_back(wi);
        utils.push_back(v);
    }

    cout << knapsack() << endl;
    return 0;
}

Measured memory_bytes: 79104
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int N, A, B; cin >> N >> A >> B;
	int ans = min(B,N*A);
	cout << ans << endl;


	return 0;

}


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

int a[100];
int main()
{
    int n , x ;
    cin>>n>>x;
    for (int i = 0; i < n; i++) 
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int ans = 0;
    for (int i = 0; i < n; i++) 
    {
        if (a[i] <= x) 
        {
    	ans++;
    	x -= a[i];
        }
    }
    if (ans == n && x > 0)
    {
        ans--;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>
using namespace std;
#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
typedef long long ll;


// 9系でわるか，6系でわるか，二分探索

int binsearch(int N,int cnt){
  if (N<6){
    return cnt + N;
  }
  float logN = log(N);
  int log6N = logN/log(6);
  int log9N = logN/log(9);

  int a = pow(6,log6N);
  int b = pow(9,log9N);
  int resa = binsearch(N-a,cnt+1);
  int resb = binsearch(N-b,cnt+1);
  return min(resa,resb);
}

int main()
{
  int N;

  cin >> N;

  int r = binsearch(N,0);

  cout << r << endl;

  return 0;
}


Measured memory_bytes: 640
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
//typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//define
#define i(X) cin>>X;
#define ol(X) cout<<X<<endl;
#define os(X) cout<<X<<" ";
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define line cout<<"\n";
#define pbp(a,b) push_back(make_pair(a,b));
#define vll(A) vector<long lonh> A;
#define ivt(A,n,p) vector<long long> A(n,p);
#define vst(A) sort(A.begin(),A.end());
#define rvst(A) sort(A.rbegin(),A.rend());
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair

const long long inf=(long long)1e18;
const long long mod=(long long)(1e9+7);

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; 
} 
ll modInverse(ll a,ll p)
{
   return power(a,p-2,p);
}

int main()
{
    // #ifndef ONLINE_JUDGE
    //    freopen ("input.txt" , "r" , stdin);
	// 	// freopen ("OUTPUT.txt" , "w" , stdout);
	// #endif
    fio;
    ll testcase=1;
    //cin>>testcase;
    while(testcase--)
    {
        ll n,k;
        i(n);
        i(k);
        ll a[n];
        forin(i,0,n-1)
        {
            i(a[i]);
        }
        sort(a,a+n);
        ll s=0;
        forin(i,0,k-1)
        s+=a[i];
        ol(s);
    }
    return 0;
}

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

typedef long long ll;

const ll MOD = 1e9+7;

ll dmod(ll x){
	return x%MOD;
}

ll fe(ll x, ll p){
	if(p==0) return 1;
	if(p==1) return x;
	ll ret = fe(x,p/2);
	ret = dmod(ret*ret);
	if(p&1) ret = dmod(ret*x);
	return ret;
}

string s;

int main(){
	cin >> s;
	ll ans = 0ll;
	int j1 , j0;
	j1 = j0 = 0;
	// 1 => (0 1) (1 0)
	// 0 => (0 0)
	for(int i=0;i<s.size();i++){
		if(s[i] == '0') j0++;
		else j1++;
		if(s[i] == '0') {
//			ans = dmod(ans + fe(2,j1));
			continue;
		}
		ans = dmod(ans + dmod(fe(2,j1-1) * fe(3,s.size()-i-1)));
//		cout << ans << endl;
	}
	ans = dmod(ans + fe(2,j1));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,s;
const int INF = 1e14;
int ans = INF;
signed main() {
  cin >> n >> s;

  if(s == n) {
    cout << n + 1 << endl; return 0;
  }

  for(int i = 2; i * i <= n; i++) {
    int tmp = n;
    int sum = 0;
    while(tmp > 0) {
      sum += tmp % i;
      tmp /= i;
    }
    if(sum == s) {
      cout << i << endl;
      return 0;
    }
  }
  for(int i = 1; i * i < n; i++) {
    int b = (n - s) / i + 1;
    int tmp = n;
    int sum = 0;
    if(b < 2) continue;
    while(tmp > 0) {
      sum += tmp % b;
      tmp /= b;
    }
    if(sum == s) {
      ans = min(ans,b);
    }
  }

  if(ans == INF) cout << "-1"<<endl;
  else cout << ans << endl;
}
      

  


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int H, W;
	cin >> H >> W;
	vector<vector<int>> a(H, vector<int>(W));
	for (auto i = 0; i < H; ++i)
	{
		for (auto j = 0; j < W; ++j)
		{
			cin >> a[i][j];
		}
	}
	
	vector<int> prevY;
	vector<int> prevX;
	vector<int> nextY;
	vector<int> nextX;
	for (auto i = 0; i < H; ++i)
	{
		for (auto j = 0; j < W; ++j)
		{
			auto currentJ = j;
			if (i % 2 > 0)
			{
				currentJ = W - j - 1;
			}

			if (a[i][currentJ] % 2 == 0)
			{
				continue;
			}

			if (i >= H - 1 && j >= W - 1)
			{
				continue;
			}

			prevY.push_back(i + 1);
			prevX.push_back(currentJ + 1);

			auto ny = i;
			auto nx = currentJ;
			if (j >= W - 1)
			{
				++ny;
			}
			else if(i % 2 == 0)
			{
				++nx;
			}
			else
			{
				--nx;
			}
			nextY.push_back(ny + 1);
			nextX.push_back(nx + 1);
			++a[ny][nx];
		}
	}

	cout << (int)prevY.size() << endl;
	for (auto i = 0; i < (int)prevY.size(); ++i)
	{
		cout << prevY[i] << " " << prevX[i] << " " << nextY[i] << " " << nextX[i] << endl;
	}

	return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    ll N; cin>>N;
    ll res = 0;
    for(ll i = 1; i <= N; i++){
        ll tmp1 = N/i;
        res += (1+tmp1)*tmp1*i/2.0;
        
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3588
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n;
    double a[110];
    cin >> n;
    double ans = 0;
    imfor(i, n) {
        cin >> a[i];
        ans += 1.0 / a[i];
    }
    ans = 1.0 / ans;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,i,j,v,k;
	scanf("%d",&n);
	int a[n+1];
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	for(k=0;k<n-1;k++)
		printf("%d ",a[k]);
		printf("%d\n",a[k]);
	for(i=1;i<n;i++){
		v=a[i];
		j=i-1;
		while(j>=0&&a[j]>v){
			a[j+1]=a[j];
			j--;
		}
		a[j+1]=v;
		for(k=0;k<n-1;k++)
		printf("%d ",a[k]);
		printf("%d\n",a[k]);
	}
	return 0;
}


Measured memory_bytes: 2144
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
using namespace std;


unsigned long long gcd(unsigned long long m, unsigned long long n)
{
	unsigned long long tmp;
	while (m % n != 0)
	{
		tmp = n;
		n = m % n;
		m = tmp;
	}
	return n;
}

int main()
{
	unsigned long long a,b,c,d;
	cin >> a >> b >> c >> d;
	a--;

	unsigned long long lcm = c*d / gcd(c, d);
	cout << (b - a) - ((b/c + b/d - b/lcm) - (a/c + a/d - a/lcm)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define PRIMENUM 300000

int isPrime[PRIMENUM];

void makePrimeNumber(){

	isPrime[2]=1;
	isPrime[3]=1;

	for(int i=4;i<PRIMENUM;i++){
		int flag=0;
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				flag=1;
				break;
			}
		}
		if(flag==0){
			isPrime[i]=1;
			//cout<<i<<endl;
		}	
	}

}

int main(){

	makePrimeNumber();

	int ans=0;
	int n;

	while(cin>>n){
		ans=0;
		if(n==0)break;

		for(int i=n+1;i<=2*n;i++){
			if(isPrime[i]==1)ans++;
		}
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 2332
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    int N;
    int K;
    bool[] d;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Read();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        while(true){
            int i = N;
            bool b = true;
            while(i != 0){
                if(!d[i%10]){
                    b = false;
                    break;
                }
                i /= 10;
            }
            if(b){
                sb.Append(N+"\n");
                break;
            }
            else{
                N++;
            }
        }
    }
    void Read(){
        string[] str = Console.ReadLine().Split(' ');
        N = int.Parse(str[0]);
        K = int.Parse(str[1]);
        str = Console.ReadLine().Split(' ');
        d = new bool[10];
        for(int i=0;i<10;i++){
            d[i] = true;
        }
        for(int i=0;i<K;i++){
            d[int.Parse(str[i])] = false;
        }
    }    
}

Measured memory_bytes: 2776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

ll n,m;
vector<vector<ll>> g(100010); 
vector<ll> color(100010,0);

bool dfs(ll v,ll c){
  color[v]=c;
  for(auto itr:g[v]){
    if(color[itr]==c) return false;
    if(color[itr]==0 && !dfs(itr,-c)) return false;
  }
  return true;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>m;
    rep(i,m){
      ll a,b;
      cin>>a>>b;
      g[a].push_back(b);
      g[b].push_back(a);
    }

    if(dfs(1,1)){
      ll b=count(begin(color),end(color),1);
      ll w=count(begin(color),end(color),-1);
      cout<<b*w-m<<endl;
    }else{
      cout<<n*(n-1)/2-m<<endl;
    }
}

Measured memory_bytes: 7552