akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("atcoder-problems/abc133_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, D;
  cin >> N >> D;
  
  vector<vector<int>> x(N, vector<int>(D, 0));
  rep(i, N) rep(j, D) { cin >> x[i][j]; }

  ll ans = 0;
  rep(i, N - 1) repi(j, i + 1, N) {
    int tmp = 0;
    rep(k, D) { tmp += pow(x[i][k] - x[j][k], 2); }
    int dis = sqrt(tmp);
    ans += pow(dis, 2) == tmp;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int M,N,i;
	int A[101];
	int sum=0;
    scanf("%d%d",&N,&M);
    for(i=0;i<N;i++){
    	if(scanf("%d",&A[i])==1)
    	sum+=A[i];
	}
	float ave;
	ave=(double)sum/(4*M);
	for(i=0;i<N;i++){
		if(A[i]>=ave) M--;
		if(M==0) break;
	}
	if(M==0) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 128
import sys

# S = input()
# N, M = map(int, input().split())
# nums = list(map(int, input().split()))
# nums_2d = [list(map(int, input().split())) for _ in range(N)]


def main():

    N = int(input())

    total = 0
    for i in range(1, N+1):
        if i % 3 == 0 or i % 5 == 0:
            continue

        total += i

    print(total)


if __name__ == '__main__':
    main()


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

ll dp[3010][6010], A[3010];

int main() {
	for (int i = 0;i < 3010;i++) {
		for (int j = 0;j < 6010;j++) {
			dp[i][j] = 0;
		}
	}
	ll N, S;
	cin >> N >> S;
	for (int i = 0;i < N;i++) {
		cin >> A[i];
	}
	ll ans = 0;
	for (ll i = 0;i <= N;i++) {
		dp[i + 1][A[i]] += i + 1;
		dp[i + 1][0] += dp[i][0];

		dp[i + 1][A[i]] %= MOD;
		dp[i + 1][0] %= MOD;
		for (int j = 1;j < S;j++) {
			dp[i][j] %= MOD;
			dp[i + 1][j + A[i]] += dp[i][j];
			dp[i + 1][j] += dp[i][j];
			dp[i + 1][j + A[i]] %= MOD;
			dp[i + 1][j] %= MOD;
		}
		ans += dp[i][S] * (N - i + 1) % MOD;
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 141568
#include <algorithm>
#include<vector>
#include<iostream>
#include<string>
int main(void) {
	std::string a ,b;
	std::cin >> a;
	std::cin >> b;
	if (a.at(0) == b.at(2) && a.at(2) == b.at(0)&& a.at(1) == b.at(1))
		std::cout << "YES" << std::endl;
	else
		std::cout << "NO" << std::endl;

}

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

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

  int n;
  cin >> n;
  lint ans = 0;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  } 
  for (int i = 1; i < n; i++) {
    if (a[i - 1] > a[i]) {
      ans += a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
  }
  cout << ans << "\n"; 
  return 0;
}


Measured memory_bytes: 3988
import java.util.Scanner;
public class Main {


//参照する山札


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int d = 0;
	int a = sc.nextInt();//行
	int card[][]= {{1,2,3,4,5,6,7,8,9,10,11,12,13},
					{1,2,3,4,5,6,7,8,9,10,11,12,13},
					{1,2,3,4,5,6,7,8,9,10,11,12,13},
					{1,2,3,4,5,6,7,8,9,10,11,12,13}};
	int j=0;
while(d<a){
	String m = sc.next();//マーク
	int b = sc.nextInt();//数字

	//行分
			if(m.equals("S")){
				card[0][b-1]=0;
			}

			if(m.equals("H")){
				card[1][b-1]=0;
			}

			if(m.equals("C")){
				card[2][b-1]=0;
			}

			if(m.equals("D")){
				card[3][b-1]=0;
			}
			d++;
	}
	while(j<3){
		for(int k =0;k<13;k++){
		if(card[0][k]!=0)
			System.out.println("S "+card[j][k]);
		}
		j=j+1;
		for(int k =0;k<13;k++){
		if(card[1][k]!=0)
			System.out.println("H "+card[j][k]);
		}
		j=j+1;
		for(int k =0;k<13;k++){
		if(card[2][k]!=0)
			System.out.println("C "+card[j][k]);
		}
		j=j+1;
		for(int k =0;k<13;k++){
		if(card[3][k]!=0)
			System.out.println("D "+card[j][k]);
		}
	
		
	  }
	}

}



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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int ans=0;
  for(int i=0;i<n;i++){
    int count=0;
    for(int j=i;j<n;j++){
      if(a[j]==a[i]&&a[i-1]!=a[i]){
        count++;
      }
      else{
        break;
      }
    }
    ans+=count/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
A, B, C, D, E, F = [int(v) for v in input().split()]
# print(A, B, C, D, E, F)
An = [(100*A)*(v) for v in range(int(F/(100*A))+1)]
Bn = [(100*B)*(v) for v in range(int(F/(100*B))+1)]
# print(An, Bn, 1)
 
 
def per1(RE):
  Cn = [C*v for v in range(int(RE/C)+1)]
  Dn = [D*v for v in range(int(RE/D)+1)]
  rtn = 0
  for v2 in Cn:
    for w2 in Dn:
      r = v2 + w2
      if rtn < r <= RE:
        rtn = r
  return rtn
  
  
max_suger_per = 0
max_water = 0
max_suger = 0
for v in Bn:
  for w in An:
    s = v + w
    if s > F or s == 0: continue
    re = int(s * E / 100)
    if s + re > F: re = F - s
    # print(s, re)
    result = per1(re)
    # print(result)
    suger = (100 * result) / (s + result)
    if suger > max_suger_per:
      max_suger_per = suger
      max_water = s + result
      max_suger = result
    
if max_water == 0:
  max_water = An[1]
print(max_water, max_suger)
  

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int field[15][15];
int dx[12] = {-1, 0, 1, 0, -1, -1, 1, 1, -2, 0, 2, 0};
int dy[12] = {0, -1, 0, 1, -1, 1, -1, 1, 0, -2, 0, 2};

void wfs(int y, int x, int size) {
  int n;
  if(size == 1) n = 4;
  else if(size == 2) n = 8;
  else n = 12;

  field[y][x]++;
  REP(i, n) {
    int nx = x+dx[i], ny = y+dy[i];
    if(nx < 0 || 9 < nx || ny < 0 || 9 < ny) continue;
    field[ny][nx]++;
  }
}

int main() {
  int x, y, size;
  char c1, c2;
  
 memset(field, 0, sizeof(field));
  while(cin >> x >> c1 >> y >> c2 >> size) {
    wfs(x, y, size);
  }  
    
  int max = 0;
  int cnt = 0;
  REP(i, 10) {
    REP(j, 10) {
      if(field[i][j] > max) max = field[i][j];
      if(field[i][j] == 0) cnt++;
    } 
  }  
  cout << cnt << endl;
  cout << max << endl;
}

Measured memory_bytes: 1160
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int X = sc.nextInt();
		int A[] = new int[2000001];
		for(int i = 0; i < 2 * K - 1; i++) {
			System.out.print(X - K + 1 + i + " ");
		}
		System.out.println("");
		sc.close();
	}

}
/*
□□□□□■□□□■□□□□□□□
□□□□□■□□□■□□□□□□□
□□□□□■□□□■□□□□□□□
□□□□□■□□□■□□□■■□□
■■■■■■□□□■□■■■□□□
□□□□□■□□□■■■□□□□□
□□□□□■□□□■□□□□□□□
□□□□□■□□□■□□□□□□□
□□□□□■□□□■□□□□□□□
□□□□□■□□□■□□□□□□□
□□□□□■□□□■□□□□□□□
□□□■■■□□□■□□□□□□□
□■■■□■□□□■□□□□□■□
■■□□□■□□□■■□□□■■□
□□□□□■□□□□■■■■■□□
□□□□□■□□□□□□□□□□□
□□□□□□□■□□□□□□□□□
□□□□□□□■□□□□□□□□□
□□□□□□□■□□□□□□□□□
□□□□□□□■□□□□□□□□□
□□□□□□□■□□□□□□□□□
■■■■■■■■■■■■■■■■□
□□□□□□□■□□□□□□□□□
□□□□□□■■■□□□□□□□□
□□□□□□■□■□□□□□□□□
□□□□□□■□■■□□□□□□□
□□□□□■■□□■□□□□□□□
□□□□□■□□□■■□□□□□□
□□□□■■□□□□■■□□□□□
□□□■■□□□□□□■■□□□□
□□■■□□□□□□□□■■□□□
■■■□□□□□□□□□□■■■□
*/

Measured memory_bytes: 30164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main() {
    int N, D, count=0;
    cin >> N >> D;

    for(int i=0; i<N; i++) {
        int x, y;
        cin >> x >> y;
        if(D >= sqrt(pow(x,2) + pow(y,2))) {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3696
import math
from decimal import Decimal
a,b,h,m=map(int, input().split())

hkaku = h * 30 + m * 0.5
mkaku = m * 6

th = 0
if hkaku > mkaku:
    th = hkaku - mkaku
else:
    th = mkaku - hkaku
if th > 180:
    th = abs(th -360)

ans =  a**2 + b**2 + (-2 * a * b * Decimal(math.cos(math.radians(th))))
ans =  Decimal(ans).sqrt()
print(ans)


Measured memory_bytes: 10336
import bisect

def solve(n, l):
    l.sort()
    r = 0
    for i in range(n - 2):
        li = l[i]
        for j in range(i + 1, n - 1):
            r += bisect.bisect_left(l, li + l[j], j + 1) - j - 1
    return r

def main():
    n = int(input())
    l = [int(x) for x in input().split()]
    print(solve(n, l))


main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;
 
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
 
template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}
 
// ------------------------------------------------------------------------------------------

map<vector<int>, int> mp;

void init() {
   vector<int> v(8);
   iota(all(v), 0);
   mp[v] = 0;

   queue<vector<int>> que;
   que.push(v); // 最終状態をpush
   while (que.size()) {
      vector<int> cur = que.front(); que.pop();
      int idx = find(all(cur), 0) - cur.begin(); // 0の場所

      rep (i, 4) {
         int ny = (idx / 4) + dy[i]; // 上段
         int nx = (idx % 4) + dx[i]; // 下段
         if (ny < 0 || ny >= 2 || nx < 0 || nx >= 4) continue;
         int nc = ny * 4 + nx; // 2次元座標を1次元に変換したもの
         vector<int> tmp = cur;
         swap(tmp[nc], tmp[idx]); // 0の場所を入れ替える
         if (mp.count(tmp)) continue; // 計算済みならはじく
         mp[tmp] = mp[cur] + 1;
         que.push(tmp);
      }
   }
}

int main() {
   init();
   vector<int> vs(8);
   while (cin >> vs[0]) {
      repp (i, 1, 8) cin >> vs[i];
      cout << mp[vs] << endl;
   }

   return 0;
}


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

int main() {
  int a,b;
  cin>>a>>b;
  
  if(b>=a){
  cout<<"unsafe"<<endl;
  }
  else{
  cout<<"safe"<<endl;
  }
}


Measured memory_bytes: 3624
#include<stdio.h>

#define min(a,b) ((a)<(b)?(a):(b))

int main(){
	int n,k,i,j,g=-1;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++){
		if(i*(n-i-1)+i*(i-1)/2>=k){
			g=i;
			break;
		}
	}
	if(g==-1){
		puts("-1");
		return 0;
	}
	int anss[10000][2],c=0;
	for(i=1;i<=n-g;i++){
		for(j=i+1;j<=n-g;j++){
			anss[c][0]=i;
			anss[c][1]=j;
			c++;
		}
	}
	for(i=n-g+1;i<=n;i++){
		anss[c][0]=1;
		anss[c][1]=i;
		c++;
	}
	int nok=g*(n-g-1)+g*(g-1)/2-k;
	int nn=nok;
	for(i=0;i<=nok/(n-g-1);i++){
		for(j=0;j<min(nn,(n-g-1));j++){
			anss[c][0]=j+2;
			anss[c][1]=n-g+1+i;
			c++;
		}
		nn-=(n-g-1);
		if(nn<=0)break;
	}
	printf("%d\n",c);
	for(i=0;i<c;i++)printf("%d %d\n",anss[i][0],anss[i][1]);
	return 0;
}

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


int main() {
    int A, B, C;
    cin >> A >> B >> C;

    if(A + B + C > 21){
        cout << "bust" << endl;
    }

    else{
        cout << "win" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
void f(int w[],int k[],int b[],int a[],int c,int n,int e,int g){
  int i,j;
  int bb[10];
  if(c==n){
    if(a[10]==0||a[10]>g){
      a[10]=g;
      memcpy(a,b,sizeof(bb));
    }
  }else{
    for(i=0;i<n;i++){
      if(k[i]>=e){
	for(j=0;j<c;j++){
	  if(i==b[j])
	    break;
	}
	if(j==c){
	  memcpy(bb,b,sizeof(bb));
	  bb[c]=i;
	  f(w,k,bb,a,c+1,n,e+w[i],g+w[i]*(n-c));
	}
      }else
	break;
    }
  }
  return;
}
int main(){
  int h,i;
  int w[10],k[10],b[10],a[11],swap,n;
  char s[11][64];
  for(;;){
    scanf("%d",&n);
    if(n==0)
      break;
    for(i=0;i<n;i++)
      scanf("%s%d%d",s[i],&w[i],&k[i]);
    do{
      h=0;
      for(i=1;i<n;i++){
	if(k[i-1]<k[i]){
	  swap=k[i-1];
	  k[i-1]=k[i];
	  k[i]=swap;
	  swap=w[i-1];
	  w[i-1]=w[i];
	  w[i]=swap;
	  sprintf(s[10],"%s",s[i-1]);
	  sprintf(s[i-1],"%s",s[i]);
	  sprintf(s[i],"%s",s[10]);
	  h=1;
	}
      }
    }while(h);
    memset(b,0,sizeof(b));
    memset(a,0,sizeof(a));
    f(w,k,b,a,0,n,0,0);
    for(i=0;i<n;i++)
      printf("%s\n",s[a[n-i-1]]);
  }
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
static const int N = 100;

int main(){
  int M[N][N];
  int n,u,k,v;

  cin >> n;

  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++) M[i][j] = 0;
  }

  for(int i = 0;i < n;i++){
    cin >> u >> k;
    u--;
    for(int j = 0;j < k;j++){
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      if(j) cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }

  return 0;
}



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

typedef unsigned long long ull;

ull maxi(ull a, ull b){
  if (a>b) return a;
  else return b;
}

int main(){
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  
  ull ans=0;
  if(A+B<2*C){
    ans+=(A+B)*min(X,Y);
  }else{
    ans+=2*C*min(X,Y);
  }
  
  int R=max(X,Y)-min(X,Y);
  if(max(X,Y)==X){
    if(A*R<2*C*R){
      ans+=A*R;
    }else{
      ans+=2*C*R;
    }
  }
  else if(max(X,Y)==Y){
    if(B*R<2*C*R){
      ans+=B*R;
    }else{
      ans+=2*C*R;
    }
  }
  cout << ans <<endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    if(n>81)
        printf("No");
    else
    {
        for(int i=1;i<=9;i++)
            for(int j=1;j<=9;j++)
            if(i*j==n)
        {
            printf("Yes");
            return 0;
        }
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define ll                    long long int
#define fo(i,a,b)          for( i=(ll)a;i<(ll)b;++i)
#define loopr(i,a,b)          for(int i=(int)a;i>=(int)b;--i)
#define pb                    push_back
#define mset(a,b,c)           loop(i,0,b) a[i]=c
#define F                     first
#define S                     second
#define mp                    make_pair
#define clr(x)                x.clear()
#define MOD                   1000000007
#define MAX                   1e9
#define MIN                   -1e9
#define vi                    vector<ll>
#define vvi                   vector<vi>
#define pll                   pair<ll,ll>
#define all(p)                p.begin(),p.end()
#define max(x,y)              (x>=y)?x:y
//#define min(x,y)              (x<=y)?x:y
#define mid(s,e)              (s+(e-s)/2)
#define start()                  int t; scanf("%d",&t); while(t--)
using namespace std;
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll min(ll x,ll y)
{
		return x<=y?x:y;
}

int main()
{
   int n,k;
   cin>>n>>k;
   vector<int> snk(n+1,0);
   for(int i=0;i<k;i++)
   {
       int d;
       cin>>d;
       for(int j=0;j<d;j++)
       {
           int k;
           cin>>k;
           snk[k]+=1;
       }
   }
   int ans=0;
   for(int i=1;i<n+1;i++)
   {
    //    cout<<snk[i];
       if(snk[i]==0)ans++;
   }
    cout<<ans;


}

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

int main() {
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n);
  ll upper=0,lower=0;
  rep(i,n){
    cin >> a[i];
    upper = max(upper,a[i]);
  }
  
  if(k == 0){
    cout << upper << endl;
    return(0);
  }
  
  ll len=ceil((upper+lower)*1.0/2);
  while(upper - lower > 1){
    ll times=0;
    rep(i,n) times += (ceil(a[i]*1.0/len)-1);
    //cout << times << endl;
    if(times <= k){
      upper = len;
    }else{
      lower = len;
    }
    //cout << upper << " " << lower << endl;
    len=ceil((upper+lower)*1.0/2);
  }
  cout << (ll)(ceil(len)) << endl;
  
  return(0);
}

Measured memory_bytes: 4888
require "prime"

N_MAX = 10 ** 5

# is_prime = [false] * (N_MAX+1)
is_number_like_2017 = [false] * (N_MAX+1)
# Prime.each(N_MAX).each{ |t| is_prime[t] = true }
(1..N_MAX).each{ |i| is_number_like_2017[i] = true if i.prime? && ((i+1)/2).prime? }
f = [0] * (N_MAX+1)
(1..N_MAX).each do |i|
  f[i] = f[i-1]
  f[i] += 1 if is_number_like_2017[i]
end

q = gets.to_s.to_i
q.times do |i|
  l, r = gets.to_s.split.map{|t| t.to_i }
  puts f[r] - f[l-1]
end

Measured memory_bytes: 4476
#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define lli long long int
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#include<queue>
#define ii pair<int,int>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
ll pows(ll a,ll n,ll m)
{
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}	
	}
	return res%m;
}
ll  gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else 
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
			return false;
			}	
	}
	return true;
}
int n;
int w;
int dp[105][100005];
int weight[105];
int val[105];
int getans(int idx,int va)
{
	if(va==0)
	{
		return 0;
	}
	if(va<0)
	{
		return mod;
	}
	if(idx==n+1)
	{
		return mod;
	}
	if(dp[idx][va]!=-1)
	{
		return dp[idx][va];
	}
	int ans=mod;
	ans=min(getans(idx+1,va),getans(idx+1,va-val[idx])+weight[idx]);
	return dp[idx][va]=ans;
}
int main()
{
ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
memset(dp,-1,sizeof(dp));
cin>>n;
cin>>w;
for(int i=1;i<=n;i++)
{
	cin>>weight[i]>>val[i];
}
int ans=0;
for(int i=1;i<=100003;i++)
{
	int wet=getans(1,i);
	if(wet<=w)
	{
		ans=i;
	}
}
cout<<ans<<endl;
}





Measured memory_bytes: 44552
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define PI acos(-1)
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define sp fixed<<setprecision
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

const int M = 998244353;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n,k;
        cin>>n>>k;
        int a[k],b[k];
        for(int i=0;i<k;i++)cin>>a[i]>>b[i];
        int dp[n+1] = {},sum[n+1] = {};
        dp[1] = 1;
        sum[1] = 1;
        for(int i=2;i<=n;i++)
        {
            for(int j=0;j<k;j++)
            {
                int l = max(0LL,i-b[j]);
                int r = max(0LL,i-a[j]);
                dp[i] += sum[r] - (l ? sum[l-1] : 0LL);
                dp[i] += M;
                dp[i] %= M;
                sum[i] = dp[i] + sum[i-1];
                sum[i] %= M;
            }
        }
        cout<<dp[n]<<endl;
    }
    return 0;
}


Measured memory_bytes: 6724
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;

signed main() {
	int m; cin >> m;
	int sd = 0, sc = 0;
	rep(i, m) {
		int d, c; cin >> d >> c;
		sc += c;
		sd += d*c;
	}
	int sum = sc - 1;
	if (sd % 9)sum += sd / 9;
	else sum += sd / 9 - 1;
	cout << sum << endl;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

class WeightedUnionFind:
    def __init__(self, node:int) -> None:
        self.n = node
        self.par = [i for i in range(self.n)]
        self.rank = [0 for i in range(self.n)]
        self.diff_weight = [0 for i in range(self.n)]
        
    # ノードxのルートを求める
    def find(self, x:int) -> int:
        if x == self.par[x]:
            return x
        else:
            r = self.find(self.par[x])
            self.diff_weight[x] += self.diff_weight[self.par[x]]
            self.par[x] = r
            return self.par[x]
        
    # ノードxのルートからの距離を求める
    def weight(self, x:int) -> int:
        self.find(x)
        return self.diff_weight[x]
        
    # weight(y) - weight(x) = w となるようにする
    def unite(self, x:int, y:int, w:int) -> bool:
        if self.isSame(x,y):
            return False
        
        w += self.weight(x)
        w -= self.weight(y)
        
        rx = self.find(x)
        ry = self.find(y)
        
        if self.rank[rx] < self.rank[ry]:
            rx, ry = ry, rx
            w = -w

        self.par[ry] = self.par[rx]
        self.diff_weight[ry] = w
        
        if self.rank[rx] == self.rank[ry]:
            self.rank[rx] += 1
                
        return True
                
    
    def isSame(self, x:int, y:int) -> bool:
        return self.find(x) == self.find(y)
    
    def diff(self, x:int, y:int) -> int:
        if self.isSame(x,y):
            return self.weight(y)-self.weight(x)
        else:
            raise ValueError("xとyは同じ木に属していません")


n,m = li()

lrd = []
for _ in range(m):
    l,r,d = li()
    l -= 1
    r -= 1
    lrd.append((l,r,d))
 
exist = True

wuf = WeightedUnionFind(n)

for l,r,d in lrd:
    wuf.unite(l,r,d)
    if wuf.diff(l,r) != d:
        exist = False
        break
    
if exist:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 40312
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main()
	{
		var s = Console.ReadLine();

		Console.WriteLine(s.ToArray().Count(c => c == '1'));

		//デバッグ実行での確認用。そのまま提出しても問題なし
		Console.ReadKey();
	}
}


Measured memory_bytes: 13268
#include <iostream>

using namespace std;

int digit_sum(int N) {
    int sum = 0;
    while (N > 0) {
        sum += N % 10;
        N /= 10;
    }
    return sum;
}

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

    int sum = 0;
    for (int i = 1; i <= N; i++) {
        int ds = digit_sum(i);
        if (ds >= A && ds <= B) {
            sum += i;
        }
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
import math
from functools import reduce
l = [int(input()) for _ in range(5)]
ans = 9
n = j = 0
for i in [I % 10 for I in l]:
    if i != 0 and i < ans:
        ans = i
        n = j
    j += 1
ceil = lambda n: math.ceil(n / 10) * 10
print(l.pop(n) + reduce(lambda a, b: ceil(a) + ceil(b), l))


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111

	void solve(){



		ini(n);
		ini(nm);
		ini(n1);
		ini(n1m);
		ini(x);
		int tmp = (n1-n)*60-nm+n1m;
		out(tmp-x);







	}	























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;            //

int main(void)
{
    ll N, K;
    cin >> N >> K;

    ll minimum = N;

    if (N % K == 0)
    {
        minimum = 0;
        cout << minimum << endl;
        return 0;
    }
    else
    {
        N = N % K;
    }
    ll counter = 0;

    while (counter <= 10000)
    {
        N = abs(N - K);
        minimum = min(minimum, N);
        if (minimum == 1)
        {
            break;
        }
        counter++;
    }
    cout << minimum << endl;
    return (0);
}

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

using namespace std;

pair<int, pair<int, int>> calc(int pos, int prev, const vector<vector<int>>& g, const string& S){
    vector<pair<int, int>> tmp;
    pair<int, int> res = make_pair(0, 0);
    pair<int, int> maxChild = make_pair(0, 0);
    int node = 0;
    for(auto& t : g[pos]){
        if(t == prev) continue;
        auto cur = calc(t, pos, g, S);
        node += cur.first;
        cur.second.first += cur.first;
        cur.second.second += cur.first;
        tmp.push_back(cur.second);
        res.second += tmp.back().second;
        if(tmp.back().first > maxChild.first || (tmp.back().first == maxChild.first && tmp.back().second < maxChild.second)){
            maxChild = tmp.back();
        }
    }
    if(maxChild.first > res.second - maxChild.second){
        res.first = maxChild.first - (res.second - maxChild.second);
    } else {
        res.first = res.second%2;
    }
    node += S[pos] - '0';
    return make_pair(node, res);
}

int main(){
    int N;
    while(cin >> N){
        string S; cin >> S;
        vector<vector<int>> g(N);
        for(int i=0;i<N-1;i++){
            int a, b; cin >> a >> b;
            --a; --b;
            g[a].push_back(b);
            g[b].push_back(a);
        }
        int res = -1;
        for(int i=0;i<N;i++){
            if(calc(i, -1, g, S).second.first) continue;
            vector<int> dist(N, -1); dist[i] = 0;
            queue<int> qu; qu.push(i);
            int sum = 0;
            while(!qu.empty()){
                int c = qu.front(); qu.pop();
                sum += (S[c]-'0') * dist[c];
                for(auto& t : g[c]){
                    if(dist[t] != -1) continue;
                    dist[t] = dist[c] + 1;
                    qu.push(t);
                }
            }
            if(res == -1 || res > sum/2) res = sum/2;
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pll;
int main(){
  ll inf=1000000000000000000;
  ll n;cin>>n;ll a[n-1],b[n-1],c[n-1];
  vector<pll>v[n+1];
  for(ll i=0;i<n-1;i++){
    cin>>a[i]>>b[i]>>c[i];
    v[a[i]].push_back(make_pair(c[i],b[i]));
    v[b[i]].push_back(make_pair(c[i],a[i]));
  }
  ll q,k;cin>>q>>k;
  priority_queue<pll,vector<pll>,greater<pll>>p;
  ll d[n+1];
  fill(d,d+n+1,inf);
  p.push(make_pair(0,k));
  d[k]=0;
  bool used[n+1];
  fill(used,used+n+1,false);
  while(p.size()>0){
    pll pnow=p.top();p.pop();
    ll pnf=pnow.first,pns=pnow.second;
    if(used[pns])continue;
    used[pns]=true;
    for(ll i=0;i<v[pns].size();i++){
      ll vnf=v[pns][i].first,vns=v[pns][i].second;
      if(d[vns]>pnf+vnf){
        d[vns]=pnf+vnf;
        p.push(make_pair(d[vns],vns));
      }
    }
  }
  for(ll i=0;i<q;i++){
    ll x,y;cin>>x>>y;
    cout<<d[x]+d[y]<<endl;
  }
}
               

Measured memory_bytes: 13552
#include <bits/stdc++.h>
#include <algorithm>
#include <limits>
#include <stdlib.h> 
using namespace std;
 
int main(){
  int y,m,d;
  char s,t;
  cin>>y>>s>>m>>t>>d;
  
  long q=d+100*m+10000*y;
  if(q>20190430)cout<<"TBD"<<endl;
  else cout<<"Heisei"<<endl;
}
    
    

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int min(int a,int b){return a<b?a:b;}
int main(){
    int n,x,y,a[100010]={};
    scanf("%d%d%d",&n,&x,&y);
    for(int i=1;i<n;i++) a[i]=0;
    for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++)
           a[min(j-i,abs(x-i)+1+abs(y-j))]++;
    for(int i=1;i<n;i++) printf("%d\n",a[i]);
    return 0;
}

Measured memory_bytes: 512
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;

const int N = (int) 0, mod = (int) 0;

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string x;
    cin >> x;
    int n = (int) x.size();
    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j)
            if (x[i] == 'C' && x[j] == 'F') {
                cout << "Yes" << endl;
                return 0;
            }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 764
from collections import deque
N, M = map(int, input().split())
d = dict()
for m in range(M):
    a, b = map(int, input().split())
    d.setdefault(a-1, []).append(b-1)
    d.setdefault(b-1, []).append(a-1)
n = [-1] * N
n[0] = 0
q = deque()
q.append(0)
if 0 in d:
    while len(q) > 0:
        i = q.popleft()
        for dd in d[i]:
            if n[dd] == -1:
                n[dd] = i
                q.append(dd)
if -1 not in n:
    print('Yes')
    for x in range(1, N):
        print(n[x] + 1)
else:
    print('No')

Measured memory_bytes: 106236
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
typedef pair<int,int> P;
#define mod 1000000007
 
int main(){
    int x,y;
    cin >> x >> y;
    cout << x+y/2 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt(), b = scan.nextInt(), c = scan.nextInt();
 
 
        long multi = (long)a * (long)b;
        long right = c - a - b;
      
        if( right > 0 && multi * 4 < (right * right)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
 
        scan.close();
    }
}

Measured memory_bytes: 21972
<?php
$line = readline();
readline_add_history($line);
$inputs = explode(" ", $line);
$a = intval($inputs[0]);
$b = intval($inputs[1]);
function compare($a, $b) {
if ($a < $b) return "<";
if ($a > $b) return ">";
return "==";
}
printf("a %s b", compare($a, $b));
?>

Measured memory_bytes: 6580
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  map<int, ll> mp;
  rep(i, 0, n) {
    int a;
    cin >> a;
    mp[a]++;
  }

  std::map<int, ll>::reverse_iterator i = mp.rbegin();
  ll edge[2] = {0, 0};
  int count = 0;
  for (; i != mp.rend(); ++i) {
    ll c = i->second;
    if (c / 2 >= 1) {
      if (c / 2 == 1 || count) {
        edge[count] = i->first;
        count++;
      } else {
        edge[0] = edge[1] = i->first;
        count = 2;
      }
    }
    if (count == 2)
      break;
  }

  cout << edge[0] * edge[1] << endl;
}


Measured memory_bytes: 6528
#include <iostream>

using namespace std;

int main(int argc, const char *argv[])
{
    int n;
    string s;
    cin >> n >> s;

    int cnt = 0;
    for (int i = 0; i + 2 < s.length(); i++)
    {
        if (s.substr(i, 3) == "ABC")
        {
            cnt++;
            i += 2;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
for i in range(int(raw_input())):
    out = hit = score = 0
    while 1:
        event = raw_input()
        if event == 'OUT':
            if out < 2:
                out += 1
            else:
                print score
                break
        elif event == 'HIT':
            if hit < 3:
                hit += 1
            else:
                score += 1
        else:
            score += hit + 1
            hit = 0

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

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

using namespace std;

int main(){
	int h,w; scanf("%d%d",&h,&w);

	int B[80][80];
	rep(i,h) rep(j,w) scanf("%d",&B[i][j]);
	rep(i,h) rep(j,w) {
		int tmp; scanf("%d",&tmp);
		B[i][j]=abs(B[i][j]-tmp);
	}

	const int OFS=80*80;
	static bool dp[80][80][2*80*80+1];
	dp[0][0][ B[0][0]+OFS]=true;
	dp[0][0][-B[0][0]+OFS]=true;
	rep(i,h) rep(j,w) for(int a=-80*80;a<=80*80;a++) if(dp[i][j][a+OFS]) {
		if(i<h-1 && a+B[i+1][j]<= 80*80) dp[i+1][j][a+B[i+1][j]+OFS]=true;
		if(i<h-1 && a-B[i+1][j]>=-80*80) dp[i+1][j][a-B[i+1][j]+OFS]=true;
		if(j<w-1 && a+B[i][j+1]<= 80*80) dp[i][j+1][a+B[i][j+1]+OFS]=true;
		if(j<w-1 && a-B[i][j+1]>=-80*80) dp[i][j+1][a-B[i][j+1]+OFS]=true;
	}

	int ans=80*80;
	for(int a=-80*80;a<=80*80;a++) if(dp[h-1][w-1][a+OFS]) ans=min(ans,abs(a));
	printf("%d\n",ans);

	return 0;
}


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

int count;

void dfs(long long x, long long n){
    if(x<=n) {
        int flag7=0, flag5=0, flag3=0, flagelse=0;
        for(char c :to_string(x)) {
            if(c-'0'==7)
                flag7 = 1;
            else if(c-'0'==5)
                flag5 = 1;
            else if(c-'0'==3)
                flag3 = 1;
            else{
                flagelse= 1;
            }
        }
        if(flag7 && flag5 && flag3 && !flagelse) {
            //  cout << x << "count!" <<endl;
            count++;
        }
        if(x<=n) {
            dfs(10*x+3, n);
            dfs(10*x+5, n);
            dfs(10*x+7, n);
        }
    }
}

int main(){
    long long n;
    cin >> n;
    dfs(0, n);
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, string S) {
    long ans;
    foreach (l; 0 .. N) foreach (i, v; zAlgorithm(S[l .. $])) {
        auto r = l + i;
        ans = ans.max(min(r - l, N - r, v));
    }
    return ans;
}


long[] zAlgorithm(R)(R range) if (isSomeString!R || isRandomAccessRange!R) {
    const length = range.length;
    auto lens = new long[](length);
    
    long c;
    foreach (r; 1 .. cast(long) length) {
        if (r + lens[r - c] < c + lens[c]) {
            lens[r] = lens[r - c];
        } else {
            long len = max(0, c + lens[c] - r);
            while (r + len < length && range[len] == range[r + len])
                ++len;
            lens[r] = len;
            c = r;
        }
    }

    lens[0] = length;
    return lens;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    string S;
    S = input.front.to!string;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(N, S);
    else
        solve(N, S).writeln;
}


Measured memory_bytes: 4732
#include<iostream>
#include<vector>
#include<queue>

int main()
{
    int N,Q;
    std::cin>>N>>Q;
    std::vector<std::vector<int>> hen(N);//各頂点と接続している辺を格納する
    std::vector<int> ans(N);
    for(int i=0;i+1<N;i++){
        int a,b;
        std::cin>>a>>b;
        a--;
        b--;
        hen[a].push_back(b);
        hen[b].push_back(a);
    }
    for(int i=0;i<Q;i++){
        int p,x;
        std::cin>>p>>x;
        p--;
        ans[p] += x;
    }
    std::queue<int> que;
    que.push(0);
    std::vector<bool> used(N);
    used[0] = true;
    while(que.size()){
        int i = que.front();
        que.pop();
        for(auto j : hen[i]){
            if(used[j])continue;
            used[j] = true;
            ans[j] += ans[i];
            que.push(j);
        }
    }
    for(int i=0;i<N;i++)std::cout<<ans[i]<<" ";
    return 0;    


    
    
}

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

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

  int n;
  cin >> n;
  vector<int> a(n + 1);
  rep(i, 0, n + 1) cin >> a[i];
  ll ans = 0;
  rep(i, 0, n) {
    int b;
    cin >> b;

    int m1 = min(b, a[i]);
    b -= m1;
    int m2 = min(b, a[i + 1]);
    a[i + 1] -= m2;
    ans += m1 + m2;
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define mod 1000000007
#define dbl double
#define pb push_back
#define vec vector<ll>
#define vecp vector<pair<ll,ll> >
using namespace std;
void fio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
}

int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	int ans=0;
	for(int i=0;i<k;i++)
	ans+=a[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
const int SIDE = 100000010;
const int FAIL = 1000000007;
int R, C, N;
vector<pi> v;
stack<int> s;
int encode(int x, int y) {
    if (x == 0) {
        return y;
    }
    if (x == R) {
        return 3*SIDE - y;
    }
    if (y == 0) {
        return 4*SIDE - x;
    }
    if (y == C) {
        return SIDE + x;
    }
    return FAIL;
}
int main () {
    scanf("%d%d%d", &R, &C, &N);
    for (int i = 1, a, b, c, d; i <= N; ++i) {
        scanf("%d%d%d%d", &a, &b, &c, &d);
        int x = encode(a, b), y = encode(c, d);
        if (x == FAIL || y == FAIL) continue;
        if (x > y) swap(x, y);
        v.emplace_back(x, i);
        v.emplace_back(y, -i);
    }
    sort(v.begin(), v.end());
    bool fail = 0;
    for (auto it:v) {
        if (it.second > 0) s.push(it.second);
        else {
            if (s.top() != -it.second) fail = 1;
            else s.pop();
        }
        if (fail) break;
    }
    if (fail) puts("NO");
    else puts("YES");
}

Measured memory_bytes: 2420
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, x;
    cin >> n >> x;
    int a[110];
    rep(i, n) cin >> a[i];
    sort(a, a + n);
    int ans = 0;
    rep(i, n - 1) {
        if(x >= a[i]) {
            x -= a[i];
            ans++;
        }
    } 
    if(x == a[n - 1]) ans++;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3528
ts = []
ts_mod = []
for i in range(5):
    ts.append(int(input()))
    ts_mod.append(ts[i] % 10)


def find_index(ts, ts_mod):
    if all([x == 0 for x in ts_mod]):
        return 0
    else:
        result = 10
        for i in range(len(ts_mod)):
            if ts_mod[i] == 0:
                pass
            else:
                if result > ts_mod[i]:
                    result = ts_mod[i]
        return ts_mod.index(result)

min_ind = find_index(ts, ts_mod)

last_ts = ts[min_ind]

del ts_mod[min_ind]
del ts[min_ind]


result = 0
for i in range(len(ts_mod)):
    if ts[i] % 10 == 0:
        result += ts[i]
    else:
        result += ts[i] + ( 10 - ts[i] % 10 )
        
result += last_ts
print(result)

Measured memory_bytes: 3064
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();

    let mut broken: Vec<bool> = vec![false; n + 1];
    for _i in 0..m {
        let a: usize = iterator.next().unwrap().parse().unwrap();
        broken[a] = true;
    }

    let mut dp: Vec<usize> = vec![0; n + 1];
    dp[n] = 1;
    dp[n - 1] = if broken[n - 1] { 0 } else { 1 };
    for i in (0..(n-1)).rev() {
        if broken[i] {
            dp[i] = 0;
            continue;
        }

        dp[i] = (dp[i + 1] + dp[i + 2]) % MOD;
    }

    return dp[0].to_string();
}

const MOD: usize = 1_000_000_007;


Measured memory_bytes: 6396
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll solve(ll i,ll n,ll temp,vector<vector<ll> > &s,ll m,vector<ll> &p)
{
    if(i==n)
    {
        ll k = 0;
        for(ll i=0;i<m;i++)
        {
            ll on = 0;
            for(auto &x:s[i])
            {
                ll j = x-1;
                ll mask = (1<<j)&(temp);
                if(mask)
                {
                    on++;
                }
            }
            if(on%2 == p[i]%2)
            {
                k++;
            }
        }
        if(k==m)
        {
            return 1;
        }
        return 0;
    }
    ll ans1 = solve(i+1,n,temp,s,m,p);
    temp = ((1<<i)|temp);
    ll ans2 = solve(i+1,n,temp,s,m,p);
    ans1 += ans2;
    return ans1;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,m;
    cin>>n>>m;
    vector<vector<ll> > s(m);
    for(ll i=0;i<m;i++)
    {
        ll k;
        cin>>k;
        s[i] = vector<ll>(k);
        for(auto &x:s[i])
        {
            cin>>x;
        }
    }
    vector<ll> p(m);
    for(auto &x:p)
    {
        cin>>x;
    }
    ll ans = solve(0,n,0,s,m,p);
    cout<<ans;
    return 0;
}































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

int main() {
    int N;

    while(cin >> N, N) {
        string s; cin >> s;

        vector< vector<int> > dp(1 << 10, vector<int>(10));
        int bit = 0, ok = true, ok1 = true;
        for(int i=0; i<N; i++) {
            if(s[i] == 'u') {
                bit = 0;
                ok1 = true;
            }
            else {
                int c = s[i] - '0';
                if(bit >> c & 1) {
                    ok = ok1 = false;
                    continue;
                }
                bit |= (1 << c);

                if(s[i+1] != 'u' && ok1) {
                    dp[bit][ s[i+1] - '0' ] = true;
                    // printf("bit = %d, nxt = %d -> true\n", bit, s[i+1] - '0');
                }
            }
        }

        while(1) {
            bool update = false;
            vector< vector<int> > nxt = dp;
            for(int bita=0; bita<(1<<10); bita++) {
                for(int x=0; x<10; x++) {
                    if(dp[bita][x] == false) continue;
                    int rest = ((1 << 10) - 1) ^ bita;
                    for(int bitb=rest; ; bitb=(bitb-1)&rest) {
                        for(int y=0; y<10; y++) {
                            if(dp[bitb][y] == false) continue;

                            int nbit = bita | bitb;
                            if(nxt[nbit][y]) continue;
                            if(!(bitb >> x & 1)) continue;
                            if( (bitb >> x & 1) && (bita >> y & 1) ) ok = false;
                            // printf("nbit = %d, y = %d -> true\n", nbit, y);
                            update = nxt[nbit][y] = true;
                        }
                        if(bitb == 0) break;
                    }
                }
            }
            if(!update) break;
            swap(dp, nxt);
        }
        printf("%s\n", ok ? "SAFE" : "UNSAFE");
    }
    return 0;
}


Measured memory_bytes: 3236
<?php
	$n = trim(fgets(STDIN));
	$ret = "";
	if($n == 0){
      echo "0";
      exit;
    }
	while($n != 0){
		$m = abs($n % 2);
      	$n = $n - $m;
      	$n /= 2;
        $n *= -1;
	    $ret = $m.$ret;
    }
	echo $ret;

Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fs first
#define sn second
#define mp make_pair
typedef long long int ll;

template<typename T, typename U> static inline void amin(T &x, U y){if (y < x)x = y;}  
template<typename T, typename U> static inline void amax(T &x, U y){if (x < y)x = y;} 

const ll mod = 1e9+7; 

//void precomp(){}

void solve(){
    
    int n;cin>>n;ll a[n][3];
    for(auto& i: a){
    	for(auto& j: i)cin>>j;
    }
    ll dp[n][3]={0};
    dp[0][0]=a[0][0];dp[0][1]=a[0][1];dp[0][2]=a[0][2];
    for(int i=1;i<n;i++){
        dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<"\n";
}

int main(){
	
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);cout.tie(NULL);

    //precomp();
	
	//int tc;cin>>tc;while(tc--)
    solve();

    return 0;
}

Measured memory_bytes: 8344