akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <list>
//#include <unordered_map>
//#include <unordered_set>
#include <ctime>

using namespace std;

typedef long long			LL;
typedef long double			LD;
typedef unsigned long long	ULL;
typedef unsigned int		UI;
typedef unsigned short		US;

//#define FILE
#define fr			first
#define sc			second
#define mp			make_pair
#define pb			push_back
#define all(x)		(x).begin(), (x).end()
#define sz(x)		LL((x).size())
#define F(i,a,b)	for (int i = a; i < b; i++)
#define R(i,a,b)	for (int i = a - 1; i >= b; i--)

const UI		N = 200005;
const LL		Mod = 1000000007;
const LL		INF = 1000000000;
const LL		INF64 = 1000000000000000000;
const LD		PI = acos(-1.0);
const LD		E = 2.7182818284590452353602874713527;
const UI		dir = 4;
const int		prime = 31;

LL gcd(LL a, LL b) { return a != 0 ? gcd(b%a, a) : b; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
LL length(LL n) { return n < 10 ? 1 : 1 + length(n / 10); }

LL n, k, a[N];
LL counts[64];

void input()
{
	cin >> n >> k;
	F(i, 0, n)
		cin >> a[i];
}

void solve()
{
	for (int i = 0; i < 60; i++) {
		for (int j = 0; j < n; j++) {
			if (a[j] & (1LL << i)) {
				counts[i]++;
			}
		}
	}

	LL X = 0;
	bool started = false;
	for (LL i = 59; i >= 0; i--) {
		if (counts[i] > 0)
			started = true;
		if ((1LL << i) > k)
			continue;
		
		if (!started) {
			X += (k & (1LL << i));
			continue;
		}

		if (counts[i] <= n - counts[i]) {
			X |= (1LL << i);
			if (X > k) {
				X ^= (1LL << i);
			}
		}
	}

	LL ans = 0;
	F(i, 0, n) {
		ans += X ^ a[i];
	}
	cout << ans << endl;
}	

int main()
{

#ifdef FILE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int testcases = 1;
	// cin >> testcases;
	while (testcases--) {
		input();
		//clock_t start = clock();
		solve();
		//printf("---------------------\n%.5f seconds\n---------------------\n", (clock() - start + 0.) / CLOCKS_PER_SEC);
	}

	return 0;
}

Measured memory_bytes: 1024
N,Ma,Mb=map(int, input().split())
A = []
B = []
C = []
for i in range(N):
  a,b,c=map(int, input().split())
  A.append(a)
  B.append(b)
  C.append(c)
sa = sum(A)
sb = sum(B)

dp = [[[10000]*(sb+1) for _ in range(sa+1)] for _ in range(N+1)]
dp[0][0][0] = 0

ta = 0
tb = 0
for i in range(N):
  a = A[i]
  b = B[i]
  for j in range(sa):
    for k in range(sb):
      if j - a >= 0 and k - b >= 0:
        dp[i+1][j][k] = min(dp[i][j-a][k-b]+C[i], dp[i][j][k])
      else:
        dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])

ans = 10000
for i in range(1, sa+1):
  for j in range(1, sb+1):
    if Ma * j == Mb * i:
      ans = min(ans, dp[N][i][j])
if ans == 10000:
  ans = -1
print(ans)

Measured memory_bytes: 30956
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[100010],n;
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
	int ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]&&a[i-1])a[i]--,ans++;
		ans+=(a[i]>>1);
		a[i]&=1;
	}
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4392
from collections import deque

N = int(input())
dic = {i + 1:[] for i in range(N)}
color = [-1 for i in range(N + 1)]

for i in range(N - 1):
    f, t, d = map(int, input().split())
    dic[f].append((t, d & 1)) #奇数だったら1
    dic[t].append((f, d & 1))

q = deque()
q.append(1)
color[1] = 0
while len(q) > 0:
    v = q.popleft()
    for t in dic[v]:
        if not color[t[0]] == -1:
            continue
        color[t[0]] = 1 - color[v] if t[1] == 1 else color[v]
        q.append(t[0])

for c in color[1:]:
    print(c)


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

int main()
{
  int n,m;
  int M[100][100],b[100],bond[100]={};
  cin>>n>>m;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin>>M[i][j];
    }
  }
  for(int i=0;i<m;i++)cin>>b[i];
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      bond[i]+=M[i][j]*b[j];
    }
  }
  for(int i=0;i<n;i++)cout<<bond[i]<<endl;
  return 0;
}



Measured memory_bytes: 3148
#include <stdio.h>

int main(void)
{
	int A[100][100];
	int b[100];
	int c,i,j,n,m;
	scanf("%d %d",&n,&m);
	
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&A[i][j]);
		}
	}
	for(i=0;i<m;i++){
		scanf("%d",&b[i]);
	}
	
	for(i=0;i<n;i++){
		c=0;
		for(j=0;j<m;j++){
			c+=A[i][j]*b[j];
		}
		printf("%d\n",c);
	}
	
	return 0;
}




Measured memory_bytes: 2036
#include <stdio.h>


int main() {
	int i, n;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		int x = i;
		if (x % 3 == 0) printf(" %d", i);
		else {
			while (x) {
				if (x % 10 == 3) {
					printf(" %d", i);
						break;
				}
				x /= 10;
			}
		}
	}
	printf("\n");
}


Measured memory_bytes: 1928
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.length();
  REP(i, n) { cout << "x"; }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        long A = sc.nextLong();
        String strB = sc.next();

        int B_100 = Integer.parseInt(strB.replace(".", ""));

        long tmp = A*B_100;
        System.err.println(tmp);

        String tmpStr = Long.toString(tmp);
        int length = tmpStr.length();

        String result;
        if(length >= 3) {
            result = tmpStr.substring(0, length-2);
        }else {
            result = "0";
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 35744
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#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 rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

ll dp[14][2];

int main(){
  ll n,k; cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  int mxi=0;
  ll K=k;
  while(K>0){
    K/=2;
    mxi++;
  }mxi--;
  ll ans=0;
  bool miman=0;
  for(int i=mxi;i>=0;i--){
    int cnt1=0;
    rep(j,n){
      if((1ll<<i)&a[j]) cnt1++;
    }
    if(cnt1<n-cnt1&&((k&(1ll<<i))||miman)){
      ans+=(1ll<<i)*(n-cnt1);
    }
    else if(cnt1>=n-cnt1&&(k&(1ll<<i))){
      miman=1;
      ans+=(1ll<<i)*cnt1;
    }
    else{
      ans+=(1ll<<i)*cnt1;
    }
  }
  rep(j,n){
    for(int i=mxi+1;i<=40;i++){
      ans+=a[j]&(1ll<<i);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4056
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	int r,g,b,n;
	cin>>r>>g>>b>>n;

	int ans=0;
	for(int i=0;i*r<=n;i++){
		for(int j=0;j*g<=n;j++){

			int sum=i*r+j*g;
			if(sum<=n&&(n-sum)%b==0)ans++;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}


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

int main()
{
    int64_t N, A, B;
    cin >> N >> A >> B;

    //int syou = 0;
    //int amari = 0;
    //int ans = 0;
    /*if (A == 0)
    {
        cout << 0 << endl;
    }
    else
    {
        amari = N % (A + B);
        syou = N / (A + B);
        if (amari > A)
        {
            ans = syou*A + A;
            cout << ans << endl;
        }
        else if(amari <= A)
        {
            ans = syou*A + amari;
            cout << ans << endl;
        }*/

        int64_t ans = (N/(A + B))*A;
        ans += min(N%(A+B), A);
        cout << ans << endl;
    //}
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int i, D, a[] = {21, 17, 13, 9};
    char *t = "Christmas Eve Eve Eve";
    scanf("%d", &D);
    for (i = 0; i < a[D - 22]; i++) {
        printf("%c", t[i]);
    }
    printf("\n");
    return 0;
}


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

//cmdで g++ test.cpp とするとコンパイルできる

int main() {
  int N;
  cin>>N;
  vector<int> a(N*3);
  for(int i=0;i<N*3;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  long ans=0;
  for(int i=0;i<N;i++){
    ans+=a.at(i*2+1);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<par<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

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

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    double ans=0;
    rep(i,n){
        double x;
        string u;
        cin>>x>>u;
        if(u=="JPY")ans+=x;
        else ans+=x*380000.0;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

const int maxn = 1e5 + 5;

int a[maxn];

int main()
{
	int n;
	scanf("%d",&n);
	int four = 0;
	int two = 0;
	int one = 0;
	for(int i=1;i<=n;i++)
	{
		cin >> a[i];
		if(a[i] % 4 == 0)
			four++;
		else if(a[i] % 2 == 0)
			two++;
		else
			one++;
	}
	
	if(one > four + 1|| (one == four + 1 && two != 0))
		cout << "No" << endl;
	else
		cout << "Yes" << endl; 
	return 0;
}

Measured memory_bytes: 640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class ACantWaitForHoliday {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        string S;
        in>>S;
        if(S=="SUN") out<<7<<'\n';
        else if(S=="MON") out<<6<<'\n';
        else if(S=="TUE") out<<5<<'\n';
        else if(S=="WED") out<<4<<'\n';
        else if(S=="THU") out<<3<<'\n';
        else if(S=="FRI") out<<2<<'\n';
        else out<<1<<'\n';
    }
};


int main() {
	ACantWaitForHoliday solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3648
n = gets.to_i
edges = gets.split(' ').map(&:to_i).sort

count = 0

(0..n-3).each do |i_a|
  a = edges[i_a]
  (i_a+1..n-2).each do |i_b|
    b = edges[i_b]

    rests = edges[i_b+1..n-1]
    rests_count = n - i_b - 1
    ng_index = rests.bsearch_index{ |c| c >= a + b }
    
    ok_edges_size = ng_index || rests_count
    count += ok_edges_size
  end
end

puts count

Measured memory_bytes: 1912
import java.util.Arrays;
    import java.util.Scanner;
     
    public class Main {
     
    static Scanner sc = new Scanner(System.in);
    static int N, M;
    static Prof[] p;
     
    static void solve() {
    final int INF = 1 << 30;
    int[] dp = new int[N + 1];
    Arrays.fill(dp, INF);
    dp[0] = 0;
    Arrays.sort(p);
    for (int i = 0; i < M; ++i) {
    if (dp[p[i].a - 1] == INF) {
    System.out.println("Impossible");
    return;
    }
    int count = INF;
    for (int j = p[i].a - 1; j <= p[i].b; ++j) {
    count = Math.min(dp[j], count);
    }
    for (int j = p[i].a; j <= p[i].b; ++j) {
    dp[j] = Math.min(dp[j], count + 1);
    }
    }
    System.out.println(dp[N] == INF ? "Impossible" : dp[N]);
    }
     
    static class Prof implements Comparable<Prof> {
    int a, b;
     
    Prof(int a, int b) {
    this.a = a;
    this.b = b;
    }
     
    public int compareTo(Prof o) {
    return this.a - o.a;
    }
    }
     
    public static void main(String[] args) {
    N = sc.nextInt();
    M = sc.nextInt();
    p = new Prof[M];
    for (int i = 0; i < M; ++i) {
    int a = sc.nextInt();
    int b = sc.nextInt();
    p[i] = new Prof(a, b);
    }
    solve();
    }
    }

Measured memory_bytes: 12000
#include <stdio.h>

#define rep(i, n) for(i = 0; i < n; ++i)
#define repf(i, f, l) for(i = f; i < l; ++i)

char fld[1001][1001];
int J[1001][1001];
int O[1001][1001];

int main(void){
    int m, n, k;
    register int i, j;
    scanf("%d%d%d", &m, &n, &k);
    getchar();
    rep(i, m){
        rep(j, n) fld[i][j] = getchar();
        getchar();
    }
    n++; m++;

#define FOR_EACH(F) {F(J, 'J'); F(O, 'O');}
#define PSUM(ARR, SYM)                        \
    repf(i, 1, m){                        \
        register int __c = 0;                          \
        repf(j, 1, n){                    \
            if(fld[i-1][j-1] == SYM) __c++;   \
            ARR[i][j] = ARR[i - 1][j] + __c;  \
        }                                     \
    }                                         
    FOR_EACH(PSUM);

    while(k --> 0){
        int a, b, c, d, jsum, osum;
        scanf("%d%d%d%d", &a, &b, &c, &d);
        a--; b--;
        jsum = J[c][d] - J[c][b] - J[a][d] + J[a][b];
        osum = O[c][d] - O[c][b] - O[a][d] + O[a][b];
        printf("%d %d %d\n", jsum, osum, (c - a) * (d - b) - jsum - osum);
    }

    return 0;
}

Measured memory_bytes: 9368
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {

    string s; cin >> s;

    if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a;
    cin>>a;
    string A,B;
    cin>>A;
    B=A;
    int ans=0;
    if(A.size()<B.size())swap(A,B);
    for(int i=-(int)(B.size())+1;i<(int)A.size();i++){
        int cou=0;
        //printf("[%d]\n",i);
        for(int j=0;j<B.size();j++){
            if(0<=i+j&&i+j<A.size()){
                //printf("[%c][%c]\n",A[i+j],B[j]);
                if(A[i+j]==B[j])cou++;
                else cou=0;
                int pe=0;;
                pe=i;
                if(pe<0)pe*=-1;
                ans=max(ans,min(pe,cou));
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;

int main() {
  int N,W;
  cin >>N>>W;
  rep(i,N){
   vector<char> A(W);
    rep(j,W) in(A[j]);
    rep(j,W) cout << A[j];
    cout <<endl;
    rep(j,W) cout << A[j];
    cout <<endl;
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        Queue<Integer> queue = new PriorityQueue<>( (s1, s2) -> (s2 - 1) % 10 - (s1 - 1) % 10 );
        
        for(int i = 0; i < 5; i++){
            queue.add(sc.nextInt());
        }

        int totalTime = 0;
        for(int i = 0; i < 5; i++){
            int x = queue.poll();
            if( i != 4 ) x = (((x - 1) / 10) + 1) * 10;
            totalTime += x;
        }
        
        System.out.println(totalTime);
    }
}


Measured memory_bytes: 27988
s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0]*(m+1) for _ in range(n+1)]
for i in range(1,n+1):
    for j in range(1,m+1):
        if s[i-1]==t[j-1]:
            if i>0 and j>0:
                dp[i][j]=dp[i-1][j-1]+1
        else:
            if i>0:
                dp[i][j]=max(dp[i][j],dp[i-1][j])
            if j>0:
                dp[i][j]=max(dp[i][j],dp[i][j-1])
leng=dp[n][m]
i,j=n,m
ans=""
while leng>0:
    if s[i-1]==t[j-1]:
        ans+=s[i-1]
        i-=1
        j-=1
        leng-=1
    else:
        if dp[i-1][j]==dp[i][j]:
            i-=1
        elif dp[i][j-1]==dp[i][j]:
            j-=1
print(ans[::-1])

Measured memory_bytes: 144588
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long n,ans=0,a=0,i=1;
    cin >> n;
    while (i<(n-i)/i){
        if ((n-i)%i==0) ans=ans+(n-i)/i;
        i++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int c, f, l;
char a[10001];
int main()
{
	c = 0xffff, f = -1;
	scanf("%s", &a);
	l = strlen(a);
	for(int i = 0; i < l; i++)
	{
		if (a[i] == 'F') 
		{
			f = i;
			if (c < f) 
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
		if (a[i] == 'C') c = i;
		
		
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int sum(long long int number_n) {
  if(number_n < 10) {
    return number_n;
  } else {
    return (number_n % 10) + sum(number_n / 10);
  }
}

int main() {
  int sum_number;
  long long int number_n;
  scanf("%lld", &number_n);
  sum_number = sum(number_n);
  if(number_n % sum_number == 0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
//#include<iostream>
using namespace std;

#define LL long long
int n,m;
#define maxn 200011
struct event
{
	int t,a,id;
	bool operator < (const event &b) const {return t<b.t;}
}e[maxn];int le=0;
LL X,ans[maxn];
int main()
{
	scanf("%lld%d",&X,&n);
	for (int i=1;i<=n;i++) le++,scanf("%d",&e[le].t),e[le].id=e[le].a=0;
	scanf("%d",&m);
	for (int i=1;i<=m;i++) le++,scanf("%d%d",&e[le].t,&e[le].a),e[le].id=i;
	sort(e+1,e+1+le);
//	for (int i=1;i<=le;i++) cout<<e[i].t<<' '<<e[i].a<<' '<<e[i].id<<endl;
	LL Min=0,Max=X,pre=0;
	for (int i=1,sig=-1,last=0;i<=le;i++)
	{
		LL now=(e[i].t-last)*sig;
		if (e[i].id)
		{
			LL v=e[i].a+pre;
			if (v<Min) v=Min;
			if (v>Max) v=Max;
			v+=now;
			if (v<0) v=0;
			if (v>X) v=X;
			ans[e[i].id]=v;
		}
		else
		{
			Min+=now;Max+=now;
			if (Min<0) Min=0;if (Max<0) Max=0;
			if (Min>X) Min=X;if (Max>X) Max=X;
			pre+=now;sig*=-1;last=e[i].t;
		}
	}
	for (int i=1;i<=m;i++) printf("%lld\n",ans[i]);
	return 0;
}

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

void f(int k, vector<ll>& v, queue<ll>& q) {
  if (v.size() == k)
    return;
  ll x = q.front(), y = q.front() % 10;
  q.pop();
  v.push_back(x);
  x *= 10;
  if (y > 0 && abs(y - (y - 1)) <= 1)
    q.push(x + y - 1);
  q.push(x + y);
  if (y < 9 && abs(y - (y + 1)) <= 1)
    q.push(x + y + 1);
  f(k, v, q);
}

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

  vector<ll> v;
  queue<ll> q;
  for (ll i = 1; i < 10; ++i)
    q.push(i);
  f(k, v, q);

  sort(v.begin(), v.end());

  cout << v.back() << endl;
}

Measured memory_bytes: 8820
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

def max(a,b)
  return a[0]>b[0] ? a : b
end

def fulfil?(x,h,a,b,n)
  s=0
  n.times do|i|
    if (h[i]-x*b)>0
      s+=((h[i]-x*b).to_f/(a-b).to_f).ceil
    end
  end 
  return s<=x
end
n,a,b=get_i
h=array(n,1)
n.times do|i|
  h[i]=gets.to_i
end
head=0
tail=10**10
while tail-head>1
  mid=(tail+head)/2
  if fulfil?(mid,h,a,b,n)
    tail=mid
    else
      head=mid
  end
end
puts tail

Measured memory_bytes: 2940
#include <iostream>
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

int main(){
string S;	
  cin >> S;
//入力終了
  
  int N = S.size();
  
  //出現したかどうか(falseで初期化)
  bool appeared[26];
  rep(i, 26)
    appeared[i] = false;
  
  for(int i=0; i<S.size(); i++){
    int num = S[i]-'a';
    //既に出現していればnoで終了
	if(appeared[num] == true){
		cout << "no" << endl;
  		return 0;
  	}
    //出現済みにする
    appeared[num] = true;
  }
  
  cout << "yes" << endl;

return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD=1e9+7ll;
int n,a,b,ans;

inline int pow(int a,int n)
{
	int res=1ll;
	while (n)
	{
		if (n&1ll) res=res*a%MOD;
		a=a*a%MOD;
		n>>=1ll;
	}
	return res%MOD;
}

inline int C(int n,int m)
{
	if (n<m) return 0ll;
	if (n==m || !m) return 1ll;
	if (m<n-m) m=n-m;
	int a=1ll;
	for (register int i=m+1; i<=n; ++i) a=a*i%MOD;
	int b=1ll;
	for (register int i=1; i<=n-m; ++i) b=b*i%MOD;
	return a*pow(b,MOD-2ll)%MOD;
}

signed main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	ans=((pow(2ll,n)-C(n,a)-C(n,b)-1ll)%MOD+MOD)%MOD;
	printf("%lld\n",ans);
return 0;	
}

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

int main() {
    int N,a,b,c;
    cin >> N;

    c = N % 10;
    b = (N/10)%10;
    a = (N/10)/10;

    if (a == 7 || b == 7 || c == 7){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define ll long long
using namespace std;

int main()
{
	int n;
	string test;
	cin >> n >> test;
	int ans = 0;
	char pre = 0;

	for (int i = 0; i < n; i++) {
		if (pre == 0 || pre != test[i]) {
			ans++;
			pre = test[i];
		} 
	}

	printf("%d", ans);

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef int64_t lint;
const int mod = 1000000007;
struct mint {
	lint x;
	mint(lint x=0):x((x%mod+mod)%mod){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
	mint operator+(const mint a) const { return mint(*this) += a;}
	mint operator-(const mint a) const { return mint(*this) -= a;}
	mint operator*(const mint a) const { return mint(*this) *= a;}
	mint pow(lint t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}
	mint inv() const { return pow(mod-2);}
	mint& operator/=(const mint a) { return *this *= a.inv();}
	mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
	int N;
	cin >> N;
	vector<mint> v(N);
	mint a=0, b=0, c=0, x, y, z;
	rep(i, N) {
		cin >> v.at(i);
		a += v.at(i);
	}

	rep(i, N-1) {
		a -= v.at(i);
		b += v.at(i) * a;
	}
	std::cout << b << '\n';
}


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 0
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 100010

ll N, L;
vector<string> S;

ll ans = 0;

// val を割り切る最大の 2 べきを求める
ll grundy[MAX_N] = {};
ll GetGrundy(ll val) {
    if(val < MAX_N && grundy[val] != -1) { return grundy[val]; }
    ll cand = 1;
    ll ret = 1;
    while(val >= cand) {
        if(val % cand == 0) { ret = cand; }
        cand *= 2;
    }
    return ret;
}

// トライ木
class Trie {
    public:
        // トライ木のノード
        struct TrieNode {
            ll depth;   // 深さ
            TrieNode* next[2];    // char 1 文字全パターン分のポインタを用意
            TrieNode() {
                fill(next, next+2, nullptr);
                depth = 0;
            }
        };

        Trie() { root = new TrieNode; }

        // seal を true にする
        void Seal(const string& s, TrieNode* r) {
            for (ll i = 0; i < s.length(); ++i) {
                r->depth = i+1;
                ll c = (s[i] == '0') ? 0 : 1;
                if(!r->next[c]) {
                    r->next[c] = new TrieNode;
                    r->next[c]->depth = r->depth + 1;
                }
                r = r->next[c];
            }
        }
        void Seal(const string& s) { return Seal(s, root); }

        // 自分の子ノード 2 つのうち、片方しかないものの高さを vector に入れる
        void Check(TrieNode* n) {
            if(!n->next[0] && !n->next[1]) { return; }
            if((n->next[0] && !n->next[1]) || (!n->next[0] && n->next[1])) {
                ans ^= GetGrundy(L + 1 - n->depth);
            }
            for(ll i = 0; i < 2; ++i) {
                if(n->next[i]) { Check(n->next[i]); }
            }
        }
        void Check() { Check(root); }

    public:
        TrieNode* root; // トライ木の根
};

signed main()
{
    cin >> N >> L;

    REP(i, N) {
        string s;
        cin >> s;
        S.push_back(s);
    }

    MINUS(grundy);

    // 入力文字列からトライを作成
    Trie t;
    REP(i, N) {
        // S の文字列が通過する部分は封鎖
        t.Seal(S[i]);
    }

    // 独立した完全二分木それぞれの高さを求める
    t.Check();

    if(ans == 0) { printf("Bob\n"); }
    else { printf("Alice\n"); }

    return 0;
}


Measured memory_bytes: 6016
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	string o, e;
	cin >> o >> e;
	string ans;
	rep(i, 0, e.size()) {
		ans += o[i];
		ans += e[i];
	}
	if (o.size() - e.size() == 1) {
		ans += o[o.size() - 1];
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

string LCS(string s, string t) {

    vector<vector<int>> dp(s.size() + 1, vector<int> (t.size() + 1));
    for (int i = 0; i < s.size(); i++){
        for (int j = 0; j < t.size(); j++){
            if (s.at(i) == t.at(j)){
                dp.at(i + 1).at(j + 1) = dp.at(i).at(j) + 1;
            }
            else {
                if (dp.at(i + 1).at(j) > dp.at(i).at(j + 1)){
                    dp.at(i + 1).at(j + 1) = dp.at(i + 1).at(j);
                }
                else {
                    dp.at(i + 1).at(j + 1) = dp.at(i).at(j + 1);
                }
            }
        }
    }
    string ans = "";
    int i = s.size(), j = t.size();
    while (i != 0 || j != 0){
        if (i - 1 >= 0 && j - 1 >= 0 && dp.at(i).at(j) == dp.at(i - 1).at(j - 1) + 1 && s.at(i - 1) == t.at(j - 1)){
            i--;
            j--;
            ans += s.at(i);
        }
        else if (i - 1 >= 0 && dp.at(i).at(j) == dp.at(i - 1).at(j)){
            i--;
        }
        else if (j - 1 >= 0 && dp.at(i).at(j) == dp.at(i).at(j - 1)){
            j--;
        }
    }
    reverse(ALL(ans));
    return ans;
}

int main() {
    string s, t;
    cin >> s >> t;
    cout << LCS(s, t) << endl;
}


Measured memory_bytes: 35584
#include<bits/stdc++.h>
using namespace std;
struct shout{
	int begin,end;
};
shout a[100001];
int cmp(shout x,shout y)
{
	if(x.end!=y.end)
	{
		return x.end<y.end;
	}
	else
	{
		return x.begin<y.begin;
	}
}

int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>a[i].begin>>a[i].end;
		a[i].end--;
	} 
	sort(a+1,a+m+1,cmp);
	int s[n];
	int j=1;
	memset(s,0,sizeof(s));
	for(int i=1;i<=n-1;i++)
	{
		s[i]=s[i-1];	
		while(a[j].end==i)
		{
			if(i==a[j].end&&(s[a[j].end]==s[a[j].begin-1]))
			{
				s[i]++;
			}
			j++;
		}
	}
	cout<<s[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    int L[N];
    rep(i, N) cin >> L[i];
    sort(L, L+N);
    int sum = 0;
    rep(i, N-1) sum += L[i];
    if(sum > L[N-1]) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
import bisect

S = list(input())
T = list(input())

s_dic = {}
for i,s in enumerate(S):
    if s not in s_dic.keys():
        s_dic[s] = [i]
    else:
        s_dic[s].append(i)

def main():
    pre, n_repeat = -1, 0
    cur = -1
    for t in T:
        if t not in s_dic.keys():
            return -1
        i = bisect.bisect_right(s_dic[t], cur)
        if i >= len(s_dic[t]):
            cur = s_dic[t][0]
            n_repeat += 1
        else:
            cur = s_dic[t][i]
            if cur <= pre:
                n_repeat += 1
        pre = cur
            
    return n_repeat * len(S) + cur + 1

print(main())

Measured memory_bytes: 9052
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define MOD 998244353
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int tower = 0;
    for (int i = 1; i <= b - a; i++) {
        tower += i;
    }
    cout << tower - b << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iomanip>
using namespace std;
int main(){
	int N,K,sum=0;
	cin >> N >> K;
	int x[N];
	for(int i=0;i<N;i++){
		cin >> x[i];
	}
	for(int j=0;j<N;j++){
		sum=sum+min(2*x[j],2*(K-x[j]));
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, K, T, W, H, M, C;

const int MAX = 5100000;
const int MOD = 1e9 + 7;

const double PI=3.14159265358979323846;


long long fac[MAX], finv[MAX], inv[MAX];

vector<double> cx, cy, c;
 ll MM = 1e12;

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

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

std::vector<int> Eratosthenes(int n ){
    std::vector<bool> is_prime( n + 1 );
    for( int i = 0; i <= n; i++ ) is_prime[ i ] = true;
    std::vector<int> P;
    for( int i = 2; i <= n; i++ ){
        if( is_prime[ i ] ){
            for( int j = 2 * i; j <= n; j += i ){
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}


int main(){
    cin >> N;
    vector<int> v(N+1, 0), ans(N+1, 0);
    for (int i = 1; i <= N; ++i) cin >> v[i];

    for(int i = N; i > 0; --i){
        ll cnt = 0;
        for(int j = 2 * i; j <= N; j += i){
            cnt +=ans[j];
        }
        if(cnt%2 != v[i]) ans[i] = 1;
    }

    cout << accumulate(ALL(ans), 0) << "\n";

    REP(i,N + 1){
        if(ans[i] == 1) cout << i << " ";
    }
    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const int INF = 1 << 29;
const ll LINF = 1l << 61;
const ld PI = abs(acos(-1));
#define pq priotity_queue
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define cbuf(buf, init) memset(buf, init, sizeof(buf))

template <class T>
constexpr T modp(T x, T y)
{
    return (y + x % y) % y;
}
template <class T>
constexpr T sq(T x)
{
    return x * x;
}
template <class T>
constexpr double divd(T x, T y)
{
    static_cast<double>(x) / static_cast<double>(y);
}

template <class T>
T nextInput()
{
    T t;
    cin >> t;
    return t;
}

#define netint nextInput<ll>()
#define netstr nextInput<string>()

template <class T>
void print(T&& t)
{
    cout << forward<T&&>(t) << endl;
}

void print(double t) { cout << fixed << setprecision(14) << t << endl; }

//

ll a[200], b[200], c[200], d[200];
pair<ll, ll> ab[200], cd[200];
bool flag[200];

int main()
{
    //
    ll N = netint;
    rep(i, 0, N)
    {
        a[i] = netint;
        b[i] = netint;
        ab[i] = mp(a[i], b[i]);
    }
    rep(i, 0, N)
    {
        c[i] = netint;
        d[i] = netint;
        cd[i] = mp(c[i], d[i]);
    }
    sort(ab, ab + N);
    sort(cd, cd + N);

    ll cnt = 0;
    rep(i, 0, N)
    {
        ll idx = -1;
        rep(j, 0, N)
        {
            if (ab[j].first < cd[i].first && ab[j].second < cd[i].second &&
                !flag[j]) {
                if (idx < 0 || ab[idx].second < ab[j].second) idx = j;
            }
        }
        if (idx == -1) continue;
        flag[idx] = true;
        cnt++;
    }

    print(cnt);
}


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

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 101010
#define DEBUG_OUT true

#define ALL(x) (x).begin(), (x).end()


template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
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 solve(void)
{
  int n,k;cin>>n>>k;
  vector<int> a (n,0);
  vector<int> s1 (n + 1,0);
  vector<int> s2 (n+1,0);
  for (int i = 0; i < n; i++)
  {
    cin>>a[i];
    s1[i+1] = s1[i] + a[i];
    s2[i+1] = s2[i] + (a[i] >= 0 ? a[i]:0);
  }
  int res = -1*INF;
  for (int i = 0; i + k <= n; i++)
  {
    int l = i, r = i + k;
    int tmp = (s2[l] - s2[0]) + max(0LL,s1[r] - s1[l]) + (s2[n] - s2[r]);
    chmax(res,tmp);
  }
  cout<<res<<endl;
  
  

  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  // std::ios::sync_with_stdio(false);
  // std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 5612
/*
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	fastio;
	int n,k;
	cin>>n>>k;
	int a[1001];
	rb(i,1,n) cin>>a[i];
	sort(a+1,a+1+n);
	int res=0;
	rb(i,1,k){
		res+=a[i];
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
char s[100005];
int n;
bool chk(int k) {
	bool ok = 1;
	for (int i = 0; i + 1 < n; ++ i) {
		if (s[i] != s[i + 1]) {
			ok &= (i + 1) >= k || (n - i - 1) >= k;
		}
	}
	return ok;
}
int main() {
	scanf("%s", s);
	n = strlen(s);
	int lb = (n + 1) / 2, rb = n;
	while (lb < rb) {
		int md = (lb + rb + 1) >> 1;
		if (chk(md)) lb = md;
		else rb = md - 1;
	}
	printf("%d\n", lb);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

int main() {
    int n;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        mp[a]++;
    }
    map<int, int> rev;
    for (auto &p : mp) {
        for (int i = 1; i < 31; i++) {
            if (mp.count((1 << i) - p.first)) {
                if (p.first == (1 << i) - p.first) continue;
                rev[p.first];
            }
        }
    }

    int N = 0;
    vi rev2;
    for (auto &p : rev) {
        p.second = N++;
        rev2.push_back(p.first);
    }

    int cnt = 0;
    if (N) {
        vvi adj(N);
        for (auto &p : mp) {
            for (int i = 1; i < 31; i++) {
                if (mp.count((1 << i) - p.first)) {
                    if (p.first == (1 << i) - p.first) continue;
                    adj[rev[p.first]].push_back(rev[(1 << i) - p.first]);
                }
            }
        }

        vi visited(N);
        function<void(int, int)> dfs = [&](int v, int p) {
            for (int s : adj[v]) {
                if (s != p) {
                    assert(visited[s] == 0);
                    visited[s] = 1;
                    dfs(s, v);
                }
            }
        };

        vi roots;

        for (int i = 0; i < N; i++) {
            if (visited[i] == 0) {
                roots.push_back(i);
                dfs(i, -1);
            }
        }

        function<void(int, int)> dfs2 = [&](int v, int p) {
            for (int s : adj[v]) {
                if (s != p) {
                    if (adj[s].size() == 1) {
                        int k = min(mp[rev2[v]], mp[rev2[s]]);
                        cnt += k;
                        mp[rev2[v]] -= k;
                        mp[rev2[s]] -= k;
                    } else {
                        dfs2(s, v);
                        int k = min(mp[rev2[v]], mp[rev2[s]]);
                        cnt += k;
                        mp[rev2[v]] -= k;
                        mp[rev2[s]] -= k;
                    }
                }
            }
        };

        for (int v : roots) {
            dfs2(v, -1);
        }
    }

    for (int i = 0; i < 30; i++) {
        if (mp.count(1 << i)) {
            cnt += mp[1 << i] / 2;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 31088
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from collections import deque
INF = float('inf')
 
 
def main():
    H, W, K = map(int, readline().split())
    x1, y1, x2, y2 = map(int, readline().split())
    x1 -= 1
    y1 -= 1
    x2 -= 1
    y2 -= 1
    C = read().split()
 
    dist = [[INF] * W for i in range(H)]
    dist[x1][y1] = 0
    d = deque([[x1, y1]])
    dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
    while d:
        x, y = d.popleft()
        if (x, y) == (x2, y2):
            print(dist[x][y])
            quit()
        for dx, dy in dxy:
            xx = x
            yy = y
            for i in range(K):
                xx += dx;
                yy += dy
                if 0 <= xx < H and 0 <= yy < W and C[xx][yy] != '@':
                    if dist[xx][yy] <= dist[x][y]:
                        break
                    if dist[xx][yy] == INF:
                        d.append([xx, yy])
                    dist[xx][yy] = dist[x][y] + 1
                else:
                    break
 
    print(-1)
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 36392
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    const int dx[2] = {1,0};
    const int dy[2] = {0,1};
    ll H,W;
    cin >> H >> W;
    vector<vector<ll>> memo(H,vector<ll>(W));
    vector<vector<char>> maze(H,vector<char>(W));
    vector<vector<bool>> visit(H,vector<bool>(W,false));
    rep(i,H)
    rep(j,W)cin >> maze[i][j];
    memo[0][0] = 1;
    queue<P> que;
    que.push(P(0,0));
    visit[0][0] = true;
    while(que.size()){
        P p = que.front();
        que.pop();
        //if(p.first == H - 1 && p.second == W - 1)break;
        //visit[p.first][p.second] = true;
        rep(i,2){
            ll hx = p.first + dx[i];
            ll hy = p.second + dy[i];
            if(hx < H && hy < W && maze[hx][hy] != '#'){
                memo[hx][hy] += memo[p.first][p.second];
                memo[hx][hy] %= mod;
                if(!visit[hx][hy]){
                    visit[hx][hy] = true;
                    que.push(P(hx,hy));

                }
            }
        }/*
        rep(i,H){
        rep(j,W)cout << memo[i][j] << " ";
        cout << endl;
    }*/
    }
    cout << memo[H - 1][W - 1] << endl;
    /*rep(i,H){
        rep(j,W)cout << memo[i][j] << " ";
        cout << endl;
    }*/
}

Measured memory_bytes: 9344
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
int A, B;
int P[1111];
int S[3];

void MAIN() {
    scanf("%d%d%d", &N, &A, &B);
    REP (i, N) scanf("%d", P+i);

    REP (i, N) {
	if (P[i] <= A) S[0]++;
	else if (P[i] <= B) S[1]++;
	else S[2]++;
    }

    int ans = min(S[0], min(S[1], S[2]));
    printf("%d\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 256