akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
const long long inf=6000000000000000000ll;
int Q,n,m,D,c[27],a[N][27],t[N],as[N],su[27],ans,i,j,x,y,s=-1000000000;
set<int> p[27];
int cal(int x,int y)
{
	int sum=ans;
	sum-=a[x][t[x]];
	sum+=a[x][y];
	auto it=p[t[x]].find(x);
	auto e=it;
	--e;
	++it;
	sum+=c[t[x]]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
	it=p[y].lower_bound(x);
	e=it;
	--e;
	sum-=c[y]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
	return sum;
}
void Change(int x,int y)
{
	ans-=a[x][t[x]];
	ans+=a[x][y];
	auto it=p[t[x]].find(x);
	auto e=it;
	--e;
	++it;
	ans+=c[t[x]]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
	p[t[x]].erase(x);
	t[x]=y;
	p[t[x]].insert(x);
	it=p[t[x]].find(x);
	e=it;
	--e;
	++it;
	ans-=c[t[x]]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
}
void up()
{
	if(s<ans)
	{
		s=ans;
		for(int i=1;i<=D;++i)
			as[i]=t[i];
	}
}
mt19937 rnd(time(0));
double rand_f() {return double(rnd())/double(RAND_MAX);}
int u=0;
void SA()
{
	double T=1000;
	while(T>0.001)
	{
		int a=rnd()%D+1,b=rnd()%26+1;
		while(b==t[a])
			b=rnd()%26+1;
		int tmp=cal(a,b);
		if(tmp>ans||rand_f()<exp((tmp-ans)/T))
		{
			Change(a,b);
			up();
		}
		T=T*0.999;
	}
	//cout<<s<<' '<<ans<<endl;
}
void Find()
{
	int i,j;
	for(i=1;i<=26;++i)
	{
		p[i].clear(); 
		p[i].insert(D+1);
		p[i].insert(0);
	}
	memset(su,0,sizeof(su));
	ans=0;
	for(i=1;i<=D;++i)
	{
		for(j=1;j<=26;++j)
			++su[j];
		t[i]=1;
		for(j=2;j<=26;++j)
			if(su[t[i]]*c[t[i]]+a[i][t[i]]<su[j]*c[j]+a[i][j])
				t[i]=j;
		ans+=a[i][t[i]];
		su[t[i]]=0;
		for(j=1;j<=26;++j)
			ans-=su[j]*c[j];
		p[t[i]].insert(i);
		//as[i]=t[i];
	}
}
int main()
{
	scanf("%d",&D);
	for(i=1;i<=26;++i)
		scanf("%d",&c[i]);
	for(i=1;i<=D;++i)
		for(j=1;j<=26;++j)
			scanf("%d",&a[i][j]);
	Find();
	up();
	while(1.0*clock()/CLOCKS_PER_SEC<1.85)
	{
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		Find();
		up();
		//cout<<'?'<<' '<<s<<' '<<ans<<endl;
	}
	for(i=1;i<=D;++i)
	{
		cout<<as[i]<<endl;
		assert(as[i]>=1&&as[i]<=26);
	}
}

Measured memory_bytes: 4428
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N;
    cin >> N;

    int maxl = N / 7;
    bool ok = 0;
    REP(i,maxl+1)
    {
        int remain = N - 7 * i;
        if(remain % 4 == 0) ok = 1;

    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;


}


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

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

    int a[n+2];
    
    a[0] = -1;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        if (a[i] > a[i-1] + 1) {
            printf("-1\n");
            return 0;
        }
    }
    a[n+1] = -1;

    long long result = 0;
    for (int i = n; i > 0; i--) {
        result += 1ll * (a[i] >= a[i+1] ? a[i] : 0);
    }

    printf("%lld\n", result);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int N = 101;
const int K = 100005;
int n , k , a[101] , dp[100005];

int32_t main(){
	scanf("%d%d" , &n , &k);
	for(int i = 1 ; i <= n; i ++) scanf("%d" , &a[i]);
	dp[0] = 0;
	for(int i = 1 ; i <= k ; i ++){
		bool tb = false, ta = false;
		for(int j = 1 ; j <= n ; j ++){
			if(i >= a[j]){
				if(dp[i-a[j]] == 1) tb = true;
				else ta = true;
			}
			if(ta){
				dp[i] = 1;
			}
			else dp[i] = 0;
		}
	}
	if(dp[k]){
		puts("First");
	}
	else puts("Second");
}

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

int main()
{
    int N, L;
    cin >> N >> L;

    int ans;
    int diff = 1000000;

    int total = 0;
    for (int i = 1; i <= N; i++)
    {
        total += L + i - 1;
    }

    for (int i = 1; i <= N; i++)
    {
        int sum = 0;
        for (int j = 1; j <= N; j++)
        {
            if (i != j)
            {
                sum += L + j - 1;
            }
        }
        if (diff > abs(total - sum))
        {
            diff = abs(total - sum);
            ans = sum;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def x_cubic(x:int) -> int:
    if x < 1:
        raise ValueError('Parameter x is lower than 1.')
    if x > 100:
        raise ValueError('Parameter x is lareger than 100')

    return x * x * x

if __name__ == "__main__":
    x = int(input())
    cube = x_cubic(x)
    print(cube)



Measured memory_bytes: 5592
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long MOD = 1e9 + 7;
using namespace std;
typedef long long ll;

map<ll, int> mp;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	cout << fixed;
	cout << setprecision(10) << sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) << endl;
	return 0;
}


Measured memory_bytes: 3280
#include"bits/stdc++.h"
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std; int main(){int n,m,d[11][10010],r,t,a;while(cin>>n>>m&&n&&m){rep(i,n)rep(j,m)cin>>d[i][j];r=0;rep(i,1<<n){t=0;rep(j,m){a=0;rep(k,n)a+=(d[k][j]+!!(i&(1<<k)))%2;t+=max(a,n-a);}r=max(r,t);}cout<<r<<endl;}}

Measured memory_bytes: 1560
#include <stdio.h>
#include <stdlib.h>

char **allocate_2d(int width, int height)
{
  int i;
  char **matrix;

  matrix = malloc(sizeof(char *) * height);
  for(i = 0; i < height; i++) {
    matrix[i] = malloc(sizeof(char) * (width+1));
  }
  
  return matrix;
}

void free_(char **matrix, int height)
{
  int i;

  for(i = 0; i < height; i++) {
    free(matrix[i]);
  }

  free(matrix);
}


int main(void)
{
  int i, j;
  int width, height, two_height;
  char **matrix, **matrix_;

  scanf("%d %d",&height, &width);
  two_height = 2*height;

  matrix  = allocate_2d(width,height);
  matrix_ = allocate_2d(width,two_height);
  
  for(i = 0; i < height; i++) {
    scanf("%s", matrix[i]);
  }

  for(i = 0; i < two_height; i++) {
    for(j = 0; j < width; j++) {
      matrix_[i][j] = matrix[i/2][j];
    }
  }

  for(i = 0; i < two_height; i++) {
    printf("%s\n",matrix_[i]);
  }

  free_(matrix,height);  
  free_(matrix_,two_height);  

  return 0;
}


Measured memory_bytes: 256
/*

                              Jai Shree Krishna !!
                                 Radhe Radhe !!
                                 
             उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति मृगाः।।
             
*/
   
   
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vvi vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
#define ins insert
#define rep(i,s,e)  for(int i=s;i<=e;i++)
#define repd(i,s,e)  for(int i=e;i>=s;i--)
#define vb vector<bool>
#define read2(n,m) int n,m; cin >> n >> m;
#define range(v) v.begin(),v.end()
#define sortd(v) sort(v.begin(),v.end(),greater<int>())
#define sorti(v) sort(v.begin(),v.end())
#define PI 3.14159265358979323846264338
const ll inf = 1e18;
const ll mod = 1e9 + 7;
 
vb visited(100001);
vi adj[100001];
void dfs(int v) {
    visited[v] = true;
    for (int u : adj[v]) {
        if (!visited[u])
            dfs(u);
    }
}

signed main()
{
 
    fast;
    read2(n,m);
    rep(i,0,m-1){
    	int x,y; cin >> x >> y;
    	adj[x].pb(y);
    	adj[y].pb(x);
    }
    dfs(1);
    rep(i,1,n){
    if(!visited[i]) {
    	cout<<"No"<<endl;
    	return 0;
    }
   }
   
   queue<int> q;
vector<bool> used(n+1);
vector<int> p(n+1);
int s=1;
q.push(s);
used[s] = true;
p[s] = -1;
while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int u : adj[v]) {
        if (!used[u]) {
            used[u] = true;
            q.push(u);
            // d[u] = v;
            p[u] = v;
        }
    }
}
cout<<"Yes"<<endl;
rep(i,2,n) cout<<p[i]<<endl;
    return 0;
}

/* Pooja Yadav */

Measured memory_bytes: 14488
#include <iostream>

int main(){
  int N, result = 0;
  std::cin>>N;
  std::string S;
  std::cin>>S;

  for(int i=0;i<N;++i){
    if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C'){
      ++result;
    }
  }

std::cout<<result;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
#define NUM ((long long)1000000007)
#define int long long

using namespace std;

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

    int x, y;
    cin >> x >> y;
    cout << x + y  / 2 << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    for (int i = 0; i < 5; i++) {
        if (x[i] == 0) {
            cout << i + 1 << endl;
        }
    }
}

Measured memory_bytes: 3588
#include <cstdio>
#include <unordered_set>

int a[100000];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  int xor_sum = 0;
  for (int i = 0; i < n; i++)
    xor_sum ^= a[i];
  std::unordered_set<int> s;
  for (int i = 0; i < n; i++)
    s.insert(a[i] ^ (a[i] - 1));
  int ans = 0;
  for (int bit = 29; bit >= 0; bit--) {
    if (((1 << bit) & xor_sum) == 0) {
      continue;
    }
    int x = (1 << (bit + 1)) - 1;

    if (s.count(x)) {
      xor_sum ^= x;
      ans += 1;
    }
  }

  if (xor_sum != 0) {
    printf("-1\n");
  } else {
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 640
n=int(input())
info=[list(map(int,input().split())) for i in range(n)]
for cx in range(0,101):
    for cy in range(0,101):
        H=-10**20
        lim=10**20
        for l in info:
            x,y,h=l 
            if h==0:
                 lim=min(lim,abs(x-cx)+abs(y-cy))
                 
            else:
                if H!=-10**20 and H!=abs(x-cx)+abs(y-cy)+h :break
                H=abs(x-cx)+abs(y-cy)+h 
            if H>lim:break
        else:
            print(cx,cy,H);exit()

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int a,b; cin>>a>>b; --a;
	int i=0,j=0;
	while(j+1<b)j+=a,++i;
	cout<<i<<"\n"s;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
    string s;
    cin >> s;

    int ptr_0 = 0;

    for (int i = 0; i < s.size(); ++i) {
        if (i % 2 == 0 && s[i] != '0') {
            ++ptr_0;
        }
        else if (i % 2 == 1 && s[i] != '1') {
            ++ptr_0;
        }
    }

    int ptr_1 = 0;

    for (int i = 0; i < s.size(); ++i) {
        if (i % 2 == 0 && s[i] != '1') {
            ++ptr_1;
        }
        else if (i % 2 == 1 && s[i] != '0') {
            ++ptr_1;
        }
    }

    if (ptr_0 < ptr_1) {
        cout << ptr_0 << endl;
    }
    else {
        cout << ptr_1 << endl;
    }
}


Measured memory_bytes: 512
//g++ -std=gnu++14 a.cpp
//#include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){

  string S;
  cin >> S;
  int l = S.size();
  l--;
  vector<int> A(l);
  rep(i,l){
    A[i] = int(S.at(i));
  }


  ll ans = 0;
  //cout << s << endl;
  if(l == 0){
    int a;
    a = stoi(S);
    cout << a << endl;
    return 0;
  }

  for(int bit = 0;bit < (1 << l) ; bit++){
    ll sum = 0;
    string s;
    s = S.at(0);
    for(int i = 0; i < l ; i++){
      if(((bit >> i) & 1) && i == l-1){
        sum = stoll(s);
        ans += sum;
        //sum =0;
        sum = 0;
        s = "";
        s.push_back(S.at(i+1));
        sum = stoll(s);
        //cout << sum << endl;
        ans += sum;
        //cout << bit << ":" << sum << endl;
      } else if(i == l-1){
        s.push_back(S.at(i+1));
        sum = stoll(s);
        ans += sum;
        //cout << bit << ":" << sum << endl;
      }else if((bit >> i) & 1){
        sum = stoll(s);
        ans += sum;
        //cout << bit << ":" << sum << endl;

        s = "";
        sum = 0;
        s.push_back(S.at(i+1));
      }else{
        s.push_back(S.at(i+1));
        //cout << s << endl;
      }

      }
    }


  cout << ans << endl;
}


Measured memory_bytes: 256
#n=int(input())
#s=input()
a,b=map(int,input().split())
#A=[list(map(int,input().split()))for i in range(n)]
ans=0
if a<b:
    ans+=b
    b-=1
else:
    ans+=a
    a-=1
ans+=max(a,b)
print(ans)


Measured memory_bytes: 2940
use proconio::fastout;
use proconio::input;
use proconio::marker::Usize1;

fn dfs(
  map: &Vec<Vec<usize>>,
  scores: &mut Vec<usize>,
  index: usize,
  last: usize
) {
  for next in map[index].iter() {
    let next = *next;
    if last == next { continue }
    scores[next] += scores[index];
    dfs(map, scores, next, index);
  }
}

#[fastout]
fn main() {
  input! {
    n: usize,
    q: usize,
    trees: [(Usize1, Usize1);n-1],
    points: [(Usize1, usize);q]
  }
  let mut scores: Vec<usize> = vec![0;n];
  let mut map: Vec<Vec<usize>> = vec![vec![];n];
  let NotMatchIndex = n * 10;
  
  for (from, to) in trees {
    map[from].push(to);
    map[to].push(from);
  }

  for (root, point) in points {
    scores[root] += point;
  }
  
  dfs(&map, &mut scores, 0, NotMatchIndex);  

  println!("{}", scores
    .into_iter()
    .map(|v| v.to_string())
    .collect::<Vec<String>>()
    .join(" ")
  );
}

Measured memory_bytes: 43476
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n,a,b;
cin >> n >> a >> b;
if(n*a>=b) {
  cout << b << endl;
} else {
  cout << a*n << endl;
}
return 0;
}


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


string S, T;


int main(void){

    cin >> S >> T; 

    reverse(S.begin(),S.end());
    reverse(T.begin(),T.end());
    int SL = S.length();
    int TL = T.length();

    char SR[SL];
    char TR[TL];

    for (int i = 0; i < SL; i++) SR[i] = S[i];
    for (int i = 0; i < TL; i++) TR[i] = T[i];

    bool exist = false;
    int existpos = 0;

    for (int i = 0; i <= SL - TL;i++){
        int start = i;
        bool jud = false;
        for (int j = 0;j < TL;j++){
//            cout << TR[j] << "," << SR[start + j];
            if (TR[j] == SR[start + j] || SR[start + j] == '?') jud = true;
            else {
                jud = false;
                break;
            }
        }
        if (jud) {
            exist = true;
            existpos = start;
            break;
        }
    } 

    if (exist) {
        for (int i = 0;i < TL; i++) SR[existpos + i] = TR[i];
        for (int i = 0;i < SL; i++) {
            if (SR[i] == '?') SR[i] = 'a';
        }
        string Ans = "";
        for (int i = 0;i < SL; i++) Ans += SR[i];
        reverse(Ans.begin(),Ans.end());
        cout << Ans << endl;
    } else {
        cout << "UNRESTORABLE" << endl;
    }
       return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define mo 998244353
#define N 32800
using namespace std;
int a[N],b[N],R[N];
char s1[N],s2[N];
int n[N],ans[N];
int power(int x,int y){
	int s=1;
	for (;y;y/=2,x=1ll*x*x%mo)
		if (y&1) s=1ll*s*x%mo;
	return s; 
}
void FFT(int *a,int n,int f){
	for (int i=0;i<n;i++)
		if (i<R[i]) swap(a[i],a[R[i]]);
	for (int d=1;d<n;d<<=1){
		int wn=power(3,(mo-1)/(d<<1));
		if (f==-1) wn=power(wn,mo-2);
		for (int i=0;i<n;i+=(d<<1))
			for (int j=i,w=1;j<i+d;j++){
				int y=1ll*w*a[j+d]%mo;
				a[j+d]=(a[j]+mo-y)%mo;
				a[j]=(a[j]+y)%mo;
				w=1ll*w*wn%mo;
			}
	}
	if (f==-1){
		int v=power(n,mo-2);
		for (int i=0;i<n;i++)
			a[i]=1ll*a[i]*v%mo;
	}
}
int m,e;
void solve(int times,int c){
	for (;times;){
		FFT(a,c,1);
		if (times&1){
			FFT(b,c,1);
			for (int i=0;i<c;i++)
				b[i]=1ll*b[i]*a[i]%mo;
			FFT(b,c,-1);
			for (int i=m+1;i<c;i++) b[i]=0;
		}
		if (times/=2){
			for (int i=0;i<c;i++)
				a[i]=1ll*a[i]*a[i]%mo;
			FFT(a,c,-1);
			for (int i=m+1;i<c;i++) a[i]=0;
		}
	}
}
int main(){
	scanf("%s%s",s1+1,s2+1);
	int n=strlen(s1+1);
	m=0,e=0;
	for (int i=1;i<=n;i++)
		if (s1[i]^s2[i]) e++;
		else if (s1[i]-'0') m++;
	e/=2;
	a[0]=b[0]=1;
	for (int i=1;i<=m;i++)
		a[i]=1ll*a[i-1]*power(i+1,mo-2)%mo;
	int c=1,L=0;
	for (;c<=2*m;c<<=1,L++);
	for (int i=1;i<c;i++)
		R[i]=(R[i>>1]>>1)|((i&1)<<(L-1));
	solve(e,c);
	int ans=0;
	for (int i=0;i<=m;i++)
		ans=(ans+b[i])%mo;
	for (int i=1;i<=m;i++)
		ans=1ll*ans*i%mo;
	for (int i=1;i<=e;i++)
		ans=1ll*ans*i%mo;
	for (int i=1;i<=m+e;i++)
		ans=1ll*ans*i%mo;
	printf("%d\n",ans);
} 

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long ll;

template <typename T> inline bool chkmin(T &x,T y) { return y < x ? x = y,1 : 0; }
template <typename T> inline bool chkmax(T &x,T y) { return x < y ? x = y,1 : 0; }

const int INF = 0x3f3f3f3f;
const int N = 5e2 + 10,Lim = 1e4 + 10;

int dir[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int prime[Lim],vis[Lim],cnt = 0;
ll res[N][N];

inline int read() {
	int x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-')ch = getchar();
	if(ch == '-')flag = -1,ch = getchar();
	while(isdigit(ch))x = (x << 3) + (x << 1) + (ch - '0'),ch = getchar();
	return x * flag;
}

inline ll Lcm(ll a,ll b) {
	return a / __gcd(a,b) * b;
}

inline void init(int n) {
	For(i,2,n) {
		if(!vis[i]) prime[++cnt] = i;
		for(int j = 1;j <= cnt && i * prime[j] <= n;j++) {
			vis[i * prime[j]] = 1;
			if(i % prime[j] == 0) break;
		}
	}
}

int main() {

	int n = read();
	if(n == 2) { puts("4 7\n23 10");return 0; }
	init(1e4);
	For(i,1,n) For(j,1,n) if((i + j) % 2 == 0)
		res[i][j] = prime[(i + j) / 2];
	For(i,1,n) For(j,1,n) if((i + j) % 2 == 0)
		res[i][j] *= prime[n + (n - i + 1 + j) / 2];
	For(i,1,n) For(j,1,n) if(!res[i][j]) {
		ll Prod = 1;
		For(k,0,3) {
			int x = i + dir[k][0],y = j + dir[k][1];
			if(x <= 0 || y <= 0 || x > n || y > n) continue;
			Prod = Lcm(Prod,res[i + dir[k][0]][j + dir[k][1]]);
		}
		res[i][j] = Prod + 1;
	}
	For(i,1,n) For(j,1,n) printf("%lld%c",res[i][j],j == n ? '\n' : ' ');

	return 0;
}

Measured memory_bytes: 5120
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);
    
    while (in.hasNext()) {
      int A = in.nextInt();
      int B = in.nextInt();
      
      if (A < 1 || A > 9 || B < 1 || B > 9) {
        System.out.println(-1); 
      } else {
        System.out.println(A * B);
      }
    }
  }
}

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

int main()
{
    ios_base::sync_with_stdio(0);

    string a,b;
    cin >> a >> b;
    int n=b.size();
    for(int i=0;i<n;i++)
        cout << a[i] << b[i];
    if(a.size()>n)
        cout << a[n];

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {

	Scanner in;
	PrintWriter out;

	int[] hh;
	int[] cc;

	public static void main(String... args) {
		new Main().solve();
	}

	void solve() {
		in = new Scanner(new InputStreamReader(System.in));

		int n = in.nextInt();
		int k = in.nextInt();
		hh = new int[n];
		cc = new int[n];
		Arrays.fill(cc, Integer.MAX_VALUE);

		for (int i = 0; i < n; ++i) {
			hh[i] = in.nextInt();
		}
      
      	int len = hh.length;
		cc[len-1] = 0;
		cc[len-2] = Math.abs(hh[len-1]-hh[len-2]);
		for (int i = len-3; i >= 0; --i) {
			int maxJump = k;
			while (i+maxJump >= len) --maxJump;
			for (int j = 1; j <= maxJump; ++j)
				cc[i] = Math.min(cc[i], cc[i+j]+Math.abs(hh[i]-hh[i+j]));
		}

		System.out.println(cc[0]);
	}
}


Measured memory_bytes: 63060
N = int(input())
S = input()
ans = []
tmp = 0
for i in range(N):
    for j in range(97,123):
        A = S[:i]
        B = S[i:]
        if A.count(chr(j)) > 0 and B.count(chr(j)) > 0:
            tmp += 1
    ans.append(tmp)
    tmp = 0
print(max(ans))

Measured memory_bytes: 39536
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int grid[3010][3010];
ll dp[3010][3010][4];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, m, k, x, y, v;
	cin >> n >> m >>  k;
	
	memset(grid, 0, sizeof(grid));
	
	for(int i=0; i<k; i++){
    	cin >> x >> y >> v;
    	x--; y--;
    	grid[x][y] = v;
	} 
	
	for(int i=0; i<n; i++){
	    for(int j=0; j<m; j++){
	        for(int k = 0; k<4; k++){
    	        dp[i][j][k] = -1e17;
	        }
	    }
	}
	
	dp[0][0][0] = 0;
	
	for(int i=0; i<n; i++){
	    for(int j=0; j<m; j++){
	        if(grid[i][j]>0){
	            for(int k = 2; k>=0; k--){
    	            dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j][k] + grid[i][j]);
    	            
	            }
	        }
	        
	        for(int k=0; k<4; k++){
	            dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k]);
	            dp[i][j+1][k] = max(dp[i][j+1][0], dp[i][j][k]);
	        }
	    }
	}
	
	ll ans = 0;
	for(int i=0; i<4; i++) ans = max(ans, dp[n-1][m-1][i]);
	cout << ans << "\n";
}

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

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi                  3.14159265359
ll INF=1e18+10;
ll MOD=998244353;

int main()
{
    ll w,h,x,y;cin>>w>>h>>x>>y;
    double one=(w/2.0);
    one*=h;
    if(w%2==0 && h%2==0 && (w/2)==x && (h/2)==y)
        cout<<fixed<<setprecision(6)<<one,cout<<" "<<1;
    else
        cout<<fixed<<setprecision(6)<<one,cout<<" "<<0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    int a,b;
    cin >> a >> b;
    if(a==b)cout << 2*a;
    else cout << max(2*a-1,2*b-1);
    


}

/*



 */



Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t H,W;
char map[1010][1010];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> H>>W;
	std::queue<std::pair<int32_t, int32_t>> que,next;
	for (int32_t i = 0; i < W+2; i++)
	{
		map[H+1][i] = map[0][i] = '#';
	}
	for (int32_t i = 1; i <= H; i++)
	{
		in >> map[i] + 1;
		map[i][0] = map[i][W+1] = '#';
		for (int32_t j = 1; j <= W; j++)
		{
			if (map[i][j] != '.') {
				que.emplace(i, j);
			}
		}
	}

	int64_t count = 0;
	while (!que.empty())
	{
		while (!que.empty())
		{
			auto pos = que.front(); que.pop();
			const int diff[5] = { 0,1,0,-1,0 };
			for (size_t i = 0; i < 4; i++)
			{
				auto nh = pos.first + diff[i];
				auto nw = pos.second + diff[i + 1];
				if (map[nh][nw] == '.') {
					map[nh][nw] = '#';
					next.emplace(nh, nw);
				}
			}
		}
		if (!next.empty()) {
			++count;
		}
		std::swap(que, next);
	}
	out << count << endl;


	return 0;
}
#endif


Measured memory_bytes: 9488
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define ld long double
#define oo 2e18
#define OS tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

string s;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> s;
    if (s == "ABC") cout << "ARC\n";
    else cout << "ABC\n";
    return 0;
}

Measured memory_bytes: 3568
N = int(input())
X = list(map(int, input().split()))

tmp_m = 10 ** 10
for i in range(1, max(X)+1):
    tmp = 0
    for j in range(N):
        tmp += (X[j] - i) ** 2

    tmp_m = min(tmp_m, tmp)

print(tmp_m)

Measured memory_bytes: 3060
// 	A - Table Tennis Training
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> n >> a >> b;
  c = b - a;
  if (c % 2 == 1)
  {
    if (a == 1 || a == n || b == 1 || b == n)
    {
      cout << (b + 1 - a) / 2 << endl;
    }
    else
    {
      ans = min(a - 1, n - b);
      ans += (b + 1 - a) / 2;
      cout << ans << endl;
    }
  }
  else if (c % 2 == 0)
  {
    cout << c / 2 << endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

	switch (D) {
	case 22:
		cout << "Christmas Eve Eve Eve" << endl;
		break;
	case 23:
		cout << "Christmas Eve Eve" << endl;
		break;
	case 24:
		cout << "Christmas Eve" << endl;
		break;
	case 25:
		cout << "Christmas" << endl;
		break;
	}
	return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll, int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const int N = 100005;

int n,m,k;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

bool valid(int x, int y){
	return x >= 1 and x <= n and y >= 1 and y <= m;
}

void solve(){
	cin >> n >> m >> k;
	queue<ii> q;
	char v[n+1][m+1];
	int see[n+1][m+1], x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			cin >> v[i][j];
			see[i][j] = mod;
		}
	}
	q.push({x1,y1});
	see[x1][y1] = 0;
	while(!q.empty()){
		int i = q.front().fst, j = q.front().snd; q.pop();
		for(int t = 0; t < 4; t++){
			for(int l = 1; l <= k; l++){
				int ni = i + dx[t]*l, nj = j + dy[t]*l;
				if(!valid(ni, nj) or v[ni][nj] == '@' or see[ni][nj] < see[i][j]+1)
					break;
				if(see[ni][nj] > see[i][j]+1){
					see[ni][nj] = see[i][j]+1;
					q.push({ni, nj});
				}
			}
		}
	}
	cout << (see[x2][y2] == mod ? -1 : see[x2][y2]) << "\n";
}

int main(){
	fastio;
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 10020
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);    
        String word;
        String Lower_word;
        String text;
        String Lower_text;
        int count = 0;
        word = sc.next();
        Lower_word = word.toLowerCase();
        while(true){
            text = sc.next();
            if (text.equals("END_OF_TEXT")){
                break;
            }
            Lower_text = text.toLowerCase();
            if(Lower_text.equals(Lower_word)){
                count++;
            }
        }
        System.out.println(count);
        sc.close();
    }
}


Measured memory_bytes: 26272
def resolve():
    N, X, Y = map(int, input().split())
    from collections import defaultdict
    dist = defaultdict(int)
    for i in range(1, N):
        for j in range(i+1, N+1):
            _dist = min(j-i, abs(X-i) + 1 + abs(j-Y), abs(Y-i) + 1 + abs(j-X))
            dist[_dist] += 1
    for i in range(1, N):
        print(dist[i])

resolve()

Measured memory_bytes: 3956
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

vector<ll> T,P;
ll dfs(int N,ll end){
	if(N==0) return 1LL;

	ll M=T[N]/2LL+1LL;

	ll V=0;
	if(end>M){
		V += P[N-1]+1LL;
		V += dfs(N-1,end-M);
	}
	else if(end==M){
		V += P[N-1]+1LL;
	}
	else if(end>1){
		V += dfs(N-1,end-1);
	}
	return V;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	ll N=in(),X=in<ll>();
	T.resize(51,0);
	P.resize(51,0);
	T[0]=1,P[0]=1;
	REP(i,50){
		T[i+1] = 2LL*T[i]+3LL;
		P[i+1] = 2LL*P[i]+1LL;
	}
	out(dfs(N,X));
	return 0;
}


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

bool ok(vector<int> w, int k, int p){
    vector<int>::iterator it = w.begin();
    int sum = 0;
    int num = 1;
    while(it!=w.end()){
        if(*it > p) return false;
        if(sum+*it > p){
            num++;
            sum = 0;
        }
        sum += *it;
        it++;
    }
    if(k>=num)
        return true;
    else
        return false;
}




int min_sufficient_load(vector<int> w, int k){
    int left = 0;
    int right = 1000000000;
    int mid;
    while(left<right-1){
        mid = (left+right)/2;
        if(ok(w,k,mid)){
            right = mid;
        }
        else{
            left = mid;
        }
    }
    return right;
}



int main(){
    int n; cin >> n;
    int k; cin >> k;
    vector<int> weight(n);
    for(int i= 0;i<n;i++){
        cin >> weight[i];
    }
    cout << min_sufficient_load(weight,k) << endl;
}

Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner stdIn = new Scanner(System.in);
		
		while(true)
		{
			int n = stdIn.nextInt();
			int x = stdIn.nextInt();
			
			if(n==0 && x==0)
			{
				break;
			}
			
			int count = 0;
			
			for(int i=n;i>=3;i--)
			{
				for(int j=i-1;j>=2;j--)
				{
					for(int k=j-1;k>=1;k--)
					{
						if((i+j+k)==x)
						{
							count++;
						}
					}
				}
			}
			
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 19612
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        for(int i = a; i <= b; i++){
            if(i % k == 0){
                System.out.println("OK");
                return;
            }
        }
        System.out.println("NG");
    }
}

Measured memory_bytes: 27080
using System;

class MainClass {
    static void Main() {
        Scanner cin=new Scanner();

        int N=cin.nextInt(), K=cin.nextInt();
        int X=cin.nextInt(), Y=cin.nextInt();

        Console.WriteLine(Math.Min(K, N)*X + Math.Max(0, N-K)*Y);
    }
}

class Scanner {
    string[] buf;
    int i;
    char[] SplitChar=new char[] {' '};
    public Scanner() {
        buf = new string[0];
        i = 0;
    }
    public string next() {
        if (i < buf.Length) return buf[i++];

        string tmp=Console.ReadLine();
        while (tmp == "")
            tmp = Console.ReadLine();

        buf = tmp.Split(SplitChar, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return buf[i++];
    }
    public int nextInt() {
        return int.Parse(next());
    }
    public long nextLong() {
        return long.Parse(next());
    }
    public double nextDouble() {
        return double.Parse(next());
    }
}


Measured memory_bytes: 2648
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var dp []int64

func getNextWord(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextWord(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	n := getNextInt(scanner)
	aList := make([]int, n)
	hList := make([]int, n)
	for i := 0; i < n; i++ {
		hList[i]=getNextInt(scanner)
	}
	for i := 0; i < n; i++ {
		aList[i]=getNextInt(scanner)
	}

	segSize := 1
	for segSize < n {
		segSize = segSize << 1
	}
	dp = make([]int64, segSize*2)
	for i := 0; i < n; i++ {
		dp[segSize-1+hList[i]-1] = int64(aList[i]) + query(0, hList[i]-1, 0, 0, segSize)
		update(segSize - 1 + hList[i] - 1)
	}
	fmt.Println(query(0, n, 0, 0, n))
}

func query(a int, b int, k int, l int, r int) int64 {
	if b <= l || r <= a {
		return int64(0)
	}
	if a <= l && r <= b {
		return dp[k]
	}
	vl := query(a, b, k*2+1, l, (l+r)/2)
	vr := query(a, b, k*2+2, (l+r)/2, r)
	if vl < vr {
		return vr
	}
	return vl
}

func update(i int) {
	for i > 0 {
		i = (i - 1) / 2
		dp[i] = dp[i*2+1]
		if dp[i] < dp[i*2+2] {
			dp[i] = dp[i*2+2]
		}
	}
}


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

using namespace std;

int main() {
	
	int n, k;
	
	cin>>n>>k;
	
	int arr[n];
	
	for (int i = 0; i < n; i++) {
		cin>>arr[i];
	}
	
	sort(arr, arr + n);
	
	int i = 0;
	int ans = 0;
	while (k--) {
		ans += arr[i++];
	}
	
	cout<<ans;
	
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#define ll long long
using namespace std;

int n,a,b,m;
bool l=0;

int main()
{
    cin>>n>>a>>b;
    for(m=a;m<=b;m++)
    {
        if(m%n==0)
        {
            l=1;
            break;
        }
    }
    if(l) cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define N 100

void print(int *a,int n){
	for(int i=0;i<n;i++){
		cout << a[i];
		if(i!=n-1){
			cout << " ";
		}
	}
}




int main () {
	int a[N],n;

	cin >> n;
	for(int i=0;i<n;i++){
		int k;
		cin >> k;
		a[i]=k;
	}
	print(a,n);
	

	for(int i=1;i<n;i++){
		cout << endl;
		int v = a[i];
		int j = i - 1;
		while(j>=0 && a[j]>v){
			a[j+1] = a[j];
			j--;
		}
		a[j+1]=v;
		print(a,n);
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3048
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int,int> p;
typedef pair<p,p> P;
typedef pair<P,int> PP;
int c,n,used[10],ww;

int x0[10];
int y2[10];
int x1[10];
int y3[10];
PP dd[10];

void dfs(vector<int> L){
  for(int i=0;i<(int)L.size();i++){
    if(used[L[i]])continue;
    used[L[i]]=++c;
     int minx=ww;
    for(int j=0;j<n;j++)
      if(y2[dd[j].s]<y3[L[i]]&&y3[L[i]]<y3[dd[j].s]&&minx>x0[dd[j].s])minx=x0[dd[j].s];

    vector<int> l;
    for(int j=0;j<n;j++)
      if(!used[dd[j].s]&&y3[dd[j].s]<=y3[L[i]]&&minx>=x1[dd[j].s])
	l.push_back(dd[j].s);
    if(l.size())dfs(l);
  }
}



int main(){
  bool f=0;
  while(cin>>n,n){
    if(f)cout<<endl;
    f=1;
    memset(used,0,sizeof(used));
    ww=c=0;
    for(int i=0,q,w,e,r;i<n;i++){
      cin>>q>>w>>e>>r;
      y2[i]=min(w,r);
      x0[i]=min(e,q);
      y3[i]=max(w,r);
      x1[i]=max(e,q);
      ww=max(ww,x1[i]);
      dd[i]=PP(P(p(x0[i],y2[i]),p(x1[i],y3[i])),i);
    }
    sort(dd,dd+n);
    vector<int> v;
    for(int i=0;i<n;i++)v.push_back(dd[i].s);
    dfs(v);
    for(int i=0;i<n;i++)cout<<used[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3064
#include <stdio.h>
     
int main() {
    int n, A, B, r=0;
    scanf("%d %d %d", &n,&A,&B);
    for (int i = 1; i <= n; i++) {
        int c = 0, t = i;
        for (int j = 0; j < 5; j++) {
          c += t % 10;
          t /= 10;
        }
        
		if (c >= A && c <= B) {
		r += i;
		}
    }
      
	printf("%d",r);
	return 0;
}

Measured memory_bytes: 1724
//int -> ll
//http://web.mit.edu/~ecprice/acm/acm08/notebook.html#file12
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include<bits/stdc++.h>
typedef long long ll;
#define x first
#define y second
#define all(aaa) (aaa).begin(),(aaa).end()
#define REP(i,sss,eee) for(int i=sss;i<=eee;++i)
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
#define N 1000000007
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

long long ex(long long a, long long b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	long long tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
long long inv(long long k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
int solve()
{
	int n,k;cin>>n>>k;
	if(n%2==0){n=(n/2);}
	else{n=((n/2)+1);}
	if(n>=k){cout<<"YES\n";}
	else
	{
		cout<<"NO\n";
	}
}
signed main(){
	speed
	int tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
INF = float('inf')
n, m = map(int, input().split())
a = list(map(int, input().split()))
cost = [2, 5, 5, 4, 5, 6, 3, 7, 6]
l = [[x, cost[x-1]] for x in a]
l = sorted(l, key = lambda x: x[1]*10-x[0])
r = l[0]
_max = [0] + [-INF]*n
for i in range(1, n+1):
  for x in l:
    ind = i-x[1]
    if ind >= 0:
      _max[i] = max(_max[i], _max[ind]*10 + x[0])
ans = str(_max[n])
print(ans)

Measured memory_bytes: 14516
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N + 2];
		
		A[0] = 0;
		A[N + 1] = 0;
		
		for (int i = 1; i <= N; i++) {
			A[i] = sc.nextInt();
		}
		
		int originalCost = 0;
		for (int i = 1; i < A.length; i++) {
			originalCost += Math.abs(A[i] - A[i - 1]);
		}
		
		for (int i = 1; i <= N; i++) {
			int cost = originalCost - Math.abs(A[i] - A[i - 1]) - Math.abs(A[i] - A[i + 1]) + Math.abs(A[i + 1] - A[i - 1]);
			System.out.println(cost);
		}
	}
}

Measured memory_bytes: 60644
#include<iostream>

int main() {
	bool flag;
	int a, b;
	std::cin >> a >> b;

	flag = a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0;

	std::cout << (flag ? "Possible" : "Impossible" )<< std::endl;

	return 0;
}

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

void solve () {
    int n;
    cin >> n;
    set<string> s;
    for (int i = 0; i < n; i++) {
        string x;
        cin >> x;
        s.insert(x);
    }
    cout << s.size();

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


Measured memory_bytes: 19172
import itertools
import math
import fractions
import functools
k = int(input())



sum = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        gcd1 = math.gcd(i, j)
        for l in range(1,k+1):
            sum += math.gcd(gcd1,l)

print(sum)

Measured memory_bytes: 10360
#include <iostream>
 
int main () {
	int a,b,c;
  
  std::cin >> a >> b >> c;
  std::string res;
  
  if (c-b == b-a) {
  	res = "YES";
  } else {
  	res = "NO";
  }
  
  std::cout << res << std::endl;
}

Measured memory_bytes: 3592
import java.util.Scanner;

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

        int[] w = new int[N];
        long[] v = new long[N];
        long[][] dp = new long[N+1][W+1];

        for(int i = 0 ; i < N ; i++){
            w[i] = sc.nextInt();
            v[i] = sc.nextLong();
        }

        for(int i = 0 ; i < N ; i++){
            for(int j = 0 ; j <= W ; j++){
                if(j + w[i] <= W) {
                    dp[i + 1][j + w[i]] = Math.max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
                }
                dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j]);
            }
        }

        long ans = 0;
        for(int i = 0 ; i <= W ; i++){
            ans = Math.max(ans, dp[N][i]);
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 125140
local n, x, m = io.read("*n", "*n", "*n")
local t = {x}
local used = {}
used[x] = 1
local loopStartPos = false
local loopLength = -1
local prv = x
for i = 2, n do
  local nxt = (prv * prv) % m
  if used[nxt] then
    loopStartPos = used[nxt]
    loopLength = i - used[nxt]
    break
  end
  used[nxt] = i
  table.insert(t, nxt)
  prv = nxt
end
if n == #t then
  local sum = 0
  for i = 1, #t do
    sum = sum + t[i]
  end
  print(sum)
else
  local sum = 0
  for i = 1, loopStartPos - 1 do
    sum = sum + t[i]
  end
  local rem = n - (loopStartPos - 1)
  local loopCount = rem // loopLength
  local lpv = 0
  for i = loopStartPos, loopStartPos + loopLength - 1 do
    lpv = lpv + t[i]
  end
  sum = sum + lpv * loopCount
  local offset = loopStartPos - 1 + loopCount * loopLength
  for i = offset + 1, n do
    local pos = (loopStartPos - 1) + i - offset
    sum = sum + t[pos]
  end
  print(sum)
end


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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

const ll INF = 3234566667;

set <ll> save;
int k;

void go(int idx, ll cur, int last) {
  if(cur > 0 and cur <= INF) {
    save.insert(cur);
  }
  if(cur > INF) return;
  vector <int> p;
  if(idx == 0) {
    for(ll i = 1; i <= 9; i++) {
      go(idx + 1, cur * 10ll + i, i);
    }
  }
  else {
    for(int x : {last, last - 1, last + 1}) {
      if(x < 0 or x > 9) continue;
      go(idx + 1, cur * 10ll + x, x);
    }
  }
}

int main() {
  cin >> k;
  go(0, 0, 0);
  //cout << save.size() << '\n';
  while(k > 1) {
    save.erase(save.begin());
    k--;
  }
  //for(auto x : save) cout << x << '\n';
  cout << *save.begin() << '\n';
}

Measured memory_bytes: 4992