akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

//10進数を2進数に変換_63個の要素を持つ配列
vector<int> Convert10to2(ll n) {
	vector<int> ans(63);
	rep(i, 63) {
		ans[i] = n % 2;
		n -= n % 2;
		n /= 2;
	}
	return ans;
}
//2進数を10進数に変換_63個の要素を持つ配列
ll Convert2to10(vector<int> a) {
	ll ans=0;
	ll j = 1;
	rep(i, a.size()) {
		ans += a[i] * j;
		if (i != a.size() - 1) {
			j *= 2;
		}
	}
	return ans;
}
//XORを計算
vector<int> CalcXOR2to2(vector<int> a, vector<int> b) {
	rep(i, 63) {
		if (a[i] != b[i]) {
			a[i] = 1;
		}
		else {
			a[i] = 0;
		}
	}
	return a;
}

//最大公約数
int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a%b);
}


int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	int ans = a[0];
	rep(i, n - 1) {
		ans = gcd(ans, a[i + 1]);
	}
	cout << ans << endl;



	return 0;
}



Measured memory_bytes: 640
X = int(input())

if X == 2:
	print(2)
else:
	while True:
		flg = 1
		for i in range(2, X):
			if X % i == 0:
				flg = 0
				break
		if flg == 1:
			print(X)
			break
		else:
			X += 1

Measured memory_bytes: 38640
menu = [int(input()) for i in range(5)]
def kuriage(n):
    if n %10 == 0:
        return 0
    else:
        return 10-(n %10)
ans = 0
mini = 10
k = 5
for i in range(5):
    if menu[i] %10 < mini and menu[i]%10 !=0:
        mini = menu[i] %10
        k = i
for i in range(5):
    if i == k:
        menu[i], menu[-1] = menu[-1], menu[i]

for i in range(5):
    if i != 4:
        ans += menu[i] + kuriage(menu[i])
    else:
        ans += menu[-1]
        print(ans)


Measured memory_bytes: 8988
using System;
using System.Linq;

class Plogram
{
    static void Main()
    {

        int num = int.Parse(Console.ReadLine());

        int[] value = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        int[] cost = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        int total = 0;
        for(int i = 0; i<num; i++)
        {
            if(value[i]>cost[i])
            {
                total += value[i] - cost[i];
            }
        }
        Console.WriteLine(total);
    }
}

Measured memory_bytes: 13268
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
 
public class Main {
 
  public static void main(String[] args) {
      Scanner in = new Scanner(System.in);
      String s = in.nextLine();
 
      String[] ar = s.split(" ");
      StringBuilder sb = new StringBuilder();
 
      String newStr = "";
      for (int i = 0; i < ar.length; i++) {
        String temp = ar[i];
        newStr += temp.substring(0, 1);
 
      }
 
      System.out.println(newStr.toUpperCase());
  }
}

Measured memory_bytes: 23636
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate#,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial
#import sys

setrecursionlimit(10**6)
input=stdin.readline

n=int(input().rstrip())
info=[]
num=[]
ans=0
for _ in range(n):
    a=int(input().rstrip())
    num.append(a)
    x=[tuple(map(int,input().split())) for _ in range(a)]
    info.append(x)
#print(info)
for i in range(2**n):
    s=bin(i)[2:].zfill(n)
    now=s.count("1")
    check=[bool(int(ii)) for ii in s]
    ch=True
    for j in range(n):
        #print(check)
        if (not ch) or (not check[j]): continue
        for k in range(num[j]):
            #print(check[info[j][k][0]-1],info[j][k][1])
            if check[info[j][k][0]-1]!=bool(info[j][k][1]):
                ch=False
                break
    #print(ch)
    if ch:
        ans=max(ans,now)
print(ans)

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

int main() {
	string aa;
	cin >> aa;
	char s = '1';
	int k,n=0;
	cin >> k;
	for(int i=0;i<aa.size();i++)
	{
		if(aa.at(i) != '1')
		{
			s = aa.at(i);
			n = i+1;
			break;
		}
	}
	if(k < n)
	{
		s = '1';
	}
    cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N,X,D; cin >> N >> X >> D;

    if (D == 0) {
        cout << (X == 0 ? 1 : N+1) << ln;
        return 0;
    }
    if (D < 0) {
        D = -D;
        X = -X;
    }
    ll DD = D*2;
    map<ll, map<ll, ll>> dic;
    for (ll i = 0; i <= N; i++) {
        ll P = X*(i*2 - N);
        //ll c = (P - K) >= 0 ? (P-K)/D : -((K-P)/D);
        ll l = i*(i-1)/2 - (N-1+i)*(N-i)/2;
        ll K = (P+l*D) >= 0 ? (P+l*D) % DD : (DD - (-(P+l*D))%DD) % DD;
        ll r = (N*2-1-i)*i/2 - (N-1-i)*(N-i)/2;
        dic[K][P+l*D]++;
        dic[K][P+(r+2)*D]--;
    }
    /*
    for (auto mp : dic) {
        auto it = mp.second.begin();
        while (1) {
            cout << it->first << " " << it->second << ln;
            if (next(it)==mp.second.end()) break;
            ll val = it->second;
            it++;
            it->second += val;
        }
    }
    */
    ll ans = 0;
    for (auto mp : dic) {
        auto it = mp.second.begin();
        bool ok = false;
        ll l;
        while (1) {
            //cout << it->first << " " << it->second << ln;
            if (!ok and it->second > 0) {
                ok = true;
                l = it->first;
            } else if (ok and it->second <= 0) {
                ok = false;
                ans += (it->first - l)/DD;
            }
            if (next(it)==mp.second.end()) break;
            ll val = it->second;
            it++;
            it->second += val;
        }
    }

    cout << ans << ln;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,r;
  while(cin >> n >> r && n && r){
    vary(ll,v,n,0);
    rep(i,n){
      v[i] = n-i;
    }
    ll p,c;
    rep(i,r){
      cin >> p >> c;
      auto v2 = v;
      REP(j,p-1,p+c-1){
        v2[j-p+1] = v[j];
        v[j] = -1;
      }
      for(ll j = 0; j < n;){
        if(v[j] == -1){
          ++j;
        }
        else{
          v2[c] = v[j];
          ++c;
          ++j;
        }
      }
      v = v2;
    }
    cout << v[0]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3016
/*
ABC151-D AC in 10ms
幅優先探索 : 最短距離を求める
参考　: https://qiita.com/drken/items/6a95b57d2e374a3d3292#4-2-%E3%82%B0%E3%83%A9%E3%83%95%E4%B8%8A%E3%81%AE%E6%8E%A2%E7%B4%A2
*/

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> Pii;

int H, W;
vector<string> S(20);
void input(){
  cin>>H>>W;
  for(int i=0; i<H; i++){
    cin>>S[i];
  }
}

//4方向の移動を示す
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int bfs(int sx, int sy){
  //(sx, sy)からの最大距離を返す
  int ans = 0;
  vector<vector<int>> dist(H, vector<int>(W, -1)); //dist=-1のマスは未発見
  queue<Pii> unvisited; //発見したけど訪問していないマスの情報
  /*
  pushは後ろから入れる
  popは先頭から出す
  */

  dist[sx][sy] = 0; //スタートを発見
  unvisited.push(Pii(sx, sy)); //訪問はしてないのでスタートを入れる

  //探索開始
  while(!unvisited.empty()){
    //unvisitedが空になるまで
    pair<int, int> current = unvisited.front(); //先頭を読む
    unvisited.pop(); //先頭を捨てる
    int x = current.first;
    int y = current.second;

    for(int i=0; i<4; i++){
      //4方向にnextを探索
      int next_x = x + dx[i];
      int next_y = y + dy[i];
      if(next_x<0 || next_x>=H || next_y<0 || next_y>=W) continue; //外に出たらダメ
      if(S[next_x][next_y]=='#') continue; //壁はダメ

      if(dist[next_x][next_y] == -1){
        //未発見だったらこれで発見なので未訪問キューに入れる
        unvisited.push(Pii(next_x, next_y));
        dist[next_x][next_y] = dist[x][y] + 1; //nextのdistは現在地+1
        ans = max(ans, dist[next_x][next_y]);
      }
    }
  }
  return ans;
}

int main(){
  input();
  int ans = 0;

  for(int sx=0; sx<H; sx++)for(int sy=0; sy<W; sy++){
    if(S[sx][sy]=='.'){
      //スタートにできるとき      
      ans = max(ans, bfs(sx, sy));
    }
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)

int main(){

    fast;
    string s,t;
    cin>>s>>t;
    int a[26]={0},i;
    int b[26]={0};
    int ans=0;
    for(i=0;i<s.length();i++)
    {
    	if(s[i]!=t[i])
    	ans++;
	}
	cout<<ans;
	
    
}

Measured memory_bytes: 3888
import java.util.*;
import static java.lang.Math.*;
import static java.lang.System.out;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().AOJ0005();
	}
	
	void AOJ0005(){	// GCD and LCM
		while(sc.hasNext()){
			int a=sc.nextInt(), b=sc.nextInt();
			int temp=gcd(max(a,b), min(a,b));
			out.println(temp+" "+max(a,b)/temp*min(a,b));
		}
	}
	int gcd(int x, int y){
		if(y==0)	return x;
		else	return gcd(y, x%y);
	}
	
	int c197=0;
	void AOJ0197(){	// Greatest Common Divisor: Euclidean Algorithm
		while(sc.hasNext()){
			int x=sc.nextInt(), y=sc.nextInt();
			if(x<2)	break;
			c197=0;
			out.println(gcd197(max(x,y), min(x,y))+" "+c197);
		}
	}
	int gcd197(int x, int y){
		if(y==0)	return x;
		c197++;
		return gcd197(y, x%y);
	}
	
	void AOJ0001(){	// List of Top 3 Hills
		int[] m = new int[10];
		for(int i=0; i<10; i++)	m[i]=sc.nextInt();
		Arrays.sort(m);
		for(int i=9; i>=7; i--)	out.println(m[i]);
	}
	
	void AOJ10029(){	// Sort II
		int n=sc.nextInt();
		int[] ans = new int[n];
		for(int i=0; i<n; i++)	ans[i]=sc.nextInt();
		Arrays.sort(ans);
		out.print(ans[0]);
		for(int i=1; i<n; i++)	out.print(" "+ans[i]);
		out.println();
	}
	
	int[][] p26 = new int[10][10];
	int c26=100;
	void AOJ0026(){	// Dropping Ink
		int ans=0;
		while(sc.hasNext()){
			Scanner sc2 = new Scanner(sc.nextLine()).useDelimiter(",");
			int x=sc2.nextInt(), y=sc2.nextInt(), s=sc2.nextInt();
			// out.println("x"+x+" y"+y+" s"+s);
			ans=max(solve26(x,y),ans);
			ans=max(solve26(x-1,y),ans);	ans=max(solve26(x+1,y),ans);
			ans=max(solve26(x,y-1),ans);	ans=max(solve26(x,y+1),ans);
			if(s>=2){
				ans=max(solve26(x-1,y-1),ans);	ans=max(solve26(x-1,y+1),ans);
				ans=max(solve26(x+1,y-1),ans);	ans=max(solve26(x+1,y+1),ans);
			}
			if(s>=3){
				ans=max(solve26(x-2,y),ans);	ans=max(solve26(x+2,y),ans);
				ans=max(solve26(x,y-2),ans);	ans=max(solve26(x,y+2),ans);
			}
		}
		out.println(c26);
		out.println(ans);
	}
	int solve26(int x, int y){
		int r=-1;
		if(0<=x && x<=9 && 0<=y && y<=9){
			c26 -= p26[x][y]==0? 1: 0;
			p26[x][y]++;
			r=p26[x][y];
		}
		return r;	// RA
	}
	
	void AOJ0008(){	//Sum of 4 Integers
		while(sc.hasNext()){
			int ans=0, n=sc.nextInt();
			for(int a=0; a<10; a++){
				for(int b=0; b<10; b++){
					for(int c=0; c<10; c++){
						for(int d=0; d<10; d++)		if((a+b+c+d)==n)	ans++;
					}
				}
			}
			out.println(ans);
		}
	}
	
	void AOJ0055(){	// Sequence
		while(sc.hasNext()){
			double last=sc.nextDouble(), ans=last;
			for(int i=2; i<=10; i++){
				ans+= i%2==0? last*2: last/3;
				last = i%2==0? last*2: last/3;
				// out.println(last);
			}
			out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
#include <cstdio>
#include <climits>
#include <cstring>

#define STATION_MAX 101

//#define dprintf(arg1, ... ) printf( arg1, __VA_ARGS__)
#define dprintf(arg1, ... ) 

/*
typedef struct {
	
} LINE;
*/
int line_cnt, stat_cnt;
int line_cost[2][STATION_MAX][STATION_MAX];
int stat_cost[STATION_MAX];
bool stat_flag[STATION_MAX];

void check_tonari( int lcost[STATION_MAX][STATION_MAX], int nowstat ) {
	for ( int i=1; i<stat_cnt+1; i++ ) {
		if ( lcost[nowstat][i] == -1 ) { continue; }
		if ( stat_cost[i] == -1 ||  stat_cost[i] > stat_cost[nowstat] + lcost[nowstat][i] ) {
			dprintf( "Refresh stat_cost[%d]:  %d (old: %d)\n", i, stat_cost[nowstat] + lcost[nowstat][i], stat_cost[i]);
			stat_cost[i] = stat_cost[nowstat] + lcost[nowstat][i];
		}
	}
}

int main(void) {

	while(1) {
		scanf("%d %d\n", &line_cnt, &stat_cnt);
		if ( line_cnt==0 && stat_cnt== 0 ) { break; }
		
		memset( line_cost, -1, sizeof(int)*2*STATION_MAX*STATION_MAX );
		
		int a; int b; int fee; int time;
		for( int i=0; i<line_cnt; i++ ) {
			scanf("%d %d %d %d\n", &a, &b, &fee, &time );
			line_cost[0][a][b] = line_cost[0][b][a] = fee;
			line_cost[1][a][b] = line_cost[1][b][a] = time;
		}
		
		int query_cnt;
		scanf("%d\n", &query_cnt );
		
		for( int i=0; i<query_cnt; i++ ) {
			int start, end, type;
			
			scanf("%d %d %d\n", &start, &end, &type );
			
			memset( stat_cost, -1, sizeof(int)*STATION_MAX );
			memset( stat_flag, false, sizeof(bool)*STATION_MAX );
			
			stat_cost[start] = 0;
			
			while(1) {
				int minstat = -1;
				int minval=INT_MAX;
				for ( int i=1; i<stat_cnt+1; i++ ) {
					if ( stat_cost[i] == -1 ) { continue; }
					if ( stat_flag[i] == true ) { continue; }
					if ( stat_cost[i] < minval ) { minstat = i; minval = stat_cost[i]; }
				}
				if ( minstat == -1 ) { break; }
				dprintf("minstat: %d stat_cost=%d\n", minstat, stat_cost[minstat]);
				
				stat_flag[minstat] = true;
				check_tonari( line_cost[type], minstat );
			}
			
			printf("%d\n", stat_cost[end]);
		}
	}
	
	return 0;
}

Measured memory_bytes: 852
#include <stdio.h>
int main(){
  int h,w,i,j;

  while(1){
    scanf("%d %d",&h,&w);
    if((h==0)&&(w==0)) break;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++) printf("#");
      printf("\n");
    }
    printf("\n");
  }

  return 0;
}

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

typedef long long ll;

#define REP(i,m,n) for(int i=(int)m; i < (int) n; ++i)
#define rep(i,n) REP(i,0,n)
#define all(a) (a).begin(), (a).end()


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

    int n;
    string s;
    cin >> n >> s;

    int ans = 0;
    REP(i, 1, n) {
        string p = s.substr(0, i);
        string q = s.substr(i, n-i);
        
        int cnt = 0;
        for(char c = 'a'; c <= 'z'; c++) {
            bool pFound = false, qFound = false;
            rep(j, p.size()) {
                if(p[j] == c) pFound = true;
            }
            rep(j, q.size()) {
                if(q[j] == c) qFound = true;
            }
            if(pFound && qFound) cnt++;
        }
        ans = max(ans, cnt);
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

int main(){
ll n;cin>>n;
ll t;cin>>t;
ll sum=0;
for(ll i=0;i<t;i++){ll a;cin>>a;sum+=a;}
if(n-sum<=0)cout<<"Yes";
else cout<<"No";

}

Measured memory_bytes: 256
a = int(input())
b = list(map(int,input().split()))
c = 0
d = []
e = []
for i in range(a):
  while b[i] % 2 == 0:
    c += 1
    b[i] /= 2
  d.append(c)
  e.append(b[i])
  c = 0

d.sort()
print(d[0])

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	ll n; cin >> n;
	vector<pair<ll, ll>> res;
	for (ll a=2; a*a <=n; ++a) {
		if (n%a!=0) continue;
		ll ex = 0;
		while (n%a == 0) {
			++ex;
			n /= a;
		}
		res.push_back({a, ex});
	}
	if (n!=1) res.push_back({n, 1});

	ll ret = 0;
	vector<ll> sum(100, 0);
	for (int i=1; i<100; i++) {
		sum[i] = sum[i-1] + i;
	}

	for (auto p : res) {
		auto itr = lower_bound(sum.begin(), sum.end(), p.second);
		if (*itr != p.second) itr--;
		ret += itr - sum.begin();
	}
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 3648
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll N, K;
    cin >> N >> K;

    vll v(N);
    REP(i, N) cin >> v[i];

    ll ng = 0, ok = INF;
    while(ok - ng > 1) {
        ll mid = (ng + ok) / 2;
        ll cnt = 0;
        REP(i, N) {
            ll c = v[i];
            if (mid >= c) continue;
            cnt += c / mid;
        }

        if (cnt <= K) ok = mid;
        else ng = mid;
    }

    print(ok);
}


Measured memory_bytes: 4732
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int cx[n],cy[n],ch[n],h=0,x,y;
  for(int i=0;i<n;i++){
    cin>>cx[i]>>cy[i]>>ch[i];
    if(ch[i]>h){
      x=cx[i];
      y=cy[i];
      h=ch[i];
    }
  }
  for(int i=0;i<=100;i++){
    for(int j=0;j<=100;j++){
      int hh=h+abs(i-x)+abs(j-y);
      bool f=false;
      for(int k=0;k<n;k++){
        if(ch[k]==max(hh-abs(i-cx[k])-abs(j-cy[k]),0)){
          f=true;
        }else{
          f=false;
          break;
        }
      }
      if(f){
        cout<<i<<" "<<j<<" "<<hh;
        return 0;
      }
    }
  }
}
    

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int h[n],now=0,ans=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>h[i];
		if (now<=h[i])
		{
			now=h[i];
		}
		else
		{
			ans+=now-h[i];
			now=h[i];
		}
	}
	cout<<ans+now<<endl;
	return 0;
}


Measured memory_bytes: 256
H,W= map(int,input().split())
mine = [list(input()) for i in range(H)]

def count(ch):
  return 1 if ch == '#' else 0

for i in range(H):
  for j in range(W):
    num = 0
    if mine[i][j] == '#':
      continue
    else:
      for k in range(-1,2):
        for l in range(-1,2):
          if 0<=i+k<H and 0<=j+l<W:
            num += (1 if mine[i+k][j+l]=='#' else 0) 
      mine[i][j] = num
      
for i in range(H):
  for j in range(W):
    print(mine[i][j],end='')
  print()

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string n;
ll res=0;
void search(ll,string);
ll calc(string);

int main(){
  cin>>n;
  //reverse(n.begin(),n.end());
  search(1,n.substr(0,1));
  cout<<res<<endl;
}

void search(ll i, string q){
  // cout<<i<<" "<<q<<endl;
  
  if((int)n.size()==i){
    res+=calc(q);
    //cout<<q<<"="<<calc(q)<<endl;
    return;
  }
 
  //足し算にする場合
  search(i+1, q+"+"+n.substr(i,1));
  //桁を連結する場合
  search(i+1, q+n.substr(i,1));
}

ll calc(string q){
  ll ans=0,tmp=0,cnt=1;
  reverse(q.begin(),q.end());
  for(int i=0; i<(int)q.length(); i++){
    if(q[i]=='+'){
      ans+=tmp;
      tmp=0;cnt=1;
    }else{
      tmp+=cnt*(q[i]-'0');
      cnt*=10;
    }
  }
  ans+=tmp;
  return ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi   = vector<int>;
using vll  = vector<ll>;
using vc   = vector<char>;
using vvll  = vector<vll>;
using vvi  = vector<vi>;
using vvc  = vector<vc>;
using vb   = vector<bool>;
using vvb  = vector<vb>;
using pii  = pair<int,int>;
using vpii = vector<pii>;


int main() {
    int r, D, x_2000; cin >> r >> D >> x_2000;
    int x_now, x_old = x_2000;

    for (int i = 0; i < 10; i++) {
        x_now = r*x_old - D;
        x_old = x_now;
        cout << x_now << endl;
    }
}

Measured memory_bytes: 3524
#include <iostream>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
//#define hell        1000000007
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.000000001
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e7+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

using namespace std;
#include <stdio.h>

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0){
    if(y%2) res=(x%hell*res%hell)%hell;
    x=(x%hell*x%hell)%hell;
    y=y/2;
  }
  return res;
}

ll modinv(ll x){
  return power(x,hell-2);
}

void solve();


void fastIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);

/*
  For freq or prime factors

for(auto pri:prime){
  while(k%pri==0){
    pcnt[pri]++;
    k/=pri;
  }
}*/
bool comp(ll x,ll y){
    return x>y;
}

void solve(){
  int test;
  //cin>>test;
  test=1;
  
  while(test--){
      int n,k;
      cin>>n>>k;
      
      ll a[n];
      forn(i,0,n)
      {
          cin>>a[i];
      }
      sort(a,a+n,comp);
      ll s=0;
      for(int i=min(n,k);i<n;i++)
      s+=a[i];
      cout<<s;
  }    
}    

    




///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll a,ll b)
{
    while( b != 0)
	{
		ll  t = b;
		b= a %t;
		a = t;
	}
	return a;
}


ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1))*k);
  else
  return ((pw(k,x/2))*(pw(k,x/2)));
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProblemB
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var As = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            long res = As[0];
            bool exceedLimit = false;
            if (As.Contains(0))
                Console.WriteLine(0);
            else if (res > 1000000000000000000)
                Console.WriteLine(-1);
            else
            {
                for (int i = 1; i < As.Length; i++)
                {
                    if(As[i] > 1000000000000000000/res)
                    { 
                        exceedLimit = true;
                        break;
                    }
                    else
                        res *= As[i];
                }
                Console.WriteLine(exceedLimit ? -1 : res);
            }
        }
    }
}


Measured memory_bytes: 41388
import itertools

D,G = map(int,input().split())
pc = [list(map(int,input().split())) for i in range(D)]

ans = 10**5

for v in itertools.product([0,1],repeat=D):
    p = 0
    t = 0
    for i in range(D):
        if v[i] == 1:
            p += (i+1)*100*pc[i][0] + pc[i][1]
            t += pc[i][0]
    w = G-p
    if w > 0:
        for i in range(D):
            if v[i] == 0 and w <= (i+1)*100*(pc[i][0]-1):
                a = (i+1)*100
                tt = t+(w+a-1)//a
                ans = min(ans,tt)
    else:
        ans = min(ans,t)
print(ans)



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

int main(void)
{
  int N;
  cin >> N;
  int a[105] = {0};
  for (int i = 0; i < N; ++i)
  {
    cin >> a[i];
  }
  sort(a, a + N);
  reverse(a, a + N);

  int Alice = 0, Bob = 0;
  for (int i = 0; i < N; ++i)
  {
    if (i % 2 == 0)
    {
      Alice += a[i];
    }
    else
    {
      Bob += a[i];
    }
  }

  cout << Alice - Bob << endl;

  return 0;
}

Measured memory_bytes: 256
time = gets.chomp.to_i
contents = gets.chomp.split.map(&:to_i)
ans = 0
time.times do |num|
  next if num == 0 || contents[num] > contents[num - 1]
  ans += contents[num - 1] - contents[num]
  contents[num] = contents[num - 1]
end
puts ans 


Measured memory_bytes: 30280
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>     // pow
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }
// cout << fixed << setprecision(10);
// vector<vector<int>> vec(H, vector<int>(W))    // int H*W

int main() {
    int N;
    cin >> N;
    vector<int> V(N);
    for(size_t i = 0; i < N; i++) {
        cin >> V[i];
    }
    sort(V.begin(), V.end());
    float sum = 0.0;
    sum += V[0];
    for(auto v : V){
        sum = (sum+v)/2;
    }
    cout << sum << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(int argc, char const *argv[]) {
    char str[1001];
    int q;
    scanf("%s", str);
    scanf("%d", &q);

    for (int i = 0; i < q; i++) {
        char order[8];
        int a, b;
        scanf("%s", order);
        scanf("%d %d", &a, &b);


        if (strcmp(order, "print") == 0) {
            for (int j = a; j <= b; j++) {
                printf("%c", str[j]);
            }
            printf("\n");

        } else if (strcmp(order, "reverse") == 0) {
            char temp[1001];
            for (int j = a; j <= b; j++) {
                temp[j] = str[a+b-j];
            }

            for (int j = a; j <= b; j++) {
                str[j] = temp[j];
            }
        } else {
            int p_len = b - a + 1;
            char p[p_len];
            scanf("%s", p);

            for (int j = 0; j < p_len; j++) {
                str[a+j] = p[j];
            }
        }
    }

    return 0;
}


Measured memory_bytes: 2100
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, = read_line(str)

if (n[0] == n[1] and n[1] == n[2]) or (n[1] == n[2] and n[2] == n[3]):
    print('Yes')
else:
    print('No')


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

using namespace std;
long long MOD = 1000000007LL;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	int N, M;
	string num = "";
	cin >> N >> M;
	for (int i = 0; i < N; ++i)num += "*";
	for (int i = 0; i < M; ++i) {
		int s;
		char c;
		cin >> s >> c;
		if (num[s - 1] != '*' && num[s - 1] != c) {
			cout << -1 << endl;
			return 0;
		}
		else {
			num[s - 1] = c;
		}
	}

	if (num[0] == '0' && N != 1) {
		cout << -1 << endl;
		return 0;
	}
	else if (num[0] == '*' && N == 1) {
		num[0] = '0';
	}
	else if (num[0] == '*') {
		num[0] = '1';
	}

	for (int i = 0; i < N; ++i) {
		if (num[i] == '*') {
			num[i] = '0';
		}
	}

	cout << num << endl;
	return 0;
}



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

#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; i++)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }

typedef long long ll;
using namespace std;

const int INF = 0x7FFFFFFF;

int main() {
    
    int n;
    cin >> n;
    vector<int> h(n, 0);
    REP(i, n) cin >> h[i];

    vector<int> dp(n, INF);
    dp[0] = 0;

    REP(i, n-1) {
        if (i+1 < n)
            chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
        if (i+2 < n)
            chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
    }

    cout << dp[n-1] << endl;
    
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define N 1005
#define ll long long
#define x first
#define y second
#define all(v) v.begin(),v.end()
using namespace std;
vector< pair< ll , ll > > ar;
ll n;
int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            cout.tie(NULL);
            cin>>n;
            ar.resize(n);
            ll x,d;
            for(int i=0;i<n;i++){
                cin>>x>>d;
                ar[i].x= x-d; ar[i].y = x+d;
            }
            sort(all(ar));
            ll ans= 0;
            ll cr = - 1e15;
            ans = 0;
            for(int i=0;i<n;i++){
                if(ar[i].x>=cr){
                    ans++;
                    cr = ar[i].y;
                }
                cr = min(cr,ar[i].y);
            }
            cout<<ans;
             return 0;
}


Measured memory_bytes: 1792
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        a: u128,
        b: f64,
    }

    let ans: u128 = (a * ((b * 100.0 + 0.5) as u128) / 100) as u128;
    println!("{}", ans);
}


Measured memory_bytes: 2172
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(in) in.begin(),in.end()

using ll = long long;
using namespace std;

int main(){
    ll n, q; cin >> n >> q;
    vector<ll> a(n); rep(i,n) cin >> a[n-1-i];
    vector<ll> sum(n+1,0), odd(n+1,0);
    rep(i,n){
        sum[i+1] = sum[i] + a[i];
        odd[i+1] = odd[i] + (i%2 == 0 ? a[i] : 0);
    }

    vector<ll> judge(n/2), ans(n/2);
    rep(i,n/2) judge[i] = (a[i+1]+a[2*i+2])/2;
    rep(i,n/2) ans[i] = sum[i+1] + odd[n] - odd[2*i+2];
    if(n%2 == 1) ans.push_back(sum[(n+1)/2]);
    reverse(all(judge)); // rep(i,judge.size()) cout << judge[i] << " "; cout << endl;
    reverse(all(ans)); // rep(i,ans.size()) cout << ans[i] << " "; cout << endl;

    while(q--){
        ll x; cin >> x;
        ll id = lower_bound(all(judge), x) - judge.begin();
      if(n%2 == 0 && id >= 1) id--;
        cout << ans[id] << endl;
    }
}

Measured memory_bytes: 6688
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if ( a==b && b!=c){
    cout << "Yes" << endl;
  }
  else if ( c==b && c!=a){
    cout << "Yes" << endl;
  }
  else if ( c==a && a!=b){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

int char_to_number(char c){
	return  c - '0';
}

int digital_sum(string number){
	int sum = 0;
	for(auto ch : number){
		sum += char_to_number(ch);
	}
	return sum;
}

int digital_sum(int number){
	return digital_sum(std::to_string(number));
}

int main(){
	int n; cin >> n;
	int ds = digital_sum(n);
	if( n % ds == 0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}


	return 0;
}


Measured memory_bytes: 256
B = 101
DIV = 1<<32
def rolling_hash(s, n)
  hash = Array.new(n+1)
  hash[0] = 0
  n.times{ |i| hash[i+1] = (hash[i]*B + s[i].ord) % DIV }
  hash
end
s = gets.chomp
t = gets.chomp
sl = s.size
tl = t.size
p = Array.new(sl+1)
p[0] = 1
sl.times{ |i| p[i+1] = p[i]*B % DIV }
h1 = rolling_hash(s,sl)
h2 = rolling_hash(t,tl)
(0..(sl-tl)).each do |i|
  p i if (h1[i+tl] - h1[i]*p[tl]) % DIV == h2[tl]
end

Measured memory_bytes: 26948
s = input()
q = int(input())
queries = []
for _ in range(q):
    queries.append(list(input().split()))

state = False
head = ''
tail = ''
for query in queries:
    if query[0] == '1':
        state = not state
    elif (query[1] == '1') ^ state:
        head = head + query[2]
    else:
        tail = tail + query[2]

head = head[::-1]
res = head + s + tail

if state:
    res = res[::-1]

print(res)

Measured memory_bytes: 31080
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  long n, m;
  scanf("%ld%ld", &n, &m);
  long ans;
  if (n==1 && m==1) ans = 1;
  else if (n==1) ans = m-2;
  else if (m==1) ans = n-2;
  else ans = (n-2)*(m-2);
  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    vector<int> b(N);
    REP(i, N) cin >> b[i],b[i]--;
    stack<int> ans;
    for(int i=N-1;i>=0;--i) {
        bool ok=false;
        for(int j=i;j>=0;--j){
            if(b[j]==j){
                ans.push(j+1);
                b.erase(b.begin()+j);
                ok=true;
                break;
            }
        }
        if(ok) continue;
        cout<<-1<<endl;
        return 0;
    }
    while(!ans.empty()){
        cout<<ans.top()<<endl;
        ans.pop();
    }
}


Measured memory_bytes: 256
l, r = map(int, input().split())
mod = 2019
r = min(r, l+673)

res = mod
for i in range(l, r):
    for j in range(r, l-1, -1):
        if i == j:
            break
        tmp = i*j % mod
        if tmp < res:
            res = tmp

print(res)

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

bool match(string s, string t) {
    rep(i, s.size()) {
        if(s.at(i) != '?' & s.at(i) != t.at(i)) {
            return false;
        }
    }
    return true;
}

int main() {
    string s, t;
    cin >> s >> t;
    stack<string> st;
    rep(i, s.size() - t.size() + 1) {
        string ans = s;
        string subs = ans.substr(i, t.size());
        if(match(subs, t)) {
            ans.replace(i, t.size(), t);
            st.push(ans);
        }
    }
    if(st.empty()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    string ans = st.top();
    for(int pos = ans.find("?"); pos != string::npos; pos = ans.find("?")) {
        ans.replace(pos, 1, "a");
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
# 初期入力
X = int(input())

#素数リスト
n = X # X以下の素数
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

n = X *2# Xの2倍までの素数
primes_bai = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes_bai.difference_update(range(i*2, n+1, i))
primes_bai=list(primes_bai)

# 2倍までの素数からX以下の素数を引く
X_koetasaisyo = set(primes_bai) - set(primes) 
X_koetasaisyo_list = list(X_koetasaisyo)
X_koetasaisyo_list.append(primes[-1])
X_koetasaisyo_list.sort()

if X == X_koetasaisyo_list[0]: # Xと等しかったらそれが答え
    print(X_koetasaisyo_list[0])
else:
    print(X_koetasaisyo_list[1])

Measured memory_bytes: 25572
/**********************************
	author:  mariogzsl
**********************************/

#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,b,a) for(int i=b-1;i>=a;i--)
#define f first
#define s second
#define puts(x) cout<<x<<endl
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N;
	cin>>N;
	vector<ll>A(N,-1);
	int neg=0;
	FOR(i,0,N){
		cin>>A[i];
		if(A[i]<0)neg++;
	} 
	FOR(i,0,N)A[i]=abs(A[i]);
	sort(A.begin(), A.end());
	ll ans=0;
	FOR(i,neg%2,N)ans+=A[i];
	FOR(i,0,neg%2)ans-=A[i];

	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
from collections import defaultdict
inpl = lambda: list(map(int,input().split()))
N, A = inpl()
x = inpl()
y = [ X-A for X in x ]
cur = defaultdict(int)
cur[0] = 1
cur[y[0]] += 1
for i in range(1,N):
    prev = cur
    cur = defaultdict(int)
    for k in prev.keys():
        cur[k] += prev[k]
        cur[k+y[i]] += prev[k]
print(cur[0]-1)

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

using namespace std;
typedef long long ll;
#define MOD 1000000007
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main(){
    int n, u, v;
    cin >> n >> u >> v;
    u--; v--;

    vector<vector<int>> graph(n);
    int a, b;
    for (int i = 0; i < n-1; i++){
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vector<int> distA(n), distT(n);

    queue<pair<int,int>> q;
    q.push({u, 0});
    vector<int> visited(n, false);
    while (!q.empty()){
        int node = q.front().first;
        int d = q.front().second;
        q.pop();
        if(visited[node])
            continue;
        visited[node] = true;
        distT[node] = d;
        for (auto next: graph[node]){
            if (!visited[next]) q.push({next, d+1});
        }
    }

    q.push({v, 0});
    visited = vector<int>(n, false);
    while (!q.empty()){
        int node = q.front().first;
        int d = q.front().second;
        q.pop();
        if(visited[node])
            continue;
        visited[node] = true;
        distA[node] = d;
        for (auto next: graph[node]){
            if (!visited[next]) q.push({next, d+1});
        }
    }

    int ans = -1;
    for(int i=0; i<n; i++) {
        if(distT[i] < distA[i])
            ans = max(ans, distA[i]-1);
    }
    cout << ans << endl;

    return 0;
}

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

int main(void){
  string s1,s2,s3;
  cin >> s1 >> s2 >> s3;
  printf("%c%c%c\n",'A' - 'a' + s1[0], 'A' - 'a' + s2[0], 'A' - 'a' + s3[0]);
}

Measured memory_bytes: 256
function main(inputs) {
  const N = inputs[0]
  const a = inputs[1].split(' ').map(Number)
  let sorted = a.sort((b, c) => { return b < c ? 1 : -1 })
  const r = sorted.reduce((h, e, i) => {
      if (i % 2 === 0) {
        return h + e
      } else {
        return h - e
      }
    }, 0)
  console.log(r)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').split('\n'))


Measured memory_bytes: 30372
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
using namespace std;

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

typedef long long ll;
typedef unsigned long long int ulli;

const ll INF = ll(1e18) + 1;

//--------------------------------------------------

ulli gcd(ulli a, ulli b) {
	return (b <= 0) ? a : gcd(b, a % b);
}

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

pair<int, int> fanc(int x) {
	int a = x % 10;
	int b = 0;
	while (x) {
		b = x % 10;
		x /= 10;
	}
	return pair<int,int>(a,b);
}

//---------------------------------------------------



void Main()
{
	ll n, ans = 0; cin >> n;
	map<pair<int, int>, int> mp;
	for (int i = 1; i <= n; i++) {
		pair<int, int> p = fanc(i);
		mp[p]++;
	}
	for (int i = 1; i <= n; i++) {
		pair<int, int>p = fanc(i);
		pair<int, int > q(p.second, p.first);
		ans += mp[q];
	}
	cout << ans << endl;
}

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

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

#define int long long

signed main(){

  int S;
  int ans = 0, con = 0;
  map<int,int> mp;
  
  cin>>S;

  for(int i = 1; i <= S; i++){
    for(int j = i, sum = i; sum <= S; j++){
      mp[sum]++;
      // cout<<"i "<<i<<" j "<<j<<" "<<sum<<endl;
      sum += j+1;
      
      con++;
    }
  }

  // cout<<con<<endl;

   for(int i = 1; i <= S; i++){
     if(S%i) continue;
     int a = mp[i], b = mp[S/i];

     // if(i == S/i) b--;

      if(a < 0 || b < 0) continue;

     ans += a * b;
   }

   cout<<ans<<endl;

  return 0;
}




Measured memory_bytes: 9228
a, b, x = map(int, input().split())
if b * 2 <= a:
  ans = b * (x // 500 + bool(x % 500))
else:
  ans = a * (x // 1000) + min(b * ((x % 1000) // 500 + bool((x % 1000) % 500)), a * bool(x % 1000))
print(ans)



Measured memory_bytes: 5600
a,b=map(int,input().split())
c=[str(input()) for i in range(a)]
for i in range(a):
  c[i]="."+c[i]+"."
c=["."*(b+2)]+c +["."*(b+2)]
d=[["0"for i in range(b)]for j in range(a)]
for i in range(1,a+1):
  for j in range(1,b+1):
    f=0
    for k in range(-1,2):
      for l in range(-1,2):
        if c[i+k][j+l]=="#":
          f+=1
    d[i-1][j-1]=str(f)
for i in range(1,a+1):
  for j in range(1,b+1):
    if c[i][j]=="#":
      d[i-1][j-1]="#"
for i in range(a):
  dd=""
  for j in range(b):
    dd+=str(d[i][j])
  print(dd)

Measured memory_bytes: 3188
import java.util.*;
import java.io.*;
import java.text.*;
public class Main{
    //SOLUTION BEGIN
    void pre() throws Exception{}
    void solve(int TC) throws Exception{
        int n = ni(), m = ni();
        long[] ways = new long[1+n];
        ways[0] = 1;
        boolean[] wa = new boolean[1+n];
        while(m-->0)wa[ni()] = true;
        for(int i = 0; i< n; i++){
            if(!wa[i]){
                if(i+1<= n)ways[i+1] = (ways[i+1]+ways[i])%mod;
                if(i+2<= n)ways[i+2] = (ways[i+2]+ways[i])%mod;
            }
        }
        pn(ways[n]);
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    long mod = (long)1000000007, IINF = (long)1e18;
    final int INF = (int)1e9, MX = (int)2e5+5;
    DecimalFormat df = new DecimalFormat("0.00000000000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-8;
    static boolean multipleTC = false, memory = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        in = new FastReader();
        out = new PrintWriter(System.out);
        //Solution Credits: Taranpreet Singh
        int T = (multipleTC)?ni():1;
        pre();for(int t = 1; t<= T; t++)solve(t);
        out.flush();
        out.close();
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next() throws Exception{
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    throw new Exception(e.toString());
                }
            }
            return st.nextToken();
        }

        String nextLine() throws Exception{
            String str = "";
            try{   
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }  
            return str;
        }
    }
}

Measured memory_bytes: 38296
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const ll mod = 1e9+7;

ll Pow(ll x, ll n){
  if(n == 0) return 1;
  if(n % 2 == 0) return Pow(x*x % mod, n/2);
  else return x * Pow(x,n-1) % mod;
}

int main(){
  ll n;
  cin >> n;
  ll a[n];
  rep(i,n) cin >> a[i];
  vector<ll> d(64,0);
  rep(i,64) {
    rep(j,n) {
      if(a[j] % 2) d[i]++;
      a[j] /= 2;
    }
  }
  ll ans = 0;
  rep(i,64) {
    ll q = (d[i]*(n-d[i])) % mod;
    ans = (ans + Pow(2,i)*q) % mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560