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

void solve(int n, int m){
	int a[m] = {};
	for(int i=0; i<n; ++i){
		int d, v;
		cin >> d >> v;
		a[d-1] = max(a[d-1], v);
	}
	int ans = 0;
	for(int i=0; i<m; ++i) ans += a[i];
	cout << ans << "\n";
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int n, m;
		cin >> n >> m;
		if(n == 0 && m == 0) return 0;
		solve(n, m);
	}
}


Measured memory_bytes: 3076
<?php
  fscanf(STDIN, "%d %d", $D, $N);
  if($D == 0){
    $basenum = 1;
  } elseif($D == 1){
    $basenum = 100;
  } elseif($D == 2){
    $basenum = 10000;
  }
  if($N == 100){
    $N++;
  }
  $ansnum = $basenum * $N;
  echo $ansnum;
?>

Measured memory_bytes: 3576
d=list("abcdefghijklmnopqrstuvwxyz")
s=input()
ss=list(s)
unused=list(set(d)^set(ss))
unused.sort()
if len(s)==26:
    cnt=1
    l=d.index(s[-1])
    for i in range(2,27):
        if d.index(s[-i])>l:
            l=d.index(s[-i])
            cnt+=1
        else:
            i=ss[-cnt-1]
            j=1
            while True:
                if d.index(i)>d.index(ss[-j]):
                    j+=1
                else:
                    break
            ans=ss[:-cnt-1]+[ss[-j]]
            print("".join(ans))
            exit()
    print(-1)
else:
    ans=ss+[unused[0]]
    print("".join(ans))

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

const int INF=1001001001;

int main() 
{
  int h,n;
  cin>>h>>n;
  
  int a[1000];
  int b[1000];
  
  vector<int> dp(h+1,INF);
  dp[0]=0;
  for(int i=0;i<n;++i)
  {
    cin>>a[i]>>b[i];
    for(int j=0;j<h;++j)
    {
      int nj=min(j+a[i],h);
      dp[nj]=min(dp[nj],dp[j]+b[i]);
    }
  }
  cout<<dp[h];
  
  return 0;
}


Measured memory_bytes: 256
i = map(int,raw_input().split())
if i[0] < i[1]:
        if i[2] < i[0]:
                print i[2],
                print i[0],
                print i[1]
        elif i[1] < i[2]:
                print i[0],
                print i[1],
                print i[2]
        else:
                print i[0],
                print i[2],
                print i[1]
else:
        if i[2] < i[1]:
                print i[2],
                print i[1],
                print i[0]
        elif i[0] < i[2]:
                print i[1],
                print i[0],
                print i[2]
        else:
                print i[1],
                print i[2],
                print i[0]

Measured memory_bytes: 4252
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

vector<vector<int>> a(100010, vector<int>()), b(100010, vector<int>()), graph(100010, vector<int>());
vector<int> odda(100010), oddb(100010), ans(100010), va(100010), vb(100010), vis(100010);

void dfs1(int n, int p, vector<vector<int>> &g, vector<int> &odd) {
	int check = 0;
	for (int i : g[n]) {
		if (i == p) continue;
		dfs1(i, n, g, odd);
		check ^= 1;
	}
	check ^= 1;
	odd[n] = check;
}

void dfs2(int n, int p, vector<vector<int>> &g, vector<int> &ver) {
	vector<int> one;
	if (ans[n]) one.pb(n);
	for (int i : g[n]) {
		if (i == p) continue;
		dfs2(i, n, g, ver);
		if (ver[i] != -1 && ans[ver[i]]) one.pb(ver[i]);
	}
	while (one.size() >= 2) {
		int u = one[one.size() - 2]; int v = one[one.size() - 1];
		graph[u].pb(v);
		graph[v].pb(u);
		one.pop_back(); one.pop_back();
	}
	ver[n] = one[0];
}

void dfs3(int n, int p, int c) {
	ans[n] = c;
	if (vis[n]) return;
	vis[n] = true;
	for (int i : graph[n]) {
		if (i == p) continue;
		dfs3(i, n, c * -1);
	}
}

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

	int n;
	cin >> n;
	int roota, rootb;
	rep(i, n) {
		int v;
		cin >> v;
		if (v == -1) roota = i;
		else {
			v--;
			a[i].pb(v);
			a[v].pb(i);
		}
	}
	rep(i, n) {
		int v;
		cin >> v;
		if (v == -1) rootb = i;
		else {
			v--;
			b[i].pb(v);
			b[v].pb(i);
		}
	}
	dfs1(roota, -1, a, odda); dfs1(rootb, -1, b, oddb);
	if (odda != oddb) {
		cout << "IMPOSSIBLE\n";
		return 0;
	}
	ans = odda;
	rep(i, n) va[i] = i, vb[i] = i;
	dfs2(roota, -1, a, va); dfs2(rootb, -1, b, vb);
	rep(i, n) {
		if (ans[i] != 0 && !vis[i]) dfs3(i, -1, 1);
	}
	cout << "POSSIBLE\n";
	rep(i, n) cout << ans[i] << ' ';
	cout << '\n';
}

Measured memory_bytes: 27404
import java.util.Scanner;
import java.lang.*;
public class Main{
        public static void main(String[] args) {
                // TODO Auto-generated method stub
    double[] p1=new double[2],p2=new double[2]; //[0]=x,[1]=y
    Scanner sca =new Scanner(System.in);
     int n=sca.nextInt();
     p1[0]=0.0;
     p2[0]=100.0;
     p1[1]=0.0;
     p2[1]=0.0;
     System.out.println(p1[0]+" "+p1[1]);
     koho(p1,p2,n);
     System.out.println(p2[0]+" "+p2[1]);
        }
    public static void koho(double p1[],double p2[],int n){
	if(n<1)return;
	double subx,suby;
	//referenced textbook method(use vectors)
	double[]beffro=new double[2],befback=new double[2];//(x,y)=([0],[1]);
	double[]afrote=new double[2];//Rotated vector
	double rotation = Math.toRadians(60);//require to rotate vectors(60 degree)
	beffro[0]=(2.0*p1[0]+p2[0])/3.0;//take dividing points
	beffro[1]=(2.0*p1[1]+p2[1])/3.0;
        befback[0]=(p1[0]+2.0*p2[0])/3.0;
	befback[1]=(p1[1]+2.0*p2[1])/3.0;
	subx=befback[0]-beffro[0];
	suby=befback[1]-beffro[1];
	afrote[0]=subx*Math.cos(rotation)-suby*Math.sin(rotation)+beffro[0];
	afrote[1]=subx*Math.sin(rotation)+suby*Math.cos(rotation)+beffro[1];
	//referenced rot formula.;
	koho(p1,beffro,n-1);
        System.out.println(beffro[0]+" "+beffro[1]);
	koho(beffro,afrote,n-1);
        System.out.println(afrote[0]+" "+afrote[1]);
	koho(afrote,befback,n-1);
        System.out.println(befback[0]+" "+befback[1]);
	koho(befback,p2,n-1);
    }
}




Measured memory_bytes: 32104
#include<stdio.h>
#define N 2000001
int B[N], C[N];

void countingSort(int A[], int B[], int k, int num){
  int i, j;

  for(i=0;i<=k;i++){
    C[i]=0;
  }
  for(j=1;j<=num;j++){
    C[A[j]]++;
  }
  for(i=1;i<=k;i++){
    C[i]=C[i]+C[i-1];
  }
  for(j=num;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
  for(i=1;i<=num;i++){
    printf("%d", B[i]);
    if(i!=num) printf(" ");
  }
  printf("\n");
}

int main(){
  int A[N];
  int i,j,n,k=0;
  scanf("%d", &n);
  for(i=1;i<=n;i++){
    scanf("%d", &A[i]);
    if(k < A[i]) k=A[i];
  }
  countingSort(A, B, k, n);
  return 0;
}



Measured memory_bytes: 17460
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

using namespace std;

bool root(int x){
    for(int i=1;i*i<=x;i++){
	if(x==i*i){
	    return true;
	}
    }
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    int n,d,sum=0;
    cin>>n>>d;
    
    int x[n+5][d+3];
    reps(i,n){
	reps(j,d){
	    cin>>x[i][j];
	}
    }

    reps(i,n-1){
	for(int j=i+1;j<=n;j++){
	    int total=0;
	    reps(z,d){
		total+=abs(x[i][z]-x[j][z])*abs(x[i][z]-x[j][z]);
	    }
	    
	    if(root(total)){
		sum++;
	    }
	}
    }
    cout<<sum<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int i, j, length, keydata, data[100]; 

  //入力データの格納
  scanf("%d",&length);
  
  for(i = 0; i < length; i++) {
    scanf("%d",&data[i]);
  }

  //ソート前の出力
  for(i = 0; i < length; i++) {
    printf("%d",data[i]);
    if(i != length-1) printf(" ");
  }
  printf("\n");

  //ソートの実行とソート毎の出力
  for(i = 1; i <= length-1; i++) {
    keydata = data[i];
    j = i - 1;
    while(j >= 0 && data[j] > keydata) {
      data[j+1] = data[j];
      j--;
    }
    data[j+1] = keydata;

    for(j = 0; j < length; j++) {
      printf("%d",data[j]);
      if(j != length-1) printf(" ");
    }
    printf("\n");
  }

  return 0;
}





Measured memory_bytes: 2144
/* tempate
 *
 *
 */

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    bool f = false;
    if(s[0] == s[1]){
        if(s[2] == s[3] && s[2] != s[0]) f = true;
    }
    if(s[0] == s[2]){
        if(s[1] == s[3] && s[1] != s[0]) f = true;
    }
    if(s[0] == s[3]){
        if(s[1] == s[2] && s[1] != s[0]) f = true;
    }
    if(f) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}


Measured memory_bytes: 760
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)                                                                             
#define seg_size 524288
long long geko[300000] = {};
long long multi[300000] = {};
long long inv(long long now) {
	long long ans = 1;
	long long geko = MAX_MOD - 2;
	while (geko != 0) {
		if (geko % 2 == 1) {
			ans *= now;
			ans %= MAX_MOD;
		}
		now *= now;
		now %= MAX_MOD;
		geko /= 2;
	}
	return ans;
}
int main() {
#define int long long
	long long h, w, a, b;
	cin >> h >> w >> a >> b;
	geko[1] = 1;
	for (int i = 2;i <= w;++i) {
		geko[i] = geko[i - 1];
		geko[i] *= inv(i - 1);
		geko[i] %= MAX_MOD;
		geko[i] *= (i - 2) + (h - a);
		geko[i] %= MAX_MOD;
	}
	multi[w] = 1;
	for (int i = w - 1;i > b;--i) {
		multi[i] = multi[i + 1];
		multi[i] *= inv(w - i);
		multi[i] %= MAX_MOD;
		multi[i] *= (a - 1) + (w - i);
		multi[i] %= MAX_MOD;
	}
	long long ans = 0;
	for (int i = 1;i <= w;++i) {
		ans += geko[i] * multi[i];
		ans %= MAX_MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3072
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int Q = sc.nextInt();

    int[] nums = new int[N];

    for (int i = 0; i < Q; i++) {
      int n = sc.nextInt();
      nums[n-1]++;
    }

    for (int i = 0; i < N; i++) {
      int n = nums[i];
      if(n + K-Q >0 ){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
    }
    }

}

Measured memory_bytes: 60212
N = int(input())
sho = N
if sho == 0 or sho == 1:
    kotae = str(sho)
else:
    kotae = ''
while sho != 1 and sho != 0:
    if sho % (-2) == 0:
        newsho = sho // (-2)
    else:
        newsho = sho // (-2) + 1
    amari = sho - newsho * (-2)
    kotae = str(amari) + kotae
    if newsho == 1:
        kotae = str(newsho) + kotae
    sho = newsho
print(kotae)


Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <vector>

#define pb push_back
#define mp make_pair
#define fi first
#define se second

typedef long long ll;

const int N=1e5+5;

int n,sz[N]; ll d_rt;

std::vector<int> g[N];

std::pair<ll,int> a[N];

void dfs(int u,int dep){
	d_rt+=dep; for(auto v: g[u]) dfs(v,dep+1);
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){ scanf("%lld",&a[i].fi); a[i].se=i; sz[i]=1; }
	std::sort(a+1,a+1+n);
	for(int i=n;i>=2;--i){
		int u=a[i].se; ll d_fa=a[i].fi+2*sz[u]-n;
		int pos=std::lower_bound(a+1,a+1+n,std::mp(d_fa,0))-a;
		if(a[pos].fi!=d_fa){ puts("-1"); return 0; }
		sz[a[pos].se]+=sz[u]; g[a[pos].se].pb(u);
	}
	dfs(a[1].se,0); if(d_rt!=a[1].fi){ puts("-1"); return 0; }
	for(int u=1;u<=n;++u){
		std::sort(g[u].begin(),g[u].end());
		for(auto v: g[u]) printf("%d %d\n",u,v);
	}
	return 0;
}

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

int main(){
  	ll n,cnt=0,ans=0; cin>>n;
	char a[200005];
	for (ll i=1;i<=n;i++)  cin>>a[i];
	for (ll i=1;i<=n;i++){
		if (a[i]=='W')  cnt++;
	}
	for (ll i=n-cnt+1;i<=n;i++){
		if (a[i]!='W')  ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

using ll = long long;
using pii = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;

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

namespace std {
    template <>
    class hash<tuple<int, int, int>> {
    public:
        size_t operator()(const tuple<int, int, int>& t) const {
            int x, y, d;
            tie(x, y, d) = t;
            return x * 10000 + y * 10 + d;
        }
    };
}

int main() {
    string s;
    cin >> s;
    int X, Y; cin >> X >> Y;
    int d = 0;
    vector<vector<int>> v(2);
    int cnt = 0;
    bool first = true;
    for(int i = 0; i < s.size(); ++i) {
        if(s[i] == 'T') {
            if(cnt > 0) {
                if(first) {
                    X -= cnt;
                } else {
                    v[d].push_back(cnt);
                }
            }
            first = false;
            d ^= 1;
            cnt = 0;
        } else {
            cnt++;
        }
    }
    if(!first && cnt > 0) {
        v[d].push_back(cnt);
    } else if(first) {
        X -= cnt;
    }

    int MAX = 20000;
    vector<bool> dpx(MAX, false);
    vector<bool> dpy(MAX, false);
    const int c = MAX / 2;
    dpx[c] = true;
    dpy[c] = true;
    for(auto dx : v[0]) {
        vector<bool> nxt(MAX);
        for(int j = 0; j < MAX; ++j) {
            if(dpx[j]) {
                assert(j - dx >= 0 && j + dx < MAX);
                nxt[j - dx] = nxt[j + dx] = true;
            }
        }
        dpx = move(nxt);
    }
    for(auto dy : v[1]) {
        vector<bool> nxt(MAX);
        for(int j = 0; j < MAX; ++j) {
            if(dpy[j]) {
                assert(j - dy >= 0 && j + dy < MAX);
                nxt[j - dy] = nxt[j + dy] = true;
            }
        }
        dpy = move(nxt);
    }
    if(X + c >= 0 && X + c < MAX && dpx[X + c] && 0 <= Y + c && Y + c < MAX && dpy[Y + c]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static int H, W;
    static int[] dx = new int[] { 1, 0, -1, 0 };
    static int[] dy = new int[] { 0, -1, 0, 1 };
    static int dfs(int i,int j,char[,] maze)
    {
        Queue<int> que_x=new Queue<int>();
        Queue<int> que_y = new Queue<int>();
        int[,] d = new int[H,W];
        for (int k = 0; k < H; k++)
        {
            for (int l = 0; l < W; l++)
            {
                d[k,l] = -1;
            }
        }
        que_x.Enqueue(j);
        que_y.Enqueue(i);
        d[i,j] = 0;
        while (que_x.Count > 0)
        {
            int temp_x = que_x.Dequeue();
            int temp_y = que_y.Dequeue();
            for (int k = 0; k < 4; k++)
            {
                if (temp_y+dy[k]>=0&& temp_y + dy[k] < H && temp_x + dx[k] >= 0 && temp_x + dx[k] < W &&
                    maze[temp_y+dy[k],temp_x+dx[k]] == '.' && d[temp_y + dy[k], temp_x + dx[k]] == -1)
                { que_x.Enqueue(temp_x + dx[k]); que_y.Enqueue(temp_y + dy[k]); d[temp_y + dy[k],temp_x + dx[k]] = d[temp_y,temp_x] + 1; }

            }
        }
        int max = 0;
        for (int k = 0; k < H; k++)
        {
            for (int l = 0; l < W; l++)
            {
                max =Math.Max(max, d[k,l]);
            }
        }
        return max;
    }
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split();
        H = int.Parse(input[0]);
        W = int.Parse(input[1]);
        char[,] maze = new char[H,W];
        for (int i =0; i < H; i++)
        {
            string temp = Console.ReadLine();
            for (int j = 0; j < W; j++)
            {
                maze[i,j] = temp[j];
            }
        }
        int max = 0;
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                if (maze[i,j] == '.') max=Math.Max(max,(dfs(i,j, maze)));
            }
            }
        Console.WriteLine(max);
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll A, V;
    cin >> A >> V;
    ll B,W;
    cin >> B >> W;
    ll T;
    cin >> T;
    ll D=abs(A-B);
    ll D2=(V-W)*T;
    puts(D<=D2?"YES":"NO");
}



Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MN=1e5+10,MW=1e5+10;
int n,w;
ll ans,dp[MW];
typedef pair<int,int> P;
P a[MN];
int main()
{
    scanf("%d%d",&n,&w);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&a[i].first,&a[i].second);
    for(int i=1;i<=n;i++)
        for(int j=w;j;j--)
            if(j-a[i].first>=0)
                dp[j]=max(dp[j],dp[j-a[i].first]+a[i].second),ans=max(ans,dp[j]);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.Random;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AnandOza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BMixJuice solver = new BMixJuice();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMixJuice {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), k = in.nextInt();
            int[] p = in.readIntArray(n);

            Util.safeSort(p);

            long answer = 0;
            for (int i = 0; i < k; i++) {
                answer += p[i];
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] readIntArray(int n) {
            int[] x = new int[n];
            for (int i = 0; i < n; i++) {
                x[i] = nextInt();
            }
            return x;
        }

    }

    static class Util {
        public static void safeSort(int[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffle(int[] x) {
            Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void swap(int[] x, int i, int j) {
            int t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        private Util() {
        }

    }
}



Measured memory_bytes: 26144
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define pb(a) push_back(a)
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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;}
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;

int GCD(int p, int q)
{
    return q ? GCD(q, p % q) : p;
}

vector<bool> prime_table(int n)
{
    vector<bool> prime(n + 1, true);
    if (n >= 0)
        prime[0] = false;
    if (n >= 1)
        prime[1] = false;
    for (int i = 2; i * i <= n; i++)
    {
        if (!prime[i])
            continue;
        for (int j = i + i; j <= n; j += i)
        {
            prime[j] = false;
        }
    }
    return prime;
}
int main()
{
    vector<bool> v=prime_table(1000);
    vector<int> o;
    REP(i,1001){
        if(v[i]){
            o.push_back(i);
        }
    }
    int n;
    cin >> n;
    vector<int> a(n);
    set<int> s;
    int b=1;
    vector<int> ans(1000001,0);
    REP(i,n){
        cin >> a[i];
        if(i==0){
            b=a[i];
        }
        b=GCD(b,a[i]);
        if(a[i]==1){
            continue;
        }
        ans[a[i]]++;
        REP(j,o.size()){
            if(o[j]*o[j]>a[i]){
                continue;
            }
            if(a[i]%o[j]==0){
                ans[o[j]]++;
                if(a[i]/o[j]==o[j]){
                    continue;
                }
                ans[a[i]/o[j]]++;
            }
        }
    }
    if(b!=1){
        cout << "not coprime" << endl;
        return 0;
    }
    REP(i,1000001){
        if(ans[i]>1){
            cout << "setwise coprime" << endl;
            return 0;
        }
    }
    cout << "pairwise coprime" << endl;
}


Measured memory_bytes: 10956
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define REP1(i,n) for(int i=1; i<=(int)(n); i++)
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v)  reverse(v.begin(), v.end())
using namespace std;

int main() {
  int N; cin>>N;
  vector<long long> x(N),y(N),h(N);
  REP(i,N) cin>>x[i]>>y[i]>>h[i];

  for(long long Cx = 0; Cx <= 100; Cx++) {
    for(long long Cy = 0; Cy <= 100; Cy++) {
      bool isOK = true;
      long long H;
      long long Hmin = 1e10;
      for(int i = 0; i < N; i++) {
        if(h[i] != 0) {
          H = h[i] + abs(x[i] - Cx) + abs(y[i] - Cy);
          break;
        }
      }
      for(int i = 0; i < N; i++) {
        if(h[i] == 0) {
          if(H - abs(x[i] - Cx) - abs(y[i] - Cy) > 0) {
            isOK = false;
            break;
          }
        }
        else {
          long long Hi = h[i] + abs(x[i] - Cx) + abs(y[i] - Cy);
          if(H != Hi) {
            isOK = false;
            break;
          }
        }
      }
      if(isOK) {
        cout<<Cx<<" "<<Cy<<" "<<H<<endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<complex>
#include<vector>
#include <climits>

using namespace std;


int main(void)
{
    int n,H[30],i,m,count=0;

    scanf("%d",&n);

    
    for(i=0;i<n;i++)
    {
        scanf("%d",&H[i]);

        for(m=0;m<i;m++)
        {
            if(H[i]<H[m]) break;
            else if(m==i-1) count++;
            
        }
    }


    printf("%d",count+1);
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstring>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erase(unique(all(v)),v.end());
#define pvec(v) rep(i,v.size()){ cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sizeof(m))

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
#define mod 1e9 + 7;
ll dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}





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

	ll a = 0, b = 0, c = 0, d, e, ans = 0, n, ret = M, m, x = 0, y = 0;
	//bool x = false;
	string s,t;
	cin >> s;
	if (s[0] == '9' || s[1] == '9') cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    int a,b,c,d;
    cin >>  a >> b >> c >> d;
    if(abs(a-c)<=d||(abs(b-a)<=d&&abs(b-c)<=d)) cout << "Yes\n";
    else    cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;

void solve(int n) {
	while (n != 1) {
		cout << " ";
		if (n == 2 || n == 3) {
			cout << n;
			n /= n;
			break;
		}

		for (int i = 2; i <= sqrt(n);i++) {
			if (n%i == 0) {
				n /= i;
				cout << i;
				break;
			}
			if (i == (int)sqrt(n)) {
				cout << n;
				n /= n;
				break;
			}
		}
	}
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n; cin >> n;
	cout << n << ":";
	solve(n);
	cout << endl;
	return 0;
}

Measured memory_bytes: 3132
import numpy as np
a,b = map(str,input().split(' '))
N = int(str(a)+str(b))
n=1
f=0
while n <= int(np.sqrt(N))+1:
    if int(n*n)==N:
        print('Yes')
        f=1
        break
        
    else:
        n+=1
if f == 0:
    print('No')

Measured memory_bytes: 13876
#include <bits/stdc++.h>
#define ll long long
#define sz size
#define pb push_back
#define er erase
#define in insert
#define fr first
#define sc second
#define mp make_pair
#define pi pair
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
#define rc(s) return cout<<s,0
const int mod=1e9+7;
const int inf=1e5;
using namespace std;

long long a[4][4],lol=1;

int main(){
    cin >> a[1][1] >> a[1][2] >> a[1][3] >> a[2][1] >> a[2][2] >> a[2][3] >> a[3][1] >> a[3][2] >> a[3][3];
    if((a[1][1]-a[2][1]==a[1][2]-a[2][2] &&a[1][1]-a[2][1]==a[1][3]-a[2][3]) && (a[1][1]-a[3][1]==a[1][2]-a[3][2] &&a[1][1]-a[3][1]==a[1][3]-a[3][3]) && (a[2][1]-a[3][1]==a[2][2]-a[3][2] &&a[2][1]-a[3][1]==a[2][3]-a[3][3]) && lol==1  && (a[1][1]-a[1][2]==a[2][1]-a[2][2] &&a[1][1]-a[1][2]==a[3][1]-a[3][2]) && (a[1][1]-a[1][3]==a[2][1]-a[2][3] &&a[1][1]-a[1][3]==a[3][1]-a[3][3])  && (a[1][2]-a[1][3]==a[2][2]-a[2][3] &&a[1][2]-a[1][3]==a[3][2]-a[3][3])) rc("Yes");
    rc("No");

}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
#include <queue>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

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


int main(int argc, char const *argv[]) {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    REP(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    if (a[a.size()-1] < k) {
        cout << "IMPOSSIBLE" << std::endl;
        return 0;
    }
    ll G = 0;
    if (n <= 1) G = a[0];
    else G = gcd(a[0], a[1]);
    for (int i = 2; i < n; ++i) G = gcd(G, a[i]);
    if (k%G == 0) cout << "POSSIBLE" << std::endl;
    else cout << "IMPOSSIBLE" << std::endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e7;
const int inf=1e9;
int main(){
	long N;cin>>N;
	long A[N];
    long cnt[N+1] = {}; long sum = 0;
	rep(i,0,N){
        cin>>A[i];
        cnt[A[i]]++;
    }rep(i,1,N+1) sum += cnt[i]*(cnt[i]-1)/2;
	rep(i,0,N){
		cout<<sum - cnt[A[i]]*(cnt[A[i]]-1)/2 + (cnt[A[i]]-1)*(cnt[A[i]]-2)/2<<endl;
	}
}

Measured memory_bytes: 5760
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    m = sum(a)/n
    f = {}
    for i in range(n):
        if not a[i] in f:
            f[a[i]] = i
    a = list(set(a))
    a.sort()
    i = bisect.bisect_left(a,m)-1
    if abs(m-a[i]) < abs(a[i+1]-m):
        print(f[a[i]])
    elif abs(m-a[i]) == abs(a[i+1]-m):
        print(min(f[a[i]],f[a[i+1]]))
    else:
        print(f[a[i+1]])
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 40432
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair

const int MOD = 1000000007;
const int N = 1e5 + 18;


int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        //for (int tt = 1; tt <= t; tt++) {
        string s;
        cin >> s;
        int ans = 0;
        int n = s.size();
        for (int i = 0; i < n; i++) {
            ans += s[i] - '0';
        }
        if (ans % 9 == 0)
            cout << "Yes";
        else    cout << "No";
    }
    return 0;

}




Measured memory_bytes: 3720
#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 for1(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define endl '\n'
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    ll int n, x;
    cin >> n >> x;
    ll int a[100];
    rep(i, n) {
        cin >> a[i];
    }
    sort(a, a+n);

    ll int sum = 0, m = 0;
    int i;
    for (i = 0; i < n; i++) {
        sum += a[i];  // sumに子供の欲しがるキャンディの数を足す
        if (sum > x) {  // xを超えたら終了
            break;
        }
    }
    if (i == n) {
        if (sum == x) {  // もしsumがxと等しかったらn人が満足する
            cout << n << endl;
        } else {  // そうでないときは1人は多すぎるからn-1人が満足する
            cout << n - 1 << endl;
        }
    } else {  // これはxを超えたときの場合(i = nまで到達しなかったとき)で，このときちょうどの個数を分けれる子供はi人
        cout << i << endl;
    }
	return 0;
}

Measured memory_bytes: 256
<?php
$inputs = explode(" ", trim(fgets(STDIN)));

$nums = [];
foreach ($inputs as $input) {
    if (is_numeric($input)) {
        array_push($nums, (int) $input);
        continue;
    }

    $n1 = array_slice($nums, -2, 2)[0];
    $n2 = array_slice($nums, -2, 2)[1];
    $rl;

    if ($input == "+") $rl = $n1 + $n2;
    if ($input == "-") $rl = $n1 - $n2;
    if ($input == "*") $rl = $n1 * $n2;

    unset($nums[count($nums) - 1]);
    unset($nums[count($nums) - 1]);
    $nums = array_values($nums);
    array_push($nums, $rl);
}

print($nums[0]."\n");



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

int64_t gcd(int64_t a, int64_t b){
    return b==0 ? a : gcd(b, a%b);
}
int64_t lcm(int64_t a, int64_t b){
    return a * (b/gcd(a, b));
}

int main(){
    int64_t A, B;
    cin >> A >> B;
    cout << lcm(A, B) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
ll i,j,k;
ll n,m;
ll a,b,c;
ll ans=0;


int main(){
	cin>>a>>b>>c;
	if(!(a*b*c&1))ans=0;
	else ans=min(a*b,min(b*c,c*a));
	cout<<ans<<endl;
	
	return 0;
}

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

      int a = sc.nextInt();
      int b = sc.nextInt();
      String s = sc.next();
      
      int s1;
      boolean ans = true;

      if(s.charAt(a)!='-'){
        System.out.println("No");
        System.exit(0);
      }

      for(int i =0;i<a;i++){
        s1 = (int)s.charAt(i);
        if(s1>=48&&s1<58){
          ans=true;
        }else{
          System.out.println("No");
          System.exit(0);
        }
      }

      for(int i =a+1;i<s.length();i++){
        s1 = (int)s.charAt(i);
        if(s1>=48&&s1<58){
          ans=true;
        }else{
          System.out.println("No");
          System.exit(0);
        }

      }
      if(ans){
        System.out.println("Yes");
      }

  }
}


Measured memory_bytes: 21844
def f(a, b, n):
    if b == 1:
        print(0)
    else:
        Max = 0
        step = 1 if b // a ==  0 else b // a
        for x in range(b // a, n + step, step):
            res = (a * x) // b - a * (x // b)
            if res > Max:
                Max = res
        print(Max)

a, b, n = map(int, input().split()); f(a, b, n)


Measured memory_bytes: 9084
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#include<string>
using namespace std;
const int N=10+5,dx[]={0,0,1,-1},dy[]={1,-1,0,0},INF=0x3f3f3f3f;

int main()
{
    int n,m,w[10][10],a[40000+10];
    while(~scanf("%d%d",&n,&m)){
        long long sum=0;
        for(int i=0;i<=9;i++)
            for(int j=0;j<=9;j++){
                scanf("%d",&w[i][j]);
                if(w[i][j]==0) w[i][j]=INF;
            }
        for(int i=0;i<n*m;i++){
            scanf("%d",&a[i]);
        }
        for(int k=0;k<=9;k++)
            for(int i=0;i<=9;i++)
                for(int j=0;j<=9;j++){
                    w[i][j]=min(w[i][k]+w[k][j],w[i][j]);
                }
        for(int i=0;i<n*m;i++){
            if(a[i]!=-1&&a[i]!=1){
                sum+=w[a[i]][1];

            }
        }
        printf("%lld",sum);
    }
    return 0;
}



Measured memory_bytes: 384
s = int(input())
list = []
if s <= 2:
    print(4)
else:
    for i in range(100000):
        if i == 0:
            list.append(s)
        else:
            if list[i-1] % 2 == 0:
                temp = int(list[i-1] / 2)
            else:
                temp = int(list[i-1]) * 3 + 1
            list.append(temp)
        if list[i] == 4:
            break
    print(len(list)+3)

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll INF=1000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}
vector<ll> divisor(ll x){
	vector<ll> div;
	for(int i=1;i*i<=x;i++){
		if(i*i!=x && x%i==0){
			div.pb(i);
			div.pb(x/i);
		}
		else if(x%i==0) div.pb(i);
	}
	return div;
}

int main(){
	ll N; cin>>N;
	string s; cin>>s;

	ll tmp=0;
	//if ################
	rep(i,N){
		if(s[i]=='.') tmp++;
	}
	ll ans=tmp;

	// .#################
	rep(i,N){
		if(s[i]=='.') tmp--;
		else tmp++;
		ans=min(ans,tmp);
	}
	cout<<ans;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
// For ordered_set
int main(){
    long long x;cin>>x;
    long long y=(x-x%500)/500;
    long long z=((x%500)-(x%500)%5)/5;
    cout<<1000*y+5*z<<"\n";
   return 0;
}

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

using namespace std;

int main(){
  int abcd;
  cin>>abcd;
  int a,b,c,d;
  a = abcd/1000;
  abcd %= 1000;
  b = abcd/100;
  abcd %= 100;
  c = abcd/10;
  d = abcd % 10;

  //cout<<a<<b<<c<<d<<endl;
  for(int i = 0;i<2;i++){
    int tmp_b = (i == 0)?b:-b;
    for(int j = 0;j<2;j++){
      int tmp_c = (j ==0)?c:-c;
      for(int k = 0;k<2;k++){
	int tmp_d = (k ==0)?d:-d;
	//cout<<tmp_d<<endl;
	if(a + tmp_b+tmp_c+tmp_d == 7){
	  cout<<to_string(a)<<((i == 0)?"+":"")<<to_string(tmp_b)<<((j == 0)?"+":"")<<to_string(tmp_c)<<((k == 0)?"+":"")<<to_string(tmp_d)+"=7"<<endl;
	  return 0;
	}
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	A = 0
	B = 1
	C = 2
)

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func main() {
	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	var v [3][100000]int
	var dp [3][100000]int

	var N int
	fmt.Scan(&N)
	for i := 0; i < N; i++ {
		sc.Scan()
		v[A][i], _ = strconv.Atoi(sc.Text())
		sc.Scan()
		v[B][i], _ = strconv.Atoi(sc.Text())
		sc.Scan()
		v[C][i], _ = strconv.Atoi(sc.Text())
	}
	dp[A][0] = v[A][0]
	dp[B][0] = v[B][0]
	dp[C][0] = v[C][0]
	for i := 1; i < N; i++ {
		dp[A][i] = max(dp[B][i-1], dp[C][i-1]) + v[A][i]
		dp[B][i] = max(dp[A][i-1], dp[C][i-1]) + v[B][i]
		dp[C][i] = max(dp[A][i-1], dp[B][i-1]) + v[C][i]
	}
	ans := max(max(dp[A][N-1], dp[B][N-1]), dp[C][N-1])
	fmt.Println(ans)
}


Measured memory_bytes: 8224
#include <bits/stdc++.h>
using namespace std;
#define fast_io {cin.sync_with_stdio(0); cout.sync_with_stdio(0);}
#define out(x,y) {cout<<x<<y;}
using ll = long;


ll a[2019];

int main(){
	fast_io;
	string s;
	cin>>s;
	ll n = s.length();
	ll rem = 0;
	ll p = 1;
	for(ll i=n-1;i>=0;i--){
		ll d = s[i]-'0';
		rem = (d*p+rem)%2019;
		a[rem]++;
		// cout<<rem<<endl;
		p = (p*10)%2019;
	}
	ll ans = 0;
	for(ll i=0;i<2019;i++){
		ans = (ans+((a[i]*(a[i]-1))/2));
	}
	ans+=a[0];
	cout<<ans<<endl;
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	int K, T;  cin >> K >> T;
	int max_num = -1, sum = 0;
	REP(i, T){
		int input;  cin >> input;
		max_num = max(max_num, input);
		sum += input;
	}

	if(2 * max_num > sum)  cout << 2 * max_num - sum - 1 << endl;
	else                   cout << 0 << endl;

	return 0;
}

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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

vector<bool> sieve(int n)
{
  vector<bool> prime(n+1, true);
  prime[0] = prime[1] = false;

  for (int i = 2; i <= n; ++i) {
    if (!prime[i]) continue;

    for (int j = 2; i * j <= n; ++j) prime[i * j] = false;
  }

  return prime;
}

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  auto prime = sieve(100005);
  int a[100005] = {};

  for (int i = 3; i < 100005; i += 2) if (prime[i] && prime[(i+1)/2]) a[i] = 1;
  rep(i, 100004) a[i+1] += a[i];
  
  int q; cin >> q;
  while (q --> 0) {
    int l, r; cin >> l >> r;
    cout << a[r] - a[l-1] << endl;
  }
}


Measured memory_bytes: 4064
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b, c, x; cin >> a >> b >> c >> x;
	int y = x/50;
	int cnt = 0;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				if(k==y-10*i-2*j && i+j+k>=1){
					cnt++;
					//cout << i << ' ' << j << ' ' << k << endl;
				}
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	n, k = IN()
	rr=0
	if k%2==0:
		pp=(n+(k//2)) // k
		#print(pp,rr)
		rr+=pp**3
		
	pp = n//k
	#print(pp,rr)
	rr += pp**3
	
	print(rr)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

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

class Mod{
  public:
    ll mod;
    // mod must be a prime number
    Mod(ll m){
        mod = m;
    }
    //a^p
    ll modpow(ll a, ll p){
        if(p == 0) return 1;
        if(p%2 == 0){
            ll half = modpow(a, p/2);
            return half * half % mod;
        }
        else return a * modpow(a,p-1) % mod;
    }

    //nCr
    ll comb(ll n, ll r){
        if(r > n-r) return comb(n,n-r);
        ll mul = 1;
        ll div = 1;
        for (int i = 0;i < r;i++){
            mul *= n-i;
            mul %= mod;
            div *= i+1;
            div %= mod;
        }
        return mul * modpow(div,mod-2) % mod;
    }
};

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

    ll X,Y;
    Mod m(1e9+7);

    cin >> X >> Y;

    if((X+Y)%3 == 0){
        ll l = (X+Y)/3;
        ll i = X-l;
        if(i < 0 || i > l){
            cout << 0 << endl;
            return 0;
        }
        //cout << l << " " << i << endl;
        cout << m.comb(l,i) << endl;
        return 0;
    }

    cout << 0 << endl;
    return 0;


    /*vector<ll> a,b;

    a = vector<ll>(1);
    a[0] = 1;

    int l = 1;

    //cout << a[0] << endl;

    while(true){
        b = vector<ll>(l+1,0);
        if(X+Y < (l-1)*3) break;
        cout << l << endl;
        for (int i = 0;i < l;i++){
            a[i] %= mod;
            //cout << a[i] << endl;
            if(X+Y == (l-1)*3 && l+i-1 == X){
                cout << a[i]%mod << endl;
                //cout << i << " " << l << endl;
                return 0;
            }
            b[i] += a[i];
            b[i+1] += a[i];
        }
        a = b;
        l++;
    }

    cout << 0 << endl;*/

    return 0;

}

Measured memory_bytes: 256