akhauriyash/Code-Regression huggingface dataset:
//四則演算 #pragma GCC target("avx")
//並列計算 #pragma GCC optimize("O3")
//条件分岐を減らす #pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(i) sort(i.begin(),i.end())
#define rSORT(i) sort(i.rbegin(),i.rend())
#define fSORT(i,a) sort(i.begin(),i.end(),a)
#define all(i) i.begin(),i.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
inline void print() { cout << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

void dfs(         ) {

}

int main() {
    init();

    string s; cin >> s;
    each(i, s)if (i == '?')i = 'D';
    cout << s << "\n";

    return 0;
}

Measured memory_bytes: 3784
# coding: utf-8
# Your code here!
import sys

x = int(input()) 
san = list(map(int,input().split(" ")))

if x == 1:
    print("0")
    sys.exit()

sta = min(san)
goa = max(san)

if sta == goa:
    print("0")
    sys.exit()

tai = 0
ans = [] 

for i in range(sta,goa):
    tai = 0
    for j in range(x):
        tai += (i - san[j])**2
    ans.append(tai)
    
print(min(ans))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

string S;


int main()
{
	cin >> S;

	int N;
	N=S.size();
	int s=1;
	int n=1;
	int e=1;
	int w=1;
	if( S.find("S") == string::npos )	s=0;
	if( S.find("N") == string::npos )	n=0;
	if( S.find("E") == string::npos )	e=0;
	if( S.find("W") == string::npos )	w=0;
	if (s==1){
		if (n==0){
			puts("No");
			return 0;
		}
	}
	if (n==1){
		if (s==0){
			puts("No");
			return 0;
		}
	}
	if (e==1){
		if (w==0){
			puts("No");
			return 0;
		}
	}
	if (w==1){
		if (e==0){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int n; cin >> n;
    pair<pair<string,int>,int> p[105];
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        int x; cin >> x;
        p[i] = make_pair(make_pair(s,-x),i);
    }
    sort(p, p+n);
    for(int i= 0; i < n; i++) cout << p[i].second + 1 << endl;
    return 0;
}
//Saw the editorial

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
typedef long long ll;
int h1, m1, h2, m2, k;
int main()
{
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int m = (h2 - h1) * 60 + (m2 - m1);
    if(m >= k) printf("%d\n", m - k);
    else printf("0\n");
}


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

int main() {
    ll N, M;
    cin >> N >> M;
    vector<int> k(M), s(M, 0);
    rep(i, M) {
        cin >> k[i];
        rep(j, k[i]) {
            int tmp;
            cin >> tmp;
            --tmp;
            s[i] |= (1 << tmp);
        }
    }
    vector<int> p(M);
    rep(i, M) cin >> p[i];

    int ans = 0;
    for (int bit = 0; bit < (1 << N); ++bit) {
        int ok = 1;
        rep(i, M) {
            ok ^= (__builtin_popcount(bit & s[i]) % 2 ^ p[i]);
            if (!ok) break;
        }
        if (ok) ++ans;
    }
    cout << ans << endl;
}

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

int main(){
  long int N,K;
  cin >> N >> K;
  vector<int> h(N);
  for(int i=0;i<N;i++){
    cin >> h.at(i);
  }
  sort(h.begin(),h.end());
  long int ans =0;
  for(int i=0;i<N-K;i++) ans+=h.at(i);
  cout << ans << endl;
}

Measured memory_bytes: 4036
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std;
int N=0,deli[55]={0};
int Add[55]={0};
int main(void)
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++)scanf("%d",&deli[i]);
	for(int i=N-1;i>=1;i--)Add[i]=deli[i+1]+Add[i+1];
	long long ans=0ll;
	for(int i=1;i<N;i++)ans+=deli[i]*Add[i];
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
lst = []
for i in range(m):
    lst.append(list(map(int,input().split())))
p = list(map(int,input().split()))

ans = 0
for bit in range(1<<n):
    on_e = 0
    sw = bin(bit)[2:].zfill(n)
    for i in range(m):
        on_cnt = 0
        for j in range(lst[i][0]):
            if sw[lst[i][j+1]-1] == '1':
                on_cnt += 1
        else:
            if on_cnt % 2 != p[i]:
                continue
            else:
                on_e +=1
    else:
        if on_e == m:
            ans +=1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;
 
int main(){
  using namespace std;
  int A, B, m;
  cin>>A>>B>>m;
  vector<int> a(A), b(B);
  int x[m], y[m], c[m];
  REP(i, A){
    cin>>a[i];
  }
  REP(i, B){
    cin>>b[i];
  }
  int ans = 200'010;
  REP(i, m){
    cin>>x[i]>>y[i]>>c[i];
    x[i]--;y[i]--;
    int temp = a[x[i]] + b[y[i]] - c[i];
    ans = min(ans, temp);
  }
  sort(ALL(a));
  sort(ALL(b));
  ans = min(ans, a[0] + b[0]);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>
#include<algorithm>
#define MAX_V 10000
using namespace std;

int d[MAX_V][MAX_V];
int V=10;
int a[MAX_V][MAX_V];

void floyd(){
	for(int k=0;k<V;k++){
		for(int i=0;i<V;i++){
			for(int j=0;j<V;j++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
}

int main(){
	int n,m,i,j,ans;
	while(scanf("%d%d",&n,&m)!=EOF){
		ans=0;
		for(i=0;i<10;i++){
			for(j=0;j<10;j++){
				scanf("%d",&d[i][j]);
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				scanf("%d",&a[i][j]); 
			}
		}
		floyd();
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				if(a[i][j]!=-1&&a[i][j]!=1){
					ans+=d[a[i][j]][1];
				}
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
int s[100005],t[100005];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&s[i]);
    }
    if(n==2){
        printf("%lld\n",1ll*abs(s[0]-s[1]));
        return 0;
    }
    long long sum=0;
    sort(s,s+n);
    int l=s[0],r=s[0];
    int i=1,j=n-1;
    while(i<=j){
        int a=abs(s[i]-l),b=abs(s[i]-r);
        int c=abs(s[j]-l),d=abs(s[j]-r);
        int e=max(max(a,b),max(c,d));
        sum+=e;
        if(e==a){
            l=s[i];
            i++;
        }else if(e==b){
            r=s[i];
            i++;
        }else if(e==c){
            l=s[j];
            j--;
        }else if(e==d){
            r=s[j];
            j--;
        }
    }
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int x,a,b,y,z;
    cin>>x>>a>>b;
    y=abs(x-a);
    z=abs(x-b);
    if(y<z)
        cout<<"A";
    else
        cout<<"B";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a[100],s=0,b[100],c[100];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n-1;i++){
        cin>>c[i];
    }
    for(int i=0;i<n-1;i++){
        if(a[i+1]-a[i]==1){
            s+=c[a[i]-1];
        }
    }
    for(int i=0;i<n;i++){
        s=s+(b[a[i]-1]);
    }
    cout<<s;
}


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

five = 0
seven = 0

for i in list:
  if i == 5:
    five += 1
  elif i == 7:
    seven += 1
  else:
      pass

if seven == 1 and five == 2:
  print("YES")
else:
    print("NO")

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

const int num[] = {0, 1, 2, 3, 5, 7, 8, 9};

int main()
{
  int n;
  
  while (cin >> n, n){
    long long ct = 0, d = 1;
    while (n > 0){
      ct += num[n % 8] * d;
      d *= 10;
      n /= 8;
    }
    cout << ct << endl;
  }
  return (0);
}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

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

    for (int i = 0; i < n; ++i) {
        if (i == 0) f[i] = a[i];
        else f[i] = gcd(f[i - 1], a[i]);
    }

    for (int i = n - 1; i >= 0; --i) {
        if (i == n - 1) b[n - 1] = a[n - 1];
        else b[i] = gcd(b[i + 1], a[i]);
    }

    ll maxd = 0;
    for (int i = 0; i < n; ++i) {
        if (i == 0) d[i] = b[1];
        else if (i == n - 1) d[i] = f[n - 2];
        else d[i] = gcd(f[i - 1], b[i + 1]);

        maxd = max(maxd, d[i]);
    }

    cout << maxd << endl;

}

Measured memory_bytes: 3328
package main
 
import (
	"strings"
		"fmt"
)
 
func main() {
		var a string
		fmt.Scan(&a)
		ans := "Yes"
		for i:=0;i<4;i++{
			if strings.Count(a, a[i:i+1]) != 2{
				ans = "No"
			}
		}
			fmt.Println(ans)
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
	public static void main(String args[]) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		double T = scn.nextInt();
		int A = scn.nextInt();
		int p = 0;
		double delta = 1000000000;
		for(int i = 0;i < N;i++) {
			double H = scn.nextDouble();
			if(delta > Math.abs(T - H * 0.006 - A)) {
				p = i;
				delta =  Math.abs(T - H * 0.006 - A);
			}
		}

		System.out.println(p + 1);

	}
}


Measured memory_bytes: 27880
N, M = map(int, input().split(' '))
dist = [[10 ** 9 for _ in range(N)] for _ in range(N)]
edges = []

for _ in range(M):
    a, b, c = map(int, input().split(' '))
    dist[a - 1][b - 1] = min(dist[a - 1][b - 1], c)
    dist[b - 1][a - 1] = min(dist[b - 1][a - 1], c)
    edges.append((a - 1, b - 1, c))

for k in range(N):
    dist[k][k] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

ans = 0
for (u, v, cost) in edges:
    flag = False
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            flag |= ((dist[i][u] + cost + dist[v][j]) == dist[i][j])
    ans += 1 - int(flag)
print(ans)

Measured memory_bytes: 44268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void app() {
  int n,m;
  cin>>n>>m;

  if(n%2==1){
    rep(i,m){
      cout<<(i+1)<<" "<<(n-i)<<"\n";
    }
    return;
  }

  rep(i,m){
    if(i==n/4) break;
    cout<<(i+1)<<" "<<(n-i)<<"\n";
  }
  rep_range(i,n/4,m){
    cout<<(i+2)<<" "<<(n-i)<<"\n";
  }
}

int main(){app();return 0;}


Measured memory_bytes: 3636
#include <stdio.h>


void swap(int x,int y) {
    
    int tmp;
    
    
    
}

int main(int argc, const char * argv[]) {
    
    int a,b,c,tmp;
    
    scanf("%d %d %d",&a,&b,&c);
    
    if (c < b) {
        tmp = a;
        a = c;
        c = tmp;
    }
    
    if (b < a) {
        tmp = a;
        a = b;
        b = tmp;
    }
    
    if (c < b) {
        tmp = b;
        b = c;
        c = tmp;
    }
    
    
    printf("%d %d %d\n",a,b,c);
    return 0;
}

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

int main(int argc, const char * argv[]) {
    int len,wid,per,area;
    cin >> len;
    cin >> wid;
    per = len*2 + wid*2;
    area = len*wid;
    cout << area<< " " << per << endl;
    return 0;
}

Measured memory_bytes: 1164
n = int(input())
l = list(map(int, input().split()))
dp = [float("inf")]*n
dp[0] = 0
dp[1] = abs(l[0]-l[1])
for i in range(2,n):
    dp[i]=(min(dp[i-1]+(abs(l[i]-l[i-1])),dp[i-2]+(abs(l[i]-l[i-2]))))
print(dp[-1])

Measured memory_bytes: 13928
#include <stdio.h>

int main(){
  
  char uno,dos,tres;

  scanf("%c%c%c",&uno,&dos,&tres);

  if(uno=='S' && dos=='U' && tres=='N')
    printf("7");
  
  if(uno=='M' && dos=='O' && tres=='N')
    printf("6");

  if(uno=='T' && dos=='U' && tres=='E')
    printf("5");

  if(uno=='W' && dos=='E' && tres=='D')
    printf("4");

  if(uno=='T' && dos=='H' && tres=='U')
    printf("3");

  if(uno=='F' && dos=='R' && tres=='I')
    printf("2");

  if(uno=='S' && dos=='A' && tres=='T')
    printf("1");

}

Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
count_1 = 0
count_2 = 0
sum_1 = 0
sum_2 = 0

for i in range(len(a)):
    sum_1 += a[i]
    if i % 2 == 1:
        if sum_1 <= 0:
            count_1 += 1 - sum_1
            sum_1 = 1
    elif i % 2 == 0:
        if sum_1 >= 0:
            count_1 += sum_1 + 1
            sum_1 = -1

for i in range(len(a)):
    sum_2 += a[i]
    if i % 2 == 1:
        if sum_2 >= 0:
            count_2 += sum_2 + 1
            sum_2 = -1
    elif i % 2 == 0:
        if sum_2 <= 0:
            count_2 += 1 - sum_2
            sum_2 = 1

print(count_1 if count_1 < count_2 else count_2)

Measured memory_bytes: 20392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;

int main(){
  int N;
  cin>>N;
  vi A2(2*N);
  int a;
  ll all = 0;
  for(int i=0; i<N; i++){
    cin>>a;
    all += a;
    A2[i] = A2[i+N] = a*2;
  }

  vector<ll> B(N);
  B[0] = all;
  for(int i=1; i<N; i+=2){
    B[0] -= A2[i];
  }
  for(int i=2; i<N; i+=2){
    B[i] = B[i-2] + A2[i-1] - A2[i-2+N];
  }

  B[1] = all;
  for(int i=2; i<N; i+=2){
    B[1] -= A2[i];
  }
  for(int i=3; i<N; i+=2){
    B[i] = B[i-2] + A2[i-1] - A2[i-2+N];
  }

  for(int x: B){
    cout<<x<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 2944
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		System.out.println((char) ((int) s.charAt(0) + 1));
	}

	public static long modFactorial(long n, long mod) {
		long ans = 1;
		for (int i = 1; i <= n; i++) {
			ans *= i;
			ans %= mod;
		}
		return ans;
	}

	public static int arrayMax(int[] array) {
		int ans = Integer.MIN_VALUE;
		for (int i = 0; i < array.length; i++) {
			if (array[i] > ans)
				ans = array[i];
		}
		return ans;
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, a, b;
    cin>>n>>a>>b;
    ll ans = 0;
    ll x = n / (a+b);
    ans = x * a;
    ans += min(a, n - x*(a+b));
    cout<<ans<<endl;
}

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

using namespace std;
#ifdef ONLINE_JUDGE
#define cerr if(false)cerr
#endif

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define int long long
#define ld1 long double
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL),cout<<setprecision(14);
#define vint vector<int>
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define pb push_back
#define mm0(X) memset((X), 0, sizeof((X)))
#define mm1(X) memset((X), -1, sizeof((X)))
#define INF (int)1e9
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define endl '\n'
#define vcc vector<char>
#define rep(i,a,b) for(int i=a;i<b;i++)

// if you have no idea just guess the appropriate well-known algo instead of doing nothing -- Benq inspiration
const int mod=998244353;
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int powmod(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return powmod(a,mod-2);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

const int N=(int)1e6+6;

void solve(){
    int n,k; cin >> n >> k;
    int p[n]; for(int i=0;i<n;i++) cin >> p[i];
    sort(p,p+n);
    int final=0;
    for(int i=0;i<k;i++) final+=p[i];
    cout<<final<<endl;
}

int32_t main() {
    faster;

#ifndef ONLINE_JUDGE
    READ("input.txt");
    WRITE("output.txt");
    double beg=clock();
#endif

    int t=1;
//    cin>>t;

//    cout<<"hello"<<endl;
    while(t--){
        solve();
    }

#ifndef ONLINE_JUDGE
    double endd=clock();
    cout<<endl;
    cerr<<"*** Total time = "<<(endd-beg)/CLOCKS_PER_SEC;
#endif
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int (i) = (a); (i) < (b); ++(i))
#define per(i, a, b) for (int (i) = (a); (i) >= (b); --(i))
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define ff first
#define ss second
#define sz(x) ((int) x.size())
#define rd(type, ...) type __VA_ARGS__; sc(__VA_ARGS__)
#define rda(a, n) rep(i, 0, n) cin >> a[i];
#define rdaa(a, n, m) rep(i, 0, n) rep(j, 0, m) cin >> a[i][j];
#define rdv(type, v, n) vector<type> v(n); rep(__ii, 0, n) cin >> v[__ii]
#define rdm(type, v, h, w) vector<vector<type>>(h, vector<type>(w)) v; rep(__ii, 0, h) rep(__jj, 0, w) cin >> v[__ii][__jj]
#define rdv2(type, n, ...)std::vector<type> __VA_ARGS__;MACRO_rdv2_Init(n, __VA_ARGS__); for(int w_=0; w_<n; ++w_){MACRO_rdv2_Scan(w_, __VA_ARGS__);}
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "] : ", debug_out(__VA_ARGS__)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
void solve();
signed main() {ios::sync_with_stdio(false); cin.tie(0);
  cout << fixed; cout.precision(20); solve(); return 0;}
template<typename T> void chmin(T &a, T b) {if (a > b) a = b;}
template<typename T> void chmax(T &a, T b) {if (a < b) a = b;}
template<typename T> void MACRO_rdv2_Init(int n, T& t) { t.resize(n); }
template<typename First, typename... Rest> void MACRO_rdv2_Init(int n, First& first, Rest& ...rest) { first.resize(n); MACRO_rdv2_Init(n, rest...); }
template<typename T> void MACRO_rdv2_Scan(int p, T& t) { std::cin >> t[p]; }
template<typename First, typename... Rest> void MACRO_rdv2_Scan(int p, First& first, Rest& ...rest) { std::cin >> first[p]; MACRO_rdv2_Scan(p, rest...); }
template<typename T> void wrv(const vector<T> &v) {rep(__ii, 0, sz(v)) {if (__ii) cout << ' '; cout << v[__ii];} cout << '\n';} 
template<typename T> void wrm(const vector<vector<T>> &v) {rep(__ii, 0, sz(v)) {rep(__jj, 0, v[__ii].size()) {if (__jj) cout << ' '; cout << v[__ii][__jj];} cout << '\n';}}
template<typename T> void sc(T& x) {cin >> x;}
template<typename Head, typename... Tail> void sc(Head& head, Tail&... tail) {cin >> head; sc(tail...);}
template<typename T> void wr(const T& x) {cout << x << '\n';}
template<typename Head, typename... Tail> void wr(const Head& head, const Tail&... tail) {cout << head << ' '; wr(tail...);}
template<typename T> void wrf(const T& x) {cout << x << endl;}
template<typename Head, typename... Tail> void wrf(const Head& head, const Tail&... tail) {cout << head << ' '; wrf(tail...);}
template<typename T> void debug_out(const T& x) {cerr << x << '\n';}
template<typename Head, typename... Tail> void debug_out(const Head& head, const Tail&... tail) {cerr << head << ' '; debug_out(tail...);}
template<typename... T> void err(const T&... cod) {wr(cod...); exit(0);}

void solve() {
  rd(int, n, a, b);
  wr(abs(a - b) % 2 ? "Borys" : "Alice");
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 8080
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;

typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

long long int MOD = 1000000007;
int N,M;
vi G[114514];
int color[114514]={0};
int main(){
	cin>>N;
	for(int i=0;i<N-1;i++){
		int a,b;
		cin>>a>>b;a--;b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	//cout<<"XXX"<<endl;
	queue<pii> hoge1,hoge2;
	hoge1.push(mp(0,0));
	hoge2.push(mp(N-1,0));
	color[0]=1;
	color[N-1]=2;
	int cnt=0;
	while(!hoge1.empty()||!hoge2.empty()){
		while(!hoge1.empty()&&hoge1.front().second==cnt){
			int F=hoge1.front().first;
			//cout<<F<<endl;
			hoge1.pop();
			for(int i=0;i<G[F].size();i++){
				int now=G[F][i];
				//cout<<now<<endl;
				if(color[now]==0){
					color[now]=1;

					hoge1.push(mp(now,cnt+1));
				}
			}
			//cout<<endl;
		}
		while(!hoge2.empty()&&hoge2.front().second==cnt){
			int S=hoge2.front().first;
			hoge2.pop();
			for(int i=0;i<G[S].size();i++){
				int now=G[S][i];
				//cout<<now<<endl;
				if(color[now]==0){
					color[now]=2;
					hoge2.push(mp(now,cnt+1));
				}
			}
		}
		cnt++;
	}
	
	int cntF=0,cntS=0;
	for(int i=0;i<N;i++){
		
		if(color[i]==1)cntF++;
		else cntS++;
	}
	//cout<<cntF<<" "<<cntS<<endl;
	if(cntF>cntS)cout<<"Fennec"<<endl;
	else cout<<"Snuke"<<endl;
}

Measured memory_bytes: 6656
#include<stdio.h>
#include<stdlib.h>
typedef struct list{
  int u, k, *v;
}T_list;
typedef struct graph{
  int d, f;
}T_graph;
int n;
T_list *lst;
T_graph *grp;
//int t;
int que[100];
int p, q;
void bfs(int);
int main(){
  scanf("%d", &n);
  lst = (T_list *)malloc(sizeof(T_list) * n);
  grp = (T_graph *)malloc(sizeof(T_graph) * n);
  int i, j;
  for(i = n - 1; i >= 0; i--)
    grp[i].d = -1;
  for(i = 0; i < n; i++){
    scanf("%d %d", &lst[i].u, &lst[i].k);
    if(lst[i].k){
      lst[i].v = (int *)malloc(sizeof(int) * lst[i].k);
      for(j = 0; j < lst[i].k; j++){
	scanf("%d", &lst[i].v[j]);
	//mat[lst[i].u - 1][lst[i].v[j] - 1] = 1;
      }
      //free(lst[i].v);
    }
  }
  grp[0].d = 0;
  p, q = 0;
  que[q] = 0;
  q++;
  for(p = 0; p < n; p++)
    //if(!grp[que[p]].d)
      bfs(que[p]);
  for(i = 0; i < n; i++){
    if(lst[i].k)
      free(lst[i].v);
    printf("%d %d\n", i + 1, grp[i].d);
  }
  free(grp), free(lst);
  return 0;
}

void bfs(int v){
  //static int t = 0;
  //printf("%d %d %d\n", v + 1, grp[v].d, lst[v].k);
  int i;
  for(i = 0; i < lst[v].k; i++){
    if(!(grp[lst[v].v[i] - 1].d + 1)){
      grp[lst[v].v[i] - 1].d = grp[v].d + 1;
      que[++q] = lst[v].v[i] - 1;
      //printf(" %d\n", lst[v].v[i] - 1);
    }
  }
  //grp[v].f = ++t;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

double dist(pair<double,double>A,pair<double,double>B){
    double x = A.first-B.first;
    double y = A.second-B.second;
    return sqrtl(x*x+y*y);
}

int main(){
    int N;
    cin >> N;
    vector<pair<double,double>> town(N);
    rep(i,N){
        double x,y;
        cin >> x >> y;
        town[i] = make_pair(x,y);
    }
    vector<int> perm(N);
    double fact=1;
    rep(i,N){
        perm[i]=i;
        fact*=(i+1);
    } 
    double sum=0;
    do{
        for(int i=0;i<N-1;i++){
            sum+=dist(town[perm[i]],town[perm[i+1]]);
        }
    }while(next_permutation(perm.begin(),perm.end()));
    double ans = sum/fact;
    
    cout << setprecision(20) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
A = list(input())
B = list(input())
C = list(input())

s = {'a': A, 'b': B, 'c': C}
turn = 'a'
while True:
    D = s[turn]
    if len(D) > 0:   
        turn = D.pop(0)
    else:
        if turn == 'a':
            print('A')
            exit()
        elif turn == 'b':
            print('B')
            exit()
        elif turn == 'c':
            print('C')
            exit()


Measured memory_bytes: 3060
import heapq
n=int(input())
a=[int(input()) for i in range(n)]
b=list(map(lambda x:x*(-1), a))
heapq.heapify(b)
max1=heapq.heappop(b)*(-1)
max2=heapq.heappop(b)*(-1)

for i in range(n):
  if a[i]==max1:print(max2)
  else:print(max1)

Measured memory_bytes: 20536
#include<stdio.h>

int a[1000];
int main(){
	int n, m, b, pos = 0, ans = 0;
	scanf("%d%d", &n, &m);
	if (!(n | m))return 0;
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	for (int i = 0; i < m; i++){
		scanf("%d", &b);
		pos += b;
		if (pos >= n - 1){
			if (!ans)ans = i + 1;
			pos = 0;
		}
		pos += a[pos];
		if (pos >= n - 1 && !ans)
			ans = i + 1;
	}
	printf("%d\n", ans);
	main();
}

Measured memory_bytes: 1032
#include <stdio.h>
#include <limits.h>
int main(void){
  long int len=0,max1=LONG_MIN,min1=LONG_MAX,temp=0;
  int i=0;
  scanf("%ld",&len);
  while(scanf("%ld",&temp)!=EOF){
      if(max1<(temp-min1)){
        max1=temp-min1;
      }
      if(min1>temp){
        min1=temp;
      }
  }
    printf("%ld\n",max1);
}

Measured memory_bytes: 1828
N = int(input())
H = [int(i) for i in input().split()]

ans = "Yes"
for i in range(1, N):
    if H[i] - H[i - 1] < 0:
        ans = "No"
    elif H[i] - H[i - 1] > 0:
        H[i] -= 1
print(ans)


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

int main() {
	int a, b;
	char op;
	for (;;) {
		cin >> a >> op >> b;
		if (op == '+') cout << a + b << endl;
		else if (op == '-') cout << a - b << endl;
		else if (op == '*') cout << a * b << endl;
		else if (op == '/') cout << a / b << endl;
		else break;
	}
}


Measured memory_bytes: 3100
#include <stdio.h>

int main(void) {

    int i, n;
    long long a, min, max, sum;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%lld", &a);
        if (i == 0) {
            min = a;
            max = a;
            sum = a;
        } else {
            if (a < min) {
                min = a;
            }
            if (a > max) {
                max = a;
            }
            sum += a;
        }
    }

    printf("%lld %lld %lld\n", min, max, sum);

    return 0;

}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int ans = 1e9;
  for(int x=-100;x<=100;++x){
    int t = 0;
    rep(i,n) t+=(x-a[i])*(x-a[i]);
    ans = min(ans,t);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
import scala.math._

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val x, a = sc.nextLong

  val ans = if (x < a) 0 else 10

  println(ans)

  ///////////////////////////////////////////

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)
}

Measured memory_bytes: 25796
N,M=map(int,input().split())
edges=[list(map(int,input().split())) for i in range(M)]
ans=0
for x in edges:
    l=list(range(N))
    for y in edges:
        if y!=x:l=[l[y[0]-1] if l[i]==l[y[1]-1] else l[i] for i in range(N)]
    if len(set(l))!=1:ans+=1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n;
ll dfs(ll now) {
	if(now == 1)
	   return 1;
	else
	   return 2 * dfs(now / 2) + 1;
}
int main() {
	cin>>n;
	cout<<dfs(n)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 9223372036854775807;
constexpr auto mod = 1000000007;

ll dp[100001][3];
ll a[100000][3];

int main() {

	int n;
	cin >> n;
	
	FOR(i, n)FOR(j,3)cin >> a[i][j];

	FOR(i, n)FOR(j, 3)FOR(k, 3) {
		if (j != k) {
			dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k]);
		}
	}

	cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;


}

Measured memory_bytes: 4992
#include <stdio.h>
#include <math.h>

int main()
{
  int h, w, k;
  char C[6][6];
  int powh, poww;
  int ans = 0;

  scanf("%d", &h);
  scanf("%d", &w);
  scanf("%d", &k);

  for (int i = 0; i < h; i++)
  {
    scanf("%s", C[i]);
  }
  powh = 1 << h;
  poww = 1 << w;
  for (int i = 0; i < powh; i++)
  {
    for (int j = 0; j < poww; j++)
    {
      int black = 0;
      for (int n = 0; n < h; n++)
      {
        for (int m = 0; m < w; m++)
        {
          if ((i >> n) % 2 && (j >> m) % 2 && C[n][m] == '#')
            black++;
        }
      }
      if (black == k)
      {
        ans++;
        // printf("i = %d, j = %d\n", i, j);
      }
    }
  }

  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 1712
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef long double dd;

int main() {
	int N;
	cin >> N;
	vector<int> H;
	rep(i,N) {
		int h;
		cin >> h;
		h--;
		H.emplace_back(h);
	}
	string ans = "Yes";
	rep(i,N-1) {
		if ((H[i + 1] - H[i])==-1) {
			H[i + 1]++;
		}
		else if ((H[i + 1] - H[i])<-1) {
			ans = "No";
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1020
import numpy as np
from itertools import permutations

N, C = map(int, input().split())
D2d = np.array([list(map(int, input().split())) for _ in range(C)])
c2d = [list(map(int, input().split())) for _ in range(N)]

colors = [np.array([0 for _ in range(C)]) for i in range(3)]
for i in range(N) :
    for j in range(N) :
        colors[(i+j)%3][c2d[i][j]-1] += 1

ans = np.inf
for c0, c1, c2 in permutations(range(C), 3) :
    a = np.sum(D2d[:, c0]*colors[0]\
              +D2d[:, c1]*colors[1]\
              +D2d[:, c2]*colors[2])
    if a < ans :
        ans = a
print(ans)

Measured memory_bytes: 23076
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const LL inf = 1e9;
const int maxn = 55;
int N,K, x[maxn],y[maxn];

bool inside(const int i, const LL X[], const LL Y[])
{ return X[0] <= x[i] && x[i] <= X[1] && Y[0] <= y[i] && y[i] <= Y[1]; }

int main()
{
    while (cin >> N >> K) {
        FOR(i,0,N)
            cin >> x[i] >> y[i];
        LL ans = 2*inf*2*inf;
        /* pick 2 Xs and 2 Ys independently */
        FOR(i,0,N) FOR(j,i+1,N) FOR(k,0,N) FOR(h,k+1,N) {
            LL X[] = { x[i], x[j] };
            LL Y[] = { y[k], y[h] };
            if (X[0] > X[1])
                swap(X[0],X[1]);
            if (Y[0] > Y[1])
                swap(Y[0],Y[1]);
            const LL A = 1LL*(X[1]-X[0])*(Y[1]-Y[0]);
            if (0 < A) {
                int cnt = 0;
                FOR(ii,0,N) 
                    cnt += inside(ii,X,Y);
                if (cnt >= K)
                    ans = min(ans,A);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

int N, A;
int x[50];
long long dp[51][51][2551];

int main() {
  dp[0][0][0] = 1;
  cin >> N >> A;

  int max_sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> x[i];
    max_sum += x[i];
  }

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      for (int k = 0; k < max_sum+1; ++k) {
        dp[i+1][j+1][k+x[i]] += dp[i][j][k];
        dp[i+1][j][k] += dp[i][j][k];
      }
    }
  }

  long long ans = 0;
  for (int i = 1; i < N+1; ++i) {
    if (i*A > max_sum) {
      break;
    }
    ans += dp[N][i][i*A];
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 51072
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
ls = [A,B,C,D,E]

#1の位
A1 = int(str(A)[-1])
B1 = int(str(B)[-1])
C1 = int(str(C)[-1])
D1 = int(str(D)[-1])
E1 = int(str(E)[-1])

flag=0
ls1 = [A1,B1,C1,D1,E1]
if ls1 == [0,0,0,0,0]:
    flag=1
j=0
for i in ls1:
    if i==0:
        ls1[j]=9
    j+=1

j=0
last = min(ls1)
for i in  ls1:
    #print(i)
    if i == last:
        las = j  #最後に注文するやつのindex
    j+=1

k=0
for i in ls:
    for j in range(1,14):
        if i <= j*10:
            ls[k] = j*10
            break
    k+=1

ls[las] -= (10 - last)
#print(ls)
if flag==0:
    print(sum(ls))
else:
    print(sum([A,B,C,D,E]))

Measured memory_bytes: 38256
#include<stdio.h>
int dp[50][3001];
int main(){
	int n,m,s;
	int i,j,k;
	while(1){
	scanf("%d %d %d",&n,&m,&s);
	if(n==0)return 0;
	for(i=0;i<=n*n;i++)for(j=0;j<=s;j++)dp[i][j]=0;
	dp[0][0]=1;
	for(i=1;i<=m;i++){
		for(j=s;j>=0;j--){
			if(j+i<=s){
				for(k=0;k<n*n;k++){
					dp[k+1][j+i]=(dp[k+1][j+i]+dp[k][j])%100000;
				}
			}
		}
	}
	printf("%d\n",dp[n*n][s]);
	}
}

Measured memory_bytes: 1608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll n, k; cin >> n >> k;
    vector <ll> a(n);
    for(ll i = 0; i < n; i++) cin >> a[i];

    if(k >= n) {
        cout << 0;
        return 0;
    }

    sort(a.begin(), a.end());
    ll sum = 0;
    for(int i = 0; i < n - k; i++) {
        sum += a[i];
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 1792
n, k = map(int, input().split())
a = list(map(int, input().split()))

def check(x):
  c = 0
  for i in range(n):
    c += a[i]//x
    if a[i]%x == 0:
      c -= 1
  if c <= k:
    return True
  else:
    return False

mx = max(a)
mn = 0
ans = [mx]
while mn <= mx:
  m = (mx+mn)//2
  if m == 0:
    if check(1):
      ans.append(1)
    break
  if check(m):
    mx = m - 1
    ans.append(m)
  else:
    mn = m + 1
print (min(ans))


Measured memory_bytes: 30704
#include <iostream>
#include <vector>
#include <queue>
#include <cstdlib>

using namespace std;

int H,W;
vector<string> grid;

void Wcheck(int h,vector<vector<int>>& ans)
{
	int i,startpos,count ;
	i = 0;
	while(i < W){
		if(grid[h][i] == '.'){
			startpos = i;
			count = 1;
			i++;
			while(i < W && grid[h][i] == '.'){
				i++ ;
				count++;
			}
			for(int a = 0; a < count; a++){
				int pos = startpos + a;
				ans[h][pos] += count ;
			}
		}
		i++ ;
	}
}
void Hcheck(int w, vector<vector<int>>& ans)
{
	int i,startpos,count ;
	i = 0;
	while(i < H){
		if(grid[i][w] == '.'){
			startpos = i;
			count = 1;

			i++;
			while(i < H && grid[i][w] == '.'){
				i++ ;
				count++;
			}
			for(int a = 0; a < count; a++){
				int pos = startpos + a;
				ans[pos][w] += count ;
			}
		}
		i++;
	}
}

int main()
{
	cin >> H >> W;
	for(int i = 0; i < H; i++){
		string s ;
		cin >> s;
		grid.push_back(s);
	}

	vector<vector<int>> ans(H, vector<int>(W));
	for(int h = 0; h < H; h++){
		for(int w = 0; w < W; w++){
			ans[h][w] = 0;
		}
	}

	for(int h = 0; h < H; h++){
		Wcheck(h,ans) ;
	}
	for(int w = 0; w < W; w++){
		Hcheck(w,ans) ;
	}
	int maxans = 0 ;
	for(int h = 0; h < H; h++){
		for(int w = 0; w < W; w++){
			maxans= max(maxans,ans[h][w]);
		}
	}
	if(maxans > 0)
	{
		maxans -= 1 ;
	}
	cout << maxans << endl;
}


Measured memory_bytes: 22144
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String S = sc.next();
        String T = sc.next();

        System.out.println(solve(S, T) ? "Yes" : "No");

        sc.close();
    }

    static boolean solve(String S, String T) {
        Map<Character, Character> mapping = new HashMap<>();
        Set<Character> tos = new HashSet<>();
        for (int i = 0; i < S.length(); ++i) {
            char from = S.charAt(i);
            char to = T.charAt(i);

            if (mapping.containsKey(from)) {
                if (to != mapping.get(from)) {
                    return false;
                }
            } else {
                if (tos.contains(to)) {
                    return false;
                }

                mapping.put(from, to);
                tos.add(to);
            }
        }

        return true;
    }
}

Measured memory_bytes: 41520
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        
        if( n <= a || n % 500 == 0 || n % 500 <= a ){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


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

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..m)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let sum: usize = a.iter().sum();
    if sum > n {
        println!("-1",)
    } else {
        println!("{}", n - sum)
    }
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> l(N);
    for(int i = 0; i < N; i++){
        cin >> l.at(i);
    }
    sort(l.begin(), l.end());
    reverse(l.begin(), l.end());
    int answer = 0;
    for(int i = 0; i < K; i++){
        answer += l.at(i);
    }
    cout << answer << endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(100000000)

stp = -1 
def main():
    n, k = map(int, readline().split())
    a = [int(i)-1 for i in readline().split()]

    order = []
    ex = set()
    def dfs(node):
        global stp
        order.append(node)
        ex.add(node)
        nx = a[node]
        if nx in ex:
            stp = nx
            return
        dfs(nx)
    dfs(0)

    cnt = order.index(stp)
    if k < cnt:
        print(order[k]+1)
    else:    
        m = len(order[cnt:])
        idx = (k-cnt)%m
        print(order[cnt:][idx]+1)
if __name__ == '__main__':
    main()


Measured memory_bytes: 262904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
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;
}

int N;
vector<vector<int>> G(100000);

void dfs(int n,vector<int> &count){
    if (G[n].size()==0){
        count[n]=0;
        return;
    }
    if (G[n].size()==1){
      	dfs(G[n][0],count);
        count[n]=count[G[n][0]]+1;
        return;
    }
    priority_queue<int> pq1,pq2;
    for(auto x:G[n]){
        dfs(x,count);
        pq1.push(count[x]);
    }
    int i=1;
    while(!pq1.empty()){
        int x=pq1.top();
        pq1.pop();
        pq2.push(x+i);
        i++;
    }
    count[n]=pq2.top();
    return;
}

int main(){
    cin >> N;
    rep(i,N-1){
        int a;
        cin >> a;
        a--;
        G[a].push_back(i+1);
    }
    vector<int> count(N);
    dfs(0,count);
    cout << count[0] << endl;
}

Measured memory_bytes: 18560
N=int(input())
vo=[]
flag=True
for i in range(N):
    vo.append(input())
    
if len(vo) != len(set(vo)):
    flag=False
    
for i in range(N-1):
    a=vo[i]
    b=vo[i+1]  
    if a[len(a)-1] != b[0]:
        flag=False
        
if not flag:
    print("No")
else:
    print("Yes")

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    int H,W;
    cin >> H >> W;

    vector<string> s(H);
    rep(i,H) cin >> s[i];

    rep(i,H)
    {
        rep(j,W)
        {
            bool flag = false;
            if( s[i][j] != '#' ) continue;
            if( i != 0 )
            {
                if( s[i-1][j] == '#' ) flag = true;
            }
            if( i != H-1 )
            {
                if( s[i+1][j] == '#' ) flag = true;
            }
            if( j != 0 )
            {
                if( s[i][j-1] == '#' ) flag = true;
            }
            if( j != W-1 )
            {
                if( s[i][j+1] == '#' ) flag = true;
            }
            if( !flag )
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256