akhauriyash/Code-Regression huggingface dataset:
using System;
using System.IO;

namespace MinPro2019D
{
    public class Program
    {
        public static void Main()
        {
            Stream stream = Console.OpenStandardInput(1024);
            byte[] buffer = new byte[1024];
            int index = 0;
            int length = stream.Read(buffer, 0, 1024);
            int L = 0;

            while (48 <= buffer[index] && buffer[index] <= 57)
            {
                L = L * 10 + buffer[index] - 48;
                ++index;
                if (index < length) continue;
                index = 0;
                length = stream.Read(buffer, 0, 1024);
            }

            long[] dp = new long[5];
            long A;
            long x;

            for (int i = 0; i < L; i++)
            {
                A = 0;

                while (buffer[index] < 48 || 57 < buffer[index])
                {
                    ++index;
                    if (index < length) continue;
                    index = 0;
                    length = stream.Read(buffer, 0, 1024);
                }

                while (48 <= buffer[index] && buffer[index] <= 57)
                {
                    A = A * 10 + buffer[index] - 48;
                    ++index;
                    if (index < length) continue;
                    index = 0;
                    length = stream.Read(buffer, 0, 1024);
                }

                x = A == 0 ? 2 : A & 1;

                dp[0] += A;
                dp[1] += x;
                dp[2] += (x & 1) ^ 1;
                dp[3] += x;
                dp[4] += A;
                dp[1] = Math.Min(dp[1], dp[0]);
                dp[2] = Math.Min(dp[2], dp[1]);
                dp[3] = Math.Min(dp[3], dp[2]);
                dp[4] = Math.Min(dp[4], dp[3]);
            }

            Console.WriteLine(dp[4].ToString());
        }
    }
}


Measured memory_bytes: 13140
#include<cstdio>
#include<iostream>
#include<cstring>
const int N=190;
int rdp[N][N][N],cdp[N][N][N];
int trdp[N][N][N],tcdp[N][N][N];
char s[N][N];
int sum[N][N];
bool check(int x1,int y1,int x2,int y2) {
    int s=(x2-x1+1)*(y2-y1+1),res=sum[x2][y2]-sum[x1-1][y2]-sum[x2][y1-1]+sum[x1-1][y1-1];
    return !res||res==s;
}
int main() {
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) sum[i][j]=sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+(s[i][j]=='#');
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) {
        for(int k=j;k<=m;k++) {
            int l=i-1,r=n+1,mid;
            while(l+1<r) {
                mid=(l+r)>>1;
                if(check(i,j,mid,k)) l=mid;
                else r=mid;
            }
            rdp[i][j][k]=l;
        }
        for(int k=i;k<=n;k++){
            int l=j-1,r=m+1,mid;
            while(l+1<r) {
                mid=(l+r)>>1;
                if(check(i,j,k,mid)) l=mid;
                else r=mid;
            }
            cdp[i][j][k]=l;
        }
    }
    for(int ans=0;;ans++) {
        if(rdp[1][1][m]==n) return !printf("%d",ans);
        for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) {
            for(int k=j;k<=m;k++) {
                int x=rdp[i][j][k];
                if(x<n) x=rdp[x+1][j][k];
                trdp[i][j][k]=x;
            }
            for(int k=i;k<=n;k++) {
                int x=cdp[i][j][k];
                if(x<m) x=cdp[i][x+1][k];
                tcdp[i][j][k]=x;
            }
        }
        for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) {
            int p=n;
            for(int k=j;k<=m;k++) {
                while(p>=i&&tcdp[i][j][p]<k) --p;
                rdp[i][j][k]=std::max(trdp[i][j][k],p);
            }
            p=m;
            for(int k=i;k<=n;k++){
                while(p>=j&&trdp[i][j][p]<k) --p;
                cdp[i][j][k]=std::max(tcdp[i][j][k],p);
            }
        }
    }
    return 0;
}


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

namespace atcoderCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int H, W, h, w;
            var inputs = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            H = inputs[0];
            W = inputs[1];
            inputs = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            h = inputs[0];
            w = inputs[1];

            int ans = H * W - h * W - w * H + w * h;
            Console.WriteLine(ans);
        } 
    }
}


Measured memory_bytes: 11348
mod=1000000007
n=int(input())
a=list(map(int,input().split()))

s1=0
for i in range(0,n):
    s1+=a[i]

s3=s1*s1

s2=0
for i in range(0,n):
    s2+=(a[i]*a[i])

print (((s3-s2)//2)%mod)


Measured memory_bytes: 31604
#include<bits/stdc++.h>
using namespace std;
//      std macros
typedef long long ll;
typedef pair<int ,int> pii;
typedef pair<ll ,ll> pll;
//      dereference
#define F first
#define S second
#define pb push_back
#define mp make_pair
//      loops
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define PER(i,b,a) for(int i=b;i>=a;--i)
#define all(X) (X).begin(), (X).end()
//      I/O
#define sd(n) scanf("%d",&n)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define sll(n) scanf("%lld",&n)
#define sll2(x,y) scanf("%lld%lld",&x,&y)
#define sll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
//      debug
#define debug(x) cerr<<"debug->"<<#x<<"::"<<x<<endl
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
#define debug4(x,y,z,w) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<"\n"
//      set values
#define mset(n,k) memset(n,k,sizeof(n))
#define MOD 1000000007
ll INV2=500000004;
ll INV6=166666668;
//modular expo
ll power(ll a,ll b, ll c){
    ll x=1,y=a;
    while(b>0){
        if(b&1)
            x=(x*y)%c;
        y=(y*y)%c;
        b/=2;
    }
    return x%c;
}
//perfect numbers till 10^6 6, 28, 496, 8128
int dx[]={0,-1,0,1};
int dy[]={-1,0,1,0};//clockwise from left
int dr[]={1,1,0,-1,-1,-1, 0, 1};
int dc[]={0,1,1, 1, 0,-1,-1,-1};//anticlockwise from down
string s,aux,bux;
bool check(int i,int len) {
  aux.clear();
  bux.clear();
  bux = "";
  aux = "";
  REP(j,0,len/2 - 1) {
    aux+=s[j];
  }
  REP(j,len/2,len-1) {
    bux+=s[j];
  }
  //debug3(len,aux,bux);
  return (aux == bux);

}
int main()
{

  cin>>s;
  int n = s.size(),i;
  for(i=n-3;i>=0;i-=2) {
    if(check(i,i+1))
      break;
  }
  cout<<(i+1)<<endl;
            


return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;

int main()
{
	string a,b;
	cin>>a>>b;
	if (a.size()>b.size())
		cout<<"GREATER"<<endl;
	else if (b.size()>a.size())
		cout<<"LESS"<<endl;
	else
	{
		long long i;
		for(i=0;i<a.size();i++)
		{
			if (a[i]>b[i])
			{
				cout<<"GREATER"<<endl;
				break;
			}
			else if (a[i]<b[i])
			{
				cout<<"LESS"<<endl;
				break;
			}
		}
		if(i==a.size())
			cout<< "EQUAL" <<endl;
	}
	return 0;	
}

Measured memory_bytes: 760
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int p[8];
  
  while(1) {
    int c[8] = {4, 1, 4, 1, 2, 1, 2, 1};
    bool end = 0;
    for(int i=0; i<8; i++) {
      cin >> p[i];
      if(cin.eof()) { end=1; break; }
    }
    if(end) break;
  
    int mn = (int)1e9;
    string ans;
  
    for(int I=0; I<8; I++){
      int pep = 0;
      for(int i=0; i<8; i++) {
        pep += max(c[i]-p[i], 0);
      }
      
      if(mn > pep) {
        mn = pep;
        string s;
        for(int i=0; i<8; i++) {
          if(i) s += ' ';
          s += char('0' + c[i]);
        }
        ans = s;
      }
      else if(mn == pep) {
        string s;
        for(int i=0; i<8; i++) {
          if(i) s += ' ';
          s += char('0' + c[i]);
        }
        ans = min(ans, s);
      }
    
      rotate(c, c+1, c+8);
      /*
      for(int i=0; i<8; i++) {
        if(i) cout << ' ';
        cout << c[i];
      }
      cout << endl;
      */
    } // for I

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

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};


int main(){
  
  int n,a,b,c;
  cin >> n >> a >> b >> c;
  vector<int> l(n);
  REP(i,n)cin >> l[i];
  ll res = INF;
  for(int bita = 1;bita < (1 << n);bita++){
    vector<bool> usea(n,0);
    REP(i,n)if(bita >> i & 1)usea[i] = true;
    for(int bitb = 1;bitb < (1 << n);bitb++){
      vector<bool> useb(n,0);
      bool flag = true;
      REP(i,n){
        if(bitb >> i & 1){
          if(usea[i])flag = false;
          else useb[i] = true;
        }
      }
      if(!flag)continue;
      for(int bitc = 1;bitc < (1 << n);bitc++){
        flag = true;
        vector<bool> usec(n,0);
        ll sum = 0;
        REP(i,n){
          if(bitc >> i & 1){
            if(!usea[i] && !useb[i])usec[i] = true;
            else flag = false;
          }
        }
        if(!flag)continue;
        int aa = 0,bb = 0,cc = 0;
        int count = 0;
        REP(i,n)if(usea[i])aa += l[i],count++;
        if(count)sum += (count-1)*10;
        count = 0;
        REP(i,n)if(useb[i])bb += l[i],count++;
        if(count)sum += (count-1)*10;
        count = 0;
        REP(i,n)if(usec[i])cc += l[i],count++;
        if(count)sum += (count-1)*10;
        sum += abs(a-aa);
        sum += abs(b-bb);
        sum += abs(c-cc);
        res = min(res,sum);

      }
    }

  }
  cout << res << endl;



  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n, m, h, k;
        cin >> n >> m >> h >> k;
        if(n == 0)
            return 0;

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

        vector<pair<int, int> > horizon(m);
        for(int i=0; i<m; ++i)
            cin >> horizon[i].second >> horizon[i].first;
        sort(horizon.rbegin(), horizon.rend());

        vector<int> index(n);
        for(int i=0; i<n; ++i)
            index[i] = i;
        vector<vector<bool> > exchange(n, vector<bool>(n, false));
        for(int i=0; i<m; ++i){
            swap(index[horizon[i].second], index[horizon[i].second-1]);
            exchange[index[horizon[i].second]][index[horizon[i].second-1]] = true;
            exchange[index[horizon[i].second-1]][index[horizon[i].second]] = true;
        }

        int ret = 0;
        for(int i=0; i<k; ++i){
            for(int j=k; j<n; ++j){
                if(exchange[index[i]][index[j]])
                    ret = min(ret, score[index[j]] - score[index[i]]);
            }
        }
        for(int i=0; i<k; ++i)
            ret += score[index[i]];
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#define rep(x,to) for(x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;




int main(void){

int ww,w[32];	
int nn,ra,rb,i;
char cn;
	cin >> ww;
	cin >> nn;
	
	rep(i,ww) w[i]=i+1;
	rep(i,nn){
		cin >> ra >> cn >> rb;
		swap(w[ra-1],w[rb-1]);
	}
	rep(i,ww) cout << w[i] << endl;
	return 0;
}

Measured memory_bytes: 1160
from sys import stdin,setrecursionlimit
k,n = map(int,stdin.readline().rstrip().split())
a = list(map(int,stdin.readline().rstrip().split()))
b = []
for i in range(n-1):
    b.append(a[i+1]-a[i])
b = [0]+b
c = b.index(max(b))
print(min(a[-1]-a[0],a[c-1]+k-a[c]))

Measured memory_bytes: 26444
N,Q = map(int,input().split())
S = input()
T = [0]*(N+1)
for i in range(N):
    T[i+1] = T[i]+ (1 if S[i:i+2]=="AC" else 0)
for i in range(Q):
    l,r = map(int,input().split())
    print(T[r-1]-T[l-1])

Measured memory_bytes: 9032
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>

using ll = long long;
using namespace std;
constexpr ll inf = 1e15;

constexpr int MAX_A = 200000;
ll dp[MAX_A+1] = {0};

vector<vector<int> > calcNext(const string &S) {
    int n = (int)S.size();
    vector<vector<int> > res(n+1, vector<int>(26, n));
    for (int i = n-1; i >= 0; --i) {
        for (int j = 0; j < 26; ++j) res[i][j] = res[i+1][j];
        res[i][S[i]-'a'] = i;
    }
    return res;
}

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

    string A;
    cin>>A;

    auto next = calcNext(A);
    for (int i = 0; i < A.length(); i++) dp[i] = inf;
    dp[A.length()] = 1;
    for (int i = A.length()-1; i >= 0; i--) {
        for (int j = 0; j < 26; j++) if (next[i][j] <= A.length()) dp[i] = min(dp[i], dp[next[i][j]+1]+1);
    }

    string ans = "";
    int pos = 0;
    for (int i = dp[0] - 1; i >= 0; i--) {
        for (int j = 0; j < 26; j++) {
            if (dp[next[pos][j] + 1] == i) {
                ans += char(j + 'a');
                pos = next[pos][j] + 1;
                break;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 28564
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;


import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			long[] as = new long[N + 1];
			long sum = 0;
			for(int i = 0; i <= N; i++) {
				as[i] = sc.nextLong();
				sum += as[i];
			}
			
			long free = 1;
			long answer = 1;
			for(int i = 0; i <= N; i++) {
				//System.out.println(free + " " + as[i]);

				free -= as[i];
				sum -= as[i];
				if(free < 0) {
					System.out.println(-1);
					return;
				}
				
				final long next_free = Math.min(free * 2, sum);
				//System.out.println(free + "- next -> " + next_free);
				free = next_free;
				answer += free;
			}
			
			System.out.println(answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


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

#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;

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

    vector<ll> l(n);
    vector<ll> xs(n+1);
    xs[0] = 0;

    REP(i, n) {
        cin >> l[i];
        if (i >= 1)
            xs[i] = xs[i-1] + l[i-1];
    }

    xs[n] = xs[n-1] + l[n-1];

    ll cnt = 0;
    REP(i, n) {
        if (xs[i] <= x) cnt++;
        else break;
    }

    if (xs[n] <= x) cnt++;
    MSG(cnt)

    return 0;
}


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

ll max_bc = 0;

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> A(n+1);
    vector<ll> B(m+1);

    for(ll i = 0; i < n; i++) {
        cin >> A[i];
    }
    for(ll i = 0; i < m; i++) {
        cin >> B[i];
    }

    vector<ll> a; a.push_back(0);
    vector<ll> b; b.push_back(0);

    for(ll i = 0; i < n; i++) {
        a.push_back(a[i] + A[i]);
    }
    for(ll i = 0; i < m; i++) {
        b.push_back(b[i] + B[i]);
    }

    ll ans = 0;
    ll j = m;

    for(ll i = 0; i < (n + 1); i++) {
        if(a[i] > k) break;

        while(b[j] > (k - a[i])) {
            j--;
        }

        ans = max(ans, i + j);
    }
    
    cout << ans << endl;
    return 0;
}

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

int main(void){
    ll n;
    cin >> n;
    vector<ll>A(n);
    ll first=0,second=0;
    for(int i=0;i<n;i++){
        cin >> A[i];
        if(second <= A[i]){
            if(first <= A[i]){
                second = first;
                first = A[i];
            }else{
                second = A[i];
            }
        }
    }

    for(int i=0;i<n;i++){
        if(A[i]==first){
            cout << second<<endl;
        }else{
            cout << first << endl;
        }
    }
    return 0;
}

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

using namespace std;


const long long divs = 998244353;

long long n, m, k;


vector<long long> fac(300001);
vector<long long> ifac(300001);

long long mpow(long long x, long long n) { //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    long long ans = 1;
    while (n != 0) {
        if (n & 1) ans = ans * x % divs;
        x = x * x % divs;
        n = n >> 1;
    }
    return ans;
}

long long comb(long long a, long long b) { //aCbをmod計算
    if (a == 0 && b == 0)return 1;
    if (a < b || a < 0)return 0;
    long long tmp = ifac[a - b] * ifac[b] % divs;
    return tmp * fac[a] % divs;
}



int main()
{
	cin >> n >> m >> k;

	long long answer = 0;


    fac[0] = 1;
    ifac[0] = 1;
    for (long long i = 0; i < 300000; i++) {
        fac[i + 1] = fac[i] * (i + 1) % divs; // n!(mod M)
        ifac[i + 1] = ifac[i] * mpow(i + 1, divs - 2) % divs; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }

    long long base = m;

    for (long long i = 1; i < n - k; i++) {
        base = (base * (m - 1)) % divs;
    }

    for (; k >= 0; k--) {

        long long ans = base;

        ans = (ans * comb(n - 1, k)) % divs;

        answer = (answer + ans) % divs;

        base = (base * (m - 1)) % divs;
    }


	cout << answer << endl;
}

Measured memory_bytes: 7880
#include <stdio.h>

int main()
{
	int H,W;
	int i,j;
	while(1){
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0) break;
		for(i=0; i<H; i++){
			for(j=0; j<W; j++){
				if(i == 0 || i == H-1 || j == 0 || j == W-1 ){
					printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
const int N=666;
bool vis[N][N];
int n,d1,d2,m;
void solve(int x)
{
    int t=0;
    while(x%4==0) x/=4,t++;
    if(x&1)
    {
        for(int i=0;i<m;i++)
            for(int j=0;j<m;j++)
            if((i>>t)+(j>>t)&1) vis[i][j]=true;
    }
    else
    {
        for(int i=0;i<m;i++)
            for(int j=0;j<m;j++)
            if((i>>t)&1) vis[i][j]=true;
    }
}
int main(void)
{
    scanf("%d%d%d",&n,&d1,&d2);
    m=n*2;
    solve(d1);
    solve(d2);
    int k=n*n;
    for(int i=0;i<m;i++)
        for(int j=0;j<m;j++)
        if(!vis[i][j])
        {
            printf("%d %d\n",i,j);
            k--;
            if(!k) return 0;
        }
}

Measured memory_bytes: 1280
#include <iostream>
int main() {
	int a, b, c;
	std::cin >> a >> b >> c;
	if (a <= b && b <= c) {
		std::cout << a << " " << b  << " " << c << std::endl;
	}
	else if (b <= a && a <= c) {
		std::cout << b << " " << a << " " << c << std::endl;
	}
	else if (a <= c && c <= b) {
		std::cout << a << " " << c << " " << b << std::endl;
	}
	else if (b <= c && c <= a) {
		std::cout << b << " " << c << " " << a << std::endl;
	}
	else if(c <= b && b <= a) {
		std::cout << c << " " << b << " " << a << std::endl;
	}
	else {
		std::cout << c << " " << a << " " << b << std::endl;
	}
	return 0;
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<int> W(N), E(N);
  W.at(0) = 0;
  for (int i = 1; i < N; i++) {
    if (S.at(i - 1) == 'W') W.at(i) = W.at(i - 1) + 1;
    else W.at(i) = W.at(i - 1);
  }
  E.at(N - 1) = 0;
  for (int i = N - 2; i >= 0; i--) {
    if (S.at(i + 1) == 'E') E.at(i) = E.at(i + 1) + 1;
    else E.at(i) = E.at(i + 1);
  }
  int ans = N;
  for (int i = 0; i < N; i++) {
    ans = min(ans, W.at(i) + E.at(i));
  }
  cout << ans << endl;
}

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

const int MAXN = 600;
const int MAXM = MAXN*MAXN;

vector<pair<int, int> >ans[4];

bool clr[20][MAXM + 5];
int x[MAXM + 5], y[MAXM + 5], id[MAXN + 5][MAXN + 5], cnt;
int main() {
	int N, D1, D2, p1 = 0, p2 = 0; scanf("%d%d%d", &N, &D1, &D2);
	while( D1 % 2 == 0 ) D1 /= 2, p1++;
	while( D2 % 2 == 0 ) D2 /= 2, p2++;
	for(int i=0;i<2*N;i++)
		for(int j=0;j<2*N;j++)
			id[i][j] = (++cnt), x[cnt] = i, y[cnt] = j;
	for(int o=0;o<20;o++)
		for(int i=1;i<=cnt;i++) {
			clr[o][i] = ((x[i] + y[i]) % 2 != 0);
			int tx = (x[i] + y[i] + clr[o][i]) / 2, ty = (x[i] - y[i] + clr[o][i]) / 2;
			x[i] = tx, y[i] = ty;
		}
	for(int i=0;i<2*N;i++)
		for(int j=0;j<2*N;j++) {
			int x = id[i][j];
			ans[clr[p1][x] | (clr[p2][x] << 1)].push_back(make_pair(i, j));
		}
	int res = 0;
	for(int i=0;i<4;i++)
		if( ans[i].size() > ans[res].size() )
			res = i;
	for(int i=0;i<N*N;i++)
		printf("%d %d\n", ans[res][i].first, ans[res][i].second);
	
}

Measured memory_bytes: 15452
// test1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include<cstdio>
#include<math.h>
#include<stack>
using namespace std;
int a[1010];
int main()
{
    int n, t,m1=0,m2=9999;
    cin >>t;
    for (int i = 0; i < t; i++) {
        cin >> a[i];
        if (a[i] < m2) {
            m2 = a[i];
        }
        if (a[i] > m1) {
            m1 = a[i];
        }
    }
    int ss = 9999999;
    for (int i = m2; i <= m1; i++) {
        int s1 = 0;
        for (int j = 0; j < t; j++) {
            s1+= (a[j] - i) * (a[j] - i);
        }
        if (s1 < ss)ss = s1;
    }
    cout << ss << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE
void solve(void)
{
  int X,A;
  cin>>X>>A;
  if(X < A)
  {
    cout<<0<<endl;
  }
  else
  {
    cout<<10<<endl;
  }
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


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

namespace ConsoleApp36 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());
            var h = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var dp = new int[N + 1];
            dp[0] = 0;
            dp[1] = Math.Abs(h[1] - h[0]);

            for (int i = 2; i < N; i++) {
                //二つ前から飛んできたとき
                int before_two = dp[i - 2] + Math.Abs(h[i] - h[i - 2]);
                //一つ前から飛んできたとき
                int before_one = dp[i - 1] + Math.Abs(h[i] - h[i - 1]);

                dp[i] = Math.Min(before_one, before_two);
            }

            Console.WriteLine(dp[N - 1]);
        }
    }
}


Measured memory_bytes: 18016
import java.util.*;

class Main{
  public static void main(String[] args){
    try(Scanner sc = new Scanner(System.in)){
      int a = Integer.parseInt(sc.next());
      int b = Integer.parseInt(sc.next());
      int c = Integer.parseInt(sc.next());
      int d = Integer.parseInt(sc.next());
      String ans = "No";
      //a<b<cではないので絶対値
      if(Math.abs(c - a) <= d){
        ans = "Yes";
      }
      if((Math.abs(b - a) <= d) && (Math.abs(c - b) <= d)){
        ans = "Yes";
      }
      System.out.println(ans);
    }
  }
}
        

Measured memory_bytes: 21844
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CANDGrid {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int H, W;
        cin >> H >> W;
        vector<vector<char>> A(H, vector<char>(W));
        REP(i, H) {
            REP(j, W) {
                cin >> A[i][j];
            }
        }
        vector<vector<char>> R(H, vector<char>(W, '.'));
        REP(i, H) {
            REP(j, W) {
                if (j == 0) {
                    R[i][j] = '#';
                } else if (i % 2 == 0 && j != W - 1) {
                    R[i][j] = '#';
                } else if (A[i][j] == '#') {
                    R[i][j] = '#';
                }
            }
        }
        vector<vector<char>> B(H, vector<char>(W, '.'));
        REP(i, H) {
            REP(j, W) {
                if (j == W - 1) {
                    B[i][j] = '#';
                } else if (i % 2 == 1 && j != 0) {
                    B[i][j] = '#';
                } else if (A[i][j] == '#') {
                    B[i][j] = '#';
                }
            }
        }

        REP(i, H) {
            REP(j, W) {
                cout << R[i][j];
            }
            cout << endl;
        }
        cout << endl;
        REP(i, H) {
            REP(j, W) {
                cout << B[i][j];
            }
            cout << endl;
        }
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CANDGrid solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1536
import itertools
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
Cp = {}
ans = 0
Cm_sum = 0
for i in range(N):
    c = A[i] - B[i]
    if c > 0:
        Cp[c] = Cp.get(c, 0) + 1
    elif c < 0:
        ans += 1
        Cm_sum -= c
if Cm_sum == 0:
    print(0)
else:
    Cp_sum = 0
    for k in sorted(Cp, reverse=True):
        count = min(1 + (Cm_sum - Cp_sum - 1) // k, Cp[k])
        ans += count
        Cp_sum += k * count
        if Cp_sum >= Cm_sum:
            print(ans)
            exit()
    print(-1)


Measured memory_bytes: 19260
import itertools


def main():
    N, M = list(map(int, input().split(' ')))
    cakes = [list(map(int, input().split(' '))) for _ in range(N)]
    ans = 0
    for sign in itertools.product([-1, 1], repeat=3):
        scores = [sum([s * c for s, c in zip(sign, cake)]) for cake in cakes]
        scores.sort(reverse=True)
        ans = max([ans, sum(scores[:M])])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

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

	int P, Q, R;
	cin >> P >> Q >> R;
	vector<int> v;
	v.push_back(P);
	v.push_back(Q);
	v.push_back(R);

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

	cout << (v[0] + v[1]) << endl;
}


Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n = f.read_int()
    return n**3


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Measured memory_bytes: 4248
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int n; cin >> n;
    vector<int> a(13,0);

    rep(i,n){
        int b; cin >> b;
        b /= 400;
        a[b]++;
    }

    int ans = 0;
    int cnt = 0;

    rep(i,8){
        if(a[i] != 0) ans++;
    }

    cnt += a[8] + a[9] + a[10] + a[11] + a[12];

    if(ans == 0){
        cout << 1 << " " << cnt << endl;
        return 0;
    }

    cout << ans << " " << ans + cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    int h, w;
    cin >> h >> w;
    vector<string> cv;
    REP(i, h){
        string s;
        cin >> s;
        cv.pb(s);
    }

    //cout << cv << endl;

    bool flag = true;
    REP(i, h){
        REP(j, w){
            if(cv[i][j] == '#'){
                bool exist = false;
                for(int k=0; k<4; k++){
                    int nx = i + dx[k];
                    int ny = j + dy[k];
                    if(nx < 0 || nx >= h || ny < 0 || ny >= w){
                        continue;
                    }
                    else{
                        if(cv[nx][ny] == '#') exist = true;
                    }
                }
                if(exist == false) flag = false;
            }
        }
    }
    if(flag) Yes();
    else No();
}

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

//===

//=== xorshift
uint32_t xorshift32() {
    static uint32_t s = 1727;
    s = s ^ (s << 13);
    s = s ^ (s >> 17);
    s = s ^ ( s << 5);
    return s;
}
//===
template<typename T, typename Compare = less<T> >
struct MeldableHeap {
    struct Node {
        T dat;
        Node *l, *r;

        Node (T dat): dat(dat), l(nullptr), r(nullptr) {};
    };

    Node *root;
    Compare cmp;

    MeldableHeap (Compare cmp = Compare()): root(nullptr), cmp(cmp) {};

    Node *meld(Node *h1, Node *h2) {
        if (h1 == nullptr) return h2;
        else if (h2 == nullptr) return h1;

        if (cmp(h2->dat, h1->dat)) swap(h1, h2);
        
        if (xorshift32() & 1) h1->l = meld(h1->l, h2);
        else h1->r = meld(h1->r, h2);

        return h1;
    };

    void push(T dat) {
        Node *u = new Node(dat);
        root = meld(root, u);
    };

    T top() { return root->dat; };
    
    T pop() {
        assert(!empty());
        T ret = top();
        Node *rm = root;
        root = meld(root->l, root->r);
        delete rm;
        
        return ret;
    };

    void merge_with(MeldableHeap &h) {
        root = meld(root, h);
        h.root = nullptr;
    };

    bool empty() { return root == nullptr; };
};
// MinHeap<T> = MeldableHeap<T, less<T>>
// MaxHeap<T> = MeldableHeap<T, greater<T>>
//===

int ABC141D() {
    llong n, m;
    llong a;
    MeldableHeap<llong, greater<llong> > h;

    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a;
        h.push(a);
    }

    for (int i = 0; i < m; i++) {
        a = h.pop() / 2;
        h.push(a);
    }

    llong sum = 0;
    while (!h.empty()) {
        sum += h.pop();
    }

    cout << sum << endl;
    
    return 0;
}

int main() {
    return ABC141D();
}


Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++)
        cin >> a[i];
    for(int i=0; i<N; i++)
        if(a[i] % 2 == 1){
            cout << "first" << endl;
            return 0;
        }
    cout << "second" << endl;
    return 0;
}

Measured memory_bytes: 640
import sys
from collections import deque

stack = deque()
input = sys.stdin.readline

N, Q = map(int, input().split())

link = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    link[a - 1].append(b)
    link[b - 1].append(a)
    
states = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    states[p - 1] += x

check = [0] * N
stack.append(1)
check[0] = 1
while stack:
    node = stack.pop()
    for next_node in link[node - 1]:
        if check[next_node - 1]:
            continue
        states[next_node - 1] += states[node - 1]
        check[next_node - 1] = 1
        stack.append(next_node)

# Output
print(*states)


Measured memory_bytes: 93972
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define INF 2e9
using namespace std;
const int N=1e6+1;
const int mod=1e9+7;
ll fastexp(ll base,ll exp){
	base%=mod;
	ll ans=1;
	while(exp>0){
		if(exp&1){
			ans*=base;
			ans%=mod;
		}
		base*=base;
		base%=mod;
		exp/=2;
	}
	return ans;
}
ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}
int sumofdigits(int n){
	int sum = 0;
	while(n!=0){
		sum += n%10;
		n = n/10;
	}
	return sum;
}
int arr[N];
int ar[N];
int main() {
		int n;
		cin >> n;
		if(n >= 400 && n <= 599){
			cout << 8;
		}
		else if(n>=600 && n <=799){
			cout << 7;
		}
		else if(n >= 800 && n <= 999){
			cout << 6;
		}
		else if(n >= 1000 && n <= 1199){
			cout << 5;
		}
		else if(n >= 1200 && n <= 1399){
			cout << 4;
		}
		else if(n >= 1400 && n <= 1599){
			cout << 3;
		}
		else if(n >= 1600 && n <= 1799){
			cout << 2;
		}
		else {
			cout << 1;
		}
		return 0;
}

Measured memory_bytes: 3600
{-# LANGUAGE BangPatterns #-}

module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import           Control.Monad.ST
import           Data.Ord

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

main = do
  n <- readInt
  s <- getLine
  let nums = scanl (\acc c -> if c == 'I' then acc + 1 else acc - 1) 0 s
  print $ maximum nums


Measured memory_bytes: 508
import Control.Monad.Trans.State

main :: IO ()
main = do
  n <- readLn
  putStrLn $ evalState solve (n, [])

solve :: State (Int, String) String
solve = do
  (n, s) <- get
  case (n, s) of
    (0, "")    -> return "0"
    (0, s)     -> return s
    (n, s)
      | odd n  -> put (-n `div` 2, '1' : s) >> solve
      | even n -> put (-n `div` 2, '0' : s) >> solve

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef vector<LL> 		VL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
//# define M_PI           3.14159265358979323846264338327950288

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
struct sushi
{
	LL d, t, ind;
};
LL n,k;
bool comp(const sushi & a, const sushi & b){
	return a.d > b.d;
}
int main() {
	#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
	srand(chrono::steady_clock::now().time_since_epoch().count());
	off;
	cin>>n>>k;
	vector< sushi > arr(n);
	rep(i,0,n){
		sushi s;
		cin>>s.t>>s.d;
		s.ind = i;
		arr[i] = s;
	}
	sort(ALL(arr), comp);
	
	LL cur = 0;
	set<LL > typeIncluded;
	multiset<LL > extra;
	LL ans = 0;
	rep(i,0,k){
		cur += arr[i].d;
		if(typeIncluded.find(arr[i].t) == typeIncluded.end()){
			typeIncluded.insert(arr[i].t);
		}
		else{
			extra.insert(arr[i].d);
		}
	}
	LL s = SZ(typeIncluded);
	ans = max(ans, cur + s*s);
	rep(i,k,n){
		if(typeIncluded.find(arr[i].t) == typeIncluded.end()){
			if(SZ(extra) > 0){
				s++;
				auto it = extra.begin();
				LL a = *it;
				// cout<<"rem : "<<a<<" add : "<<arr[i].d<<"\n";
				cur -= a;
				cur += arr[i].d;
				typeIncluded.insert(arr[i].t);
				extra.erase(it);
				ans = max(ans, cur + s*s);
			}
			else
				break;
		}
	}
	cout<<ans;
  	return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	int max_ = 0, smax_ = 0;
	for(int i = 0; i < n; i++){
		cin >> v[i];
		if(max(max_, v[i]) == v[i])
			smax_ = max_;
		else if(max(smax_, v[i]) == v[i])
			smax_ = v[i];
		max_ = max(max_, v[i]); 
	}
	for(int i = 0; i < n; i++){
		if(v[i] == max_){
			cout << smax_ << endl;
		}
		else{
			cout << max_ << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
////////////////////////////////////////

int main() {
	int H, W; cin >> H >> W;
	char G[51][51];
	int d[51][51];
	int count = 0;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> G[i][j];
			d[i][j] = INF;
			if (G[i][j] == '.')count++;
		}
	}
	queue<pii>Q;
	d[0][0] = 0;
	Q.push({ 0,0 });
	while (!Q.empty()) {
		int y = Q.front().first;
		int x = Q.front().second;
		Q.pop();
		for (int i = 0; i < 4; ++i) {
			int ny = y + dy[i];
			int nx = x + dx[i];
			if (0 <= ny && ny < H && 0 <= nx && nx < W&&G[ny][nx] == '.'&&d[ny][nx] == INF) {
				Q.push({ ny,nx });
				d[ny][nx] = d[y][x] + 1;
			}
		}
	}
	if (d[H - 1][W - 1] == INF) {
		cout << -1 << endl;
	}
	else {
		cout << count - d[H - 1][W - 1] - 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from sys import stdin, stdout

def solve():
    n = int(stdin.readline().strip())

    seqA = []
    seqB = []
    for i in range(n):
        a,b = map(int, stdin.readline().split())
        seqA.append(a)
        seqB.append(b)

    seqA = sorted(seqA)
    seqB = sorted(seqB)
    mA = seqA[n//2]
    mB = seqB[n//2]
    if n%2==0:
        mA += seqA[n//2-1]
        mB += seqB[n//2-1]

    print(mB-mA+1)

solve()

Measured memory_bytes: 93264
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define ll long long int
#define pl pair<ll, ll>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535;
const ll MOD = 1e9+7;
const ll NUM = 1e3+10;
void solve()
{
    ll n;
    cin>>n;
    ll rem=n%10;
    if(rem==2||rem==4||rem==5||rem==7||rem==9)
    cout<<"hon";
    else if(rem==0||rem==1||rem==6||rem==8)
    cout<<"pon";
    else cout<<"bon";
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>
#include<string>
#include<queue>
#include<set>
#include<stack>
#include<map>

using namespace std;

const int MAX_N=50;
long long layer[MAX_N+1];
long long numOfP[MAX_N+1];
long long numOfB[MAX_N+1];

long long solve(int M,long long x){//レベルMバーガーのx枚目までにあるパティの数
    if(M==1){
        if(x==1){
            return 0;
        }else if(x==2){
            return 1;
        }else if(x==3){
            return 2;
        }else{
            return 3;
        }
    }
    if(x==1){
        return 0;
    }else if(x == layer[M]){
        return numOfP[M];
    }else if(x == ((layer[M]+1)/2) ){
        return numOfP[M-1]+1;
    }else if(x >  ((layer[M]+1)/2) ){
        return (numOfP[M-1]+solve(M-1,x-layer[M-1]-2)+1);
    }else{
        return (solve(M-1,x-1));
    }
}

int main(){
    int N;
    long long X;
    cin>>N>>X;
    layer[0]=1;
    numOfP[0]=1;
    numOfB[0]=0;
    for(int i=1;i<=MAX_N;i++){
        layer[i]=layer[i-1]*2+3;
        numOfP[i]=2*numOfP[i-1]+1;
        numOfB[i]=2*numOfB[i-1]+2;
        //cout<<layer[i]<<' '<<numOfP[i]<<' '<<numOfB[i]<<endl;
    }
    cout<<solve(N,X)<<endl;
    return 0;
}


Measured memory_bytes: 256