akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <unordered_set>
#include <unordered_map>
#include <cassert>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define mod 1000000007
#define mod1 1000000009
#define mod2 1000000021
#define INF 500001
#define MAX 1000000001
using namespace std;

/* 🐣🐥 */
int dp[100001], b, ans;
int main() {
	int n, w, a;
	scanf("%d %d", &n, &w);
	fill(dp, dp + 100001, MAX);
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &a, &b);
		for (int j = 100000; j >=b; j--) {
			if (dp[j - b] != -1 && dp[j-b]+a <= w) {
				dp[j] = min(dp[j], dp[j - b] + a);
			}
		}
	}
	for (int i = 100000; i >= 0; i--) if (dp[i] != MAX) return !printf("%d", i);

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int cur = 0;
    ll ans = 0;
    int count = 0;
    bool before = false;
    while(cur < n)
    {
        while(cur < n && s[cur] != 'A')
        {
            count = 0;
            before = false;
            cur++;
        }
        if(cur == n) break;
        while(cur < n && s[cur] == 'A')
        {
            cur++;
            if(before)
            {
              before = false;
            }
            else
            {
              count++;
            }
        }
        if(cur == n || s[cur] == 'C') continue;
        if(cur+1 < n && s[cur+1] == 'C')
        {
            ans += count;
            s[cur+1] = 'A';
            cur++;
            before = true;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
import scala.io.StdIn._

object Main extends App {
  val Array(n,k) = readLine().split(" ").map(_.toLong)
  val ab = Array.fill(n.toInt)(readLine().split(" ").map(_.toLong))
    .map(list => (list(0), list(1)))

  def solve(): Long = {
    val default = Map.empty[Long, Long]
    val numAndCntSeq: Seq[(Long, Long)] = ab.foldLeft(default) { case (acc, (a, b)) =>
      acc.updated(a, acc.getOrElse(a, 0L) + b)
    }.toSeq.sortBy(_._1)

    var dropCnt = 0L
    numAndCntSeq.foreach { case (num, cnt) =>
      dropCnt += cnt
      if(dropCnt >= k) return num
    }
    -1L
  }

  println(solve())

}



Measured memory_bytes: 80300
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    const tmp = readln.split.to!(long[]);
    const A = tmp[0], B = tmp[1];

    // f(A,B) = AからBまでのすべての整数のxor
    // 各bitでもとめる
    // 1bit目はAからBまでのうち1のbitが奇数個なら1、偶数個なら0を返す
    // これは交互に来るから、結局(B-A+1)が奇数個かどうかで決まる
    // 2bit目はAからBまでのうち1のbitが奇数個なら1、偶数個なら0を返す
    // これは2個ずつ飛ばしで来るから、一般に
    // Nの2bit目が1であるとは、N%4が2か3であることを意味する
    // 一般にnbit目が1であるとは、N%(2^^n)が2^^(n-1)以上であることを意味する
    // 各桁を求めるにあたって、A%(2^^n) = a, B%(2^^n) = bであるとき、
    // aからはじめて2^^n個のセットは打ち消し合うので、結局そこ以降のxorをとればいい。

    long result;
    foreach (n; 1..64) {
        // A = (2^^n) * a + x
        // B = (2^^n) * b + y
        // C = (2^^n) * (a+1)
        // D = (2^^n) * b
        // [C,D)の区間には(D-C)/2個の1がある。
        // [A,C)の区間にはmax(2^^n-x, 2^^(n-1))個の1がある
        // [D,B]の区間にはmax(0, y-2^^(n-1)+1)個の1がある

        auto a = A / (1L << n);
        auto b = B / (1L << n);
        auto x = A % (1L << n);
        auto y = B % (1L << n);
        auto C = (1L << n) * (a+1L);
        auto D = (1L << n) * b;
        long cnt;
        cnt += (D-C)/2;
        cnt += min((1L << n)-x, (1L << (n-1L)));
        cnt += max(0, y-(1L << (n-1L))+1L);
        if (cnt % 2 == 1L) result |= (1L << (n-1L));
    }
    writeln(result);
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int i; cin>> i;
	cout << ((i == 0)? 1 : 0) << endl;
	return 0;
}


Measured memory_bytes: 3616
use nqp;
nqp::stmts(
(my int $a  = get.Int),
(my int $b  = get.Int),
(my int $c  = get.Int),
(my int $d  = get.Int),
say nqp::if(nqp::isle_i($a,$b),$a,$b) + nqp::if(nqp::isle_i($c,$d),$c,$d));

Measured memory_bytes: 51656
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int main(){
	int n;
	string s;
	cin >> n >> s;
	s = "0" + s + "0";

	vector<int> dp(s.size(), 0);
	range(i,1,s.size() - 1){
		dp[i + 1] = max(dp[i + 1], dp[i]);

		if(s[i - 1] == '1' && s[i] == '0' && s[i + 1] == '1'){
			int back = i - 1, front = i + 1;

			while(s[back] == '1'){
				dp[i + 1] = max(dp[i + 1], dp[back - 1] + i - back);
				back--;
			}
			while(s[front] == '1'){
				dp[front] = max(dp[front], dp[i - 2] + front - i);
				front++;
			}
		}
		//for(auto i : dp){ cout << i <<' '; } cout << endl;
	}
	cout << dp[s.size() - 1] << endl;
}


Measured memory_bytes: 2840
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
set<pii> es;

int main() {
  scanf("%d", &N);
  rep(v, N) {
    reps(u, v+1, N) {
      es.insert(pii(v, u));
    }
  }

  int lim = N/2*2;
  rep(v, lim) {
    es.erase(pii(v, lim-1-v));
  }

  printf("%d\n", (int)es.size());
  for (auto &p : es) {
    printf("%d %d\n", p.X+1, p.Y+1);
  }
}


Measured memory_bytes: 512
n = int(input())
d = list(map(int,input().split()))
 
from collections import Counter
q=Counter(d)

# 例外対応
if q[0]!=1 or d[0]!=0:
  print(0)
  exit()

ans = 1
for i in range(1,max(d)+1):
  ans *= q[i-1]**q[i]
  if ans == 0:
    break
print(ans%998244353)

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

int main() {
  long long a, b, x, ans;
  cin >> a >> b >> x;
  if (a == 0) {
    ans = (b / x) + 1;
  } else {
    ans = (b / x) - ((a - 1) / x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const double eps=1e-9;
long long n,ga,sa,ba,gb,sb,bb,w,id[4],dp[25555555];
long long trans(long long n,int ga,int sa,int ba,int gb,int sb,int bb)
{
	memset(dp,0,sizeof(dp));
	for (int i=1;i<=n;i++)
	{
		if (i>=ga) dp[i]=max(dp[i],dp[i-ga]+gb);
		if (i>=sa) dp[i]=max(dp[i],dp[i-sa]+sb);
		if (i>=ba) dp[i]=max(dp[i],dp[i-ba]+bb);
	}
	long long ans=0;
	for (int i=0;i<=n;i++) ans=max(ans,n-i+dp[i]);
	return ans;
}
int main()
{
	cin>>n>>ga>>sa>>ba>>gb>>sb>>bb;
	w=trans(n,ga,sa,ba,gb,sb,bb);
	n=trans(w,gb,sb,bb,ga,sa,ba);
	printf("%lld\n",n);
	return 0;
}

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

namespace abc059_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            string sf =input[0].Substring(0, 1);
            string ss = input[1].Substring(0, 1);
            string st = input[2].Substring(0, 1);

            string a = sf.ToUpper();
            string b = ss.ToUpper();
            string c = st.ToUpper();

            Console.WriteLine(a+b+c);
            Console.Read();
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  int a[51],b[51];
  for(int i = 0;i<N;i++){
    cin >> a[i] >> b[i] ;
  }
  int c[51],d[51];
  for(int i = 1 ; i<=M;i++){
    cin >> c[i] >>d[i] ;
  }
  int g[51];
  for(int i = 0; i<N; i++){
    int ans = 800000000;
    for(int j = M; j>0;j--){
      int e = c[j];
      int f = d[j];
      int d = abs(a[i]-e)+abs(b[i]-f);
      if(ans >= d){
      ans = d;
      g[i] = j;
    }
  }
}
for(int i =0; i <N; i++){
  cout << g[i] << endl;
}
}

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

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

    std::string str;
    int q;
    std::cin >> str >> q;
    for(int i=0; i<q; ++i){
        std::string command;
        std::cin >> command;
        if(command=="print"){
            int a, b;
            std::cin >> a >> b;
            for(int i=a; i<=b; ++i){
                std::cout << str[i];
            }
            std::cout << "\n";
        }else if(command=="reverse"){
            int a, b;
            std::cin >> a >> b;
            std::string partStr = str.substr(a, b-a+1);
            for(int i=a; i<=b; ++i){
                str[i] = partStr[b-i];
            }
        }else if(command=="replace"){
            int a, b;
            std::string replaceStr;
            std::cin >> a >> b >> replaceStr;
            for(int i=a; i<=b; ++i){
                str[i] = replaceStr[i-a];
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3200
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <time.h>
#include <stdlib.h>
using namespace std;

	

int main(){
	int a,b;
	cin >> a;
	cin >> b;
	printf("%d\n",a-b+1);
	return 0;
}
		

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

int main() {
  ll x, y;
  cin >> x >> y;
  ll absdif = abs(abs(x) - abs(y)), ans = 1e10;
  if (x <= y) ans = min(ans, y - x);                     // 0,0
  if (-1 * x <= y) ans = min(ans, y + x + 1);            // 1,0
  if (x <= -1 * y) ans = min(ans, -1 * y - x + 1);       // 0,1
  if (-1 * x <= -1 * y) ans = min(ans, -1 * y + x + 2);  // 1,1
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(void) {
    int n, m, l, a[100][100], b[100][100], i, j, k;
    long int c[100][100] = {0};
    cin >> n >> m >> l;
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    for (i = 0; i < m; i++) {
        for (j = 0; j < l; j++) {
            cin >> b[i][j];
        }
    }
    for (i = 0; i < n; i++) {
        for (j = 0; j < l; j++) {
            for (k = 0; k < m; k++) {
                c[i][j] += a[i][k] * b[k][j];
            }
            cout << c[i][j];
            if (j != l - 1)
                cout << ' ';
            else
                cout << endl;
        }
    }
    return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<vector<int>>f(n,vector<int>(10)),p(n,vector<int>(11));
	for(auto&&i:f)for(auto&&j:i)cin>>j; for(auto&&i:p)for(auto&&j:i)cin>>j;
	int64_t ans=INT_MIN;
	for(int i=1;i<(1<<10);++i){
		vector<int>c(n,0);
		for(int j=0;j<10;++j){
			if(i&(1<<j)){
				for(int k=0;k<n;++k){
					c.at(k)+=f.at(k).at(j);
				}
			}
		}
		int64_t tans=0;
		for(int j=0;j<n;++j){
			tans+=p.at(j).at(c.at(j));
		}
		ans=max(ans,tans);
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
INT C[100100];
INT Pow_Mod(INT I, INT J, INT mod){
	INT r = 1, i,j;
	for(i=1, j = I; i <= J ;i<<=1, j=(j*j)%mod)	if(i&J) r = (r*j)%mod;
	return r;
}
int main(){
	INT i, j, n, k, mod=1000000007, s=0;
	cin >> n >> k;
	for(i=k;i>0;i--){
		C[i] = Pow_Mod(k/i,n,mod);
		for(j=i+i;j<=k;j=j+i){
			C[i]=(C[i]-C[j]+mod)%mod;
		}
		s = (s+i*C[i])%mod;
	}	
	cout << s;
}

Measured memory_bytes: 4360
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;
 

int main(int argc, char* argv[])
{
    int n,m;
    scanf("%d%d", &n, &m);
    map<int,vector<pair<int,int> > > z;
    int i;
    for(i=0; i<n; i++) {
        int s,t,c;
        scanf("%d%d%d", &s, &t, &c);
        z[c].push_back(make_pair(s,t));
    }
    vector<int> a(100005);
    auto it=z.begin();
    for(; it!=z.end(); ++it) {
        vector<pair<int,int> >& vv=it->second;
        sort(vv.begin(), vv.end());

        int k;
        for(k=0; k<(int)vv.size(); k++) {
            if(k==0 || vv[k-1].second!=vv[k].first) {
                a[vv[k].first-1]++;
                a[vv[k].second]--;
            }
            else {
                a[vv[k].first]++;
                a[vv[k].second]--;
            }
        }
    }

    ll max=0;
    ll sum=0;
    for(i=0; i<=100000; i++) {
        sum+=a[i];
        max=MAX(max,sum);
    }
    printf("%lld\n", max);

    return 0;
}

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

#define N 2*123456

int isPrime[1+N];

void sieve()
{
  int i, j;
  
  for(i = 2; i <= N; ++i){
    isPrime[i] = 1;
  }
  
  for(i = 2; i < N; ++i){
    if( isPrime[i] ){
      for(j = 2; i * j <= N; ++j){
        isPrime[i * j] = 0;
      }
    }
  }
}

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

  while(1){
    int x, n;
    int res = 0;

    scanf("%d", &n);
    if( n == 0 ) break;
    
    for(x = n+1; x <= 2*n; ++x){
      if( isPrime[ x ] ) ++res;
    }
    
    printf("%d\n", res);
  }
  return (EXIT_SUCCESS);
}

Measured memory_bytes: 0
from collections import defaultdict

N = int(input())
S = input()

S1 = S[:N]
S2 = S[N:][::-1]

ans = 0
D = defaultdict(int)

for i in range(2**N):
    bit = bin(2**N+i)[3:]

    red1 = "".join([d for d, s in zip(S1, bit) if s == "1"])
    blue1 = "".join([d for d, s in zip(S1, bit) if s == "0"])
    D[(red1, blue1)] += 1

for i in range(2**N):
    bit = bin(2 ** N + i)[3:]

    red2 = "".join([d for d, s in zip(S2, bit) if s == "1"])
    blue2 = "".join([d for d, s in zip(S2, bit) if s == "0"])
    ans += D[(blue2, red2)]

print(ans)


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

int main(){
	int n,k;	cin>>n>>k;
	int ans=0;
	for(int i=0;i<n;i++){
		int h;	cin>>h;
		if(k<=h)ans++;
	}
	cout<<ans<<endl;


	return 0;
}


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

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pii> vii; 
typedef vector<ll> vl; 
typedef vector<vl> vvl; 

double EPS=1e-9; 
int INF=1000000005; 
long long INFF=1000000000000000005ll; 
double PI=acos(-1); 
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 }; 
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 }; 
const ll MOD = 1000000007;

#define DEBUG fprintf(stderr, "====TESTING====\n") 
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl 
#define OUT(x) cout << x << endl 
#define OUTH(x) cout << x << " " 
#define debug(...) fprintf(stderr, __VA_ARGS__) 
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a)) 
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a)) 
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a)) 
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a)) 
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a)) 
#define EACH(a, b) for (auto&(a) : (b)) 
#define REP(i, n) FOR(i, 0, n) 
#define REPN(i, n) FORN(i, 1, n) 
#define MAX(a, b) a=max(a, b) 
#define MIN(a, b) a=min(a, b) 
#define SQR(x) ((ll)(x) * (x)) 
#define RESET(a, b) memset(a, b, sizeof(a)) 
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back 
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define SIZE(v) (int)v.size() 
#define SORT(v) sort(ALL(v)) 
#define REVERSE(v) reverse(ALL(v)) 
#define SORTA(arr, sz) sort(ALLA(arr, sz)) 
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) 
#define PERMUTE next_permutation 
#define TC(t) while (t--) 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)


void solve() {

}

int main()  
{ 
    FAST_INP;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
    #endif
    
    int n; cin >> n;
    vl a(n);
    READ(a);
    ll ans=0;
    FOR(i,1,n){
        if(a[i]<a[i-1]) {
            ans+=(a[i-1]-a[i]);
            a[i]=a[i-1];
        }
    }
    OUT(ans);
    return 0; 
} 


Measured memory_bytes: 4776
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;


ll dp[112345];
ll sum[112345];

ll mpow(ll x,ll n){
  if(n<=0)return 1;
  ll ret=mpow(x*x%MOD,n/2);
  if(n&1)ret=ret*x%MOD;
  return ret;
}
int main(){
  string S;cin >>S;
  cout << (S.length()>=4&&S.substr(0,4)=="YAKI"? "Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque

n,m = map(int, input().split())
edges = [{} for i in range(n+1)]

for i in range(m):
    l, r, d = map(int, input().split())
    edges[l][r] = d
    edges[r][l] = d * -1

remains = set(range(1,n+1))
deq = deque()

min_ = -1 * 10**10
xs = [min_] * (n+1)

while( len(remains) > 0):
    deq.append( remains.pop() )
    while(len(deq) > 0):
        tmp = deq.popleft()
        if(xs[tmp]  == min_):
            xs[tmp] = 0
        tmp_x = xs[tmp]

        edge = edges[tmp]

        for key,val in edge.items():
            if(xs[key] == min_):
                xs[key] = tmp_x + val
                deq.append( key )
                remains.remove( key )
            else:
                if( xs[key] != tmp_x + val ):
                    print('No')
                    exit()

print('Yes')


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

int main(){
  int N, M; cin >> N >> M;
  vector<vector<bool>> connection(8, vector<bool> (8));
  for (int i=0; i<M; i++){
    int x, y;
    cin >> x >> y;
    connection.at(x-1).at(y-1)=connection.at(y-1).at(x-1)=true;
  }
  
  vector<int> pattern(N);
  for (int i=0; i<N; i++){
    pattern.at(i)=i;
  }
  
  int cnt = 0;
do {
  bool visited_all = true;
  for (int i=1; i<N; i++){
    int x = pattern.at(i-1);
    int y = pattern.at(i);
    if (!connection.at(x).at(y)) {
      visited_all = false;
      break;
    } 
  }
  if (visited_all && pattern.at(0) == 0) {cnt += 1;}
} while (next_permutation(pattern.begin(), pattern.end()));
  
  cout << cnt << endl;
}

Measured memory_bytes: 3596
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=2e5,MOD=998244353;
ll N;
string X;
map<ll,ll> f;
vector<ll> divv;

void cal_div(){
	for(ll i=1;i*i<=N*2;i++){
		if(2*N%i==0){
			divv.push_back(i);
			if(i*i!=2*N){
				divv.push_back(2*N/i);
			}
		}
	}
}
void cal_f(ll k){
	if(2*N/k%2==0)return;
	ll pw2=1,ans=0,sm=0;
	REP(i,k/2){
		sm+=pw2*(X[k/2-i-1]-'0');
		sm%=MOD;
		pw2*=2;
		pw2%=MOD;
	}
	ans=sm;
	string y=X.substr(0,k/2),z,x2=y;
	REP(i,k/2){
		z.push_back((1-(y[i]-'0'))+'0');
	}
	REP(i,N/k){
		x2+=z;
		x2+=y;
	}
	if(x2<=X){
		ans++;
		ans%=MOD;
	}
	f[k]=ans;
}
map<ll,ll> moe;
void cal_moe(ll n){
	vector<ll> p;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			p.push_back(i);
			while(n%i==0)n/=i;
		}
	}
	if(n!=1)p.push_back(n);
	ll m=p.size();
	REP(i,1<<m){
		ll mo=1,d=1;
		REP(j,m){
			if((i>>j)&1){
				mo*=-1;
				d*=p[j];
			}
		}
		moe[d]=mo;
	}
}
	
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>X;
	cal_div();
	for(auto i:divv){
		cal_f(i);
	}
	cal_moe(2*N);
	ll ans=0;
	for(auto n:divv){
		ll g=0;
		for(auto d:divv){
			if(n%d==0){
				g+=moe[n/d]*f[d]+MOD;
				g%=MOD;
			}
		}
//		cout<<"g["<<n<<"]="<<g<<endl;
		ans+=g*n;
		ans%=MOD;
	}
	cout<<ans<<endl;
	for(auto n:divv){
//		cout<<"f["<<n<<"]="<<f[n]<<endl;
	}
}

Measured memory_bytes: 1300
#include <iostream>
#include <string>
#include<math.h>


using namespace std;


char tmp_answer[100000];

char decide_next(char answer, char left, char center){
    if(answer == 'o'){
        if(center == 'S') return left;
        else if(center == 'W'){
            if(left == 'W') return 'S';
            else return 'W';
        }
    }
    else if(answer == 'x'){
        if(center == 'S'){
            if(left == 'S') return 'W';
            else if (left == 'W') return 'S';
        }
        else return left;
    }
}


bool check_answer(int N, char s[], char first, char second){
    tmp_answer[0] = first;
    tmp_answer[1] = second;
    for(int i=2;i<N;i++){
        tmp_answer[i] = decide_next(s[i-1], tmp_answer[i-2], tmp_answer[i-1]);
    }
    if((tmp_answer[0] == decide_next(s[N-1], tmp_answer[N-2], tmp_answer[N-1]))
        and 
       (tmp_answer[1] == decide_next(s[0], tmp_answer[N-1], tmp_answer[0]))){
           return true;
       }
    else return false;
}


int main(void){
    int N;
    char s[100000];

    cin >> N;
    cin >> s;

    /*
    char first[4] = 'SSWW';
    char second[4] = 'SWSW';
    */

    if(check_answer(N, s, 'S', 'S')){
        cout << tmp_answer << endl;
        return 0;
    }
    if(check_answer(N, s, 'S', 'W')){
        cout << tmp_answer << endl;
        return 0;
    }
    if(check_answer(N, s, 'W', 'S')){
        cout << tmp_answer << endl;
        return 0;
    }
    if(check_answer(N, s, 'W', 'W')){
        cout << tmp_answer << endl;
        return 0;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(void){
  int h,w,i,j;
  while(1){
    cin>>h>>w;
    if(h==0&&w==0)break;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	cout<<"#";
      }
      cout<<endl;
    }
    cout<<endl;
  }
  return 0;
}

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


int main()
{


     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
        char temp;
    cin>>temp;
    int i=temp-'A';

    if(i<=28)
      cout<<"A"<<endl;
    else
      cout<<"a"<<endl;

    return 0;
    

}

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

int main(){
    int N, H, W;
    cin >> N >> H >> W;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int A, B;
        cin >> A >> B;
        if (A >= H && B >= W) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int h1 , w1;
    cin >> h1 >> w1;
    int h2 , w2;
    cin >> h2 >> w2;

    int first = h2*w1;
    int second = h1*w2;
    int total = first + second - (h2*w2);

    int remain = h1*w1 - total;
    cout << remain << "\n";



return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int n,m;
int a[20][20];
int tmp[20][20];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

void rotate(int r,int c,int s){
    for(int i=0;i<s;i++){
        for(int j=0;j<s;j++){
            tmp[j][s-1-i]=a[i+r][j+c];
        }
    }
    for(int i=0;i<s;i++){
        for(int j=0;j<s;j++){
            a[r+i][c+j]=tmp[i][j];
        }
    }
}

void dfs(int r,int c,int col){
    a[r][c]=1-a[r][c];
    for(int i=0;i<4;i++){
        int nx=c+dx[i];
        int ny=r+dy[i];
        if(nx>=0 && nx<n && ny>=0 && ny<n){
            if(a[ny][nx]==col){
                dfs(ny,nx,col);
            }
        }
    }
}

int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(int i=0;i<m;i++){
        int t;
        scanf("%d",&t);
        if(t==0){
            int r,c,s,ang;
            scanf("%d%d%d%d",&r,&c,&s,&ang);
            r--;
            c--;
            for(int j=0;j<ang;j+=90){
                rotate(r,c,s);
            }
        }
        if(t==1){
            int r,c,s;
            scanf("%d%d%d",&r,&c,&s);
            r--;
            c--;
            for(int j=0;j<s;j++){
                for(int k=0;k<s;k++){
                    a[r+j][c+k]=1-a[r+j][c+k];
                }
            }
        }
        if(t==2){
            int r;
            scanf("%d",&r);
            r--;
            for(int j=0;j<n;j++){
                tmp[0][(n-1+j)%n]=a[r][j];
            }
            for(int j=0;j<n;j++){
                a[r][j]=tmp[0][j];
            }
        }
        if(t==3){
            int r;
            scanf("%d",&r);
            r--;
            for(int j=0;j<n;j++){
                tmp[0][(j+1)%n]=a[r][j];
            }
            for(int j=0;j<n;j++){
                a[r][j]=tmp[0][j];
            }
        }
        if(t==4){
            int r,c;
            scanf("%d%d",&r,&c);
            r--;
            c--;
            dfs(r,c,a[r][c]);
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            printf("%d%c",a[i][j],(j+1)==n?'\n':' ');
        }
    }
    return 0;
}



Measured memory_bytes: 3228
N = gets.to_i
caps = gets.split.map(&:to_i)
check = caps.uniq

# 要素数が3の倍数、かつ、重複なしで3つ
if !(N % 3 == 0 || check == 3 || caps.select{|cap| cap == 0}.size == caps.size)
    puts 'No'
    exit
end

puts caps.inject{|acc, cap| acc ^ cap} == 0 ? 'Yes' : 'No'


Measured memory_bytes: 12548
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	double a = scan.nextDouble();
	double b = scan.nextDouble();
	int c = scan.nextInt();
	double h = b * Math.sin(Math.toRadians(c));
	double x = Math.sqrt(h * h +
			     (a - b * Math.cos(Math.toRadians(c)))*(a - b * Math.cos(Math.toRadians(c))));
	double S = a * h / 2;
	System.out.println(S);
	System.out.println(a+b+x);
	System.out.println(h);
    }
}

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

using namespace std;

// z[i] = len of lcp of s, s[i..]; lcp(longest common prefix)
vector<int> z_fn(const string& s) {
    int n = s.size();
    vector<int> z(n, 0);
    for (int i = 1, l = 0, r = 0; i < n; i++) {
        if (i <= r)
            z[i] = min(r-i+1, z[i-l]);
        while (i+z[i] < n && s[z[i]] == s[i+z[i]]) {
            z[i]++;
        }
        if (i+z[i]-1 > r) {
            l = i; r = i+z[i]-1;
        }
    }
    return z;
}

const char L = 'a'-1;
const char H = 'z'+1; 
const int N = 2001; 
const int LEN = 10001; 
bool dp[N][LEN];

void solve() {
    int n, T;
    cin >> n >> T;
    vector<string> s(n);
    for (auto& x: s) {
        cin >> x;
    }

    // prep dp
    dp[n][0] = true;
    for (int i = n-1; i >= 0; i--) {
        int len = s[i].size();
        memcpy(dp[i], dp[i+1], sizeof dp[i]);
        for (int j = 0; j <= T; j++) {
            if (j - len >= 0)
                dp[i][j] |= dp[i+1][j-len];
        }
    }

    // sustitute
    vector<bool> cat(T, false);
    cat[0] = true;
    string mi(T, H);
    for (int i = 0; i < n; i++) {
        string tmp = s[i] + L + mi;
        auto z = z_fn(tmp);
        int len = s[i].size();
        int id = -1;
        for (int j = 0; j+len <= T; j++) {
            if (!cat[j] || !dp[i+1][T - (j+len)]) continue;
            int lcp = z[len+1+j];
            if (j + lcp >= T) continue;
            if (lcp >= len) continue;
            if (s[i][lcp] >= mi[j+lcp]) continue;
            id = j; break;
        }
        if (id == -1) continue;
        for (int j = 0; j < len; j++) {
            mi[id+j] = s[i][j];
        }
        for (int j = id+len; j < T; j++) {
            mi[j] = H;
        }
        for (int j = id+z[len+1+id]+1; j < T; j++) {
            cat[j] = false;
        }
        cat[id+len] = true;
    }
    
    cout << mi;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 20992
#include <iostream>
using namespace std;
int main(void)
{
	char s[2][4];

	cin>>s[0];
	cin>>s[1];

	if(s[0][0]!=s[1][2]){
		cout<<"NO"<<endl;
	}else if(s[0][1]!=s[1][1]){
		cout<<"NO"<<endl;
	}else if(s[0][2]!=s[1][0]){
		cout<<"NO"<<endl;
	}else{
		cout<<"YES"<<endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

#define int long long
const int M = 1000000007;
int dp[205][10005];

signed main(){
	int n, w;
	cin >> n >> w;

	vector<int> a(n + 1, -1);
	rep(i,n) cin >> a[i + 1];
	sort(all(a));

	vector<int> sum(all(a));
	sum[0] = 0;
	range(i,1,n + 1){
		sum[i] += sum[i - 1];
	}

	dp[0][0] = 1;
	range(i,1,n + 1){ //???????????¨?????????????????\????????¨???
		if(sum[i] > w) break;
		dp[0][sum[i]] = 1;
	}

	range(i,1,n + 1){ //i - 1????????????????????¨??¨??\??????i ????????????????????\???????????¨???
		if(sum[i] > w) break;
		dp[i][sum[i - 1]] = 1;
		range(j,i + 1,n + 1){
			for(int k = w; k >= sum[i - 1]; k--){
				if(k + a[j] > w) continue;
				//show(k)
				(dp[i][k + a[j]] += dp[i][k]) %= M;
			}
		}
	}

	//rep(i,n + 1){ rep(j,w + 1){ cout << dp[i][j] <<' '; } cout << endl; }
	
	int ans = 0;
	range(i,1,n + 1){
		range(j,sum[i], w + 1){
			if(j + a[i] <= w) continue;
			//show(dp[i][j])
			//cout << i << ' ' << j << endl;
			(ans += dp[i][j]) %= M;
		}
	}

	cout << ans + 1 << endl; //????????????????????\????????¨??????1??????
}

Measured memory_bytes: 4028
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll dp[100100][2];

int main() {
	string s = "000";
	string s1;
	cin>>s1;
	s += s1;
	dp[0][1] = 1;
	rep(i,1,s.sz){
		if(s[i]=='0'){
			dp[i][1] += dp[i-1][1];
			dp[i][0] += dp[i-1][0]*3;
		}
		else{
			dp[i][1] += dp[i-1][1]*2;
			dp[i][0] += dp[i-1][1];
			dp[i][0] += dp[i-1][0]*3;
		}
		dp[i][0] %= MOD;
		dp[i][1] %= MOD;
	}
	cout << (dp[s.sz-1][0]+dp[s.sz-1][1])%MOD << endl;
	return 0;
}

Measured memory_bytes: 2048
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n = I()
        if n == 0:
            break
        a = sorted(LI())
        r = inf
        for i in range(n-1):
            tr = a[i+1] - a[i]
            if r > tr:
                r = tr
        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())




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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    string s; cin >> s;
    sort(s.begin(), s.end());

    cout << (s[0] == s[1] && s[2] == s[3] && s[1] != s[2] ? "Yes" : "No");
}


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

typedef long long ll;
const ll INF = 0x3f3f3f3f;
const int maxlen = 1e5;
int main()
{
    int num,x;
    while( scanf("%d",&num) && num)
    {
        for(int len = maxlen; len >= 1; --len)
        {
            if(2*num % len == 0 && ((2*num)/len+1-len)%2==0 )
            {
                x = ( (2*num/len+1-len) >> 1 );
                if(x >= 1)
                {
                    printf("%d %d\n",x,len);
                    break;
                }
            }

        }
    }
    return 0;
}



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

vector<string> s;
int h, w;
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

void dfs(int x, int y, char c){
    if(s[x][y] != c) return;
    s[x][y] = '.';
    for(int i = 0; i < 4; i++){
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(nx < 0 || nx >= h || ny < 0 || ny >= w)continue;
        if(s[nx][ny] == c)dfs(nx,ny,c);
    }
    return;
}

int main(){
    while(cin >> h >> w, h){
        vector<string> in(h);
        for(int i = 0; i < h; i++) cin >> in[i];
        s = in;
        int ans = 0;
        for(int i = 0; i < h; i++)for(int j = 0; j < w; j++){
            if(s[i][j] != '.'){
                ans++;
                dfs(i,j,s[i][j]);
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 4144
#include <cstdio>
#include <algorithm>
using namespace std;
int N;
long long a[300005];
int main(){
    scanf("%d", &N);
    for(int i = 0; i < 3 * N; i++)
        scanf("%lld", &a[i]);
    sort(a, a+3*N);
    reverse(a,a+3*N);
    long long  ans = 0;
    int i = 1;
    while(N--)
    {
        ans += a[i];
        i+=2;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define sevensins ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define mod  1000000007
#define vect vector<long long int>
#define bins binary_search
#define vecti vector<int>::iterator
#define bitout __builtin_popcount
#define binsrch binary_search
int main() 
{sevensins
ll t,i,j,k,n;
cin>>n;

k=(n*(n+1))/2;

for(i=1;i<=n;i++)
{
    if(i%3==0)
    k-=i;
    else if(i%5==0)
    k-=i;
    else if(i%15==0)
    k-=i;
}
cout<<k<<"\n";



return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define REP(i,N) for(int i=0;i<N;i++)

int par[100000+1];

int find(int x){
    if(par[x]!=x){
        par[x]=find(par[x]);
    }
    return par[x];
}

void unite(int x, int y){
    int xr = find(x);
    int yr = find(y);
    if(xr==yr) return;
    par[xr] = yr;
}

int main(){

    for(int i=0;i<100000+1;i++){
        par[i] = i;
    }

    int n; cin>>n;
    int m; cin>>m;
    for(int i=0;i<m;i++){
        int x,y,z; cin>>x>>y>>z;
        unite(x,y);
    }
    bool visited[100000+1];
    for(int i=0;i<100000+1;i++){
        visited[i]=false;
    }
    for(int i=1;i<=n;i++){
        visited[find(par[i])] = true;
    }
    int ans = 0;
    for(int i=1;i<=n;i++){
        ans+=visited[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1152
N, M = map(int, input().split())
shop = []
for i in range(N):
    shop.append(list(map(int, input().split())))
shop.sort(key=lambda x: x[0])
ans = 0
for A, B in shop:
    if M <= B:
        ans += A * M
        break
    else:
        ans += A * B
        M -= B
print(ans)


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

int main()
{
  int a,b;
  cin >> a >> b;
  int d = a / b;
  int r = a % b;
  double f = (double)a / (double)b;
  printf("%d %d %.6f\n",d,r,f);
  return 0;
}

Measured memory_bytes: 1192
#line 2 "codes/header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); }
template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "codes/solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;


int solve() {
    int n,k;cin>>n>>k;
    vector<ll> p(n);
    rep(i, n) {
        cin>>p[i];
    }
    sort(all(p));
    dump(p);
    int ans = 0;
    rep(i, k) ans += p[i];
    cout << ans << endl;
    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 3660
n,m = map(int,input().split())
para_val = []
for i in range(m) :
    a,b = map(int,input().split())
    para_val.append([a,b])

migi = []
hidari = []
for i,j in para_val:
    migi.append(i)
    hidari.append(j)

a = max(migi)
b = min(hidari)

if b - a >= 0 : print("{}".format(b-a+ 1))
else : print("0")

Measured memory_bytes: 21272
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),char_cmp_r);
#define chsort(s) qsort(s,strlen(s),sizeof(char),cmp)
#define chsort_r(s) qsort(s,strlen(s),sizeof(char),char_cmp_r);
#define TYPE char
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int main(void){
	int i,s,a=0;
	rep(i,3){
		scanf("%1d",&s);
		a+=s;
	}
	print(a);
	return 0;
}

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

int main(void){
    ll l;
    ll r;
    cin >> l >> r;
    int  min=2020;
  	if((r-l)>=2018){
      min = 0;
    }
  	else{
      for(ll i=l;i<r;i++){
          for(ll j=l+1;j<=r;j++){
              int num=0;
              num = (i*j)%2019;
              if(num<min){
                  min = num;
              }
              if(min==0){
                  break;
              }
          }
      }
    }
    cout << min <<  endl;
    
    
    return 0;
}















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

using namespace std;

const int mod = 1e9 + 7;

int d;
string k;

void adm(int& a, int b){
    a = (a + b) % mod;
}

int main(){
    cin>>k>>d;
    int l = k.length();
    vector<vector<int>> dp(d, vector<int>(2));
    dp[(k[0] - '0')%d][0] = 1;
    for(int i = 0; i < k[0] - '0'; i++){
        dp[i%d][1]++;
    }
    for(int i = 1; i < l; i++){
        vector<vector<int>> ndp(d, vector<int>(2));
        for(int a = 0; a <= k[i] - '0'; a++){
            for(int r = 0; r < d; r++){
                adm(ndp[(r + a%d)%d][a < k[i] - '0'], dp[r][0]);
            }
        }
        for(int a = 0; a < 10; a++){
            for(int r = 0; r < d; r++){
                adm(ndp[(r + a%d)%d][1], dp[r][1]); 
            }
        }
        dp = ndp;
    }
    int res = ((dp[0][0] + dp[0][1])%mod - 1 + mod) % mod;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 998244353;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  cin >> a;
  a.insert(a.begin(), 0);
  a.push_back(0);

  int ans = 0;
  rep(i, sz(a)) {
    int c = i + 1;
    for (int j = sz(a) - 1; j >= i + 1; --j) {
      c++;
      if (c > k + 2) break;

      priority_queue<int, vector<int>, greater<int> > q;
      rep(l, i + 1) q.push(a[l]);
      for (int l = sz(a) - 1; l >= j; --l) q.push(a[l]);
      
      rep(l, k + 2 - c) {
        if (!sz(q) || q.top() > 0) break;
        q.pop();
      }
      int sum = 0;
      while (!q.empty()) {
        sum += q.top();
        q.pop();
      }
      chmax(ans, sum);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;

#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265358979;



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

    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0;i < n;i++){
        cin >> a[i];
    }
    vector<ll> b(n);
    for (ll i = 0;i < n;i++){
        cin >> b[i];
    }

    vector<ll> d(n);
    for (ll i = 0;i < n;i++){
        d[i] = a[i] - b[i];
    }

    ll sum = 0;
    for (ll i = 0; i < n; i++){
        sum += d[i];
    }
    if (sum < 0){
        cout << -1 << endl;
        return 0;
    }

    ll minus = 0;
    ll ans = 0;
    for (ll i = 0; i < n; i++){
        if (d[i] < 0){
            minus -= d[i];
            ans++;
        }
    }

    sort(d.begin(), d.end());
    reverse(d.begin(), d.end());

    for (ll i = 0; minus > 0; i++){
        minus -= d[i];
        ans++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 5564