akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>

using ll = long long;
using namespace std;
using P = pair<int, int>;
static const int INF = 10000000;
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
int dis[1002][1002];
bool ma[1002][1002] = {};

int main() {
    int h, w, n, t = 0;
    cin >> h >> w >> n;
    P cp[10];
    queue<P> Q;
    fill_n(&dis[0][0], 1002*1002, INF);
    for (int i = 1; i < h+1; ++i) {
        string s;
        cin >> s;
        for (int j = 1; j < w+1; ++j) {
            ma[i][j] = s[j-1] != 'X';
            if(s[j-1] == 'S') cp[0] = make_pair(i, j);
            if('1' <= s[j-1] && s[j-1] <= '9') cp[s[j-1]-'0']= make_pair(i, j);
        }
    }

    for (int i = 0; i < n; ++i) {
        fill_n(&dis[0][0], 1002*1002, INF);
        P st = cp[i], gl = cp[i+1];
        Q.push(st);
        dis[st.first][st.second] = 0;
        while(!Q.empty()){
            int y = Q.front().first, x = Q.front().second; Q.pop();
            for (int j = 0; j < 4; ++j) {
                int ny = y + dy[j], nx = x + dx[j];
                if(dis[ny][nx] == INF && ma[ny][nx]){
                    dis[ny][nx] = dis[y][x] + 1;
                    Q.push(make_pair(ny, nx));
                }
            }
        }
        t += dis[gl.first][gl.second];
    }
    cout << t << "\n";
    return 0;
}



Measured memory_bytes: 8136
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;
		int yakusu = 0;
		try {
			while ((buffer = reader.readLine())  != null) {
				Integer a = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")));
				buffer = buffer.substring(buffer.indexOf(" ") + 1);
				Integer b = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")));
				buffer = buffer.substring(buffer.indexOf(" ") + 1);
				Integer c = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")));
				for (int i = 1; i <= c; i++) {
					int sho = c / i;
					if (c == sho * i) {
						if (a <= i && i <= b) {
							yakusu++;
						}
					}
				}
				System.out.println(yakusu);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}

Measured memory_bytes: 24424
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int N,M;
   cin >> N >> M;
   int A[N];
   long long S = 0;
   priority_queue<int> pq;
   for(int i=0;i<N;i++){
      cin >> A[i];
      pq.push(-A[i]);
      S+=A[i];
   }
   vector< pair<int,int> > p;
   for(int i=0;i<M;i++){
      int B,C;
      cin >> B >> C;
      p.push_back(make_pair(C,B));
   }
   sort(p.begin(),p.end());
   reverse(p.begin(),p.end());
   for(int i=0;i<M;i++){
      int C = p[i].first;
      int B = p[i].second;
      for(int j=0;j<B;j++){
         if(-pq.top()<C){
            //cout << pq.top() <<"->"<< C << endl;
            S += C+pq.top();
            pq.pop();
            pq.push(-C);
         }
         else break;
      }
   }
   cout << S << endl;
   return 0;
}


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  int max = 0;
  for (int i = 1; i < N; i++) {
    string bef, aft;
    bef = S.substr(0, i);
    aft = S.substr(i);
    int count = 0;
    for (char c = 'a'; c < 'a' + 26; c++) {
      if (bef.find(c) != std::string::npos && aft.find(c) != std::string::npos)
        count++;
    }
    if (count > max) max = count;
  }
  cout << max << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <numeric>
#include <limits>
#include <utility>
using namespace std;
typedef long long longlong;
typedef long long LL;

int main(void) {
	LL ma = 0, mi = 1001, ans, a, n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		mi = min(mi, a);
		ma = max(ma, a);
	}
	cout << ma - mi << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
//bismillahir rahmanir rahim            //Author:Fayed Anik

#include <bits/stdc++.h> 

using namespace std;


#define         ll                         long  long
#define         lf                         double 
#define         pb(x)                      push_back(x)
#define         ull                        unsigned long long
#define         sfl(a)                     scanf("%lld",&a)
#define         sf(a)                      scanf("%d",&a)
#define         pf(a)                      printf("%d\n",a)
#define         pfl(a)                     printf("%lld\n",a)
#define         pdl(a)                     printf("%llf\n",a)
#define         FOR(x,n)                   for(ll x=1;x<=n;++x)
#define         vii                        vector< ll > v
#define         pi                         3.14159265359
#define         mex                        10000000
#define         pii                        pair< ll , ll >
#define         mem(m,a)                   memset( m, a,sizeof m)
#define         mp(a,b)                    make_pair(a,b)
#define         maxn                       100000
#define         mod                        1000000007
#define         INF                        1e17
#define         f1                         first
#define         f2                         second
#define         all(v)                     v.begin(),v.end()
#define         PI                         acos(-1)
#define         printminusone              printf("-1\n")
#define         bug                        printf("bug")

stack <char>st;
int main(){
	string s;
	cin>>s;
	ll len=s.size();
	ll cnt=0;
	for(ll i=0;i<len;i++){
		if(st.size()>0){
			char x=st.top();
			if(x!=s[i]){
				st.pop();
				cnt +=2;
			}
			else{
				st.push(s[i]);
			}
		}
		else{
			st.push(s[i]);
		}
	}

	pfl(cnt);
}



Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int i;
	int n;
	int min, max;
	long long int sum = 0;
	int temp = 0;
	
	
	scanf("%d", &n);
	
	for(i = 0; i < n; i++){
		
		scanf("%d", &temp);
		
		if(i == 0){
			min = temp;
			max = temp;
		}
		else{
			
			if(min > temp){
				min = temp;
			}
			
			if(max < temp){
				max = temp;
			}
			
		}
		
		sum += temp;
	}
	
	printf("%d %d %lld\n", min, max, sum);
	
	return 0;
}

Measured memory_bytes: 600
/*
reference https://ark4rk.hatenablog.com/entry/2018/03/07/230257
similar problem https://atcoder.jp/contests/arc056/tasks/arc056_c
*/
#include "bits/stdc++.h"

using namespace std;

void solve()
{
	int N;
	cin >> N;
	vector<vector<long>> score(N, vector<long>(N));
	vector<long> dp(1<<N);

	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
		{
			cin >> score[i][j];
		}

	for (int s = 0; s < 1<<N; s++)
		for (int i = 0; i < N-1; i++)
			for (int j = i+1; j < N; j++)
			{
				if (s >> i & 1 && s >> j & 1)
				{
					dp[s] += score[i][j];
				}
			}

	for (int s = 0; s < 1<<N; s++)
	{
		for (int t = s; t; t = (t-1)&s)
		{
			dp[s] = max(dp[s], dp[t]+dp[s^t]);
		}
	}
	cout << dp.back() << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 768
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  int64_t D, G;
  cin >> D >> G;
  vector<int64_t> p(D);
  vector<int64_t> c(D);
  rep(i, D){
    cin >> p.at(i) >> c.at(i);
  }
  int64_t cnt = 0;
  int64_t ans = 1001001001;
  int64_t pnt = 0;
  int64_t sav = 0;
  for (int tmp = 0; tmp < (1 << D); tmp++) {
    bitset<10> s(tmp);
    rep(i, D){
      if(s.test(i)){
        cnt += p.at(i);
        pnt += 100*(i+1)*p.at(i)+c.at(i);
      }
    }
    if(pnt >= G){
      chmin(ans, cnt);
      cnt = 0;
      pnt = 0;
    }
    else{
      rep(i, D){
        sav = p.at(D-1-i);
        if(!(s.test(D-1-i))){
          while(p.at(D-1-i) > 1){
            p.at(D-1-i)--;
            cnt++;
            pnt += 100*(D-i);
            if(pnt >= G){
              p.at(D-1-i) = sav;
              chmin(ans, cnt);
              cnt = 0;
              pnt = 0;
              break;
            }
          }
          p.at(D-1-i) = sav;
          if(pnt >=G){
            break;
          }
        }
        if(i == D-1 && pnt < G){
          p.at(0) = sav;
          cnt = 0;
          pnt = 0;
        }
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
    int N;
    cin >> N;
    string S;

    for (int i = 0; i < N; i++) {
        cin >> S;
        if (S == "Y") {
            break;
        }
        else {
        }
    }

    if (S == "Y") {
        cout << "Four" << endl;
    }
    else {
        cout << "Three" << endl;
    }
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(){
    int a, b, c, N, Y;
    cin >> N >> Y;

    int resA, resB, resC;
    resA = -1;
    resB = -1;
    resC = -1;
    for(int a = 0; a <= N; ++a){
        for(int b = 0; b <= N-a; ++b){
            int c = (N - a - b);
            if(10000*a + 5000*b + 1000*c == Y){
                resA = a;
                resB = b;
                resC = c;
            }
        }
    }

    cout << resA << " " << resB << " " << resC;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();

		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				param.add(sc.nextLine());
			}
		}
		Method(num, param);
	}
	
	static void Method(ArrayList<Integer> num, ArrayList<String> param) {
		
		Set<Integer> set = new HashSet<Integer>(num);
		
		System.out.println(set.size());	
	}
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                             \
  cerr << __LINE__ << ": " << #x << " = {";          \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) { \
    cerr << ((hoge) ? "," : "") << x[hoge];          \
  }                                                  \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  string s = S.substr(0, S.length() / 2),
         t = S.substr(S.length() / 2 + 1, S.length() / 2);
  bool isok = true;
  for (int i = 0; i < s.length() / 2; i++)
    isok &= s[i] == s[s.length() - 1 - i];
  isok &= s == t;
  cout << (isok ? "Yes" : "No") << endl;
  return 0;
}


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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  int M;
  cin >> M;
  cout << 48 - M << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n,m,l;
    cin >> n >> m >> l;
    int dataa[n][m];
    int datab[m][l];
    long long datac[n][l]={};
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> dataa[i][j];
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<l;j++){
            cin >> datab[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            for(int k=0;k<l;k++){
                datac[i][k]+=dataa[i][j]*datab[j][k];
            }
        }
    }
    
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            if(j){
                cout << " ";
            }
            cout << datac[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3256
import sys
from collections import deque
input = sys.stdin.readline
def combination_to_index(a,b,n):
    if(b<a):
        a,b = b,a
    return (2*n-a)*(a-1)//2+b-a

def main():
    N = int(input())
    M = N*(N-1)//2
    gp = [[] for _ in range(M+1)]
    cnts = [0]*(M+1)
    for a in range(1,N+1):
        A = [int(x) for x in input().split()]
        for ind,b in enumerate(A[:-1]):
            fr = combination_to_index(a,b,N)
            to = combination_to_index(a,A[ind+1],N)
            gp[fr].append(to)
            cnts[to] += 1

    for ind,i in enumerate(cnts):
        if(i==0 and ind!=0):
            gp[0].append(ind)
            cnts[ind]+=1

    ans = 0
    cnt = 0
    stk = deque()
    stk.append((0,0))
    while stk:
        n,ans = stk.popleft()
        for x in gp[n]:
            cnts[x]-=1
            if(cnts[x]==0):
                stk.append((x,ans+1))
                cnt += 1
    if(cnt!=M):
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 112980
#include <iostream>

using namespace std;

int main()
{
  int a, b;
  cin >> a >> b;
  if (a == 1) a = 14;
  if (b == 1) b = 14;
  if (a == b) {
    cout << "Draw" << endl;
    return 0;
  }
  cout << ((a > b) ? "Alice" : "Bob") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define vll vector <ll>
#define vi vector <int>
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	int n; cin>>n;
	vll a(n);
	forn(i,n) cin>>a[i];
	vll suff(n+1,0);
	for(int i=n-1;i>=0;i--)
	{
		suff[i] = (suff[i+1] + a[i])%M;
	}
	ll ans = 0;
	forn(i,n)
	{
		ll g = ( a[i]*(suff[i+1]) )%M + M;
		g %= M;
		ans = ( ans + g )%M;
	}
	cout<<ans;

	return 0;
}


Measured memory_bytes: 6392
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b,c=INTM()
    k=INT()
    d=max(a,b,c)
    e=d*(2**k)
    ans=a+b+c+e-d
    print(ans)
    
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <queue>
using namespace std;

int main () {
    priority_queue<int,vector<int>,greater<int> > pq;
    int n;
    cin >> n;
    int s=0;
    for (int i=0;n>i;i++) {
        int x;
        cin >> x;
        pq.push(x);
        s += x;
    }
    if (s%10 !=0) cout<<s<<endl;
    else {
        while (!pq.empty()) {
            if (pq.top() % 10 != 0) {
                s-=pq.top();
                break;
            }
            pq.pop();
        }
        if (s%10==0) cout<<0<<endl;
        else cout<<s<<endl;
    }
}



Measured memory_bytes: 256
import java.io.*;
class Main {
    public static  void main(String...args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] formula = br.readLine().split(" ");
        Stack stack = new Stack(formula.length);
        for(String element : formula) {
            if(element.matches("[0-9]*?") ){
                int elem = Integer.parseInt(element);
                stack.push(elem);
            } else {
                int left = stack.pop();
                int right = stack.pop();
                switch (element) {
                    
                    case "+":
                        stack.push(right + left);
                        break;
                    case "-":
                        stack.push(right - left);
                        break;
                    case "*":
                        stack.push(right * left);
                        break;
                    case "/":
                        stack.push(right / left);
                        break;
                }
            }
        }
        System.out.println(stack.pop());
    }
}
class Stack {
        int maxLen;
        int point;
        int [] stackAry;
    public  Stack(int maxLen) {
        this.maxLen = maxLen;
        this.point = 0;
        this.stackAry = new int[maxLen];
   }
    
    public boolean isEmpty() {
        return point == 0;
   }

    public boolean isFull() {
        return point >= maxLen-1;
    }

    public void push(int x) {
        if(isFull()) {
            System.out.println(x + "はプッシュできません");
        } else {
            stackAry[++point] = x;
        }
    }
    public int pop() {
        if(isEmpty()) {
            System.out.println("要素がからです");
            return 0;
        } else {
            point--;
            return this.stackAry[point+1];
        }
    }
}
        

        




Measured memory_bytes: 24540
N, A = map(int, input().split())
X = list(map(int, input().split()))
n = N * 50
dp = [[[0]*(n+1) for j in range(N+1)] for i in range(N+1)]
dp[0][0][0] = 1

for i, a in enumerate(X, 1):
  for j in range(N+1):
    for s in range(n+1):
      dp[i][j][s] = dp[i-1][j][s]
      if a <= s:
        dp[i][j][s] += dp[i-1][j-1][s-a]

ans = 0
for m in range(1, N+1):
  ans += dp[-1][m][A*m]

print(ans)

Measured memory_bytes: 93660
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#pragma warning( disable:4996 )


int main(void) {
	int n, m, k[31], a[31][31];
	int ans[31] = { 0 };
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%d", &k[i]);
		for (int j = 0; j < k[i]; j++) {
			scanf("%d", &a[i][j]);
			ans[a[i][j]]++;
		}
	}
	int count = 0;
	for (int i = 1; i <= m; i++) {
		if (ans[i] == n) {
			count++;
		}
	}
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n;
    int ans = 0;
    cin >> n;
    vector<int> a(n), b(n), c(n - 1);
    
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    }

    for(int i = 0; i < n; i++){
        cin >> b.at(i);
    }

    for(int i = 0; i < n - 1; i++){
        cin >> c.at(i);
    }

    ans += accumulate(b.begin(), b.end(), 0);
    for(int i = 0; i < n - 1; i++){
        if(a.at(i) == a.at(i+1) - 1) ans += c.at(a.at(i) - 1);
    }
    cout << ans;
}


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

using namespace std;

#define REP(i,n) for (int i=0;i<(n);++i)

int main() {
	int p[3], j[2];
	REP(i,3) cin >> p[i];
	REP(i,2) cin >> j[i];

	sort(p, p+3);
	sort(j, j+2);

	int ans = p[0] + j[0] - 50;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define Lower(a,t) lower_bound(All(a),t)
using namespace std;
void Debug(auto a);


signed main(){
    int n;
    cin >> n;
    vec(a,9);
    REP(i,n){
        int t;
        cin >> t;
        int x = t/400;
        if(x>8){
            x = 8;
        }
        a[x]++;
    }
    int ans = 0;
    REP(i,8){
        if(a[i]!=0){
            ans++;
        }
    }
    int ans_max = ans + a[8];
    if(ans == 0){
        ans = 1;
    }
    cout << ans << " " << ans_max << endl;

    return 0;
}



void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    int H = scanner.nextInt();
    int W = scanner.nextInt();
    char[][] map = new char[H][W];
    for (int i = 0; i < H; i++) map[i] = scanner.next().toCharArray();

    boolean[] emptyH = new boolean[H];
    boolean[] emptyW = new boolean[W];
    for (int i = 0; i < H; i++) {
      emptyH[i] = true;
      for (int j = 0; j < W; j++) emptyH[i] &= map[i][j] == '.';
    }
    for (int i = 0; i < W; i++) {
      emptyW[i] = true;
      for (int j = 0; j < H; j++) emptyW[i] &= map[j][i] == '.';
    }
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) if (!emptyH[i] && !emptyW[j]) System.out.print(map[i][j]);
      System.out.println();
    }
  }
}


Measured memory_bytes: 27460
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
using namespace std;
using ll = long long;
int main(){
  int n, k;
  cin >> k >> n;
//  cout << n << endl;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> deviation(n);
  rep(i,n-1){
    deviation[i] = a[i+1] - a[i];
  }
  deviation[n-1] = a[0]+k-a[n-1];
  int mx=0;
//  rep(i,n) cout << deviation[i] << endl;
  for(auto p:deviation){
    mx = max(mx,p);
  }
  cout << k- mx << endl;
}

Measured memory_bytes: 1792
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var lrd = Console.ReadLine().Split()
                .Select(double.Parse).ToArray();
            double l = lrd[0];
            double r = lrd[1];
            double d = lrd[2];

            int countR = (int)Math.Floor(r / d);
            int countL = (int)Math.Floor((l-1) / d);
            int result = countR - countL;

            Console.WriteLine(result);
        }
    }
}

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

using namespace std;
typedef long long ll;

#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359

int main(void)
{
  int a, b;
  char op;
  cin >> a >> op >> b;

  if(op == '+') cout << a+b << endl;
  else cout << a-b << endl;

  return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
grid = []
count_array = [0] * W
for _ in range(H):
    S = input()
    if '#' in S:
        grid.append(S)
        for i in range(W):
            if S[i] == '.':
                count_array[i] += 1
delete_target = []
for i in range(W):
    if count_array[i] == len(grid):
        delete_target.append(i)
ans = []
for i in grid:
    tmp = ''
    for k in range(W):
        if k in delete_target:
            continue
        tmp += i[k]
    ans.append(tmp)
for i in ans:
    print(i)

Measured memory_bytes: 3064
import java.util.*;
public class Main{
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
     int n=sc.nextInt();
    int sum=0;
    int k=sc.nextInt();
    ArrayList<Integer> a=new ArrayList<Integer>();
    for(int i=0;i<n;i++)
      a.add(sc.nextInt());
    Collections.sort(a);
    for(int y=0;y<k;y++)
    {
        sum=sum+a.get(y);
    }
    System.out.println(sum);
      
  }
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    int64_t n = s.size();
    int64_t ans = 0;
    for (auto i : irange(0L, n)) {
        if (s[i] != t[i]) {
            ++ans;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3840
K,N=map(int,input().split())                            # 1行2列
inList=list(map(int,input().split()))                     # 1行N列・・・Nは任意
distList=[]

for i in range(N):
	right = 0
	left  = 0
	if i == 0:
		left  = inList[0]+(K - inList[1])
		right = inList[N-1] - inList[0]
	elif i == N-1:
		left  = (K - inList[i]) + inList[i - 1]
		right = inList[i] + (K - inList[0])
	else:
		left  = (K - inList[i]) + inList[i - 1]
		right = inList[i] + (K - inList[i + 1])

	if(left < right):
		distList.append(left)
	else:
		distList.append(right)

distList.sort()
print(distList[0])

Measured memory_bytes: 26444
#include <bits/stdc++.h> 
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+2;
bool dp[N];
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);

      int n;
      cin>>n;
      string s;
      cin>>s;
      int ans=0;
      for(int i=0;i<=9;i++)
      {
        for(int j=0;j<=9;j++)
        {
          for(int k=0;k<=9;k++)
          {
            string o="";
            o+=i+'0';o+=j+'0';o+=k+'0';
            int p=0;
            for(int l=0;l<n&&p<3;l++)
            {
              if(s[l]==o[p]) p++;
            }
            if(p==3) ans++;
          }
        }
      }
      cout<<ans;
}
// I never lose. I either win or I learn

Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i=0; i<(n); ++i)
inline void chmax(int &a, int b) {
    if (a < b) a = b;
}

int main() {
    string s, t;
    cin >> s >> t;
    int sn = (int)s.size();
    int tn = (int)t.size();
    vector<vector<int>> dp(sn+1, vector<int>(tn+1, 0));
    rep(i, sn) {
        rep(j, tn) {
            chmax(dp[i+1][j+1], dp[i+1][j]);
            chmax(dp[i+1][j+1], dp[i][j+1]);
            if (s[i] == t[j]) {
                chmax(dp[i+1][j+1], dp[i][j] + 1);
            }
        }
    }
    string ans = "";
    while (sn > 0 && tn > 0) {
        if (dp[sn][tn] == dp[sn-1][tn]) {
            sn--;
        } else if (dp[sn][tn] == dp[sn][tn-1]) {
            tn--;
        } else {
            ans = s[sn-1] + ans;
            sn--; tn--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 35584
/*
      author  : nishi5451
      created : 14.08.2020 21:40:50
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    int k,n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    int len = 0;
    for(int i=1; i<n; i++){
        len = max(len,a[i]-a[i-1]);
    }
    len = max(len,k-a[n-1]+a[0]);
    cout << k-len << endl;
    return 0;
}

Measured memory_bytes: 4052
while True:
    try:
        s = 0
        a,b,n = map(int,input().split())
        ama = a % b
        for i in range(1,n + 1):
            s += int((ama * 10)/ b)
            ama = (ama * 10) % b
        print(s)
    except EOFError:
        break

Measured memory_bytes: 7468
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_130
{
    class C
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            long[] whxy = ReadLongs();
            long w = whxy[0];
            long h = whxy[1];
            long x = whxy[2];
            long y = whxy[3];
            double size = 0.5 * w * h;
            int dupli = 0;
            if (w % 2 == 0 && w / 2 == x && h % 2 == 0 && h / 2 == y)
            {
                dupli = 1;
            }
            WriteLine(size + " " + dupli);

        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main(){
    int n,y;
    cin >> n >> y;
    int sen = -1;
    int gosen = -1;
    int man = -1;
    for(int a = 0; a <= n; a++){
        for(int b = 0; b + a <= n; b++){
            int c = n - a - b;
            int total = a * 1000 + b * 5000 + c * 10000;
            if(total == y){
                sen = a;
                gosen = b;
                man = c;
            }
        }
    }
    cout << man << " " << gosen << " " << sen << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,dp[100005][3];
int main(void){
    scanf("%lld",&n);
    for(int i=0;i<n;i++){
        ll a,b,c;
        scanf("%lld%lld%lld",&a,&b,&c);
        dp[i+1][0]=max(dp[i+1][0],max(dp[i][1],dp[i][2])+a);
        dp[i+1][1]=max(dp[i+1][1],max(dp[i][0],dp[i][2])+b);
        dp[i+1][2]=max(dp[i+1][2],max(dp[i][0],dp[i][1])+c);
    }
    printf("%lld\n",max(dp[n][0],max(dp[n][1],dp[n][2])));
}


Measured memory_bytes: 2560
N = int(input())

X = []
Y = []
ans = 0

for i in range(N):
    x, y = map(int, input().split())
    X.append(x+y)
    Y.append(x-y)
    
m = [max(X), max(Y)]
s = [min(X), min(Y)]
    
for i in range(2):
    ans = max(ans, m[i]-s[i])
    
print(ans)

Measured memory_bytes: 24860
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		System.out.println(Math.min(a * n, b));
	}
}


Measured memory_bytes: 23252
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>

using namespace std;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define INF 11111111111111111
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;

ll n = 0, m = 0, k = 0, ans = 0, sum = 0, cnt = 0, temp = 0;
string s;
bool flag;

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

#define MAX 10000

int main(void) {
  ll d, x;
  vll a;

  cin >> n;
  cin >> d >> x;

  FOR(i, 0, n) {
	cin >> temp;
	a.push_back(temp);
  }

  FOR(i, 0, n) {
	temp = 1;
	while (temp <= d) {
	  temp += a[i];
	  ans++;
	}
  }

  cout << ans + x << endl;

  return 0;
}

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

typedef long long ll;
const int MAX_N = 100000;

int main() {
  int N, Q, K;

  std::cin >> N;
  std::vector<std::vector<std::pair<int, ll>>> e(N);
  for(int i = 0; i < N - 1; ++i) {
    int a, b;
    ll c;
    std::cin >> a >> b >> c;
    e[a - 1].push_back(std::make_pair(b, c));
    e[b - 1].push_back(std::make_pair(a, c));
  }

  std::cin >> Q >> K;
  ll d[MAX_N + 1] = {};

  std::stack<int> s;
  s.push(K);

  while(!s.empty()) {
    int x = s.top(); s.pop();
    for(auto p : e[x - 1]) {
      int y = p.first;
      if(y == K or d[y] > 0) continue;
      d[y] = d[x] + p.second;
      s.push(y);
    }
  }

  ll ans[MAX_N];
  for(int i = 0; i < Q; ++i) {
    int x, y;
    std::cin >> x >> y;
    ans[i] = d[x] + d[y];
  }

  for(int i = 0; i < Q; ++i) {
    std::cout << ans[i] << std::endl;
  }
}


Measured memory_bytes: 10752
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> pint;
typedef long long ll;

int main()
{
    int N, T;
    cin >> N >> T;
    vector<pint> data(N, pint(0, 0));
    rep(i, N)
    {
        int a, b;
        cin >> a >> b;
        data[i] = pint(a, b);
    }
    sort(data.begin(), data.end());
    rep(i, N)
    {
        if (data[i].second <= T)
        {
            cout << data[i].first << endl;
            return 0;
        }
    }
    cout << "TLE" << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
str = gets.chomp
turner = str.count(?E)
minimum = n
str.split('').each do |c|
  case c
  when ?W
    turner += 1
    minimum = [minimum, turner - 1].min
  when ?E
    turner -= 1
    minimum = [minimum, turner].min
  end
end
puts minimum

Measured memory_bytes: 29468
<?php
fscanf(STDIN, "%d %d", $min, $k);

$min =  $min%$k;
while(true) {
  $a = abs($min-$k);
  $b = abs($k-$min);
  $tmp = ($a>$b)?$b:$a;
  
  if($tmp<$min) {
    $min = $tmp;
  } else {
	break;
  }
}

echo $min;

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

#pragma region mod
const int p = 1e9 + 7; //10^9 + 7
struct mint
{
    ll x;
    mint(ll xx = 0) : x(xx % p) {}
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= p)
            x -= p;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += p - a.x) >= p)
            x -= p;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= p;
        return *this;
    }

    mint operator+(const mint a) const
    {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const
    {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const
    {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const
    {
        mint r = 1;
        mint a = *this;
        while (true)
        {
            if (t & 1)
            {
                r *= a;
            }
            t >>= 1;
            if (t == 0)
                break;
            a *= a;
        }

        return r;
    }

    mint inv() const
    {
        return pow(p - 2);
    }

    mint &operator/=(const mint a)
    {
        return (*this) *= a.inv();
    }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

struct comb
{
    vector<mint> fact, invs;
    comb(ll n) : fact(n + 1), invs(n + 1)
    {
        assert(n < p);

        fact[0] = 1;
        for (ll i = 1; i <= n; ++i)
            fact[i] = fact[i - 1] * i;

        invs[n] = fact[n].inv();
        for (ll i = n; i >= 1; --i)
            invs[i - 1] = invs[i] * i;
    }
    mint operator()(ll n, ll k)
    {
        if (k < 0 || k > n)
            return 0;
        return fact[n] * invs[n - k] * invs[k];
    }
};
#pragma endregion

int main()
{
    ll k;
    string s;
    cin >> k >> s;
    ll n = s.length() + k;
    if (n > 1e9)
    {
        return 0;
    }
    comb ncr(n);
    mint ans = 0;
    for (int i = s.length(); i <= n; i++)
    {
        ans += ncr(i - 1, s.length() - 1) * mint(25).pow(i - s.length()) * mint(26).pow(n - i);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 35608
#include <cstdio>
#include <cmath>
#include <algorithm>
#define ROP(i,n) for(int i=0;i<n;i++)
using namespace std;
int A[2017];
int N,Z,W,i;
int main(){
  scanf("%d %d %d",&N,&Z,&W);
  ROP(i,N) scanf("%d",&A[i]);
  if(N==1) printf("%d\n",abs(A[N-1]-W));
  else printf("%d\n",max(abs(A[N-1]-W),abs(A[N-2]-A[N-1])));
  return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
 
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        ArrayDeque<Integer> left = new ArrayDeque<Integer>();
        ArrayDeque<Integer> areaLeft = new ArrayDeque<Integer>();
        ArrayDeque<Integer> area = new ArrayDeque<Integer>();
         
        for(int i = 0; i < s.length(); ++i) {
            char c = s.charAt(i);
            if(c == '\\'){
                left.addFirst(i);
            }else if(c == '/'){
                if(!left.isEmpty()) {
                    int l = left.removeFirst();
                    areaLeft.addFirst(l);
                    area.addFirst(i-l);
                }
            }
        }
         
        int lastl = s.length();
        while(!areaLeft.isEmpty()){
            int l = areaLeft.removeFirst();
            if(l > lastl){
                area.addLast(area.removeFirst() + area.removeLast());
            }else{
                area.addLast(area.removeFirst());
                lastl = l;
            }
        }
         
        StringBuilder sb = new StringBuilder();
        int sum = 0;
        for(Integer i : area){
            sum += i;
            sb.insert(0, " " + i);
        }
        sb.insert(0, area.size());
         
        System.out.println(sum);
        System.out.println(sb);
    }
     
}

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

using namespace std;

struct item { // value and weight for each item
  int value; 
  int weight;
};





int main()
{
  int N, W; // no. of inputs, max weight
  cin >> N >> W;

  vector< vector<int> > grid(N, vector<int>(W+1, 0)); // table for DP
  
  
  vector<item> items(N); // array to store item properties

  for (int i = 0; i < N; ++i) {
    int value, weight;
    cin >> value >> weight;
    item cur_item = {value, weight};
    items[i] = cur_item;
    //grid[i][0] = 0; // initialize first column
  }

  for (int i = 0; i <= W; ++i) {
    grid[0][i] = (items[0].weight <= i)?items[0].value:0; //initialize first row
  }

  for(int i = 1; i < N; ++i) {
    for (int j = 1; j <= W; ++j) {
      if (items[i].weight <= j) {
	grid[i][j] = max(items[i].value + grid[i-1][j-items[i].weight], grid[i-1][j]);
      } else {
	grid[i][j] = grid[i-1][j];
      }
    }
  }



    cout << grid[N-1][W] << endl;
  
  return 0;
}

Measured memory_bytes: 4964
#include<bits/stdc++.h>
using namespace std;
#define int long long
 int $(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 
signed main(){
  int a,b,c,e=1000000000000,d=0;
  cin>>a>>b;
  for(int i=0;i<b;i++){
    cin>>c;
    d=max(c,d);
    cin>>c;
    e=min(c,e);
  }
  cout<<max<long long>(0,e-d+1)<<endl;
}


Measured memory_bytes: 256
use std::io::stdin;
use std::f64;

mod utils {
    use std::io::BufRead;
    use std::str::{self, FromStr};

    pub struct StdinReader<R: BufRead> {
        reader: R,
        buf: Vec<u8>,
    }

    impl<R: BufRead> StdinReader<R> {
        pub fn new(reader: R) -> StdinReader<R> {
            StdinReader {
                reader: reader,
                buf: Vec::new(),
            }
        }

        #[allow(unused)]
        #[inline]
        pub fn reads<T: FromStr>(&mut self) -> T {
            self.read_until(b' ')
        }

        #[allow(unused)]
        #[inline]
        pub fn readl<T: FromStr>(&mut self) -> T {
            self.read_until(b'\n')
        }

        #[allow(unused)]
        #[inline]
        pub fn read_vec<T: FromStr>(&mut self) -> Vec<T> {
            return self.read_until::<String>(b'\n').trim().split_whitespace().map(|c| c.parse().ok().unwrap()).collect();
        }

        #[inline]
        pub fn read_until<T: FromStr>(&mut self, delim: u8) -> T {
            loop {
                self.buf.clear();
                let len = self.reader
                    .read_until(delim, &mut self.buf)
                    .expect("failed reading bytes");
                match len {
                    0 => panic!("early eof"),
                    1 if self.buf[0] == delim => (),
                    _ => {
                        if self.buf[len - 1] == delim {
                            self.buf.truncate(len - 1);
                        }
                        break;
                    }
                }
            }

            let elem = unsafe { str::from_utf8_unchecked(&self.buf) };
            elem.parse().unwrap_or_else(|_| panic!(format!("failed parsing: {}", elem)))
         }
    }
}


fn main(){
    let stdin = stdin();
    let mut r = utils::StdinReader::new(stdin.lock());
    let n:usize = r.readl();

    let mut greatest_multiple = 1;
    let mut i = 1;

    for i in 1..((f64::sqrt(n as f64) + 1e-9) as usize + 1){
        if n % i == 0{
            greatest_multiple = i;
        }
    }

    println!("{}",greatest_multiple - 1 + (n / greatest_multiple) - 1);
}


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

int main()
{
    string str;
    int n = 0, s = 0, e = 0, w = 0;
    cin >> str;
    int NS=0, EW=0;
    for(int i=0; i<str.length(); i++){
        if(str[i]=='N') n = 1;
        else if(str[i]=='S') s = 1;
        else if(str[i]== 'E') e = 1;
        else if(str[i]=='W') w = 1;
    }
    if ((n==s) && (e==w)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio;
void main() {
	int w, h, x, y, r;
	"%d %d %d %d %d".readf(&w, &h, &x, &y, &r);
	auto f = (x - r < 0 || x + r > w || y - r < 0 || y + r > h) ?"No" : "Yes";
	f.writeln;
}

Measured memory_bytes: 2488
n = int(input())
r1 = [int(x) for x in input().split()]
r2 = [int(x) for x in input().split()]
# If d == 0, first it moves down, then it moves right.
candies = (sum(r1[:d+1]) + sum(r2[d:]) for d in range(n))
print(max(candies))


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

#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;



int main() {
	int N;
	cin >> N;
	vector<int> A, B;
	rep(i, N-1) {
		int b;
		cin >> b;
		B.emplace_back(b);
	}
	for (int i = N - 2; 1 <= i; --i) {
		int m = min(B[i - 1], B[i]);
			A.emplace_back(m);
	}
	A.emplace_back(B[0]);
	A.emplace_back(B[N - 2]);
	int ans = 0;
	rep(i, N)ans += A[i];
	cout << ans << endl;
	return 0;
}

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

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    akari<int> as(n);
    for (int &a : as)
        cin >> a;
    cin >> n;
    akari<int> bs(n), ans;
    for (int &b : bs)
        cin >> b;
    set_difference(as.begin(), as.end(), bs.begin(), bs.end(), inserter(ans, ans.end()));
    for (int a : ans)
    {
        cout << a << '\n';
    }
}

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



Measured memory_bytes: 5476
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <cmath>

#define ll long long
#define eps 1e-8
#define MOD 1000000007

#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f

// change if necessary
#define MAXN 300

using namespace std;

// 3 2 1 
int n;
double dp[MAXN + 1][MAXN + 1][MAXN + 1];

double solve(int i, int j, int k) {
    if (k == 0 && j == 0 && i == 0) {
        return 0.0;
    }

    if (dp[i][j][k]) {
        return dp[i][j][k];
    }

    if (i > 0) {
        dp[i][j][k] += 1.0 * i / n * (solve(i - 1, j + 1, k));
    }

    if (j > 0) {
        dp[i][j][k] += 1.0 * j / n * (solve(i, j - 1, k + 1));
    }

    if (k > 0) {
        dp[i][j][k] += 1.0 * k / n * (solve(i, j, k - 1));
    }

    dp[i][j][k]++;
    dp[i][j][k] /= i + j + k;
    dp[i][j][k] *= n;

    return dp[i][j][k];
}

int main() {
    cin.tie(0)->sync_with_stdio(0);

    cin >> n;
    int cnt[4] = {0, 0, 0};
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        cnt[x]++;
    }

    cout << fixed << setprecision(15) << solve(cnt[3], cnt[2], cnt[1]) << '\n';

    return 0;
}

Measured memory_bytes: 213248
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <stdio.h>
using namespace std;

typedef long long ll;

int main()
{
    int H,W;
    cin >> H >> W;
    string S[H];
    for(int i=0; i<H; i++){
        cin >> S[i];
    }
    int tile[H][W];
    for(int h=0; h<H; h++){
        int cnt=1;
        for(int w=0; w<W; w++){
            if(S[h][w]=='.'){
                tile[h][w]=cnt;
                cnt++;
            }else{
                cnt=1;
                tile[h][w]=0;
            }
        }
        cnt=tile[h][W-1];
        for(int w=W-2; w>=0; w--){
            if(tile[h][w]!=0 && cnt==0) cnt=tile[h][w];
            else if(tile[h][w]!=0 && cnt!=0) tile[h][w]=cnt;
            else cnt=0;
        }
    }
    int tile1[H][W];
    for(int w=0; w<W; w++){
        int cnt=1;
        for(int h=0; h<H; h++){
            if(S[h][w]=='.'){
                tile1[h][w]=cnt;
                cnt++;
            }else{
                cnt=1;
                tile1[h][w]=0;
            }
        }
        cnt=tile1[H-1][w];
        for(int h=H-2; h>=0; h--){
            if(tile1[h][w]!=0 && cnt==0) cnt=tile1[h][w];
            else if(tile1[h][w]!=0 && cnt!=0) tile1[h][w]=cnt;
            else cnt=0;
        }
    }
    int ans=0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            ans=max(ans, tile[i][j]+tile1[i][j]-1);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 35584