akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define ri register int
#define il inline
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define all(x) x.begin(),x.end() 
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define per(i,a,b) for(ri i=(a);i>=(b);--i)
#define ls (x<<1)
#define rs (x<<1|1)
#define mid (l+r>>1)
#define db(x) cout << "#x:" << x << endl
#define dd() cout << "Out put!\n"
const int mod=1e9+7,maxn=10000010;
const double eps=1e-8,pi=acos(-1.0);
const int inf=0x7f7f7f7f;
using namespace std;
int a[maxn],b[maxn],v[maxn];
string s;
signed main()
{
	ios::sync_with_stdio(0);
	int t=1;
//	cin >> t;
	while(t--)
	{
		int n=1000000;
		cin >> n;
		rep(i,1,n)
		{
			for(int j=i;j<=n;j+=i)
				v[j]++;	
		} 
		int ans = 0;
		rep(i,1,n)
			ans += i*v[i] ;
		cout << ans << endl;
	} 
}


Measured memory_bytes: 81760
while 1:
    n,d=input().split()
    if n==d=='0':break
    a=[int(n)]
    while 1:
        n=''.join(sorted(n.zfill(int(d))))
        b = int(n[::-1]) - int(n)
        if b in a:break
        a+=[b]
        n=str(b)
    print(a.index(b),b,len(a)-a.index(b))

Measured memory_bytes: 7620
#include<iostream>
using namespace std;
int main(){
    int n,ans=0;
    string s;
    cin>>n>>s;
    for(int i=0;i<n-2;i++)if(s[i]=='A')ans+=(s[i+1]=='B'&&s[i+2]=='C');
    cout<<ans<<endl;
    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var ks = ConsoleUtil.IntArrayReadLine();
        int K = ks[0];
        int S = ks[1];

        int count = 0;


        for(int x = 0; x <= K; x++)
        {
            if (S - x < 0) break;

            for(int y = 0; y <= K; y++)
            {
                int z = S - x - y;

                if (z < 0) break;
                
                if (z <= K)
                    count++;
            }
        }


        Console.WriteLine(count);
        

    }
}



static class ConsoleUtil
{
    public static string[] StrArrayReadLine(char sepalator)
    {
        string str = Console.ReadLine();
        return str.Split(sepalator).ToArray();
    }
    public static string[] StrArrayReadLine()
    {
        string str = Console.ReadLine();
        if (str.Contains(','))
        {
            return str.Split(',').ToArray();
        }
        {
            return str.Split(' ').ToArray();
        }
    }
    
    public static int[] IntArrayReadLine()
    {
        return StrArrayReadLine().Select(s => int.Parse(s)).ToArray();
    }
    public static int[] IntArrayReadLine(char sepalator)
    {
        return StrArrayReadLine(sepalator).Select(s => int.Parse(s)).ToArray();
    }

    public static int IntReadLine() => int.Parse(Console.ReadLine());
}



Measured memory_bytes: 13280
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <set>
using namespace std;

int main(){
    string o, e;
    cin >> o >> e;
    int i = 0;
    if(o.length() == e.length()){
        for(i = 0; i < e.length(); i++){
            cout << o[i] << e[i];
        }
    }else{
        for(i = 0; i < e.length(); i++){
            cout << o[i] << e[i];
        }
        cout << o[i];
    }
}


Measured memory_bytes: 256
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)



int main() {
	int n, ans = 0,i=0,j=0,k;
	cin >> n;
	if (n == 3) {
		cout << 2 << endl;
		return 0;
	}
	vector<int>a(n + 1),b(n+1);
	rep(i, n+1) {
		
		k = i;
		while (1) {
			k = k / 2;
			if (k % 2 == 0)ans++;
			if (k == 0)break;
		}
		a.at(i) = ans;
		b.at(i) = ans;
		ans = 0;
	}
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	
	rep(j, n + 1) {
		if (a.at(0) == b.at(j)) {
			if (j == 0) {
				cout << n << endl;
				return 0;
			}
			if (j == 3) {
				cout << 2 << endl;
				return 0;
			}
			cout << j << endl;
			return 0;
		}
	}
	
	return 0;
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

int A[50];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N, M = 0, m = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (A[m] > A[i]) m = i;
		if (A[M] < A[i]) M = i;
	}
	cout << 2 * N - 2 << '\n';
	if (abs(A[m]) < abs(A[M])) {
		for (int i = 0; i < N; i++) {
			if (i == M) continue;
			cout << M + 1 << ' ' << i + 1 << '\n';
		}
		for (int i = 1; i < N; i++) cout << i << ' ' << i + 1 << '\n';
	}
	else {
		for (int i = 0; i < N; i++) {
			if (i == m) continue;
			cout << m + 1 << ' ' << i + 1 << '\n';
		}
		for (int i = N - 1; i > 0; i--) cout << i + 1 << ' ' << i << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <regex>
#ifdef _DEBUG
#include "debug.h"
#endif
#define int ll
#define float double
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define all(v) (v).begin(),(v).end()
#define mkpr make_pair
#define mktp make_tuple
#define tv(tp, i) get<(i)>(tp)
#define CLEAR(obj) obj = decltype(obj)()
#define var auto
#define OUT(type) type &
#define IN(type) const type &
#define self (*this)
#define in :
#define True true
#define False false
using namespace std; using int32 = int32_t; using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>; using vc = vector<char>; using vvc = vector<vc>;
using vf = vector<float>; using vvf = vector<vf>; using vd = vector<double>; using vvd = vector<vd>;
using str = string; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pff = pair<float, float>; using pdd = pair<double, double>;
using psl = pair<string, ll>; using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>;
static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7; static const ll LINF = LLONG_MAX/2;
#ifdef int
static const int INF = LINF;
#else
static const int INF = INT_MAX/2;
#endif
static double EPS = 1e-9;
#define FASTCIN() cin.tie(0);ios::sync_with_stdio(false);
#ifdef IMPORT_SAMPLE
#define DEBUG_IMPORT(file) vs args(argv, argv+argc);str sample = make_sample(args, file);ifstream ifs(sample); cin.rdbuf(ifs.rdbuf());
#else
#define DEBUG_IMPORT(file)
#endif
static inline int ord(char c) {return (int)c;}
static inline char chr(int n) {return (char)n;}
static inline bool DBLEQ(double a, double b) {return abs(a - b) < EPS;}
static inline void EPR(str msg) {cerr << msg << endl;}
static inline void AST(bool exp, str msg) {if(!exp){EPR(msg);} assert(exp);}
static inline void TAST(bool exp, str msg) {if(!exp){EPR(msg);} while(!exp){}}


int32 main(int32 argc, char* argv[]) {
    FASTCIN();
    DEBUG_IMPORT("sample-1");


    int A,B,C,D; cin>>A>>B>>C>>D;

    int turn = 0;
    REP(t,105) {
        if (t%2 == 0) {
            C -= B;
        } else {
            A -= D;
        }
        if (A <= 0 or C <= 0) {
            turn = t%2;
            break;
        }
    }

    str ans = turn==0 ? "Yes" : "No";
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3648
using System;

namespace A
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			var input = Console.ReadLine().Split();
			var heights = new int[3];
			for (var i = 0; i < 3; i++) { heights[i] = int.Parse(input[i]); }

			Console.WriteLine(heights[1] - heights[0] == heights[2] - heights[1] ? "YES" : "NO");
		}
	}
}

Measured memory_bytes: 13140
#include<iostream>

using namespace std;
int a[4][3][10];

int main()
{
    int b,f,r,v;

    int n;

    cin>>n;

    for(int i=0;i<n;i++)
    {
        cin>>b>>f>>r>>v;
        a[b-1][f-1][r-1]+=v;
    }

    for(int i=0;i<4;i++)
    {
        if(i)
        {
            for(int j=0;j<20;j++)
            {
                cout<<'#';
            }
            cout<<endl;
        }
        for(int j=0;j<3;j++)
        {
            for(int k=0;k<10;k++)
            {
                cout<<" ";
                cout<<a[i][j][k];
            }
            cout<<endl;
        }
    }



    return 0;
}



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

    	int n = sc.nextInt();
    	int[] xList = new int[n];
    	int[] yList = new int[n];
    	for(int i = 0; i < n; i++) {
    		xList[i] = sc.nextInt();
    	}
    	for(int i = 0; i < n; i++) {
    		yList[i] = sc.nextInt();
    	}
    	double p1 = 0, p2 = 0, p3 = 0, pInf = 0;
    	for(int i = 0; i < n; i++) {
    		p1 += Math.abs(xList[i] - yList[i]);
    		p2 += Math.pow(Math.abs(xList[i] - yList[i]), 2);
    		p3 += Math.pow(Math.abs(xList[i] - yList[i]), 3);
    	}
    	pInf = Math.abs(xList[0] - yList[0]);
    	for(int i = 1; i < n; i++) {
    		pInf = Math.max(pInf, Math.abs(xList[i] - yList[i]));
    	}
    	System.out.println(p1);
    	System.out.println(Math.sqrt(p2));
    	System.out.println(Math.cbrt(p3));
    	System.out.println(pInf);
    }
}

Measured memory_bytes: 26500
#include<bits/stdc++.h>
#include<iomanip>
#define fastIO  std::ios::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define rep(i, l, r) for (long long i = (l); i < (r); i++)
#define repb(i, r, l) for (long long i = (r); i > (l); i--)
#define ll long long
#define pb push_back
#define SZ(x) ((int) (x).size())
 
using namespace std;
 
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef long long int lli;
typedef long double ld;
typedef unsigned long long ull; 
const int MAX_CHAR=256;
 


bool palin(string s){
    string s1=s;
    reverse(s.begin(),s.end());
    return s==s1;
}

ll exp(lli b,lli e){
    ll sum=1;
    b=b%1000000007;
    while(e!=0){
        if(e&1) sum=(sum* b)%1000000007;
        e=e>>1;
        b=(b*b)%1000000007;
    }
    return sum;
}

bool sam(string s){
    for(int i=1;i<s.length();i++){
        if(s[i]!=s[i-1])    return false;
    }
    return true;
}

int k;

bool bool_comp(vector<ll>& v1,vector<ll>& v2){
    if(abs(v1[1]-v2[1])<abs(v1[0]-v2[0]))   return v1[1]<v2[1];
    return v1[0]<v2[0];
}
bool bool_comp1(vector<ll>& v1,vector<ll>& v2){
    
    return v1[1]<v2[1];
}
bool bool_comp2(vector<ll>& v1,vector<ll>& v2){
    
    return v1[0]<v2[0];
}

int main(){
	fastIO;
	string s;
	cin>>s;
	int ma=0,count=0;
	for(int i=0;i<3;i++){
	    if(s[i]=='R')count++;
        else count=0;
	    ma=max(ma,count);
	}
	cout<<ma;
}
// static int a=20; 
// void xyz() 
// { 
// 	printf("%d, ", a); 
// 	a = 100; 
// } 
// int main() 
// { 
// 	printf("%d, ", a); 
// 	{ 
// 		static int a = 10; 
// 		printf("%d, \n", a); 
// 		xyz(); 
// 	} 
// 	printf("%d", a); 
// } 

Measured memory_bytes: 3648
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int dx[] = {-1,0,1,1,1,0,-1,-1};
	int dy[] = {-1,-1,-1,0,1,1,1,0};

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			if( n == 0) break;
			boolean[][] map = new boolean[n+2][n+2];
			for(int i=1;i<=n;i++) {
				String str = sc.next();
				for(int j=1;j<=n;j++) {
					if(str.charAt(j-1) == '1')
						map[i][j] = true;
				}
			}
			int cnt = 0;
			for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) {
				
				if(map[i][j]) for(int k=0;k<8;k++) {
					int d = 0;
					for(int l=0;;l++) {
						if(map[i+dy[k]*l][j-dx[k]*l]) d++;
						else break;
					}
					cnt = max(cnt, d);
				}
			}
			
			System.out.println(cnt);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

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

using namespace std;
using ll = long long;

template<class T>
vector<T> subvector(vector<T> a, int l, int num) {
   vector<T> ret;
   for(int i = l; i < l + num && i < (int)a.size(); i++)ret.emplace_back(a[i]);
   return ret;
}

vector<pair<ll,ll>> f(vector<pair<ll,ll>> a) {
    int n = a.size();
    vector<pair<ll,ll>> res;
    for(int i = 0; i < (1<<n); i++) {
        ll sumval = 0, sumcos = 0;
        for(int j = 0; j < n; j++) {
            if(i & (1 << j)) {
                sumval += a[j].first;
                sumcos += a[j].second;
            }
        }
        res.emplace_back(sumcos, sumval);
    }
    sort(res.begin(), res.end());
    return res;
}

int main()
{
    int n; ll w; cin >> n >> w;
    vector<pair<ll,ll>> a(n); // valuse, cost
    for(int i = 0; i < n; i++)cin >> a[i].first >> a[i].second; 
    int fn = n / 2, bn = n - n / 2;
    vector<pair<ll,ll>> fr, bc;
    fr = f(subvector(a,0, fn));
    bc = f(subvector(a,fn, bn));



    int m = bc.size();
    for(int i = 1; i < m; i++) {
        bc[i].second = max(bc[i].second, bc[i - 1].second);
    }


    ll ans = 0;
    for(auto i : fr) { //first : cost / second : value
        ll cur = w - i.first; //cur以下のものしか入らない
        auto itr = lower_bound(bc.begin(), bc.end(), pair<ll,ll>(cur+1, -1e18));
        if(itr == bc.begin())continue;
        itr--;
        ans = max(i.second + itr->second, ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 43772
/*
  AOJ #3102
  iff
  @kankichi57301
 */
#include <stdio.h>
#include <string.h>
int n,m;
char arc[301][301];
char reach[301][301];

char visit[301];

char is_equiv(int from,int to)
{
  return(from==to || (reach[from][to] && reach[to][from]));
}
void output_1(int line)
{
  int j,spflag;

  spflag=0;

  for(j=1;j<=n;j++)
    if(is_equiv(line,j)>0)
    {
      if(spflag==1)
	putchar(' ');
    
      printf("%d",j);
      spflag=1;
    }

  putchar('\n');
}


void output()
{
  int i;

  for(i=1;i<=n;i++)
    output_1(i);
}
void dfs_1(int from)
{
  int i;
  for(i=1;i<=n;i++)
    {
      if(i==from)
	continue;
      if(arc[from][i])
	{
	  if(visit[i]==0)
	    {
	      visit[i]=1;
	      dfs_1(i);
	    }
	}
    }
}
void dfs(int from)
{
  int i;
  
  memset(visit,0,sizeof(visit));
  dfs_1(from);
  for(i=1;i<=n;i++)
    if(i!=from && visit[i])
      reach[from][i]=1;
}
void prepare()
{
  int i,j;
  for(i=1;i<=n;i++)
    dfs(i);
}
int main()
{
  int i,a,b;

  memset(reach,0,sizeof(reach));
  scanf("%d %d",&n,&m);

  for(i=0;i<m;i++)
  {
    scanf("%d %d",&a,&b); 
    arc[a][b]=1;
  }
  prepare();


  output();
  return(0);
}



Measured memory_bytes: 2120
n = int(input())
s = input()

cs = [0]*(n-1)

for i in range(n-1):
    cnt = 0
    memo = []
    for j in s[0:i+1]:
        if j in s[i+1:n] and j not in memo:
            cnt += 1
        memo.append(j)
        
    cs[i] = cnt

print(max(cs))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

const int N = 2007;
int ans[N][N];

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int n, m;
    cin >> n >> m;
    
    vector <ii> ord;
    for (int i = 0; i < n; ++i) {
        if (i & 1)
            for (int j = 0; j < m; ++j)
                ord.app(mp(i, j));
        else
            for (int j = m - 1; j >= 0; --j)
                ord.app(mp(i, j));
    }   

    int c;
    cin >> c;
    vector <int> a(c);
    int ptr = 0;
    for (int i = 0; i < c; ++i) {
        cin >> a[i];
        for (int j = 0; j < a[i]; ++j) {
            ans[ord[ptr].f][ord[ptr].s] = i+1;
            ++ptr;
        }   
    }    

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cout << ans[i][j] << ' ';
        }   
        cout << endl;
    }   
}

Measured memory_bytes: 4184
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"

int main(int argc, char const *argv[]) {

  int NN;

  std::cin >> NN;

  std::string v[NN];

  for (size_t i = 0; i < NN; i++) {
    std::cin >> v[i];
    // std::cout << v[i] << '\n';
  }

  int flag = 1;
  for (size_t i = 0; i < NN-1; i++) {
    if (v[i][v[i].size() - 1] != v[i+1][0] ) {
      flag = 0;
    }
  }

  for (size_t i = 0; i < NN; i++) {
    for (size_t i2 = 0; i2 < i; i2++) {
      if (v[i] == v[i2]) {
        flag = 0;
      }
    }
  }

  if (flag == 0) {
    std::cout << "No" << '\n';
  }else{
    std::cout << "Yes" << '\n';
  }


  return 0;
}


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

bool is_hitachi(string s){
  int l = s.length();
  if(l%2) return false;
  for(int i = 0; i < l; i += 2){
    if(s[i] != 'h' or s[i+1] != 'i')
      return false;
  }
  return true;
}

int main(){
  string s;
  cin >> s;
  cout << (is_hitachi(s) ? "Yes\n" : "No\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(15) << << endl;
#include <cassert>

using namespace std;


#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define P pair<int,int>

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;


int main(){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int m, h, w;
    cin >> h >> w >> m;
    vector<P> tate(h), yoko(w);
    rep(i,h) tate[i].second = i;
    rep(i,w) yoko[i].second = i;
    set<P> bomb;

    while(m--){
        int hm,wm;
        cin >> hm >> wm;
        hm--; wm--;
        bomb.insert(P(hm,wm));
        tate[hm].first++;
        yoko[wm].first++;
    }
    sort(tate.rbegin(),tate.rend());
    sort(yoko.rbegin(),yoko.rend());
    int tatemax = tate[0].first, yokomax = yoko[0].first;

    bool ok = false;
    rep(i,h){
        rep(j,w){
            if (tate[i].first != tatemax) break;
            if (yoko[j].first != yokomax) break;
            auto itr = bomb.find(P(tate[i].second, yoko[j].second));
            if(itr == bomb.end()){
                //爆弾がなかった
                ok = true;
                break;
            }
        }
        if(ok) break;
    }
    int ans = tate[0].first + yoko[0].first;
    if(!ok) ans--;

    cout << ans << endl;

}



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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int h, a;
    cin >> h >> a;
    if (h % a != 0)
    {
        int ans = h / a + 1;
        c(ans);
    }
    else
    {
        c(h / a);
    }
    return 0;
}

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

ll arr[51][51];

void init(int n)
{
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
            arr[i][j] = INF;

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

ll comb(int n, int r)
{
    if (r > n - r)
        return comb(n, n - r);
    if (arr[n][r] != INF)
    {
        // cout << "array" << endl;
        return arr[n][r];
    }
    else
    {
        // cout << "f" << n - 1 << "," << r - 1 << endl;
        int tmp = (comb(n - 1, r - 1) + comb(n - 1, r));
        arr[n][r] = tmp;
        return arr[n][r];
    }
}

signed main()
{
    int n, p;
    int a[50];
    cin >> n >> p;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    init(50);

    int even = 0, odd = 0;
    for (int i = 0; i < n; i++)
        if (a[i] % 2)
            odd++;
        else
            even++;

    int sum = 0;
    if (p)
    {
        for (int i = 0; i <= even; i++)
        {
            for (int j = 1; j * 2 - 1 <= odd; j++)
            {
                sum += (comb(even, i) * comb(odd, j * 2 - 1));
            }
        }
    }
    else
    {
        for (int i = 0; i <= even; i++)
        {
            for (int j = 0; j * 2 <= odd; j++)
            {
                // cout << "comb(" << i << "," << j << ")" << endl;
                sum += (comb(even, i) * comb(odd, j * 2));
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 7;
int main(){
    int h, w;
    cin >> h >> w;
    char v[h+1][w+1];
    for(int i = 1; i <= h; i++)
        for(int j = 1; j <= w; j++) 
            cin >> v[i][j];
    int d[h+1][w+1];
    d[1][1] = 1;
    for(int i = 0; i <= h; i++) d[i][0] = 0;
    for(int i = 0; i <= w; i++) d[0][i] = 0;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(i != 1 || j != 1){
                if(v[i][j] == '#') d[i][j] = 0;
                else{
                    d[i][j] = (d[i-1][j]%INF + d[i][j-1]%INF)%INF;
                }
            }
        }
    }
    cout << d[h][w];
}

Measured memory_bytes: 5120
#include<stdio.h>

int main(){
  int A[3][3];
  bool match[3][3];
  int N;
  int B[10];
  int i,j,k;
  bool ans;
  ans = false;

  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      scanf("%d",&A[i][j]);
      match[i][j] = false;
    }
  }
  scanf("%d",&N);
  for(i=0;i<N;i++){
      scanf("%d",B+i);
  }
  for(k=0;k<N;k++){
    for(i=0;i<3;i++){
      for(j=0;j<3;j++){
        if(B[k] == A[i][j]){
          match[i][j] = true;
        }
      }
    }
  }
  for(i=0;i<3;i++){
    if(match[0][i] && match[1][i] && match[2][i]){
      ans = true;
    }
    if(match[i][0] && match[i][1] && match[i][2]){
      ans = true;
    }
  }
  if(match[0][0] && match[1][1] && match[2][2]){
    ans = true;
  }
  if(match[2][0] && match[1][1] && match[0][2]){
    ans = true;
  }
  printf("%s",ans?"Yes":"No");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define mp            make_pair
#define PI            3.14159265
#define M             1000000007
#define MM            998244353
#define fr            first
#define sc            second
#define all(v)        (v).begin(),(v).end()
#define rall(v)       (v).rbegin(),v.rend()
#define vc            vector
#define vi            vector<int>
#define pii           pair<int,int>
#define psi           pair<string,int>
#define pis           pair<int,string>
#define mii           map<int,int>
#define msi           map<string,int>

int solve(){
    int w,h,x,y;
    cin>>w>>h>>x>>y;
    double d=((double)w*(double)h)/2;
    cout<<d<<" ";
    if(x+x==w&&y+y==h) cout<<1;
    else cout<<0;
}

signed main() {
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define fi first
#define se second
//#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define vi vector<int>
typedef pair<int,int> P;
#define REP(i,x,y) for(int i=x;i<=y;i++)
#define abs(x) ((x)>0?(x):-(x))
#define y1 hhf
#define mp make_pair
const int maxn = 1005;
queue<P> q;
int vis[maxn][maxn];
int d[maxn][maxn];
char b[maxn][maxn];
int n,m;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
void push(int i,int j){
	q.push(mp(i,j));
	vis[i][j]=1;
}
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>b[i][j];
			if(b[i][j]=='#') push(i,j);
		}
	}
	while(q.size()){
		P p=q.front(); q.pop();
		int x=p.fi,y=p.se;
		for(int dr=0;dr<4;dr++){
			int nx=x+dx[dr],ny=y+dy[dr];
			if(nx>=0&&ny>=0&&nx<n&&ny<m&&!vis[nx][ny]){
				vis[nx][ny]=1;
				d[nx][ny]=d[x][y]+1;
				push(nx,ny);
			}
		}
	}
	int mx=0;
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++){
			mx=max(mx,d[i][j]);
		}
	}
	cout<<mx<<endl;
	return 0;
}

Measured memory_bytes: 14224
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    if(n == 1)
    {
        cout << 1 << endl;
        return 0;
    }
    vector<int> A;
    for(int i = 0; i < n; i++)
    {
        int x; cin >> x;
        if(A.size() and A.back() == x) continue;
        A.push_back(x);
    }
    int ans = 1;
    int v = A[0];
    bool inc = A[0] <= A[1];
    for(int i = 1; i < A.size(); i++)
    {
        if(inc)
        {
            if(A[i] < v)
            {
                ans++;
                if(i + 1 < n) inc = A[i] <= A[i + 1];
                else break;
            }
        }
        else
        {
            if(A[i] > v)
            {
                ans++;
                if(i + 1 < n) inc = A[i] <= A[i + 1];
                else break;
            }
        }
        v = A[i];
    }
    cout << ans << endl;
    return 0;
}



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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

int dp[100000];
int p[10][10];

int main(){
    cin.sync_with_stdio(false);
    int n, d, x;
    cin >> n >> d >> x;
    rep(i, d)rep(j, n) cin >> p[i][j];

    memset(dp, -1, sizeof(dp));
    rep(i, d - 1) {
        rep(j, x + 1) dp[j] = j;
        rep(j, n)rep(k, x + 1) {
            if (k >= p[i][j]) {
                maxch(dp[k], dp[k - p[i][j]] + p[i + 1][j]);
            }
        }
        x = *max_element(dp, dp + x + 1);
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 3556
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();		
        int b = sc.nextInt();
		int c = 0;
        for(int i=0;i<a;i++){c+=b+i;
                            }
        if(b*(b+a-1)>0){if(b>0){c-=b;}else{c-=b+a-1;}}
		System.out.println(c);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
    int x,a; cin>>x>>a;
    if(x<a) cout<<0<<endl;
    else cout<<10<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  string ans = "Yes";
  int n; cin >> n;
  string s; cin >> s;
  if(n % 2 != 0) ans = "No";
  int k = n /2;
  for(int i = 0; i < k; i++){
    if(s.at(i) != s.at(i+k)) ans = "No";
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N , K = map(int,input().split())
S = list(input())
row = []
for i in range(N):
	if i == 0:
		judge = S[i]
		row.append(1)
	else:
		if judge == S[i]:
			row[-1] += 1
		else:
			judge = S[i]
			row.append(1)
if S[-1] == "0":
	row.append(0)
if S[0] == "0":
	row.insert(0,0)
max_row = 2 * K + 1

if max_row >= len(row):
	print(N)
else:
	sum_count = []
	temp_sum = 0
	for i in range(max_row):
		temp_sum += row[i]
	sum_count.append(temp_sum)
	i = max_row
	while i < len(row):
		sum_count.append(sum_count[-1] + row[i] + row[i+1] - row[i-max_row] - row[i-max_row+1])
		i += 2
	print(max(sum_count))
	
	

Measured memory_bytes: 6244
import java.util.Scanner;

public class Main {
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int cnt = 0;

		for(int i = 1;i <= a;i++) {
			cnt += (String.valueOf(i).length() % 2 == 1) ? 1 : 0;
		}

		System.out.println(cnt);

	}
}


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

int main(){
	int N;
	cin >> N;
	vector<int> a(N);
	int p=0; // �����Ă���{�^��
	int count=0; //�{�^��������
	
	for(int i=0;i<N;i++){
		cin >> a.at(i);
		a.at(i)--;
	} //���͏I��
	
	while((count<N)&&(p!=1)){
		p=a.at(p);
		count++;
	}
	
	if(count==N){
		cout << -1 << endl;
	}else{
		cout << count << endl;
	}
}

Measured memory_bytes: 640
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>
#include <queue>
#define _USE_MATH_DEFINES
#include <math.h>

typedef long long ll;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

//最大・最小
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a, bool g){
	if(g){
		if(a[index]<key){
			return true;
		}
	}
	else{
		if(a[index]>key){
			return true;
		}
	}
	return false;
}

ll bin_search(ll key, vector<ll> &a, bool g){
	
	ll l=-1;
	ll r=a.size();

	if(g){
		l=a.size();
		r=-1;
	}

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a, g)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}


//深さ優先探索
void dfs(vector<string> &m,vector<vector<bool>> &seen, ll x, ll y, ll h, ll w){

	seen[y][x]=true;

	
	for(ll i=0;i<4;i++){
		ll nx=x,ny=y;
		if(i==0){ //up
			ny=y-1;
		}
		else if(i==1){ //down
			ny=y+1;
		}
		else if(i==2){ //right
			nx=x+1;
		}
		else{ //left
			nx=x-1;
		}

		if(nx<0 || nx>=w || ny<0 || ny>=h){
			continue;
		}
		if(seen[ny][nx]){
			continue;
		}
		
		if(m[ny][nx]=='#'){
			continue;
		}

		dfs(m,seen,nx,ny,h,w);
	}
}


void solve(){
	
	ll n;
	cin>>n;
	vector<tuple<string,ll,ll>> s(n);

	for(ll i=0;i<n;i++){
		cin>>get<0>(s[i]);
		cin>>get<1>(s[i]);
		get<1>(s[i])=-get<1>(s[i]);
		get<2>(s[i])=i+1;
	}

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

	for(ll i=0;i<n;i++){
		cout<<get<2>(s[i])<<endl;
	}
}

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


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

int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  
  vector<int>s=a;
  sort(s.rbegin(),s.rend());
  for(int i=0;i<n;i++){
    int num=s[0];
    if(a[i]==s[0]){
      num=s[1];
    }
    cout<<num<<endl;
  }
}

Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
    int n,m,q;
    cin >> n >> m >> q;
    int a[q], b[q], c[q], d[q];
    for(int i=0; i<q; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    
    int cnt = 0;
    std::vector<int> v[100000];
    for(int i0=0; i0<m; i0++){
    for(int i1=i0; i1<m; i1++){
    for(int i2=i1; i2<m; i2++){
    for(int i3=i2; i3<m; i3++){
    for(int i4=i3; i4<m; i4++){
    for(int i5=i4; i5<m; i5++){
    for(int i6=i5; i6<m; i6++){
    for(int i7=i6; i7<m; i7++){
    for(int i8=i7; i8<m; i8++){
    for(int i9=i8; i9<m; i9++){
        v[cnt] = {i0, i1, i2, i3, i4, i5, i6, i7, i8, i9}; 
        cnt++;
    }}}}}}}}}}
    
    long long int max = 0;
    for(int i=0; i<cnt; i++){
        long long int sum = 0;
        for(int j=0; j<q; j++){
            int aj = a[j]-1;
            int bj = b[j]-1;
            if(v[i][bj]-v[i][aj] == c[j]){
                sum += d[j];
            }
        }
        if(sum > max) max = sum;
    }
            
    cout << max << endl;
}

Measured memory_bytes: 10248
#include <bits/stdc++.h>
using namespace std;
 
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")"; }
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ "; for(auto v : V) os << v << " "; return os << "]"; }
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}"; }
template<class T> ostream& operator<<(ostream &os, multiset<T> S){
    os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}"; }
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ "; for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") "; return os<<"}"; }
    #define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " |"; __f(comma + 1, args...); }
#define rng(x) x.begin(), x.end()
#define pb push_back
#define F first
#define S second
#define el '\n'
 
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<bool> vb;
 
/*-----------------------------Code begins----------------------------------*/

void solve(){
    ll n, x, t; cin>>n>>x>>t;
    cout<<((n/x + (n%x!=0))*t)<<el;
}
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int T=1, tc = 1;
    // cin>>T; 
    while(T--){
        solve();
    }
    return 0; 
}

Measured memory_bytes: 3612
package main

import (
	"fmt"
)

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

func main() {
	var a, b, k int
	var results []int
	fmt.Scan(&a, &b, &k)

	minValue := min(a, b)
	for i := minValue; i >= 1; i-- {
		if (a%i == 0) && (b%i == 0) {
			results = append(results, i)
		}
	}
	fmt.Println(results[k-1])
}


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

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

    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    while (b <= a) {
        b <<= 1;
        k--;
    }
    while (c <= b) {
        c <<= 1;
        k--;
    }
    cout << (k < 0 ? "No" : "Yes") << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
    string n;  cin>>n;
    for(int i=0;i<n.size();++i){
        if(n[i]=='1'){
            n[i]='9';
        }
        else if(n[i]=='9'){
            n[i]='1';
        }
    }
    cout<<n<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin>>N;
  vector<int>A(N);
  REP(i,N)cin>>A[i];
  vector<int>B=A;
  sort(ALL(B));
  if(B[N-1]==B[N-2]){
    for(int i=0;i<N;i++){
      cout<<B[N-1]<<"\n";
    }
  }else{
    for(int i=0;i<N;i++){
      if(A[i]==B[N-1]){
        cout<<B[N-2]<<"\n";
      }else{
        cout<<B[N-1]<<"\n";
      }
    }
  }
}


Measured memory_bytes: 3200
#include <stdio.h>
int main() {
  int N,M;
  scanf("%d %d", &N, &M);
  int K;
  int i,j; /*index of matrix or array */
  int count[31] = {0};

  for (i = 0; i < N; ++i) {
    scanf("%d",&K);
    for (j = 0; j < K; ++j) {
      int A;
      scanf("%d", &A);
      --A;
      ++count[A];
    }
  }

  int ans = 0;
  for (i = 0; i < M; ++i) {
    if (count[i] == N) {
      ++ans;
    }
  }

  printf("%d\n",ans);
  return 0;
}

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

int main() {
  long long n,a,b,ans = 0;
  cin >> n >> a >> b;
  ans += n/(a+b)*a;
  long long nn = n%(a+b);
  if(nn <= a){
    ans += nn;
  }
  else{
    ans += a;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
n = int(input())
prev_time = 0
prev_x = 0
prev_y = 0
for i in range(n):
  time, x, y = map(int,input().split())
  diff = (time - prev_time) - (x-prev_x) - (y - prev_y)
  if diff >= 0 and diff % 2 == 0:
    prev_time = time
    prev_x = x
    prev_y = y
  else:
    print("No")
    sys.exit()
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;


#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI=3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1<<29;
using Graph = vector<vector<int>>;


int main()
{
  ll n,k;
  cin >> n >> k;
  vector<ll> p(n);
  REP(i,n) cin >> p[i];

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

  ll sum =0 ;

  REP(i,k){
    sum += p[i];
  }
  cout << sum << endl;
  
  
}

Measured memory_bytes: 3620
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

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

typedef long long ll;

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

string f(ll n)
{
	string a;
	while(n)
	{
		a += ex[n % 8] + '0';
		n /= 8;
	}
	reverse(a.begin(), a.end());

	return a;
}

int main()
{
	ll n;
	while(cin >> n, n)
	{
		cout << f(n) << endl;
	}
}

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

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

using namespace std;

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

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

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

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

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int N;
    while (cin >> N) {
        int t1=0,x1=0,y1=0,t2,x2,y2;
        bool good = true; 
        while (N--) {
            cin >> t2 >> x2 >> y2;
            int z = abs(x1 - x2) + abs(y1 - y2);
            if (t2 - t1 >= z && (t2 - t1 - z) % 2 == 0)
                ;
            else
                good = false;
            
            t1=t2;x1=x2;y1=y2;
        }
        if (good == true)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
let cnt = ref 0

let insertion_sort n ?(gap=1) a =
  for i=gap to n-1 do
    let v = a.(i) in
    let j = ref (i - gap) in
    while !j >= 0 && a.(!j) > v do
      a.(!j+gap) <- a.(!j);
      j := !j - gap;
      incr cnt;
    done;
    a.(!j+gap) <- v
  done;
  a

let shell_sort array n =
  let gaps = [701;201;132;57;23;10;4;1] |> List.filter ((>=) n) in
  let m = List.length gaps in
  let rec loop a = function
      [] -> a
    | h::t -> loop (insertion_sort n ~gap:h a) t in
  let a = loop array gaps in
  Printf.printf "%d\n" m;
  Array.iteri
    (fun i x -> Printf.printf (if i=m-1 then "%d\n" else "%d ") x)
    (Array.of_list gaps);
  Printf.printf "%d\n" !cnt;
  a

let () =
  let n = read_int () in
  let rec read a = function
      i when i = n -> a
    | i -> a.(i) <- (read_int ());
      read a (i+1) in
  let a = read (Array.make n 0) 0 in
  Array.iter (Printf.printf "%d\n") (shell_sort a n)

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

int main() {
  int N;
  float a;
  std::vector<float> A;
  float answer = 0;
  cin >> N;
  for (int i = 0; i < N; ++i){
    cin >> a;
    A.push_back(1/a);
  }

  //for (int i = 0; i < N; ++i){
  //  cout << A[i];
  //}
  for (int i = 0; i < N; ++i){
  answer += A[i];
  }

  answer = 1 / answer;
  cout << answer << endl;
}


Measured memory_bytes: 256
package main

import (
    "fmt"
    "math"
)

func max(lhs, rhs int) int {
    return int(math.Max(float64(lhs), float64(rhs)))
}

func main() {
    var n, w int
    fmt.Scan(&n, &w)

    weights := make([]int, n)
    values  := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&weights[i], &values[i])
    }

    dp := make([][]int, n+1)
    for i := 0; i <= n; i++ {
        dp[i] = make([]int, w+1)
    }
    for i := 0; i < n; i++ {
        for j := 0; j <= w; j++ {
            if j >= weights[i] {
                dp[i+1][j] = max(dp[i+1][j], dp[i][j - weights[i]] + values[i])
            }
            dp[i+1][j] = max(dp[i][j], dp[i+1][j])
        }
    }
    fmt.Println(dp[n][w])
}


Measured memory_bytes: 81792
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, n) for(int i = a; i <= n; i++)
const int maxN = 3010;
int n;
double p[maxN], dp[maxN][maxN];
int main()
{
	cin >> n;
	rep(i, 1, n) cin >> p[i];
	dp[0][0] = 1.0;
	rep(i, 1, n) rep(j, 0, i) dp[i][j] = dp[i - 1][j] * (1.0 - p[i]) + dp[i - 1][j - 1] * p[i];
	double ans = 0.0;
	rep(i, (n + 1) / 2, n) ans += dp[n][i];
	printf("%.12f\n", ans);
	return 0;
}

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

signed main(void)
{
	int n, m;
	cin >> n;
	int a[n + 1];
	vector<int> out(n + 1, 0);

	m = 0;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = n; i >= 1; i--)
	{
		int sum = 0;
		for(int j = 2; i * j <= n; j++)
		{
			sum += out[i * j];
		}
		if (a[i] == 1)
		{
			if (sum % 2 == 0)
			{
				out[i] = 1;
				m++;
			}
		}
		else if (a[i] == 0)
		{
			if (sum % 2 == 1)
			{
				out[i] = 1;
				m++;
			}
		}
	}
	cout << m << endl;
	rep(i, n + 1)
	{
		if (out[i] == 1)
			printf("%d%c", i, i==n?'\n':' ');
	}
	return 0;
}


Measured memory_bytes: 2432
N, M = map(int, input().split())
PS = [list(map(str, input().split())) for _ in range(M)]
ac = [False] * N # index means p
wa = [0] * N # index means p
wa_cnt = 0
for ps in PS:
  p = int(ps[0]) - 1 # index starts from 0
  s = ps[1]
  if not ac[p] and s == "AC":
    wa_cnt += wa[p]
    ac[p] = True
  elif s == "WA":
    wa[p] += 1
print(ac.count(True), wa_cnt)

Measured memory_bytes: 33692
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265358979323846264338327950
int main()
{
  double a,b,h,m,x,y,ans;
  cin>>a>>b>>h>>m;
  x=h*30+m/2;
  y=m*6;
 ans=sqrt((b-a*cos(pi*(x-y)/180))*(b-a*cos(pi*(x-y)/180))+a*sin(pi*(x-y)/180)*a*sin(pi*(x-y)/180));
 cout<<fixed<<setprecision(19)<<ans;
}

Measured memory_bytes: 4096
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <tuple>
#define REP(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
using namespace std;

int main(){
	int t,p,r;
	while(cin>>t>>p>>r,t){
		vector<tuple<int,int,int> > inf_team(t,tuple<int,int,int>(0,0,0));//problem,time,number
		REP(i,t)get<2>(inf_team[i]) = i;
		vector<vector<int> > penalty(t,vector<int>(p,0));
		REP(i,r){
			int t_id,p_id,time;
			string mes;
			cin >> t_id >> p_id >> time >> mes;
			t_id--;p_id--;
			if(mes=="WRONG"){
				penalty[t_id][p_id]++;
			}else{
				get<1>(inf_team[t_id]) += time + 1200*penalty[t_id][p_id];
				get<0>(inf_team[t_id])--;
			}
		}
		sort(inf_team.begin(),inf_team.end());
		REP(i,t){
			cout << get<2>(inf_team[i]) + 1 << " " << get<0>(inf_team[i]) * (-1) << " " << get<1>(inf_team[i]) << endl;
		}
	}
	return 0;
}

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

const string YES = "YES";
const string NO = "NO";

void solve(long long r, long long g, long long b){
    ll res = r*100+g*10+b;
    if(res % 4 == 0) cout << YES << endl;
    else cout << NO << endl;
}

int main(){
    long long r;
    scanf("%lld",&r);
    long long g;
    scanf("%lld",&g);
    long long b;
    scanf("%lld",&b);
    solve(r, g, b);
    return 0;
}


Measured memory_bytes: 256