akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;

const int inf=2147483647;

int N;
vector<int> val,laz;
vector<bool> flg;
void init(int sz){
   N=1; while(N<sz)N<<=1;
   val.resize(2*N,0); laz.resize(2*N,0);
   flg.resize(2*N,false);
}
void eval(int k,int l,int r){
   if(flg[k]){
      val[k]+=laz[k];
      if(r-l>1){
         laz[2*k+1]+=laz[k]; laz[2*k+2]+=laz[k];
         flg[2*k+1]=1; flg[2*k+2]=1;
      } laz[k]=0; flg[k]=0;
   }
}
void upd(int a,int b,int x,int k=0,int l=0,int r=N){
   eval(k,l,r);
   if(b<=l||r<=a)return;
   if(a<=l&&r<=b){
      laz[k]+=x; flg[k]=1; eval(k,l,r);
   }
   else{
      upd(a,b,x,2*k+1,l,(l+r)/2);
      upd(a,b,x,2*k+2,(l+r)/2,r);
      val[k]=min(val[2*k+1],val[2*k+2]);
   }
}
int que(int a,int b,int k=0,int l=0,int r=N){
   eval(k,l,r);
   if(b<=l||r<=a)return inf;
   if(a<=l&&r<=b)return val[k];
   int lb=que(a,b,2*k+1,l,(l+r)/2);
   int rb=que(a,b,2*k+2,(l+r)/2,r);
   return min(lb,rb);
}

int main(){
   int n,q; scanf("%d%d",&n,&q);
   init(n);
   rep(i,0,q){
      int tmp; scanf("%d",&tmp);
      if(tmp==0){
         int s,t,x; scanf("%d%d%d",&s,&t,&x); t++;
         upd(s,t,x);
      }
      else{
         int s,t; scanf("%d%d",&s,&t); t++;
         printf("%d\n",que(s,t));
      }
   }
   return 0;
}


Measured memory_bytes: 4932
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr(i, n) for (int i = 0; i < (int)n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef long double ld;

const ll INF = 2e18 + 10;
const ld PI = acos(-1);
const ld EPS = 1e-9;
const int N = 2e5 + 10;

ll a[N];

int main()  {
    //freopen("a.in", "r", stdin);
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0;
    fr(i, n) {
        ans += (i - a[s[i]]);
        a[s[i]]++;
    }

    cout << ans + 1;
}




Measured memory_bytes: 640
/**
 *   created: 09 June 2019  14:03:36
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
	optimizeIO();
	int tt=1;
	// cin>>tt;
	while(tt--){
		int n;
		cin>>n;
		float t,a,diff;
		cin>>t>>a;
		diff= (float)INF;

		int ind=-1;
		rep(i,0,n){
			float x;
			cin>>x;
			if(diff>abs(t-x*0.006-a)){
				diff = abs(t-x*0.006-a);
				ind = i;
			}
		}
		cout<<ind+1;
	}
	return 0;
}

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

int cost[100100];
vector<pair<int, int> > v[100100];

void dfs ( int pos, int sum ) {
    if ( cost[pos] != -1 ) return;
    cost[pos] = sum;
    for ( int i = 0; i < v[pos].size(); i++ ) {
        dfs ( v[pos][i].first, sum + v[pos][i].second );
    }
}

signed main() {

    int n;
    cin >> n;
    for ( int i = 0; i < n-1; i++ ) {
        int s, t, c;
        scanf("%d %d %d", &s, &t, &c);
        s--;
        t--;
        v[s].push_back(make_pair(t, c));
        v[t].push_back(make_pair(s, c));
    }
    memset(cost, -1, sizeof(cost));

    dfs(0, 0);

    for ( int i = 0; i < n; i++ ) {
        printf("%d\n", cost[i]&1);
    }

    return 0;
}

Measured memory_bytes: 8448
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

const int M = 10'000;
int A[M], B[M], aa, bb, mi, sum;
map<int, int,    less<int>> mA;
map<int, int, greater<int>> mB;
int main() {
	until(getchar_unlocked() == '\n') { }
	while(true) {
		char c = getchar_unlocked();
		if(c == '(' || c == ')') {
			sum += (c == '(' ? +1 : -1);
			setmin(mi, sum);
		} else {
			int a = -mi, b = sum - mi;
			if(a <= b) { if(a < M) { A[a] += sum; setmax(aa, a); } else { mA[a] += sum; } }
			else       { if(b < M) { B[b] += sum; setmax(bb, b); } else { mB[b] += sum; } }
			mi = 0, sum = 0;
			if(c == EOF) { break; }
		}
	}
	
	incII(i, 0, aa) {
		setmin(mi, sum - i);
		sum += A[i];
	}
	for(auto [i, Ai]: mA) {
		setmin(mi, sum - i);
		sum += Ai;
	}
	for(auto [i, Bi]: mB) {
		sum += Bi;
		setmin(mi, sum - i);
	}
	decII(i, 0, bb) {
		sum += B[i];
		setmin(mi, sum - i);
	}
	puts(mi >= 0 && sum == 0 ? "Yes" : "No");
}


Measured memory_bytes: 3644
md = 10**9+7
N = int(input())
NN0 = (2**N)%md
NN1 = (2**(N-1))%md
NN2 = (2**(N-2))%md
C = list(map(int, input().split()))
C.sort()
ans = 0
for i in range(N):
    ans += ((C[i]%md) * NN1 )%md
    if i != (N-1):
        ans += ( (C[i]%md)*(N-1-i) * NN2 )%md
ans = (ans * NN0) %md
print(ans)

Measured memory_bytes: 25768
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

int main()
{
    int A,B;
    std::cin >> A >> B;
    int c,d,e;
    c=A+B;
    if(c<=A*B){
        c=A*B;
    }
    if(c<=A-B){
        c=A-B;
    }
    std::cout << c << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 100000

int Search(int *,int ,int);

int main(){
  int loop1,loop2;
  int retu1[N],retu2;
  int i,count=0;
 
  scanf("%d",&loop1);
  for(i=0;i<loop1;i++){
    scanf(" %d",&retu1[i]);
  }

  scanf("%d",&loop2);
  for(i=0;i<loop2;i++){
    scanf(" %d",&retu2);
    count+=Search(retu1,retu2,loop1);
  }

  printf("%d\n",count);
  return 0;
}


int Search(int *x,int y,int length){
  int side1=0;
  int side2=length;
  int center=0;

  while(1){
    if(side1>=side2)break;
    center=(side1+side2)/2;
    if(x[center]==y){
      return 1;
    }

    else if(x[center]>y){
      side2=center;
    }

    else if(x[center]<y){
      side1=center+1;
    }
  } 
  return 0;
}



Measured memory_bytes: 2108
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#include <cstdlib>
#include<bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    int max=-1, min=1001;

    rep(i, n){
        int a;
        cin >> a;
        if(max<a)max=a;
        if(min>a)min=a; 
    }
    cout << max-min<< endl;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define int long long
#define double long double
#define all(a) a.begin(), a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

struct UnionFind{ //素集合データ構造
private:
    vector<int> par;
public:
    UnionFind(int n): par(n, -1) {}
    int find(int x){
        if(par.at(x) < 0) return x;
        else return par.at(x) = find(par.at(x));
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(size(x) < size(y)) swap(x, y);
        par.at(x) += par.at(y);
        par.at(y) = x;
    }
    int size(int x){ return -par.at(find(x)); }
    bool same(int x, int y){ return find(x) == find(y); }
    void reset(int n){ par = vector<int>(n, -1); }
};

struct RollingHash{
private:
    const int base = 10007, mod = 1000000007;
    vector<int> hash, pow;
public:
    RollingHash(const string &s){
        int sz = (int)s.size();
        hash = vector<int>(sz + 1, 0);
        pow = vector<int>(sz + 1, 1);
        rep(i, sz){
            hash[i + 1] = (hash[i] * base + s[i]) % mod;
            pow[i + 1] = pow[i] * base % mod;
        }
    }
    int get(int l, int r) const {
        return ((hash[r] - hash[l] * pow[r - l]) % mod + mod) % mod;
    };
};

signed main(void){

    string s, t, u; cin >> s >> t >> u;
    u = s; while(s.size() < t.size())s += u;
    int n = s.size(), m = t.size();
    s += s;

    UnionFind uni(n);
    RollingHash r1(s), r2(t);

    rep(i, n){
        if(r1.get(i, i + m) == r2.get(0, m)){
            if(uni.same(i, (i + m) % n)){
                cout << -1 << endl;
                return 0;
            }
            uni.unite(i, (i + m) % n);
        }
    }

    int ans = -1;
    rep(i, n)chmax(ans, uni.size(i));
    cout << ans - 1 << endl;

}

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

int main(void) {
	int N[4];

	for (int i = 0; i < 4; ++i)
		cin >> N[i];
	sort(N, N + 4);
	int s = N[0] * 1000 + N[1] * 100 + N[2] * 10 + N[3];

	if (s == 1479)
		cout << "YES\n";
	else
		cout << "NO\n";
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

template <class T>
void setmin(T &a, T const &b) {
    if (a > b) a = b;
}

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

int main() {
    int D, T, S;
    cin >> D >> T >> S;
    if (T * S >= D)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define f first
  #define s second
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 998244353
  #define N 1000001
  #define INF 1000000000000
  #define eps 1e-6



int32_t main()
{


  int n;
  cin >> n;
  int arr[n+1];

  bool ok = true;

  for(int i = 1; i <= n; i++)
  {
    cin >> arr[i];
    if(arr[i]%2 ==0)
    {
      if(arr[i]%3 ==0 or arr[i]%5 ==0)
      {
        
      }
      else
      {
        ok = false;
      }
    }
  }

    if(ok)
    {
      cout <<"APPROVED";
    }
    else
    {
      cout <<"DENIED";
    }

    return 0;
}

Measured memory_bytes: 256
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.20 03:10:09
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;




template<typename T>
struct Dijkstra {
private:
    int V;
    struct edge { int to; T cost; };
    vector<vector<edge>> G;
public:
    const T inf = numeric_limits<T>::max();
    
    
    vector<T> d; 
    Dijkstra(int V) : V(V) {
        G.resize(V);
    }
    
    
    void add_edge(int from, int to, T weight, bool directed = false) {
        G[from].push_back({to,weight});
        if (!directed) G[to].push_back({from,weight});
    }
    void build(int s) {
        d.assign(V, inf); 
        typedef tuple<T, int> P; 
        priority_queue<P, vector<P>, greater<P>> pq;
        d[s] = 0; 
        pq.push(P(d[s], s)); 
        while (!pq.empty()) {
            P p = pq.top(); pq.pop();
            int v = get<1>(p);
            
            if (d[v] < get<0>(p)) continue; 
            for (const edge &e : G[v])
            {
                
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    pq.push(P(d[e.to], e.to));
                }
            }
        }
    }
};
int main() {
    int n,m;cin >> n >> m;
    Dijkstra<ll> g(n);
    for (int i = 0; i < n-1; i++) {
        g.add_edge(i+1,i,0,true);
    }
    for (int i = 0; i < m; i++) {
        int l,r,c;cin >>l >> r >> c;
        g.add_edge(l-1,r-1,c,true);
    }
    g.build(0);
    ll ans = g.d[n-1];
    if (ans == g.inf) {
        puts("-1");
    }
    else {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 12900
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int> a(N),b(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
    b.at(i)=a.at(i);
  }
  sort(b.begin(),b.end());
  int A=b.at(N-1),B=b.at(N-2);
  
  for(int i=0;i<N;i++){
    if(a.at(i)==A)cout<<B<<endl;
    else cout<<A<<endl;
  }
}

Measured memory_bytes: 3200
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

/* see https://github.com/pllk/cphb/ */
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
    tree_order_statistics_node_update> indexed_set;

typedef long long ll;
//typedef __int128 lll;

#define fori(n) for(ll i=0; i<(n); i++)

typedef pair<int, int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vi a(n);
    map<int, int> f;
    fori(n)  {
        cin>>a[i];
        f[a[i]]++;
    }

    sort(a.begin(), a.end());
    if(a[0]==0 && f.size()==1) {    // all zero
        cout<<"Yes"<<endl;
        return 0;
    }

    bool ans=(n%3==0) && (f.size()==3);
    vector<int> vals;
    for(auto e : f) {
        ans=ans && e.second==n/3;
        vals.push_back(e.first);
    }

    if(vals.size()==2 && vals[0]==0 && f[vals[0]]==n/3 && f[vals[1]]==2*n/3) { // two same and one zero
        cout<<"Yes"<<endl;
        return 0;
    }


    ans=ans && ((vals[0]^vals[1])==vals[2]);
    ans=ans && ((vals[1]^vals[2])==vals[0]);
    ans=ans && ((vals[2]^vals[0])==vals[1]);

    if(ans)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    
}



Measured memory_bytes: 4864
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

public class Main {

  static int n, m;
  static List<Integer> step;
  static Graph g;

  public static void main(String[] args) throws Exception {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(System.out);

    String[] in = br.readLine().split(" ");
    n = Integer.parseInt(in[0]);
    m = Integer.parseInt(in[1]);

    step = new ArrayList<>(n);
    for (int i = 0; i < n; i++) {
      step.add(-1);
    }

    g = new Graph(n);

    for (int i = 0; i < m; i++) {
      in = br.readLine().split(" ");
      int a = Integer.parseInt(in[0]) - 1;
      int b = Integer.parseInt(in[1]) - 1;
      g.add_edge(a, b, false);
    }

    br.close();

    Queue<Integer> que = new ArrayDeque<>();
    que.add(0);

    while(!que.isEmpty()){
      int now = que.poll();
      for (int next : g.adjacency[now]) {
        if(step.get(next) != -1) continue;
        step.set(next, now);
        que.add(next);
      }
    }

    out.println("Yes");

    for (int i = 1; i < n; i++) {
      out.println(step.get(i) + 1);
    }

    out.flush();
  }
}

class Graph {
  public ArrayList<Integer>[] adjacency;

  Graph(int n) {
    adjacency = new ArrayList[n];
    for (int i = 0; i < n; i++) {
      adjacency[i] = new ArrayList<Integer>();
    }
  }

  public void add_edge(int from, int to, boolean is_directed) {
    adjacency[from].add(to);
    if (!is_directed) {
      adjacency[to].add(from);
    }
  }
}

Measured memory_bytes: 73536
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val x = sc.nextLong()
    val y = sc.nextLong()
    if (Math.abs(x - y) <= 1) {
        println("Brown")
    } else {
        println("Alice")
    }
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 31268
#include <iostream>
#include <stdlib.h>

using namespace std;

int n,m;
int h[100005];
int dp[100005];

int main(void)
{
	cin >> n>>m;
	for(int i = 1; i <= n; i++) cin >> h[i];

	for(int i = 1; i <= n; i++) dp[i] = 1e9+5;
	dp[1] = 0;
	for(int i = 1; i < n; i++){
		dp[i+1] = min(dp[i+1], dp[i] + abs(h[i]-h[i+1]));
		for(int j=2;j<=m;j++){ 
		if(i+j <= n) dp[i+j] = min(dp[i+j], dp[i] + abs(h[i]-h[i+j]));
		}
	}
	cout << dp[n] << endl;

	return 0;
}


Measured memory_bytes: 1024
N=int(input())
T,X,Y=[0], [0], [0]
flag=0
for i in range(N):
    t,x,y = list(map(int,input().split()))
    T.append(t)
    X.append(x)
    Y.append(y)
for i in range(N):
    if X[i+1]-X[i]+Y[i+1]-Y[i]<=(T[i+1]-T[i]) and (X[i+1]-X[i]+Y[i+1]-Y[i]-(T[i+1]-T[i]))%2==0:
        continue
    else:
        flag+=1
        break
if flag==1:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 64088
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 998244353 //1000000007 // //100000000
#define INF 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

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

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}


void solve(){
    ll n, m;
    cin >> n >> m;
    vector<string> v;
    rep(i, n)
    {
        string s;
        cin >> s;
        v.pb(s); v.pb(s);
    }
    for(auto x: v) cout << x << endl;
}
main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 256
/*

 

*/


#include<bits/stdc++.h>

using namespace std;

#define fstinpt     ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll          long long
#define sn          1010
#define bn          6000007
#define M           1000000007
#define sss         cout<<" "
#define nnn         cout<<"\n"



int main()
{
        fstinpt;
        ll a,b;
        cin>>a; if(a == 0) b = 1;
        cin>>a; if(a == 0) b = 2;
        cin>>a; if(a == 0) b = 3;
        cin>>a; if(a == 0) b = 4;
        cin>>a; if(a == 0) b = 5;
        cout<<b;
        return 0;
}


/*











*/






















/**/


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 10000
#define nil -1
#define vmax 10000
#define sentinel 2000000000
constexpr long long int inf = 1000000000000;
constexpr long long int rinf = -(INT64_MAX);
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if((a+b)>=c){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


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

typedef pair<string, int> P;
typedef long long ll;
const int INF = 100000000;

ll gcd( ll a, ll b ){
    ll tmp;
    if( a < b ) { tmp = a; a = b; b = tmp; }
    if( b < 1 ) return -1;

    if( a % b == 0 ) return b;
    return gcd( b, a % b );
}

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


//入力
int n;
P res[110];
int index[110];


int main(){

    cin >> n;
    for(int i = 0; i < n; i++){
        string f; int s;
        cin >> f >> s;
        // cin >> res[i].first >> res[i].second;

        res[i].first = f; res[i].second = -s;
        index[-res[i].second] = i+1;
    }

    sort(res, res+n);

    for(int i = 0; i < n; i++){
        cout << index[-res[i].second] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define pb push_back
#define mp make_pair
#define all(a)  (a).begin(),(a).end()
#define dwn(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;
const ll inf = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	int cnt = 0;
	for (int i = 0; i < a.size(); i++) {
		if (a[a[i] - 1] == i + 1) cnt++;
	}
	cout << cnt / 2 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

#define watch(x) cout << (#x) << " is " << (x) << endl

int main() {
    string s, t;
    cin >> s >> t;
    if (s.size() == (t.size() - 1)) {
        bool isTrue = true;
        for (auto i = 0; i < s.size(); ++i) {
            if (s[i] == t[i]) {
                continue;
            } else {
                isTrue = false;
                break;
            }
        }
        if (isTrue) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <map>
#include <set>
#include <list>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

int i,j,k,l,m,n;
/////////////////////////////////////////////////////


ll a;
ll N,M;
char S[101010],T[101010];
ll gcd(ll a,ll b){
    if(b==0){
        return a;
    }
    return gcd(b,a%b);
}

int main(){
    
    scanf("%lld%lld%s%s",&N,&M,S,T);
    ll g=gcd(N,M);
    ll l=N*M/g;
    ll n=l/N,m=l/M;
    ll ni=0,mi=0;
    ll ans=0;
    while(true){
        while(ni*n<mi*m)ni++;
        while(mi*m<ni*n)mi++;
        if(mi*m==ni*n){
            if(ni==N)
                break;
            if(S[ni]!=T[mi]){
                printf("-1\n");
                return 0;
            }
            mi++;
        }
    }
    printf("%lld\n",l);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cassert>
using namespace std;

struct LowestCommonAncestor {
    size_t n;
    size_t size() const { return n; }
    vector<int> color, parent, depth, topDepth, goUp, visited;
    vector<vector<int>> g;
    LowestCommonAncestor(size_t n_) : n(n_), g(n) {}
    void addEdge(int u, int v){
        g[u].push_back(v); g[v].push_back(u);
    }
    void decomp(int root = 0, int B = 400){
        parent.assign(n, -1); depth.assign(n, 0);
        topDepth.assign(n, 0); goUp.assign(n, -1); visited.assign(n, false);
        vector<int> tord;
        vector<int> q(n+1); int l = 0, r = 0;
        q[r++] = root;
        while(l != r){
            int v = q[l++]; visited[v] = true;
            tord.push_back(v);
            for(int c : g[v]){
                if(!visited[c]){ parent[c] = v; depth[c] = depth[v] + 1; q[r++] = c; }
            }
        }
        swap(color, visited); // ?????¢????????±??????
        color.assign(n, 0);
        int c = 0;
        for(int u : tord){
            if(color[u]) continue;
            c++;
            l = 0, r = 0;
            q[r++] = u;
            for(int i = 0; i < B && l != r; i++){
                int v = q[l++];
                color[v] = c; goUp[v] = parent[u]; topDepth[v] = depth[u];
                for(int c : g[v]) if(!color[c]) q[r++] = c;
            }
        }
    }
    int solve(int u, int v){
        while(color[u] != color[v]){
            if(topDepth[u] > topDepth[v]) u = goUp[u];
            else v = goUp[v];
        }
        while(u != v){
            if(depth[u] > depth[v]) u = parent[u];
            else v = parent[v];
        }
        return u;
    }
};

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

int main(){
    int n;
    cin >> n;
    LowestCommonAncestor g(n);
    rep(i,n){
        int k;
        cin >> k;
        rep(j,k){
            int c;
            cin >> c;
            g.addEdge(i,c);
        }
    }
    g.decomp(0);
    int q;
    cin >> q;
    rep(i,q){
        int u,v;
        cin >> u >> v;
        cout << g.solve(u,v) << endl;
    }
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

vector<int> score;
vector<int> memo;

int value;

void dfs(vector<vector<int>> &G, int v, int parent){
    value += memo[v];
    score[v] = value;

    for (auto next: G[v]){
        if (next == parent)continue;
        dfs(G, next, v);
    }
    value -= memo[v];
}

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<vector<int>> G(N+1);//1-indexed
    REP(i, N-1){
        int a,b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    score.assign(N+1, 0);

    memo.assign(N+1, 0);
    REP(i,Q){
        int p, x;
        cin >> p >> x;
        memo[p] += x;
    }

    value = 0;
    dfs(G, 1, -1);

    REP(i,N){
        cout << score[i+1];
        if(i!=N-1) cout << " ";
        else cout << endl;
    }

    return 0;
}


Measured memory_bytes: 27392
#define _GLIBCXX_DEBUG
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;

int P[10010];
void init(int n){
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対グラフ

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

int main(){
    int n;
    cin >>n;
    int v[n],c[n];
    int ans=0;
    rep(i,n){
        cin >>v[i];
    }
    rep(i,n){
        cin >>c[i];
    }
    rep(i,n){
        if(v[i]-c[i]>0){
            ans+=v[i]-c[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Apr  6 20:38:26 2019

@author: Yamazaki Kenichi
"""

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if e - a > k:
    print(':(')
else:
    print('Yay!')

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

using namespace std;

int count[26];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string w, t;
    cin>>w;
    transform(w.begin(), w.end(), w.begin(), ::toupper);
    int ans=0;
    while(cin>>t) {
        if(t=="END_OF_TEXT") break;
        transform(t.begin(), t.end(), t.begin(), ::toupper);
        if(w==t) ans++;
    }
    cout<<ans<<'\n';
    return 0;
}

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

struct Node{
    int key;
    struct Node *prev,*next;
};


struct Node *nil;//node???????????¨????°?

void trace(){
    struct Node *n;
    n=nil->next;
    cout << n->key;
    n = n->next;
    while(n!=nil){
        cout<<" "<<n->key;
        n = n->next;
        if(n==nil)break;
    }
    cout << endl;
}

void init(){
    nil =(struct Node *)malloc(1*sizeof(struct Node));
    nil->prev = nil;
    nil->next = nil;
}

void insert(int key){
    struct Node *node = (struct Node *)malloc(1*sizeof(struct Node));
    node -> key = key;
    node -> next = nil->next;
    nil->next->prev = node;
    nil->next = node;
    node -> prev = nil;
    //trace();
}

void deleteNode(struct Node* node){
    if(node==nil)return;
    /*??????????????????????????????????????¨?????????????????????*/
    node->prev->next = node->next;
    node->next->prev = node->prev;
    free(node);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

struct Node* listSearch(int key) {
    struct Node *n = nil->next;
    while(n != nil && n->key != key ) {
        n = n-> next;
    }
    return n;
}

void deleteKey(int key) {
    deleteNode(listSearch(key));
    //trace();
}

// void deleteKey(int key){
//     struct Node *n;
//     n = nil->next;
//     while(n->key!=key && n!=nil){
//         //cout << "??°???" << n << endl;
//         n = n->next;
//         //cout << "??°??????" << n << endl;
        
//     }
//     delete(n);
//     trace();
// }




int main(){
    init();
    int n,key;
    string command;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> command;
        if(command=="insert"){
            cin >> key;
            insert(key);
        }else if(command=="delete"){
            cin >> key;
            deleteKey(key);           
        }else if(command=="deleteFirst"){
            deleteFirst();
            continue;
        }else if(command=="deleteLast"){
            deleteLast();
            continue;
        }
    }
    
    trace();
    
    return 0;
}

Measured memory_bytes: 34244
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    cout.precision(18);

    long long N;
    vector<long long> A;
    cin >> N;

    map<long long, long long> m;
    for (long long i = 0; i < N; i++)
    {
        long long t;
        cin >> t;
        A.push_back(t);
        m[i + 1 - t]++;
    }

    long long c = 0;
    for (long long i = 0; i < N; i++)
        c += m[i + 1 + A[i]];

    cout << c << endl;
}

Measured memory_bytes: 27460
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
using namespace std;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << (-max(a,c)+min(b,d))*(max(a,c)<min(b,d)) << endl;
}



Measured memory_bytes: 256
s = gets.chomp
# n = gets.chomp.to_i
# ary = gets.chomp.split.map(&:to_i)
flag = false
for i in 1..3
    if s[i] == s[i-1]
        flag = true
    end
end

if flag
    puts "Bad"
else
    puts "Good"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define fi first
#define se second
using ll = long long;
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector<int> p(n), b(n), c(n - 1);
    for(int i = 0; i < n; ++i) {
        cin >> p[i];
        p[i] -= 1;
    }
    for(int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    for(int i = 0; i < n - 1; ++i) {
        cin >> c[i];
    }
    int ans = 0;
    for(int i = 0; i < n; ++i) {
        int x = p[i];
        ans += b[x];
        if(i && p[i] == p[i - 1] + 1) ans += c[x - 1];
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
import builtins
import functools
import sys
import textwrap
from io import StringIO


def solve(input, print):
    A, B, C, X, Y = map(int, input().split())

    cost_min = sys.maxsize
    for c in range(max([X, Y]) + 1):
        cost = c * 2 * C
        a = X - c
        b = Y - c
        if a > 0:
            cost += a * A
        if b > 0:
            cost += b * B
        cost_min = min([cost_min, cost])
    print(cost_min)


if __name__ == '__main__':
    solve(builtins.input, functools.partial(builtins.print, flush=True))


def make_input(s):
    ss = textwrap.dedent(s).splitlines()
    it = iter(ss)
    return functools.partial(next, it)


def execute_solve(input_text):
    result = StringIO()
    solve(make_input(input_text),
          functools.partial(print, file=result, flush=True))
    return result.getvalue()


def test_solve():
    assert execute_solve('1500 2000 1600 3 2') == '7900\n'
    assert execute_solve('1500 2000 1900 3 2') == '8500\n'
    assert execute_solve('1500 2000 500 90000 100000') == '100000000\n'


Measured memory_bytes: 3684
A, B, C, X, Y = map(int, input().split())

ans = float('inf')
for i in range(max(X, Y) + 1):
    cost = 0
    cost += max(0, A * (X - i))
    cost += max(0, B * (Y - i))
    cost += C * i * 2
    ans = min(ans, cost)
print(ans)


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

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

using namespace std;
using lint=long long;

int main(){
	string s;
	lint k; cin>>s>>k;

	int n=s.length(),pos;
	rep(i,n) if(s[i]!='1') { pos=i; break; }
	cout<<(k<=pos?'1':s[pos])<<endl;

	return 0;
}


Measured memory_bytes: 256
/**
*    author:  souzai32
*    created: 01.08.2020 16:53:59
**/

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

long long int gcd(long long int a, long long int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

long long int lcm(long long int a, long long int b)
{
   return a / gcd(a, b) * b;
}
int main() {

    int n;
    cin >> n;
    vector<long long int> t(n);
    rep(i,n) cin >> t.at(i);

    long long int ans=t.at(0);
    rep(i,n-1){
        ans=lcm(ans,t.at(i+1));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<int,int> P;
#define Mod 1000000007


int main(){
    ll i,j;

    ll n;
    cin>>n;

    ll a[n];
    ll b[n];
    ll c[n];

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

    ll dp[n][3];

    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];

    for(i=1;i<n;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][2],dp[i-1][0])+b[i];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];

    }

    ll ans=max(max(dp[n-1][1],dp[n-1][2]),dp[n-1][0]);
    cout<<ans<<endl;

    
    return 0;
}

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

using ll = long long int;
using bigint = int64_t;

#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define bitcount __builtin_popcount
#define endl "\n"
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " = " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define ffi(i,a,b,c) for(ll i = a ; i <= b ; i += c)
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int MOD = 1000000007;

void io_set(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

void solve(){
    ll n, k, s = 0;
    cin >> n >> k;
    ll a[n];
    rep(i, n){
        cin >> a[i];
    } 
    sort(a, a+n);
    rep(i, k){
        s += a[i];
    }
    cout << s << endl;
}

int main(){
    IOS;
    //io_set();
    ll tt = 1;
    //cin >> tt;
    while(tt--){
        solve();
    }
    return 0;
} 

Measured memory_bytes: 3632
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let A = read![[i64]];

    let mut rain = vec![0; N];
    for i in 0..N {
        rain[0] += A[i] * if i % 2 == 0 { 1 } else { -1 };
    }

    for i in 0..N - 1 {
        rain[i + 1] = A[i] * 2 - rain[i];
    }

    println!(
        "{}",
        rain.into_iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );
}


Measured memory_bytes: 14456
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main()
{
    int r, d;
    ull x;
    cin >> r >> d >> x;
    REP(i, 10){
        cout << r * x - d << endl;
        x = r * x - d;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
template<class T> inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

//a^n mod を計算する関数
long long modpow(long long a,long long n,long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^(-1) mod すなわちaの逆元を返す関数
long long modinv(long long a,long long mod) {
    return modpow(a,mod-2,mod);
}

//最大公約数をを返す関数
long long gcd (long long a,long long b) {
    if(a % b == 0) {
        return b;
    }else {
        return (gcd(b,a%b));
    }
}

const long long INF = 1LL << 60;
const long long P = 1000000007;

//nCkを求める関数
long long conbi (long long n,long long k) {
    long long res = 1;
    long long inv;
    for(long long i = n-k+1; i <= n; i++) {
        res *= i;
        res %= P;
    }
    for(long long i = 1; i <= k; i++) {
        inv = modinv(i,P);
        res *= inv;
        res %= P;
    }
    return res;
}

int main() {
    string s;
    cin >> s;
    if(s == "AAA" || s == "BBB") {
        cout << "No";
    }else {
        cout << "Yes";
    }
    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 n = sc.nextInt();
    long ans = 0;
    HashMap<Long, Long> map = new HashMap<Long, Long>();
    long a = sc.nextLong();
    map.put(a, (long)1);
    for(int i = 1; i < n; i++) {
      long b = sc.nextLong();
      if(map.containsKey(i - b)) ans += map.get(i - b);
      if(map.containsKey(i + b)) {
        map.put(i + b, map.get(i + b) + 1);
      } else {
        map.put(i + b, (long)1);
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 71152
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();

        if (a.endsWith("s")){
            System.out.println(a + "es");
        }else{
            System.out.println(a + "s");
        }
    }
}



Measured memory_bytes: 38516
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

vector<pair<lint, int>> Pfact(lint num) {
	vector<pair<lint, int>> res;
	for (lint i = 2; i * i <= num; i++) {
		int cnt = 0;
		while (num % i == 0) {
			cnt++;
			num /= i;
		}
		if (cnt) res.emplace_back(i, cnt);
	}
	if (num != 1) res.emplace_back(make_pair(num, 1));
	return res;
}

class Combi {
private:
	vector<lint> fac, inv, finv;

	void init(int N) {
		fac[0] = fac[1] = 1; inv[1] = 1; finv[0] = finv[1] = 1;

		for (int i = 2; i < N; i++) {
			fac[i] = fac[i - 1] * i % MOD;
			inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
			finv[i] = finv[i - 1] * inv[i] % MOD;
		}
	}

public:
	Combi(int N) : fac(N + 1), inv(N + 1), finv(N + 1) { init(N + 1); }

	lint Cmod(int n, int k) {
		if (n < k) return 0;
		if (n < 0 || k < 0) return 0;
		return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}

	lint Pmod(int n, int k) {
		if (n < k) return 0;
		if (n < 0 || k < 0) return 0;
		return fac[n] * finv[n - k] % MOD;
	}
};

int main() {

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

	int N, M;
	cin >> N >> M;

	auto pfM = Pfact(M);
	
	Combi C(100030); // 30 > log2(10^9)
	lint ans = 1;
	for (const auto &elem : pfM) {

		ans *= C.Cmod(N - 1 + elem.second, N - 1);
		ans %= MOD;

	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 2560