akhauriyash/Code-Regression huggingface dataset:
/*
  AOJ 1035
  Title:Sleeping Cats
  @kankichi573
*/
#include <stdio.h>
#include <string.h>

int W,Q;
char pos[100];
char zero[100];

cat_alloc(int id,int len)
{
  int i;
  
  for(i=0;i<=W-len;i++)
    if(0==memcmp(zero,pos+i,len))
      {
	memset(pos+i,id,len);
	return(i);
      }
  return(-1);
}

cat_free(int id)
{
  int i;

  for(i=0;i<100;i++)
    if(pos[i]==id)
      pos[i]=-1;
}
dump()
{
      int i;
      for(i=0;i<W;i++)
	if(pos[i]==-1)
	  printf("-|");
	else
	  printf("%d|",pos[i]);
      printf("\n--------\n");
}
main()
{
  int i,ret,id,wid,ds;
  char sw,input[20],*p1,*p2;
  ds=0;
  while(scanf("%d %d ",&W,&Q)  && (W||Q))
    {
      if(ds)
	printf("END\n");
      ds++;
      memset(zero,-1,100);
      memset(pos ,-1,100);
      for(i=0;i<Q;i++)
	{
	  fgets(input,20,stdin);
	  if(input[0]=='s')
	    {
	      strtok(input," \n");
	      p1=strtok(NULL," \n");
	      id = atoi(p1);
	      p2=strtok(NULL," \n");
	      wid= atoi(p2);
	      if(-1!=(ret=cat_alloc(id,wid)))
		printf("%d\n",ret);
	      else
		printf("impossible\n");
	    }
	  else if(input[0]=='w')
	    {
	      strtok(input," \n");
	      p2=strtok(NULL," \n");
	      id = atoi(p1);
	      cat_free(id);
	    }
	  //dump();
	}
    }
  printf("END\n");
  return(0);
}

Measured memory_bytes: 644
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            var joinPeopleCount = int.Parse(Console.ReadLine());
            var DaysCountAndResultChocolateCount = Console.ReadLine().Split(' ').Select(int.Parse);
            var Days = DaysCountAndResultChocolateCount.ElementAt(0);
            var ResultChocolateCount = DaysCountAndResultChocolateCount.ElementAt(1);

            var BeforeChcolateCount = 0;

            for (int i = 0; i < joinPeopleCount; i++)
            {
                var EatInterval = int.Parse(Console.ReadLine());

                var eatCount = 0;

                var UserDaysCount = 0;

                while (Days > UserDaysCount)
                {
                    eatCount++;
                    UserDaysCount += EatInterval;
                }

                BeforeChcolateCount += eatCount;
            }

            Console.WriteLine(ResultChocolateCount + BeforeChcolateCount);
        }
    }
}


Measured memory_bytes: 11220
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
int main() {
    int X; cin >> X;
    cout << (X < 30 ? "No" : "Yes") << endl;
}

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

int main()
{
    int a = 0;
    while(true){
        a++;
        int x;
        cin >> x;
        if(x == 0)
            break;
        cout << "Case " << a << ": " << x << endl;
    }
}


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

const int CENTER = 8101;
bool dp[CENTER][CENTER * 2];

int main() {
    string s;
    vector<int> dx, dy;
    bool dirx = true;
    bool achievable;
    int cnt = 0;
    int x, y;
    cin >> s;
    cin >> x >> y;
    dy.push_back(0);
    for (int i=0;i<s.size();i++) {
        if (s[i] == 'F') {
            cnt++;
            if (i == s.size()-1) {
              if (dirx) {
                  dx.push_back(cnt);
              } else {
                  dy.push_back(cnt);
              }
            }
        } else {
            if (dirx) {
                dx.push_back(cnt);
            } else {
                dy.push_back(cnt);
            }
            dirx = !dirx;
            cnt = 0;
        }
    }
    memset(dp, false, sizeof(dp));
    dp[0][CENTER + dx[0]] = true;
    for (int i=0;i<dx.size()-1;i++) {
      for (int j=0;j < CENTER * 2;j++) {
        if (j - dx[i+1] >= 0) {
          dp[i+1][j-dx[i+1]] |= dp[i][j];
        }
        if (j + dx[i] < CENTER * 2) {
          dp[i+1][j+dx[i+1]] |= dp[i][j];
        }
      }
    }
    achievable = dp[dx.size()-1][CENTER + x];
    memset(dp, false, sizeof(dp));
    dp[0][CENTER] = true;
    for (int i=0;i<dy.size()-1;i++) {
      for (int j=0;j < CENTER * 2;j++) {
        if (j - dy[i] >= 0) {
          dp[i+1][j-dy[i+1]] |= dp[i][j];
        }
        if (j + dy[i] < CENTER * 2) {
          dp[i+1][j+dy[i+1]] |= dp[i][j];
        }
      }
    }
    achievable &= dp[dy.size()-1][CENTER + y];
    if (achievable) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
}


Measured memory_bytes: 128640
import java.io.*;
import java.util.Arrays;
public class Main {
        public static void main(String[] args) throws IOException {
                BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                String is;
                String ia[];
                int cc = 1;
                while(true){
                        int n = Integer.parseInt(in.readLine());
                        if(n == 0){
                                break;
                        }
                        int c = 1;
                        int v[][] = new int[n][n];
                        for(int i = 0;i <= 2*(n-1); ++i){
                                int j;
                                int d;
                                if(i%2 == 1){
                                        d = 1;
                                        j = 0;
                                        if(i >= n){
                                                j = i-n+1;
                                        }
                                } else {
                                        d =-1;
                                        j = i;
                                        if(i >= n){
                                                j = n-1;
                                        }
                                }
                                int e,s;
                                if(i < n){
                                        s = 0;
                                        e = i;
                                } else {
                                        s = i-n+1;
                                        e = n-1;
                                }
                                while(s <= j && j <= e){
                                        v[j][i-j] = c++;
                                        j += d;
                                }
                        }
                        System.out.println("Case " + cc + ":");
                        for(int i = 0;i < n; ++i){
                                for(int j = 0;j < n; ++j){
                                        System.out.printf("%3d",v[i][j]);
                                }
                                System.out.printf("\n");
                        }
                        ++cc;
                }
        }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
typedef long long ll;

int N;
ll a[100100], b[100100], inc;

int main () {
        scanf("%d", &N);
        fo(i, 0, N) scanf("%lld %lld", &a[i], &b[i]);
        for (int i = N-1; i >= 0; i--) {
                ll cur = a[i] + inc;
                ll mn = (cur + b[i] - 1ll) / b[i];
                mn *= b[i];
                inc = mn - a[i];
        }
        printf("%lld\n", inc);
        return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cmath>

using namespace std;

main(){
  int n;
  int c=0;
  while(cin>>n){
    if(n==0)break;
    ++c;

    double s=0;
    int x1,xk,y1,yk,xj,yj;
    cin>>x1>>y1;
    cin>>xj>>yj;
    for(int i=0;i<n-2;i++){
      cin>>xk>>yk;
      int px=xj-x1,py=yj-y1,qx=xk-x1,qy=yk-y1;
      s+=(px*qy-py*qx)/2.0;
      xj=xk;
      yj=yk;
    }

    printf("%d %.1f\n",c,abs(s));
  }
}

Measured memory_bytes: 0
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
int check753(long long n) {
	int check3 = 0;
	int check5 = 0;
	int check7 = 0;
	int flag = 0;
	std::string s = std::to_string(n);
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '3')
			check3++;
		else if (s[i] == '5')
			check5++;
		else if (s[i] == '7')
			check7++;
		else {
			flag = 1;
			break;
		}
	}
	if (check3 > 0 && check5 > 0 && check7 > 0 && flag == 0) {
		return 1;
	}
	else {
		return 0;
	}
}
int fac_semi753(long long  h,long long n,long long *counter) {
	if (h > n) {
		return 0;
	}
	long long temp;
	for (int i = 0; i < 3; i++) {
		if (i == 0) {
			temp = h * 10 + 3;
			if (temp > n) {
				return 0;
			}
			*counter += check753(temp);
			fac_semi753(temp, n, counter);
		}
		if (i == 1) {
			temp = h * 10 + 5;
			if (temp > n) {
				return 0;
			}
			*counter += check753(temp);
			fac_semi753(temp, n, counter);
			
		}
		if (i == 2) {
			temp = h * 10 + 7;
			if (temp > n) {
				return 0;
			}
			*counter += check753(temp);
			fac_semi753(temp, n, counter);
			
		}
	}
 
}
int main()
{
	long long n, counter = 0;
	scanf("%lld", &n);
	fac_semi753(0, n, &counter);
	printf("%lld\n", counter);
	return 0;
 
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int i,j,x,y,s,max;

  while(1){
    scanf("%d%d%d",&x,&y,&s);
    if(x==0&&y==0&&s==0)break;
    max=0;
    for(i=1;i<=s;i++){
      for(j=i;j<=s;j++){
	if(j*(100+x)/100==(s-(i*(100+x)/100))){
	  if((i*(100+y)/100)+(j*(100+y)/100)>max){
	    max=(i*(100+y)/100)+(j*(100+y)/100);
	    break;
	  }
	}
      }
    }
    printf("%d\n",max);
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define all(v) (v).begin(), (v).end()
using namespace std;
typedef long long LL;
const int INF = 999999999;
const LL mod = 1000000007;

int main(){
    LL a,b,x;
    cin >> a >> b >> x;
    if(x < a){
        cout << x%mod << endl;
        return 0;
    }
    LL t = ((x-b) / (a-b)) % mod;
    cout << (x%mod + t*(b%mod))%mod << endl;
}



Measured memory_bytes: 3080
x=int(input())

if x<600:
    print(8)
elif x<800:
    print(7)
elif x<1000:
    print(6)
elif x<1200:
    print(5)
elif x<1400:
    print(4)
elif x<1600:
    print(3)
elif x<1800:
    print(2)
else:
    print(1)

Measured memory_bytes: 9172
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = 1e9 + 7;


int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

const ll MOD = 1e9 + 7;



int main() {


	int a, b;
	cin >> a >> b;
	if (a >= 13)
	{
		cout << b << endl;
	}
	else if (6 <= a && a < 13)
	{
		cout << b / 2 << endl;
	}
	else
	{
		cout << "0" << endl;
	}




	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int  long long
using namespace std;
int32_t main()
{
    int l,r,d,c=0;
	cin>>l>>r>>d;
	for(int i=l/d;;++i)
	{
		if(d*i>=l&&d*i<=r)
		{
			++c;
		}
		if(d*i>r)
		break;
	}
	cout<<c;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
#define N 500000

typedef struct Node{
  int key;
  struct Node *parent,*left,*right;
}Node;

Node *NIL,*root;

void insert(int k){
  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z;

  z=(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else {
      x=x->right;
    }
  }

  z->parent=y;
  if(y==NIL){
    root = z;
  }
  else {
    if(z->key < y->key){
      y->left=z;
    }
    else {
      y->right=z;
    }
  }
}

void inorder(struct Node *u){

  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(struct Node *u){

  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

main(){

  int i,n,x;
  char com[N];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 24044
I,J=map(int,input().split())

i=I%2019
j=J%2019

cal=10000

#print(i,j)

if i >= j or I+2019<=J:
    print(0)
elif j<46:
    print(i*(i+1))
else:
    for a in range(j-i):
        for b in range(j-i-a):
            cal=min(cal,((i+a)*(i+a+b+1)%2019))
            #print(i+a,i+a+b+1,cal)
        if cal==0:
            break
        
    print(cal)
        
    
    

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }

void solve() {
  int N;
  cin >> N;
  vector<pii> R;
  vector<int> T(N), V(N);
  R.push_back({0, 0});
  for (int i = 0; i < N; i++) {
    cin >> T[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> V[i];
  }
  int sum = 0;
  unordered_map<double, double> m;
  for (int i = 0; i < N; i++) {
    R.push_back({sum, V[i]});
    for(double j = sum; j <= sum + T[i]; j += 0.5) {
      if (!m.count(j)) m[j] = V[i];
      else m[j] = min(m[j], (double)V[i]);
    }
    sum += T[i];
    R.push_back({sum, V[i]});
  }
  R.push_back({sum, 0});

  N = R.size();
  for(int i = 0; i < N; i++) {
    int t = R[i].first;
    int v = R[i].second;
    for(double j = 0; j <= t; j += 0.5) {
      if (!m.count(j)) m[j] = v + t - j;
      else m[j] = min(m[j], v + t - j);
    }
    for(double j = t; j <= sum; j += 0.5) {
      if (!m.count(j)) m[j] = v + j - t;
      else m[j] = min(m[j], v + j - t);
    }
  }

  vector<pair<double,double>> mm;
  for(auto &&e: m) {
    mm.push_back(e);
  }
  sort(all(mm));

  double ans = 0;
  for(int i = 0; i + 1 < mm.size(); i++) {
    double a = mm[i].second;
    double b = mm[i + 1].second;
    ans += (a + b) / 4.0;
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}

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

int main(){
  int64_t X;
  cin >> X;

  const int N = 120;

  vector<int64_t> v(N);
  for(int64_t i = 0;i < N;i++){
    v[i] = i*i*i*i*i;
  }

  for(int64_t i = 0;i < N;i++){
    for(int64_t j = 0;j < N;j++){
      if(v[j] - v[i] == X){
	std::cout << j << " " << i << std::endl; 
	return 0;
      }
      if(v[j] + v[i] == X){
	std::cout << j << " " << (-i) << std::endl; 
	return 0;
      }
    }    
  }

  // int64_t c = 0;
  // while(true){
  //   int64_t a = c*c*c*c + (c + 1)*c*c*c + (c + 1)*(c + 1)*c*c + (c + 1)*(c + 1)*(c + 1)*c + (c + 1)*(c + 1)*(c + 1)*(c + 1);
  //   cout << c << " " << a << std::endl;
  //   if(a > 1000000000) break;
  //   c++;
  // }

}


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

int main(){

	int n;
	cin >> n;
	string S[n];
	rep(i,n) cin >> S[i];

	int cnt[26] = {};
	for(int j=0; j<S[0].length(); j++) cnt[S[0][j]-'a']++;
	rep(i, n) {
		int tmp[26] = {};
		for(int j=0; j<S[i].length(); j++) tmp[S[i][j]-'a']++;
		for(int j=0; j<26; j++)cnt[j] = min(cnt[j],tmp[j]);
	}
	rep(i, 26)
		rep(j,cnt[i]) printf("%c", 'a'+i);
	printf("\n");
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> P;
typedef unsigned long long int ull;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;
const ll MOD=1e9+7;


int main(){
    ll N,K;cin>>N>>K;++K;
    vector<ll> A(N);
    for(int i=0;i<N;++i) cin>>A[i];
    ll ans=0;
    for(int d=50;d>=0;--d){
        ll tmp=0;
        ll mask=1LL<<d;
        if(!(K&mask)) continue;
        ll num=0;
        for(int e=50;e>=0;--e){
            ll num=0;
            mask=1LL<<e;
            for(int i=0;i<N;++i){
                if(A[i]&mask) ++num;
            }
            if(e>d){
                if(K&mask) tmp+=mask*(N-num);
                else tmp+=mask*num;
            }else if(e==d){
                tmp+=mask*num;
            }else{
                tmp+=mask*max(num,N-num);
            }
        }
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4048
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================
//using系

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vvi = vector<vector<int>>;
using Graph = vvi;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
using ui = unsigned int;
using qul = queue<ll>;
using pql = priority_queue<ll>;
using kaage = priority_queue<int, vector<int>, greater<int>>;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;

// ========================================================================
//define系

//#define int long long;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i <= n; i++)

// ========================================================================


ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a)
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a)
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll mch(ll n) {
	if (n == 1) return 1;
	else return n * mch(n - 1);
}
//1から整数nまでの階乗を出す(INFで割っていない)
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double m = sqrt(a);
	for (int i = 3; i <= m; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定
ll modpow(ll a, ll n, ll mod) {
	ll hi = 1;
	while (n > 0) {
		if (n & 1) hi = hi * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return hi;
}
//いろいろやります（ただの前座）
ll mg(ll a, ll mod) {
	return modpow(a, mod - 2, mod);
}
//割り算の10^9+7等対策で逆元を出します 


// ========================================================================


//ある程度のテンプレ
//これとBFS、あとその時その時で使うものはここに書く


// ========================================================================


/*signed*/int main() {
	int n; cin >> n;
	vl a(n);
	map<ll, ll> mp;
	for (int i = 0; i < n; i++) {
		cin >> a[i]; 
		mp[a[i]] = i;
	}

	sort(a.begin(), a.end());
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (mp[a[i]] % 2 != i % 2) cnt++;
	}
	cout << cnt / 2 << endl;

	return 0;
}

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


int main() {

  int n,m;

  cin >> n>>m;

  vector <int> d,c;

  d.resize(n);
  c.resize(m);

  for(int i=0;i<n;i++) cin >> d[i];
  for(int i=0;i<m;i++) cin >> c[i];

  int dp[1001][1001];

  for(int i=0;i<=m;i++)
    for(int j=0;j<=n;j++)
      dp[i][j] = 1000000000;
  
  for(int i=0;i<=m;i++)
    dp[i][0]  = 0;
  
  for(int i=1;i<=m;i++)
    for(int j=1;j<=n;j++)
      dp[i][j] = min(dp[i-1][j-1]+d[j-1]*c[i-1],dp[i-1][j]);

  cout << dp[m][n] << endl;
  
  return 0;
}
    

Measured memory_bytes: 5116
a, b, c, x, y = map(int, input().split())

p1 = a*x + b*y
p2 = 2*c*max(x, y)
p3 = 2*c*y + a*(x-y) if x > y else 2*c*x + b*(y-x)

print(min(p1, p2, p3))

Measured memory_bytes: 3060
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v) {std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

constexpr int INF = 1e7;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

int main() {

    int H, W;
    cin >> H >> W;

    vector<string> S(H);
    for (int i = 0; i < H; i++) cin >> S[i];

    vector<vector<int>> M(H, vector<int>(W, INF));
    M[0][0] = 0;
    queue<pair<int, int>> Q;
    Q.push(make_pair(0, 0));
    while (!Q.empty()) {
        auto p = Q.front();
        Q.pop();
        for (int i = 0; i < 4; i++) {
            int y = p.first + dy[i];
            int x = p.second + dx[i];
            if (x < 0 || x >= W || y < 0 || y >= H) continue;
            if (S[y][x] == '#') continue;
            if (M[y][x] > M[p.first][p.second] + 1) {
                M[y][x] = M[p.first][p.second] + 1;
                Q.push(make_pair(y, x));
            }
        }
    }

    int whiteCount = 0;
    for (int i = 0; i < H; i++)for (int j = 0; j < W; j++) if (S[i][j] == '.') whiteCount++;

    if (M[H - 1][W - 1] == INF) cout << -1 << endl;
    else cout << whiteCount - M[H - 1][W - 1] - 1 << endl;

    return 0;
}




























Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define v(x) vector<x>
#define pb push_back 
#define mp make_pair
const ll maxint=2e18;
const ll minint =-2e18;
/*
(͡ ° ͜ʖ ͡ °): Hi, be careful of overflow.
*/
const ll mod = 1e9+7;
ll binpow(ll a,ll b){
	if(b == 0)return 1;
	if(b==1)return a;
	ll res = 1;
	if(b&1)res*=a;
	ll x = binpow(a,b/2)%mod;
	res *= (x*x)%mod;
	res%=mod;
	return res%mod;
}
int main(){
	ll n;
	cin>>n;
	//10^n - ((9^n)*2-(8^2));
	cout<<(binpow(10,n)%mod-((((binpow(9,n)*2)%mod)-(binpow(8,n)%mod)+mod)%mod)+mod)%mod<<'\n';
	return 0;
}


Measured memory_bytes: 3612
n=int(input())
List = [int(i) for i in input().split()]

j=0
for i in range(1,n-1):
    #print(i)
    if List[i-1]<List[i] and List[i]<List[i+1]:
        j=j+1
    elif List[i-1]>List[i] and List[i]>List[i+1]:
        j=j+1
print(j)
    

Measured memory_bytes: 38256
import scala.io.StdIn._

object Main extends App {
  val s = readLine()
  val t = readLine()
  var u = s

  val r =
    if ((1 to t.length).exists { _ =>
          val b = u == t
          u = u.last + u.init
          b
        })
      "Yes"
    else
      "No"

  println(r)
}


Measured memory_bytes: 54760
n, m = map(int, input().split())
a = list(map(int, input().split()))

total = 0
for i in range(n):
    total += a[i]
    
num = 0
for i in range(n):
    if a[i] >= total/(4*m):
        num += 1
        
if num >= m:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> h(n), opt(n);
    cin >> h;
    for(int i = n - 1; i >= 0; i--) {
        if(i == n - 1) {
            opt[i] = 0;
        } else if(i == n - 2) {
            opt[i] = opt[i + 1] + abs(h[i] - h[i + 1]);
        } else {
            opt[i] = min(opt[i + 1] + abs(h[i] - h[i + 1]), opt[i + 2] + abs(h[i] - h[i + 2]));
        }
    }
    cout << opt[0] << endl;
    return 0;
}


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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

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

    ll n;cin >> n;
    ll t;cin >> t;
    vector<ll> times(n);
    rep(i,n)cin >> times[i];

    adjacent_difference(ALL(times),times.begin());
    ll ans = 0;
    rep(i,n){
        ans += min(times[i],t);
    }
    cout << ans+t << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#define pb emplace_back
#define LOCAL
  
using namespace std;
  
const int inf = 0x3f3f3f3f;
const int maxn = 2e5+5;
typedef long long ll;
typedef pair<int,int> Pii;
const ll mod = 1e9+7;
 
template <typename T>inline void read(T& t){
    char c=getchar();t=0;
    int f=1;
    while(!isdigit(c)){
       if(c=='-')f=-1;
        c=getchar();
    }
    while(isdigit(c))t=t*10+c-48,c=getchar();
    t=f*t;
}
  
template <typename T,typename... Args> inline void read(T& t,Args&... args){
    read(t);read(args...);
}
 
ll a[maxn],sum[maxn];
  
int main(){
    int n;
    read(n);
    for(int i=1;i<=n;i++){
        read(a[i]);
    }
    for(int i=n;i>=1;i--){
       sum[i]=(a[i]+sum[i+1])%mod;
    }
    ll ans=0;
    for(int i=n-1;i>=1;i--){
        ans=(ans+sum[i+1]*a[i]%mod)%mod;
    }
    printf("%lld\n",ans%mod);
    return 0;
}

Measured memory_bytes: 6300
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  string S;
  cin >>S;
 int x=S.size();
  bool answer=true;
  if(x%2 !=0) {
      rep(i,x/2+1) {
        if (S.at(2*i)=='L') {
           answer=false;
        }
      }
      rep(i,x/2) {
        if (S.at(2*i+1)=='R') {
           answer=false;
        }
      }
  }
  
  if(x%2 ==0) {
      rep(i,x/2) {
        if (S.at(2*i)=='L') {
           answer=false;
        }
      }
      rep(i,x/2) {
        if (S.at(2*i+1)=='R') {
           answer=false;
        }
      }
  }
  
  
  
  
  
  
  
  
  
  
  
  
  if(answer) {
cout <<"Yes" << endl;
  }
else {
cout << "No" << endl;
}
}
  
  

Measured memory_bytes: 256
A=[]
for _ in range(3):
    a=list(map(int,input().split()))
    A.append(a)
N=int(input())
L=[[0]*3 for _ in range(3)]

for _ in range(N):
    b=int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j]==b:
                L[i][j]=1

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


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

template<typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

template<int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(int x_) { if ((x = x_ % mod + mod) >= mod) x -= mod; }
    ModInt& operator+=(ModInt rhs) { if ((x += rhs.x) >= mod) x -= mod; return *this; }
    ModInt& operator-=(ModInt rhs) { if ((x -= rhs.x) < 0) x += mod; return *this; }
    ModInt& operator*=(ModInt rhs) { x = (unsigned long long) x * rhs.x % mod; return *this; }
    ModInt& operator/=(ModInt rhs) { x = (unsigned long long) x * rhs.inv().x % mod; return *this; }

    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }

    friend ostream& operator<<(ostream& s, ModInt<mod> a) { s << a.x; return s; }
    friend istream& operator>>(istream& s, ModInt<mod>& a) { s >> a.x; return s; }
};

using mint = ModInt<(int) 1e9 + 7>;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> board(h);
    for (int i = 0; i < h; i++) {
        cin >> board[i];
    }
    vector<vector<mint>> dp(h, vector<mint>(w));
    dp[0][0] = 1;
    int dx[] = {0, 1};
    int dy[] = {1, 0};
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            for (int k = 0; k < 2; k++) {
                int x = i + dx[k], y = j + dy[k];
                if (x < h && y < w && board[x][y] == '.') {
                    dp[x][y] += dp[i][j];
                }
            }
        }
    }
    cout << dp[h - 1][w - 1] << endl;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18L;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  long long int dp[n][n], ps[n];
  ps[0]=a[0];
  for(int i=1;i<n;i++) ps[i]=ps[i-1]+a[i];
  for(int i=0;i<n;i++) dp[i][i]=0;
  for(int i=1;i<n;i++)
  {
    for(int j=0;j+i<n;j++)
    {
      dp[j][j+i]=INF;
      for(int k=j;k<j+i;k++)
      {
        dp[j][j+i]=min(dp[j][j+i],dp[j][k]+dp[k+1][j+i]+ps[j+i]-((j>0)?ps[j-1]:0));
      }
    }
  }
  cout<<dp[0][n-1];
}

Measured memory_bytes: 4892
n = int(input())
a = [1]
q = [10000000000000 for _ in range(n+1)]
q[0] = 0

for i in range(6):
    a.append(6**(i+1))
for i in range(5):
    a.append(9**(i+1))
    
a.sort()

for i in range(1,n+1):
    for j in range(12):
        x = a[j]
        if i-x >= 0:
            q[i] = min(q[i] , q[i-x] + 1)
            
print(q[n])

Measured memory_bytes: 44784
N = int(input())
S = []
for i in range(N):
    S.append(input())
S.sort()
li = []
count = 0
baf = S[0]
for i in range(1, N):
    if S[i] == baf:
        baf = S[i]
        count += 1
    else:
        li.append([baf, count])
        baf = S[i]
        count = 0
li.append([baf, count])
li.sort(key=lambda x : -x[1])
baf2 = li[0][1]
print(li[0][0])
for i in range(1, len(li)):
    if li[i][1] != baf2:
        break
    print(li[i][0])

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	VI s(n), t(m);
	rep(i, n) cin >>s[i];
	rep(i, m) cin >>t[i];
	
	vector<VL> dp(n+5, VL(m+5)), sm(n+5, VL(m+5));
	dp[0][0] = sm[1][1] = 1;
	rep(i, n+1) rep(j, m+1) if(i+j !=0){
		if(i && j && s[i-1] == t[j-1]) dp[i][j] = sm[i][j] % MD;
		sm[i+1][j+1] = (sm[i+1][j] + sm[i][j+1] - sm[i][j] + dp[i][j]+MD)%MD;
	}
	cout << sm[n+1][m+1] <<"\n";
	return 0;
}


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

int min(int a,int b)
{
    return a>=b?b:a;
}

int solve(int start,int a[],int n,int ans,int dp[],int k)
{
    if(dp[start]==-1)
    {
        if(start==n-1)
            return 0;
        if(start>=n-k)
        {
            int j=1;
            dp[start]=abs(a[start]-a[start+1])+solve(start+1,a,n,abs(a[start]-a[start+1]),dp,k);
            while(start+j<n && j<=k)
            {
                dp[start]=min(abs(a[start]-a[start+j])+solve(start+j,a,n,abs(a[start]-a[start+j]),dp,k),dp[start]);
                j++;
            }
            //int ans1=abs(a[start]-a[start+1]);
            //return ans1/*+solve(start+1,a,n,ans1)*/;

            //dp[start]=ans1+solve(start+1,a,n,ans1,dp,k);
            return(dp[start]);
        }
        else
        {
            dp[start]=abs(a[start]-a[start+1])+solve(start+1,a,n,abs(a[start]-a[start+1]),dp,k);
            for(int j=2;j<=k;j++)
            {
                dp[start]=min(abs(a[start]-a[start+j])+solve(start+j,a,n,abs(a[start]-a[start+j]),dp,k),dp[start]);
            }
            return(dp[start]);
        }
    }
    else
    {
        return(dp[start]);
    }
}
int main()
{
    //cout<<"Enter number of stones: ";
    int n,k;
    cin>>n;
    cin>>k;
    //cout<<"\nEnter the height of the stones:";
    int a[n],x[n];
    for(int i=0;i<n;i++)
    {
      	x[i]=-1;
        cin>>a[i];
    }

    int start=0,ans=0;
    ans=solve(start,a,n,ans,x,k);
    cout/*<<"\n Minimum dist:"*/<<ans;

    return 0;
}


Measured memory_bytes: 11904
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    string S;
    cin >> S;
    deque<char> A;
    rep(i,len(S)) A.push_back(S[i]);
    int Q;
    cin >> Q;
    
    bool f = true;
    
    rep(qq,Q){
        int a;
        cin >> a;
        
        if(a == 1) f = !f;
        else{
            int b;
            char c;
            cin >> b >> c;
            
            if(b == 1){
                if(f) A.push_front(c);
                else A.push_back(c);
            }
            else {
                if(!f) A.push_front(c);
                else A.push_back(c);
            }
        }
        
    }
    
    
    if(f){
        while (!A.empty()) {
            cout << A.front();
            A.pop_front();
        }
    }else{
        while (!A.empty()) {
            cout << A.back();
            A.pop_back();
        }
    }
    
    cout << endl;
    
    

    return 0;
}


Measured memory_bytes: 4024
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define endl "\n";
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

const int maxn=1e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;

int main(){
	migmig;
	int a,b;
	cin>>a>>b;
    if(b==1)
    {
        cout<<'0'<<endl;
        return 0;
    }
    int ans = 1;
    b -= a;a--;
    if(b>0)
        ans += (b+a-1)/a;
    cout<<ans<<endl;
 
}

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

using namespace std;

#define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define pb push_back
#define all(x) x.begin, x.end
#define endl '\n'
#define mkp make_pair
#define trav(x, i) for(auto& i : x)

constexpr int INF =  1000000001;
constexpr int MOD =  1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

int main(){
  FASTIO;
  map<string, int> m;
  int n = 0;
  cin >> n;
  int mx = INT_MIN;
  for(int i = 0; i < n; i++){
    string temp;
    cin >> temp;
    mx = max(++m[temp], mx);
  }
  for(const auto& i : m){
    if(i.second == mx){
      cout << i.first << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 19296
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;



int main(){
    int N;
    cin >> N;
    
    int x;
    vector<int> a;
    for(int i = 0; i < N ; ++i){
        cin >> x;
        a.push_back(x);
    }
    
    int A = 0, B = 0;
    
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    
    for(int i = 0; i < N; ++i){
        if(i % 2 == 0){
            A += a[i];
        } else {
            B += a[i];
        }
    }
    
    cout << A - B << endl;
}


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

using namespace std;

const int N = 711;
bool g[N][N];
bool col[N], trk[N];
int sz[N][2];
bool dp[N][2*N];

void solve() {
    int n,m;
    cin >> n >> m;
    memset(g, 1, sizeof g);
    for (int i = 1; i <= n; i++) {
        g[i][i] = 0;
    }
    for (int _ = 0; _ < m; _++) {
        int x, y;
        cin >> x >> y;
        g[x][y] = g[y][x] = 0;
    }
    // bfs
    int cnt = 0;
    memset(trk, 0, sizeof trk);
    memset(sz, 0, sizeof sz);
    for (int i = 1; i <= n; i++) {
        if (trk[i]) continue;
        cnt++;
        col[i] = 0; trk[i] = 1;
        sz[cnt][0]++;
        queue<int> q;
        q.push(i);
        while (!q.empty()) {
            int u = q.front(); q.pop();
            for (int v = 1; v <= n; v++) {
                if (!g[u][v])continue;
                if (trk[v]) {
                    if (col[u]==col[v]) {
                        cout << -1; return;
                    }
                } else {
                    col[v] = col[u] ^ 1; trk[v] = 1;
                    sz[cnt][col[v]]++;
                    q.push(v);
                }
            }
        }
    }
    // dp
    memset(dp, 0, sizeof dp);
    dp[0][0] = 1;
    for (int i = 1; i <= cnt; i++) {
        int x = sz[i][0], y = sz[i][1];
        for (int j = 0; j <= n; j++) {
            dp[i][j + x] |= dp[i-1][j];
            dp[i][j + y] |= dp[i-1][j];
        }
    }
    int res = 1e8;
    for (int i = 0; i <= n; i++) {
        if (dp[cnt][i]) {
            res = min(res, i*(i-1)/2 + (n-i)*(n-i-1)/2);
        }
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>

// template {{{
using namespace std;

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))

using int64 = long long;

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

bool in_field(int W, int H, int x, int y) {
  return (0 <= x && x < W) && (0 <= y && y < H);
}

// pair
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
  return s << "(" << p.first << ", " << p.second << ")";
}
// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << "\t";
  }
  return s;
}

// }}}

// url: https://atcoder.jp/contests/abc124/tasks/abc124_a

int A, B;

int main() {

  cin >> A >> B;

  int ans = 0;

  if (A > B) {
    ans += A;
    A--;
  } else {
    ans += B;
    B--;
  }

  if (A > B) {
    ans += A;
    A--;
  } else {
    ans += B;
    B--;
  }

  cout << ans << endl;

  return 0;
}

// vim: foldmethod=marker


Measured memory_bytes: 256
import collections
N = int(input())

Line = [int(s) for s in input().split()]
c = collections.Counter(Line)

# print(c)
v = 0

for i in c:
    # print(i)
    v += i * c[i]
# print(v)    

Q = int(input())


for _ in range(Q):
    Line = [int(s) for s in input().split()]
    try:
        c[Line[1]] += c[Line[0]]
        
        # print(c[Line[1]],c[Line[0]])
        v += c[Line[0]] * (Line[1] - Line[0])
        c.pop(Line[0])
        # v += c[Line[0]] * (C[Line[1]-C[Line[0]]])
    except:
        pass
        
        # print('Error')
    # print(c)

    # s=0
    # for i in c:
    #     # print(i)
    #     s += i * c[i]
    print(v)    
    

Measured memory_bytes: 23260
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const W = parseInt(arg[0].split(" ")[0]);
    const H = parseInt(arg[0].split(" ")[1]);
    const x = parseInt(arg[0].split(" ")[2]);
    const y = parseInt(arg[0].split(" ")[3]);
    
	if(W / 2 === x && H / 2 === y) {
      console.log((W * H) / 2, 1);
    } else {
      console.log((W * H) / 2, 0);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7628
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;

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

	for(int n; cin >> n, n;) {
		int m;
		string s;
		cin >> m >> s;

		bool prevI = false;
		int ans = 0, cnt = -1;
		for(int i = 0; i < m; ++i) {
			if(s[i] == 'I') {
				if(prevI)
					cnt = 0;

				else {
					++cnt;
					if(cnt >= n)
						++ans;
				}

				prevI = true;
			}
			else {
				if(!prevI)
					cnt = -1;

				prevI = false;
			}
		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 2772
package main

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

func main() {
	n, k := readInt(), readInt()

	h := make([]int, n)
	for i := range h {
		h[i] = readInt()
	}

	dp := make([]int, n)
	dp[0] = 0

	for i := 1; i < n; i++ {
		minv := math.MaxInt64
		for j := 1; j < k+1; j++ {
			if i-j < 0 {
				break
			}
			minv = min(minv, dp[i-j]+abs(h[i-j]-h[i]))
		}
		dp[i] = minv
	}

	fmt.Println(dp[n-1])
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 2816