akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<fstream>
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include <cmath>
#include<string.h>
#include <stdio.h>
#include <unordered_map>
#include <queue>
#include<climits>
#include <iomanip>



using namespace std;
#define ll long long
#define clr(x) memset(x, 0, sizeof(x))
#define tcase ll t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define GCJ ll t;cin>>t;for(ll H=1;H<=t;H++){cout<<"CASE #"<<H<<": ";solve();}
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define endl "\n"
//comment out the above line when coding probs which require flushing the output





void solve()
{

    int n;
    cin>>n;
    int a[n], b[n], c[n];
    int dp[n][3];
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    dp[0][0]=a[0], dp[0][1]=b[0], dp[0][2]=c[0];
    
    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1], dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0], dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][1], dp[i-1][0])+c[i];

    }
    cout<<max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2])<<endl;
}


int main()
{
    
    
    fast;
    //tcase
    // {
    solve();
    // }
    
}






Measured memory_bytes: 5508
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
      {if((s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2])||(s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[1])||(s[1]==s[2]&&s[0]==s[3]&&s[0]!=s[1]))
         cout<<"Yes";
       else cout<<"No";}
    return 0;
}


Measured memory_bytes: 256
import collections

def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    ac = dict(collections.Counter(a))

    if n % 2 == 0:
        if 0 in ac:
            return 0
    else:
        if 0 not in ac or ac[0] != 1:
            return 0
        else:
            del ac[0]
    ans = 1

    for k, v in ac.items():
        if (k + n) % 2 == 1 and v == 2:
            ans = (ans * 2) % 1000000007
        else:
            return 0

    return ans

print(solve())


Measured memory_bytes: 16352
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main(int argc, char const* argv[])
{
  int N;
  cin >> N;
  vector<int> a_list(N);

  int sum = 0;
  for (size_t i = 0; i < N; i++) {
    cin >> a_list[i];
    sum += a_list[i];
  }

  int x = sum / N;

  int res1 = 0;
  int res2 = 0;

  for (size_t i = 0; i < N; i++) {
    res1 += (x - a_list[i]) * (x - a_list[i]);
    res2 += (x + 1 - a_list[i]) * (x + 1 - a_list[i]);
  }

  if (res1 <= res2) {
    cout << res1;
  } else {
    cout << res2;
  }
  cout << endl;

  return 0;
}

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

bool isPrime(int num){
    if(num <= 1) return false;
  	for(int i=2; i*i<=num; i++){
      if(num%i == 0) return false;
    }
  	return true;
}

int main() {
    int X;
    cin >> X;
  	int n = X;
  	while(!isPrime(n)) n++;
    cout << n << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a[1000],b[1000],i=0,k=0,j,d[1000];
	char c[1000],s;
	while(k==0){
		i++;
		scanf("%d %c %d",&a[i],&s,&b[i]);
		c[i]=s;
		if(c[i]=='?'){
			k=1;
		}
	}
	for(j=1;j<=i-1;j++){
		if(c[j]=='+'){
			d[j]=a[j]+b[j];
		}
		else if(c[j]=='-'){
			d[j]=a[j]-b[j];
		}
		else if(c[j]=='*'){
			d[j]=a[j]*b[j];
		}
		else if(c[j]=='/'){
			d[j]=a[j]/b[j];
		}
		printf("%d\n",d[j]);
	}
	return 0;
}


Measured memory_bytes: 1788
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, sum, ans, dp[10000][2], a[2000000],b[2000000];
string str, ss,dd;
bool f,ff;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<Edge>vec[10000];
vector<LL>v;
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	if (a[0] != 0) {
		cout << -1 << endl;
		return 0;
	}
	cnt = 0;
	Mfor(i, n) {
		if (cnt < a[i]) {
			cnt = a[i];
			ans += a[i];
		}
		else if (cnt != a[i]) {
			cout << -1 << endl;
			return 0;
		}
		cnt--;
	}
	if (cnt != -1) {
		cout << -1 << endl;
		return 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4608
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"

using namespace std;

long long int num[7];
long long int ans;
int box;

int main() {
	for (int i = 0; i < 7; i++) {
		cin >> num[i];
	}
	ans += (num[0] / 2) * 2;
	ans += num[1];
	ans += (num[3] / 2) * 2;
	ans += (num[4] / 2) * 2;
	if (num[0] && num[3] && num[4]) {
		box += num[0] % 2;
		box += num[3] % 2;
		box += num[4] % 2;
		if (box == 2)ans++;
		if (box == 3)ans += 3;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<15;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  int N, K;
  string S;
  cin >> N >> K >> S;
  vector<int> v;
  char now = S[0];
  int c = 1;
  if (S[0] == '0') v.push_back(0);
  for (int i=1; i<N; i++){
    if (S[i] == now) c++;
    else{
      v.push_back(c);
      c = 1;
      now = S[i];
    }
  }
  v.push_back(c);
  if (S[N-1] == '0') v.push_back(0);
  
  int sum, ans;
  int zeros = ((int)v.size()-1)/2;
  if (zeros <= K){
    ans = N;
  }else{
    sum = 0;
    for (int i=0; i<2*K+1; i++)
      sum += v[i];
    ans = sum;
    for (int i=0; i<zeros-K; i++) {
      sum = sum - v[2*i] - v[2*i+1] + v[2*K+2*i+1] + v[2*K+2*i+2];
      ans = max(ans, sum);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1020
N = int(input())
A = input().split()
result = 0
count = False
while count == False:
    if (A == ([0] * N or ["0"] * N)): break
    for i in range(N):
        if (int(A[i]) % 2 != 0): count = True
        A[i] = int(A[i]) / 2
    if (count == True): break
    result += 1

print(result)

Measured memory_bytes: 9044
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

ll gcd(ll a,ll b){
  if(b==0) return a;
  return gcd(b, a%b);
}

int main(){
  ll N,M;
  cin >> N >> M;
  vector<ll> a(N);
  set<ll> se;
  for(int i=0; i<N; i++){
    cin >> a[i];
    se.insert(a[i]);
  }
  vector<ll> b(N);
  for(int i=0; i<N; i++){
    b[i] = a[i]/2;
    ll temp = b[i];
    while(temp%2==0){
      if(se.count(temp)){
        cout << 0 << endl;
        return 0;
      }
      temp /= 2;
    }
  }
  ll lcm_b=b[0],lcm_a=a[0];
  for(int i=1; i<N; i++){
    lcm_b = lcm_b/gcd(lcm_b,b[i])*b[i];
    lcm_a = lcm_a/gcd(lcm_a,a[i])*a[i];
  }
  cout << M/lcm_b - M/lcm_a << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int[] c=new int[4];
    String str;
    for(int i=0;i<n;i++){
      str=sc.next();
      switch(str){
        case "AC":
          c[0]++;
          break;
        case "WA":
          c[1]++;
          break;
        case "TLE":
          c[2]++;
          break;
        case "RE":
          c[3]++;
          break;
      }
    }
    System.out.println("AC x "+c[0]);
    System.out.println("WA x "+c[1]);
    System.out.println("TLE x "+c[2]);
    System.out.println("RE x "+c[3]);
    
  }
}

Measured memory_bytes: 60420
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

using namespace std;
typedef pair<int, int> pii;

int main(){
    int N, K;
    cin >> N >> K;
    string s;
    cin >> s;
    vector<int> difs;
    difs.push_back(0);

    for(int i = 1; i < N; i ++){
        if(s[i] != s[i - 1]){
            difs.push_back(i);
        }
    }

    int ans = 0;

    difs.push_back(N);

    rep(i, difs.size() - 1){
        int loc = difs[i];
        int start = i;
        int tmp = start + 2 * K;
        if(s[loc] == '1'){
            tmp = start + 1 + 2 * K;
        }

        int lim = difs.size() - 1;
        int end_next = min(tmp, lim);

        int tmp_ans = difs[end_next] - difs[start];
        ans = max(ans, tmp_ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1020
import numpy as np
N = int(input())
A = map(int, input().split())
A = np.array(list(A))

def myfunc(A):
    A = A[np.mod(A,2) == 0]
  
    if len(A) == 0:
        return("APPROVED")
      
    BIN = (np.mod(A,3) == 0) | (np.mod(A,5) == 0) 
    
    if len(BIN) == np.sum(BIN):
        return("APPROVED")
    else:
        return("DENIED")

print(myfunc(A))

Measured memory_bytes: 12504
#include<iostream>
#include<algorithm>
using namespace std;
int partition(pair<char, int> A[], int left, int right)
{
	pair<char, int> base = A[right];
	int i = left - 1;
	for (int j = left; j < right; j++)
		if (A[j].second <= base.second)
		{
			i++;
			swap(A[i], A[j]);
		}
	swap(A[i + 1], A[right]);
	return i + 1;
}

void quickSort(pair<char, int> A[], int left, int right)
{
	if (left >= right)
		return;
	int idx = partition(A, left, right);
	quickSort(A, left, idx - 1);
	quickSort(A, idx + 1, right);
}
void merge(pair<char, int> A[], int left, int mid, int right)
{
	const int INF = 999999999;
	int ln = mid - left + 1;
	int rn = right - mid;
	pair<char, int> *L = new pair<char, int>[ln + 1];
	pair<char, int> *R = new pair<char, int>[rn + 1];
	for (int i = 0; i < ln; i++)
		L[i] = A[left + i];
	for (int i = 0; i < rn; i++)
		R[i] = A[mid + 1 + i];
	L[ln].second = R[rn].second = INF;
	int i = 0, j = 0;
	for (int k = left; k <= right; k++)
		if (L[i].second <= R[j].second)
			A[k] = L[i++];
		else
			A[k] = R[j++];
	delete[] L;
	delete[] R;
}
void mergeSort(pair<char, int> A[], int left, int right)
{
	if (left >= right)
		return;
	int mid = (left + right) / 2;
	mergeSort(A, left, mid);
	mergeSort(A, mid + 1, right);
	merge(A, left, mid, right);
}
bool isStable(pair<char, int> A[], pair<char, int> B[], int n)
{
	for (int i = 0; i < n; i++)
		if (A[i].first != B[i].first)
			return false;
	return true;
}
int main()
{
	int n;
	cin >> n;
	pair<char, int> *card1 = new pair<char, int>[n];
	pair<char, int> *card2 = new pair<char, int>[n];
	for (int i = 0; i < n; i++)
	{
		cin >> card1[i].first >> card1[i].second;
		card2[i].first = card1[i].first;
		card2[i].second = card1[i].second;
	}
	quickSort(card1, 0, n - 1);
	mergeSort(card2, 0, n - 1);
	cout << (isStable(card1, card2, n) ? "Stable" : "Not stable") << endl;
	for (int i = 0; i < n; i++)
		cout << card1[i].first << " " << card1[i].second << endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

vector<LLi> pri={1, 2, 3};
LLi mod=1000000007;

void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}
 
LLi modinv(LLi a) {
    LLi b = mod, u = 1, v = 0;
    while (b) {
        LLi t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}

LLi gcd(LLi a, LLi b) {
	if(a<0) a=b;
	if(b<0) b=a;
    if (b == 0) return a;
    return gcd(b, a%b);
}

void mplist(LLi x){
	int flag;

	for(int i=5;i<=x;i+=2){
		flag=0;
		for(int j=1;j<(int)pri.size();j++){
			if(i%pri[j]==0){
				flag=1;
				break;
			}
			if(x<pri[j]*pri[j]) break;
		}
		if(flag==0) pri.emplace_back(i);
	}
}

map<LLi, int> rpfac(LLi x){
	int sqx=ceil(sqrt(x));
	//cout<< "sqx=" << sqx SP << sqx*sqx << endl;//
	auto bin = lower_bound(all(pri), sqx);
	int lmt=bin-pri.begin()+1;
	map<LLi, int> tmp;
	//cout<< "lmt=" << lmt SP << pri[lmt] SP << pri[lmt]*pri[lmt] <<endl;//
	if((int)pri.size()<lmt) cout<< "rpfac: pri size is small" <<endl;

	for(int i=1;i<lmt;i++){
		while(x%pri[i]==0){
			x/=pri[i];
			tmp[pri[i]]++;
			//cout<< x <<endl;
			//tmp[0]++;//0番に何個の積でできてるかをメモれる
		}
		if(x==1) break;
	}

	//if(x!=1) cout<< "prime_fac x=" << x <<endl;
	return tmp;
}

LLi defac(map<LLi, int> mp){
	LLi tmp=1;

	/*for(int i=1;i<v.size();i++){
		if(v[i]!=0) tmp*=pow(pri[i], v[i]);
	}*/

	for (auto p : mp) {
  		LLi key = p.first;
  		int value = p.second;
		tmp*=pow(key, value);
      	tmp=tmp%mod;
	}

	return tmp;
}

int main(){

	LLi n, lc, ml, ans=0;
  	vector<LLi> v;
	map<LLi, int> mp, lcmp;
  
  	cin>> n;
  	v.resize(n);
  
  	rep(i, n) cin>> v[i];
  
  	mplist(1010);
  
  	rep(i, n){
  		mp=rpfac(v[i]);
  		ml=defac(mp);
      	if(v[i]!=ml) mp[v[i]/ml]++;
      
      	for (auto p : mp) {
  			auto key = p.first;
  			auto value = p.second;
          	lcmp[key]=max(lcmp[key], value);
        }
	}
  	
  	lc=defac(lcmp);
  
  	rep(i, n){
      	ans+=lc*modinv(v[i]);
      	ans=ans%mod;
    }
  
  	cout<< ans << endl;
  
	return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>
#include <iostream>
#include <algorithm> 
#include <string.h>
using namespace std;
long long ans,b[200001],a[30],k,p,c[30];
int main(){
	int n,i,j,l,w;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
	scanf("%lld",&b[i]);
	j=0;
	l=1;
	p=b[i];
    while(p){
    a[j]+=p%2;
    if(a[j]>1){
    	l=0;
	}
	p/=2;
	j++;
	}
	if(l==0){
	do{
		ans+=k;
		l=1;
	w=i-k;
	p=b[w];
	j=0;
	while(p){
	a[j++]-=p%2;
	p/=2; 
	}
	for(j=0;j<21;j++){
	if(a[j]>1){l=0;break;
	}
	}
	k--;
	}while(!l);
	}
	k++;
	}
   ans+=k*(k+1)/2;
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 1792
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//よくわかんないけど通った？

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


	int N, K;
	scanf("%d", &N);
	scanf("%d", &K);
	int H[302] = {};
	rep1(i, N) scanf("%d", H + i);
	ll hutuu = 0;
	rep(i, N + 1) {
		if (H[i + 1] > H[i]) hutuu += H[i + 1] - H[i];
	}

	ll dp[302][301] = {};
	rep(i, N + 1) {
		auto dpi = dp[i];
		ll tmp1 = max(0, H[i + 1] - H[i]);
		ll tmp2 = max(0, H[i] - H[i + 1]);
		ll tmp3 = min(tmp1, tmp2);
		int mae = H[i + 1];
		ll maetmp = tmp3;
		for (int j = i + 2; j <= N + 1; j++) {
			if (mae < H[j]) tmp1 += H[j] - mae;
			if (mae > H[j]) tmp2 += mae - H[j];
			tmp3 = min(tmp1, tmp2);
			if (maetmp < tmp3) {
				int k = j - i - 1;
				auto dpj = dp[j] + k;
				rep(p, K - k + 1) chmax(dpj[p], dpi[p] + tmp3);
			}
			mae = H[j];
			maetmp = tmp3;
		}
		auto dpi2 = dp[i + 1];
		rep(p, K + 1) chmax(dpi2[p], dpi[p]);
	}
	printf("%lld", hutuu - dp[N + 1][K]);


	Would you please return 0;
}

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

using namespace std;

const int INF = INT_MAX;

int main () {
  int n;
  cin >> n;
  vector <int> h(n);
  for (int i = 0; i < n; i++) cin >> h[i];
  vector <int> dp(n, INF);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    if (i + 1 < n) dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
    if (i + 2 < n) dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
  }
  cout << dp[n - 1] << endl;
  return (0);
}


Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
using namespace std;

bool is_prime (long x) {
  long d = ceil(sqrt(x));
  if (x == d) d--;
  while (d>1 && (x%d)!=0) {
    d--;
  }
  return (d==1);
}

int main (int argc, char **argv) {
  int N;
  cin >> N;

  long x;
  int count = 0;
  for (int i=0;i<N;i++) {
    cin >> x;
    if (is_prime(x)) count++;
  }
  cout << count << endl;
} 

Measured memory_bytes: 1164
while 1:
	n=input()
	if n==0:break
	b=map(int,raw_input().split())
	count=0
	while count<10001:
		if b[0]==1:
			for i in range(len(b)-1):
				if b[i+1]-b[i]!=1:
					break
			else:
				print count
				break
		l=len(b)
		for i in range(l):
			b[i]-=1
		b.append(l)
		while b.count(0)>0:
			del b[b.index(0)]
		count+=1
	else:
		print -1

Measured memory_bytes: 4316
def main():
    N = int(input())
    dic = input()

    for _ in range(N-1):
        S = input()
        temp = list(set(dic))
        totyuu = ''
        for i in range(len(temp)):
            scnt = S.count(temp[i])
            dcnt = dic.count(temp[i])
            if dcnt < scnt:
                totyuu += temp[i]*dcnt
            else :
                totyuu += temp[i]*scnt
        dic = totyuu
    print(''.join(sorted(dic)))



if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    ll n, a, b;
    cin >> n;
    if(n == 1){
        cout << "Hello World" << endl;
    }else{
        cin >> a >> b;
        cout << a + b << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	int n,x;cin >>n>>x;
	vector<int> a(n+1);
	a[0]=0;
	for(int i=0;i<=n;i++)cin >>a[i];
	int ans=0;
	for(int i=1;i<=n;i++){
		int tmp=a[i-1]+a[i]-x;
		if(tmp>0){
		ans+=tmp;
		a[i]-=tmp;
		}	
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>

std::string f(std::vector<std::string> s) {
    std::sort(s.begin(), s.end());
    std::string result = "";
    for (int i = 0; i < s.size(); i++) {
        result.append(s[i]);
    }
    return result;
}

int main() {

    int n, l;
    std::cin >> n >> l;

    std::vector<std::string> s;
    for (int i = 0; i < n; i++) {
        std::string tmp;
        std::cin >> tmp;
        s.push_back(tmp);
    }

    std::string result = f(s);
    std::cout << result << std::endl;

    return 0;
}


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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
#define test cout<<"test"<<endl;
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
const ll zero=0;
using P = pair<ll, ll>;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

vector<vector<ll>> a(100001);//隣接リスト(添え字は始点、値は終点)
vector<ll>t(100001);//訪問したかどうか
ll dfs(ll k){
  t[k]=1;
  vector<ll>tmp;
  if(a[k].size()==1&&k!=0)return 0;
  for(ll i=0;i<a[k].size();i++){
    if(t[a[k][i]]==0){
      tmp.push_back(dfs(a[k][i])); 
    }
  }
  sort(ALLR(tmp));
  ll maxbuf=0;
  ll size=(k==0)?a[k].size():a[k].size()-1;
  for(ll i=1;i<=size;i++){
    chmax(maxbuf,i+tmp[i-1]);
    //cout<<i spa tmp[i-1] spa maxbuf<<endl;
  }
  //cout<<k spa maxbuf<<endl;
  return maxbuf;
}


int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n;cin>>n;
  for(i=1;i<=n-1;i++){
    ll p;cin>>p;
    a[p-1].push_back(i);
    a[i].push_back(p-1);
  }
  cout<<dfs(0)<<endl;

  return 0;
}

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

int main(){
  int N,L;
  cin >> N >> L;
  int ans = 0;
  vector<string> vec(N);
  string s;
  for(int i=0;i<N;i++){
    cin >> s;
    vec.push_back(s);
  }
  sort(vec.begin(),vec.end());
  string res = "";
  N = vec.size();
  for(int i=0;i<N;i++){
    res += vec.at(i);
  }
  cout << res << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    int h, n;
    cin >> h >> n;
    vector<int> a(n), b(n);
    rep(i, n){
        cin >> a[i] >> b[i];
    }
    vector<int> dp(h+1, 1001001001);
    dp[0] = 0;

    rep(i, h+1){
        rep(j, n){
            if(i >= a[j]){
                dp[i] = min(dp[i], dp[i-a[j]] + b[j]);
            }else{
                dp[i] = min(dp[i], b[j]);
            }
        }
    }

    cout << dp[h] << endl;

    return 0;
}


Measured memory_bytes: 256
// by syu
package main

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

var in = NewScanner(os.Stdin, 0)

func main() {
	a, b := in.Int(), in.Int()
	Pln(a*b - b - a + 1)
}

type Scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader, max int) *Scanner {
	s := bufio.NewScanner(r)
	s.Split(scanWords)
	if max <= 0 {
		max = 1048576
	}
	s.Buffer([]byte{}, max)
	return &Scanner{s}
}
func (s *Scanner) Int() int {
	s.Scan()
	i, e := strconv.ParseInt(s.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}
func isSpace(b byte) bool {
	return b == ' ' || b == '\n' || b == '\r' || b == '\t'
}
func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	start := 0
	for start < len(data) && isSpace(data[start]) {
		start++
	}
	for i := start; i < len(data); i++ {
		if isSpace(data[i]) {
			return i + 1, data[start:i], nil
		}
	}
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	return start, nil, nil
}
func Pln(s ...interface{}) {
	fmt.Println(s...)
}


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

using namespace std;

int main(){
	int A, B;
	scanf("%d%d", &A, &B);
	if(A >= 13){
		printf("%d", B);
	}else if(A >= 6){
		printf("%d", B/2);
	}else{
		printf("0");
	}
}


Measured memory_bytes: 256
N,Y = map(int,input().split())
for x in range(N+1):
    for y in range(N+1):
        z= N -x -y
        if z < 0:
            continue
        if 10000 * x + 5000 * y + 1000 * z == Y:
            print("{} {} {}".format((x),(y),(z)))
            exit()
print("-1 -1 -1")

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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		char[] s = sc.next().toCharArray();

		boolean flag = false;
		for (char c : s) {
			if (c == 'C') {
				flag = true;
			}
			if (flag && c == 'F') {
				pr.println("Yes");
				return;
			}
		}

		pr.println("No");
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 9684
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>
 
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;
 
#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		string s,t;
		cin>>s>>t;
		ll int ans=(s[0]==t[0])+(s[1]==t[1])+(s[2]==t[2]);
		cout<<ans;
	}
	return 0;
}

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

using namespace std;
int main() {
    int N;
    cin >> N;
    int i,W[N],back_sum[N],forward_sum[N];
    rep(i,N) {
        cin >> W[i];
        if (i==0) {
            forward_sum[i]=W[i];
        } else {
            forward_sum[i]=W[i]+forward_sum[i-1];
        }
    }
    rep(i,N) {
        if (i==0) {
            back_sum[N-1-i]=W[N-1];
        } else {
            back_sum[N-1-i]=W[N-1-i]+back_sum[N-i];
        }
    }
    int nowmin=99999999;
    rep(i,N-1) {
        // cout << forward_sum[i] << "<->" << back_sum[i]<< endl;
        int av_min = abs(forward_sum[i]-back_sum[i+1]);
        nowmin = min(nowmin,av_min);
    }
    cout << nowmin << endl;



}

Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <stdio.h>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i] << std::endl;
		else std::cout << da[i] << ' ';
	}
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

int main(){
	int n;cin >> n;
	vector<int> da(1 << n);
	rip(i,1 << n,0) cin >> da[i];
	sort(all(da));
	reverse(all(da));
	int now = 1;
	vector<bool> used(1 << n,false);
	used[0] = true;
	bool ju = true;
	rip(i,n,0){
		int po = 0, lo = 1, co = 0;
		vector<bool> permu = used;
		while(lo < (1 << n) && co < now && po < (1 << n)){
			//printf("%d %d %d\n",po,lo,co);
			//vdeb(used);
			if(!permu[po]) po++;
			else if(permu[lo] || da[lo] >= da[po]) lo++;
			else{
				used[lo] = true;
				co++;
				po++;
				lo++;
			}
		}
		if(co == now){
			now *= 2;
		}
		else{
			ju = false;
			break;
		}
	}
	printf((ju)? "Yes\n":"No\n");
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a % b == 0) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
//#define REP(i,a,b) for(int i=a;i<=b;i++)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
long long MOD=1e9+7;

int num[10];
int main()
{	
	ios_base:: sync_with_stdio(0);
	cin.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int i,x;
	for(i=0;i<3;i++)
	{ cin>>x;
		num[x]++;
		}
		for(i=0;i<9;i++)
	{ 	

		if(num[i]==2) {cout<<"Yes";return 0;}
	}
	cout<<"No";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
#include <fstream>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FILL(Itr,n) fill((Itr).begin(),(Itr).end(),n)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;


int main(){
    
    ll N; cin>>N;
    vector<ll> a(N*3);
    REP(i,N*3)cin>>a[i];
    
    sort(a.begin(),a.end());
    
    ll ans = 0;
    ll idx = 3*N-2;
    REP(i,N){
        ans += a[idx];
        idx -= 2;
    }
    
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define ll long long
#define LL long long
#define PB push_back
#define INF 2000000000
#define X first
#define Y second
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAX = 600005;
int main()
{
	//freopen("input.txt" , "r" , stdin);
	int N , K;
	cin >> N >> K;
	if((N + 1) / 2 >= K)
	{
		cout << "YES" << endl;
	}
	else
		cout << "NO" << endl;
}

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

bool mySort(pair<long,long> i, pair<long,long> j){
    if (i.first == j.first) return i.second < j.second;
    else return i.first < j.first;
}

bool binarySearch(int low, int high, vector< pair<long,long> >* v, pair<long,long> i){
    int mid = (low + high)/2;
    while (high - low >= 0){
        mid = (high+low)/2;
        if ((*v)[mid].first == i.first && (*v)[mid].second == i.second) return true;
        else if (mySort((*v)[mid], i)) low = mid+1;
        else high = mid-1;
    }
    return false;
}

long long tot(long H, long W){
    return (H-2)*(W-2);
}

int main(){
    vector < pair<long, long> > points;
    long H, W, N, x, y; cin >> H >> W >> N;
    for (int i = 0; i < N; i++){
        cin >> x >> y;
        points.push_back(make_pair(x, y));
    }
    sort(points.begin(), points.end(), mySort);

    int counter[10];
    int surr[5][5];
    for (int i = 0; i < 10; i++) counter[i] = 0;
    for (int i = 0; i < N; i++){
        long x, y;
        x = points[i].first; y = points[i].second;
        for (int j = 0; j < 5; j++){
            for (int k = 0; k < 5; k++) surr[j][k] = -1;
        }
        for (long j = max(long(1), x-2); j <= min(H, x+2); j++){
            for (long k = max(long(1), y-2); k <= min(W, y+2); k++){
                if (binarySearch(0, N, &points, make_pair(j, k))){
                    surr[2+j-x][2+k-y] = 1;
                } else surr[2+j-x][2+k-y] = 0;
            }
        }
        for (int j = 0; j < 3; j++){
            for (int k = 0; k < 3; k++){
                int tempc = 0;
                bool check = true;
                for (int l = 0; l < 3; l++){
                    for (int m = 0; m < 3; m++){
                        if (surr[j+l][k+m] == 1) tempc++;
                        else if (surr[j+l][k+m] == -1) { tempc = 0; check = false; }
                    }
                }
                if (check) counter[tempc]++;
            }
        }
    }
    long long S = 0;
    for (int i = 1; i < 10; i++){
        S += counter[i]/i;
    }
    cout << tot(H, W)-S << endl;
    for (int i = 1; i < 10; i++){
        cout << counter[i]/i << endl;
    }
    return 0;
}


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

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> D(N);
    unordered_map<ll, int> mp;
    for (int i = 0; i < N; i++) {
        cin >> D[i];
        mp[D[i]]++;
    }
    int M;
    cin >> M;
    vector<ll> T(M);
    for (int i = 0; i < M; i++) {
        cin >> T[i];
    }
    for (int i = 0; i < M; i++) {
        if (mp.find(T[i]) == mp.end() or mp[T[i]] <= 0) {
            cout << "NO" << endl;
            return 0;
        } else {
            mp[T[i]]--;
        }
    }
    cout << "YES" << endl;
    return 0;
}


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

using namespace std;

int solve(vector<int> &vh, int k, vector<int> &memo, int cur = 0) {
  int n = vh.size();
  if (cur == n - 1) {
    return 0;
  }

  if (memo[cur] == -1) {
    int ans = 0;
    for (int i = 1; i <= k && cur + i < n; ++i) {
      int l_ans = solve(vh, k, memo, cur + i) + abs(vh[cur] - vh[cur + i]);
      if (i == 1 || l_ans < ans) {
        ans = l_ans;
      }
    }

    memo[cur] = ans;
  }

  return memo[cur];
}

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

  vector<int> vh(n);
  for (int i = 0; i < n; ++i) {
    cin >> vh[i];
  }

  vector<int> memo(n, -1);
  cout << solve(vh, k, memo) << '\n';
  return 0;
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  long long n, m, k;
  cin >> n >> m >> k;
  vector<long long> a(n);
  vector<long long> b(m);

  vector<long long> sa(n + 1);
  vector<long long> sb(m + 1);

  // read the input
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (long long i = 0; i < m; ++i) {
    cin >> b[i];
  }

  // prefix sum
  for (long long i = 0; i < n; ++i) {
    sa[i + 1] = sa[i] + a[i];
  }
  for (long long i = 0; i < m; ++i) {
    sb[i + 1] = sb[i] + b[i];
  }

  long long ret = 0;
  long long j = m;

  // i = 0, 1, 2, ..., n
  // j = m
  for (long long i = 0; i <= n; ++i) {
    if (sa[i] > k) break;
    while (sb[j] > k - sa[i]) {
      --j;
    }
    ret = max(ret, i + j);
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 9480
import java.util.*;

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

	public Main() {
		new AOJ0046().doIt();
	}
	
	class AOJ0046{
		void doIt(){
			ArrayList<Double> list = new ArrayList<Double>();
			while(in.hasNext())list.add(in.nextDouble());
			Collections.sort(list);
			System.out.println(Math.abs(list.get(0)-list.get(list.size()-1)));
		}
	}
	
}

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

int Partition(int A[],int p,int r)
{
	int x=A[r];
	int i=p-1;

	for(int j=p; j<=r-1; j++)
	{
		if(A[j]<=x)
		{
			i++;
			swap(A[i],A[j]);
		}
	}
	swap(A[i+1],A[r]);
	return i+1;
}

int main()
{
	int data;
	cin>>data;
	int A[100000];

	for(int i=0; i<data; i++){
		cin>>A[i];
	}

	int q= Partition(A,0,data-1);
	for(int i=0; i<data; i++)
	{
		if(i==q){
			cout<<'['<<A[q]<<']';
		}
		else{
			cout<<A[i];
		}
		if(i<data-1)
			cout<<' ';
		else
			cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3456
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

pair<int,int> dp[101][100000];

bool solve(){
  int n, p;
  
  scanf("%d", &n);

  if(n == 0) return false;
  
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n*499;j++){
      dp[i][j] = {-INF, 0};
    }
  }

  dp[0][0] = {0, 0};

  for(int i=0;i<n;i++){
    scanf("%d", &p);
    int p2 = p;
    p %= 1000; 
    for(int j=0;j<=i*499;j++){
      //1000円のみ
      dp[i+1][j + (1000-p)%500] = max(dp[i+1][j+(1000-p)%500],
                                      {dp[i][j].first + (1 <= p && p <= 500), dp[i][j].second - p2});

      //小銭で価格+500円払う
      if(p + 500 <= j){
        dp[i+1][j - (p+500)] = max(dp[i+1][j - (p+500)],
                                   {dp[i][j].first + 1, dp[i][j].second - p2});
      }

      //札+小銭で価格+500円払う
      if(p >= 501 && j >= p-500){
        dp[i+1][j - (p-500)] = max(dp[i+1][j-(p-500)],
                                   {dp[i][j].first + 1, dp[i][j].second - p2});
      }

      //買わない
      dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
    }
  }

  pair<int,int> ans = {0, 0};
  
  for(int i=0;i<=n*499;i++){
    ans = max(ans, dp[n][i]);
  }

  printf("%d %d\n", ans.first, -ans.second);

  return true;
}

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



Measured memory_bytes: 42868
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    D = [list(map(int, rl().split())) for _ in range(N)]
    
    for i in range(N - 2):
        if D[i][0] == D[i][1] and D[i + 1][0] == D[i + 1][1] and D[i + 2][0] == D[i + 2][1]:
            print('Yes')
            return
    print('No')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 62144
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author wnqmw
 */
public class Main {
    public static void main(String args[]){
        Scanner kb = new Scanner(System.in);
        
        String s = kb.nextLine();
        if(s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

int main(void){
    // char ;
    ll x,y,ans=1;
    scanf("%lld%lld",&x,&y);
    // ll [n];
    ll a=y/x;
    while(a>1){
        a/=2;
        ans++;
    }

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


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  map<int, int> mp;
  REP(i, n) mp[a[i]] = i;
  sort(ALL(a));
  map<int, int> mp2;
  REP(i, n) mp2[a[i]] = i;
  int ans = 0;
  REP(i, n) {
    if (mp[a[i]] % 2 == 0 && mp2[a[i]] % 2 == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
  int n,k;
  ll ans = 0;
  ll h[200005];

  cin >> n >> k;
 
  for(int i=0; i<n; i++) cin >> h[i];

  sort(h,h+n,greater<int>());

  for(int i=k; i<n; i++) ans += h[i];

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

template <class T>
struct SegmentTree{
  using F = function<T(T,T)>;
  F f;
  T inf;
  int n;
  vector<T> node;

  SegmentTree(vector<T> v,T inf,F f):inf(inf),f(f){
    n = 1; while(n < v.size()) n *= 2;
    node.resize(2*n-1,inf);
    for(int i = 0; i < v.size(); i++) node[i+n-1] = v[i];
    for(int i = n-2; i >= 0; i--) node[i] = f(node[2*i+1],node[2*i+2]);
  }

  void update(int k,T val){
    k += n-1;
    node[k] = val;
    while(k > 0){
      k = (k-1) / 2;
      node[k] = f(node[2*k+1],node[2*k+2]);
    }
  }

  void add(int k,T val){
    k += n-1;
    node[k] += val;
    while(k > 0){
      k = (k-1) / 2;
      node[k] = f(node[2*k+1],node[2*k+2]);
    }
  }

  T getval(int a,int b){ return getval(a,b,0,0,n); }
  T getval(int a,int b,int k,int l,int r){
    //区間[a, b)の値を返す
    if(r <= a || b <= l) return inf;
    if(a <= l && r <= b) return node[k];
    T vl = getval(a, b, 2*k+1, l, (l+r)/2);
    T vr = getval(a, b, 2*k+2, (l+r)/2, r);
    return f(vl, vr);
  }
};

signed main(){

  int n,c; cin >> n >> c;
  vector<int> x(n+2),v(n+2);
  x[0] = v[0] = 0;
  for(int i = 1; i <= n; i++){
    cin >> x[i] >> v[i];
  }
  x[n+1] = c,v[n+1] = 0;

  vector<int> dp(n+2,0),dp2(n+2,0);
  for(int i = 1; i <= n+1; i++){
    dp[i] = dp[i-1] + v[i] - (x[i] - x[i-1]);
  }
  for(int i = n; i >= 0; i--){
    dp2[i] = dp2[i+1] + v[i] - (x[i+1] - x[i]);
  }

  SegmentTree<int> seg(dp,-1,[&](int x,int y){
    return max(x,y);
  });
  SegmentTree<int> seg2(dp2,-1,[&](int x,int y){
    return max(x,y);
  });

  int ans = 0;
  for(int i = 0; i <= n+1; i++){
    ans = max(ans,max(dp[i],dp[i] + seg2.getval(i+1,n+2) - x[i]));
    //ans = max(ans,max(dp2[n+1-i],dp2[n+1-i] + seg.getval(0,i) - (c-x[n+1-i])));
  }
  for(int i = n; i >= 0; i--){
    ans = max(ans,max(dp2[i],dp2[i] + seg.getval(0,i) - (c-x[i])));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8304
#include <bits/stdc++.h>
using namespace std;
int main(){
  string O,E; cin>>O>>E;
  int size=O.length();
  for (int i=0;i<size;i++){
    if (i<E.length()){
      cout<<O[i]<<E[i];
    }
    else{
      cout<<O[i];
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int ans=100000;
    int N;
    int all=0;
    cin >>N;
    int W[N];
    REP(i,N){
        cin>>W[i];
        all+=W[i];
    }
    for(int i=0;i<N-1;i++){
        int l=0;
        for(int j=0;j<=i;j++){
            l+=W[j];
        }
        ans=min(ans,abs(2*l-all));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256