akhauriyash/Code-Regression huggingface dataset:
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N;
    std::cin >> N;

    boost::multi_array<bool, 2> mat(boost::extents[101][101]);

    std::fill(mat.data(), mat.data() + mat.num_elements(), false);

    struct P {
        int64_t x;
        int64_t y;
        int64_t h;
    };

    P o;
    std::vector<P> p;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t x, y, h;
        std::cin >> x >> y >> h;
        p.push_back({x, y, h});
        if (h > 0) {
            o = {x, y, h};
        }
    }

    for (int64_t cx = 0; cx <= 100; ++cx) {
        for (int64_t cy = 0; cy <= 100; ++cy) {
            auto H = o.h + std::abs(o.x - cx) + std::abs(o.y - cy);
            for (int64_t i = 0; i < N; ++i) {
                if (p[i].h != std::max(H - std::abs(p[i].x - cx) - std::abs(p[i].y - cy), (int64_t)0)) {
                    goto nachst;
                }
            }
            std::cout << cx << " " << cy << " " << H <<  std::endl;
            return 0;
        nachst:
            int s;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bitset>
#include<algorithm>
using namespace std;
int n,x;
bool isp[1<<20];
main()
{
	isp[0]=isp[1]=1;
	for(int i=2;i<1<<20;i++)
	{
		if(isp[i])continue;
		for(int j=i+i;j<1<<20;j+=i)isp[j]=1;
	}
	while(cin>>n>>x,x)
	{
		bitset<1000001>dp;
		dp[0]=1;
		for(int i=0;i<n;i++)
		{
			int v;cin>>v;
			for(int j=0;(v<<j)<=x;j++)dp|=dp<<(v<<j);
		}
		bool f=1;
		for(int i=x;i>0;i--)
		{
			if(!dp[i])continue;
			if(!isp[i])
			{
				cout<<i<<endl;
				f=0;
				break;
			}
		}
		if(f)cout<<"NA"<<endl;
	}
}



Measured memory_bytes: 4448
N = int(input())
mx = 3503
found = False
for i in range(1, mx):
    for j in range(1, mx):
        if i*j*4 % N != 0:
            continue
        den = ((i*j*4)//N) - i - j
        num = i*j
        if den == 0:
            continue
        if num%den == 0 and num//den > 0 and num//den < mx:
            print(i,j,num//den)
            found = True
            break
    if found:
        break

Measured memory_bytes: 9180
N,A,B,C =map(int,input().split())

l = [int(input()) for i in range(N)]

INF =10**9

def dfs(cnt,a,b,c):
    if cnt == N:
    #30引くのは元のa,b,cだけならコストかからんから
        return abs(A-a)+abs(B-b) + abs(C-c)-30 if min(a,b,c)>0 else INF
    
    ret0 = dfs(cnt+1 ,a,b,c)
    ret1 = dfs(cnt+1,a+l[cnt],b,c)+10
    ret2 = dfs(cnt+1,a,b+l[cnt],c)+10
    ret3 = dfs(cnt+1,a,b,c+l[cnt])+10
    
    return min(ret0,ret1,ret2,ret3)


print(dfs(0,0,0,0))
    

Measured memory_bytes: 3064
import java.util.*;
 
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[] s = new String[h];
		for (int i = 0; i < h; i++) {
			s[i] = sc.next();
		}
		int board[][] = new int[h][w];
		board[0][0] = 1;
		Queue<Integer> qX = new LinkedList<Integer>();
		Queue<Integer> qY = new LinkedList<Integer>();
		qX.add(0);
		qY.add(0);
		int[] lR = { 1, 0, -1, 0 };
		int[] uD = { 0, 1, 0, -1 };
		while (!qX.isEmpty()) {
			int x = qX.poll();
			int y = qY.poll();
			for (int i = 0; i < 4; i++) {
				int nextX = x + lR[i];
				int nextY = y + uD[i];
				if (0 <= nextX && nextX < w && 0 <= nextY && nextY < h && s[nextY].charAt(nextX) == '.'
						&& board[nextY][nextX] == 0) {
					board[nextY][nextX] = board[y][x] + 1;
					qX.add(nextX);
					qY.add(nextY);
				}
			}
		}
		if (board[h - 1][w - 1] == 0) {
			System.out.println(-1);
			return;
		}
		int cout = 0;
		for (int i = 0; i < w; i++) {
			for (int j = 0; j < h; j++) {
				if (s[j].charAt(i) == '.')
					cout++;
			}
		}
		System.out.println(cout - board[h - 1][w - 1]);
	}
}

Measured memory_bytes: 25172
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 1000005
#define PI 3.14159265358979323846264338327950
#define ll signed long long int
using namespace std;


signed main()
{
    FAST;
    int a , b , c , d;
    cin >> a >> b >> c >> d;
	long double x = c * 30*1.0 + d *1.0/ 2;
	long double y = d * 6.0;
	long double k = x - y;
    if(y > x)
        long double k = y - x;
    if(k > 180)
        k = 360 - k;
    long double ans = a*a +b*b - 2*a*b*cos(k *PI/180);
    cout << fixed<< setprecision(20) << sqrt(ans) << endl;
    return 0;

}


Measured memory_bytes: 4136
from collections import Counter
N=int(input())
A=list(input())
B=list(input())
C=list(input())

ans=0
for i in range(N):
  c=list(Counter([A[i],B[i],C[i]]).values())
  if c==[1,1,1]:
    ans+=2
  elif c==[2,1] or c==[1,2]:
    ans+=1
  else:
    pass
print(ans)

Measured memory_bytes: 3316
import java.util.*;

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

        int N = sc.nextInt();
        int k = sc.nextInt();
        int[] V = new int[N];
        for (int i=0; i<N; i++) {
            V[i] = sc.nextInt();
        }

        System.out.println(solve(N, k, V));
    }

    private static long solve(int N, int K, int[] V) {
        long max = 0;
        List<Integer> hold = new ArrayList<>();
        long[] sumLeft = sumLeft(N, V);
        long[] sumRight = sumRight(N, V);
        for (int k=1; k<=K; k++) {
            for (int left=0; left<=k; left++) {
                for (int right=0; right<=k-left; right++) {
                    if (left+right > N) continue;

                    long current = sumLeft[left] + sumRight[right];
                    int maxPush = k-left-right;

                    hold.clear();
                    for (int i=0; i<left; i++) {
                        hold.add(V[i]);
                    }
                    for (int i=0; i<right; i++) {
                        hold.add(V[N-i-1]);
                    }
                    Collections.sort(hold);

                    while (maxPush > 0) {
                        if (hold.size() == 0) break;
                        if( hold.get(0) < 0) {
                            current -= hold.remove(0);
                        }
                        maxPush--;
                    }

                    if (max < current) {
                        // System.err.println("left=" + left + ", right=" + right + ", current=" + current);
                        max = current;
                    }
                }
            }

        }

        return max;
    }

    private static long sum(List<Integer> list) {
        long sum = 0;
        for (int i=0; i<list.size(); i++) {
            sum += list.get(i);
        }
        return sum;
    }

    private static long[] sumLeft(int N, int[] V) {
        long[] sum = new long[N+1];
        for (int i=0; i<N; i++) {
            sum[i+1] = V[i] + sum[i];
        }
        return sum;
    }

    private static long[] sumRight(int N, int[] V) {
        long[] sum = new long[N+1];
        for (int i=0; i<N; i++) {
            sum[i+1] = V[N-i-1] + sum[i];
        }
        return sum;
    }
}


Measured memory_bytes: 45716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

// youtube editorial
// 4 段以上でもいける

// 0 indexed
int n;
ll bit[3][1000010];
void add(int a, ll w, int i) { // debuged, int w to ll w
  for (int x = a; x < n; x |= x + 1) bit[i][x] += w;
}
ll sum(int a, int i) { // [0, a), debuged, int sum to ll sum
  ll ret = 0; // debuged, int to ll
  for (int x = a - 1; x >= 0; x = (x & (x + 1)) - 1) {
    ret += bit[i][x];
  }
  return ret;
}

void solve() {
  int step = 3;
  cin >> n;

  // i 段までで, i 段の j 番目を使う場合の数

  vector<vector<ll> > a(step, vector<ll>(n));
  rep(i, step) rep(j, n) cin >> a[i][j];
  rep(i, step) sort(all(a[i]));

  rep(j, n) add(j, 1, 0);
  rep3(i, 1, step) rep(j, n) {
    int it = lb(a[i - 1], a[i][j]);
    add(j, sum(it, i - 1), i);
  }

  ll ans = sum(n, step - 1);
  cout << ans << endl;
  // rep(i, step) { rep(j, n) cout << sum(j + 1, i) - sum(j, i) << " "; cout << endl; }
}


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

int a[150] = {};

int main()
{
    string w;
    cin >> w;
    for (int i = 0; i < w.size(); ++i)
    {
        a[w[i]] += 1;
    }
    for (int i = 97; i < 123; i++)
    {
        if (a[i] % 2 != 0)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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


void solve(std::string T){
    string s = T;
    for(int i = 0;i < s.size();i++)
        if(s[i] == '?')s[i] = 'D';
    cout<<s<<endl;
}

int main(){
    std::string T;
    std::cin >> T;
    solve(T);
    return 0;
}


Measured memory_bytes: 3884
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()

cnt = 0
for a in range(1, N+1):
    # mod a毎にまとめて追加
    d, m = divmod(N, a)
    cnt += max(0, a-K) * d
    cnt += max(0, m - max(0, K-1))
print(cnt)


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

using namespace std;

int main(){
    int k;
    cin>>k;
    int a,b;
    cin>>a>>b;
    for(int i=1;;i++){
    	if(i*k > b) {
    		cout<<"NG"<<endl;
    		break;
		}
		if(i*k>=a && i*k<=b){
			cout<<"OK"<<endl;
			break;
		}
	}
	return 0;
} 

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

using ll = long long;

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

    int n = S.size();

    ll ans = 0;
    ll cnt = 0;
    for (int i = 0; i < n; i ++) {
        if (S[i] == 'W') {
            ans += (i - cnt);
            cnt ++;
        }
    }

    printf("%lld\n", ans);

    return 0;
}



Measured memory_bytes: 3840
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int main()
{
	int n,a,b;
	cin>>n>>a>>b;
	if((b-a)&1) puts("Borys");
	else puts("Alice");
}


Measured memory_bytes: 256
import scala.util.control.Breaks

object Main extends App {
  val s =  scala.io.StdIn.readLine()
  val b = new Breaks
  var result = "Yes"
  b.breakable{
    s.zipWithIndex.foreach { case(w, i) =>
      if ((i + 1) % 2 == 0) {
        if(w !='L' && w != 'U' && w != 'D') {
          result = "No"
          b.break
        }
      } else {
        if(w !='R' && w != 'U' && w != 'D') {
          result = "No"
          b.break
        }
      }
    }
  }
  println(result)
}


Measured memory_bytes: 25504
using System;

class quiz
{
    public char solve(string Sa, string Sb, string Sc)
    {
        int ai = 0, bi = 0, ci = 0;
        char abc = 'a';

        while (true)
        {
            if(abc == 'a')
            {

                if (ai == Sa.Length)
                    return 'A';
                abc = Sa[ai];
                ai++;
            }
            else if(abc == 'b')
            {
                if (bi == Sb.Length)
                    return 'B';
                abc = Sb[bi];
                bi++;
            }
            else
            {
                if (ci == Sc.Length)
                    return 'C';
                abc = Sc[ci];
                ci++;
            }
        }
        return 'e';
    }

    public int[] ParseIntBySpace(string str)
    {
        int[] array = new int[str.Length];
        int lastloc = 0, spaceloc = -1;

        for (int i = 0; i < str.Length; i++)
        {
            if (str[i] == ' ')
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc - 1));
                spaceloc = i;
            }
            else if (i == str.Length - 1)
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc));
            }
        }

        Array.Resize(ref array, lastloc);

        return array;
    }
}

class Example
{
    static void Main()
    {
        quiz ex = new quiz();

        //while (true)
        //{
        Console.WriteLine(ex.solve(Console.ReadLine(), Console.ReadLine(), Console.ReadLine()));
        //}
    }
}

Measured memory_bytes: 13140
import java.util.*;

public class Main {
  public static void main(final String[] args) {
    final Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    String[][] S = new String[H][W];
    for (int i = 0; i < H; ++i) {
      String s = sc.next();
      S[i] = s.split("");
    }
    sc.close();
    // マスに黒予定が2つ隣接していないとNG
    // 時計回り
    int dy[] = { -1, 0, 1, 0 };
    int dx[] = { 0, 1, 0, -1 };
    for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
        int cnt = 0;
        for (int k = 0; k < 4; ++k) {
          int ny = i + dy[k];
          int nx = j + dx[k];
          if (ny < 0 || nx < 0 || ny >= H || nx >= W) {
            continue;
          }
          if (S[ny][nx].equals("#")) {
            ++cnt;
          }
        }
        if (S[i][j].equals("#") && cnt == 0) {
          System.out.println("No");
          System.exit(0);
        }
      }
    }
    System.out.println("Yes");
  }
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    int n, m;
    cin >> n >> m;
    vector<bool> ac(n, false);
    vector<int> wa(n, 0);

    int p;
    string s;
    int c = 0;
    int pe = 0;
    for (int i = 0; i < m; ++i) {
        cin >> p >> s;
        p--;
        if(s == "AC"){
            if(!ac[p]){
                c++;
                ac[p] = true;
            }
        }
        else{
            if(!ac[p]){
                wa[p]++;
            }
        }
    }

    for (int i = 0; i < n; ++i) {
        if(wa[i] > 0 && ac[i]) pe += wa[i];
    }
    cout << c << " " << pe << endl;
}

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

int main() {
  int N;
  cin >> N;
  long long ans = 0;
  map<string, long long> mp;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }
  for (auto p : mp) {
    long long s = p.second;
    ans += s * (s - 1) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k=nxt(),x=nxt();
    for(int i=x-k+1;i<x+k;i++)
        cout<<i<<" ";
    cout<<endl;
    
    
    return 0;   
}


 
 


Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
N = I()
A = readInts()
import collections
dic = collections.Counter(A)
A = set(A)
is_prime = [True] * (10**6+1)
for a in A:
    if is_prime[a]:
        for v in range(a*2,10**6+1,a):
            is_prime[v] = False
cnt = 0
for a in A:
    if is_prime[a]:
        cnt += 1
for k,v in dic.items():
    if v >= 2 and is_prime[k]:
        cnt -= 1
print(cnt)


Measured memory_bytes: 50616
#include <iostream>
#include <string>
#include <vector>
#include <climits>
using namespace std;
vector<vector<int>> dp(3001,vector<int>(3001,-1));
string x, y;
// Find a longest Subsequence b/w 2 strings using memoization
int LCSstring(int n,  int m){
    if(n==0 || m==0){
        
        return 0;
    }
    if(dp[n][m] != -1){
        return dp[n][m];
    }
    if(x[n-1] == y[m-1]){
        auto p = LCSstring(n-1,m-1);
        dp[n][m] = p+1;
        return dp[n][m];
    }
    else{
        auto p1 = LCSstring( n-1,  m);
        auto p2 = LCSstring( n,  m-1);
 
        if(p1 >= p2){
            dp[n][m] = p1;
            return dp[n][m];
        }
        else{
            dp[n][m] = p2;
            return dp[n][m];
        }
    }
    return dp[n][m];
}
 
 
int main() {
    
    cin >> x >> y;
    int a=x.size();
    int b=y.size(); 
    auto p = LCSstring(a, b);
    int index = dp[a][b]; 
  
   // Create a character array to store the lcs string 
   char lcs[index+1]; 
   lcs[index] = '\0'; // Set the terminating character 
  
   // Start from the right-most-bottom-most corner and 
   // one by one store characters in lcs[] 
   int i = a, j = b; 
   while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (x[i-1] == y[j-1]) 
      { 
          lcs[index-1] = x[i-1]; // Put current character in result 
          i--; j--; index--;     // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (dp[i-1][j] > dp[i][j-1]) 
         i--; 
      else
         j--; 
   } 
   cout<<lcs<<endl;
    return 0;
}


Measured memory_bytes: 39148
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;

const lint mod = 1e9 + 7;

int main(){
    int n, a, b;
    scanf("%d%d%d", &n, &a, &b);
    lint v[n];
    rep(i, n) scanf("%lld", &v[i]);
    sort(v, v+n, greater<lint>());
    
    double sum = 0;
    rep(i, a) sum += v[i];
    printf("%.10lf\n", 1.0 * sum / a);
    
    lint C[51][51];
    C[0][0] = 1;
    For(i, 1, 51){
        C[i][0] = C[i][i] = 1;
        For(j, 1, i) C[i][j] = C[i-1][j-1] + C[i-1][j];
    }
    
    int num = 0;
    int num2 = 0;
    int num3 = 0;
    rep(i, n){
        if(v[i] > v[a-1]) ++num3;
        if(v[i] == v[a-1]) ++num2;
        if(v[i] == v[0]) ++num;
    }
    if(num <= a){
        printf("%lld\n", C[num2][a-num3]);
        return 0;
    }
    
    lint ans = 0;
    For(i, a, min(b, num)+1) ans += C[num][i];
    
    printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N,cnt;
  cin >> N;
  vector<int> P(N),Q(N);
  for(int i=0;i<N;i++)cin >> P[i];
  for(int i=0;i<N;i++)cin >> Q[i];
  if(P>Q){
    vector<int> R=P;
    P=Q;Q=R;
  }
  for(cnt=0;P!=Q;cnt++){
    next_permutation(P.begin(),P.end());
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll A, B;
    cin >> A >> B;
    if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
    {
        cout << "Possible" << endl;
    }
    else
    {
        cout << "Impossible" << endl;
    }
}

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

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

int toint(string s){
  stringstream sst;
  sst<<s;
  int a;
  sst>>a;
  return a;
}

int rec(string s){

  int kk = 0;
  rep(i,s.size()){
    if(s[i]=='[' || s[i]==']')kk++;
  }
  if(kk==2){
    return (toint(s.substr(1,s.size()-2))+1)/2;
  }
  //cout<<s<<endl;
  int cnt = 0;
  int st = 0;
  vector<int> cand;
  rep(i,s.size()){
    if(s[i]=='['){
      if(cnt==1)st = i;
      cnt++;
    }
    if(s[i]==']'){
      cnt--;
      if(cnt==1)cand.push_back(rec(s.substr(st,i-st+1)));
    }
  }
  sort(cand.begin(),cand.end());

  int sum = 0;
  rep(i,(cand.size()+1)/2){
    sum += cand[i];
  }
  return sum;
}
int solve(string s){
  return rec(s);
}

int main(){
  int n;
  cin>>n;
  rep(i,n){
    string s;
    cin>>s;
    printf("%d\n",solve(s));
  }
}

Measured memory_bytes: 1308
#include <stdio.h>

int main(void){
  char s[5];
  scanf("%s", s);

  if(s[0]==s[1] && s[1]==s[2] || s[1]==s[2] && s[2]==s[3])
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}

Measured memory_bytes: 128
/* 
   AOJ 2018
   Princess's Gamble
   2015.4.26
 */

#include<stdio.h>

int calc(int num_athlete, int winner, int deduction_rate)
{
  int i, sum_votes = 0, sum_pay = 0, one_pay = 0, ballot_box[100] = {0};
  
  for(i = 0; i < num_athlete; i++){
    scanf("%d", &ballot_box[i]);
    sum_votes += ballot_box[i];
  }
  
  sum_pay = sum_votes * (100 - deduction_rate);
  
  if(ballot_box[winner - 1] == 0)
    {
      return 0;
    }
  else
    {
      one_pay = sum_pay / ballot_box[winner - 1];
      
      return one_pay;
    }

}

int main(void)
{
  int n, m, p, dividend;
  while(1)
    {
      scanf("%d %d %d", &n, &m, &p);
      if(n == 0 && m == 0 && p == 0)
	{
	  break;
	}

      dividend = calc(n, m, p);
      printf("%d\n", dividend);
    }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <math.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	int N, A, B;
	cin >> N >> A >> B;
	cout << min(A, B) << " " << max(A+B-N, 0);
}


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

map<char,int>m;
map<char,int>::iterator it;
main()
{
    int i,j,k=1;
    string s;
    cin>>s;
    for(i=0;i<s.size();i++)
    {
        m[s[i]]++;
    }
    for(it=m.begin();it!=m.end();it++)
    {
        if(it->second%2!=0)
        {
            k=0;break;
        }
    }
    if(k==0)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (size_t i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }

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

    bool can = true;

    for (size_t i = 0; i < N-1; i++)
    {
        if(A.at(i) == A.at(i+1)){
            can =false;
            break;
        }
    }

    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;
    
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int N;
LL A[100000],sum[100000];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	cin >> N;
	for(int i=0; i<N; i++) cin >> A[i];
	sort(A,A+N);
	sum[0] = A[0];
	for(int i=1; i<N; i++) sum[i] = sum[i-1] + A[i];

	int ans = 1;
	for(int i=N-2; i>=0; i--){
		if(sum[i]*2 >= A[i+1]) ans++;
		else break;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int a;
  string s;
  cin >> a >> s;
  if (a >= 3200) P(s);
  else P("red");

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace CSsample
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            var x = input.Split();
            int N = int.Parse(x[0]);
            int K = int.Parse(x[1]);
            string S = Console.ReadLine();
            var ind = new List<int>();
            var len = new List<int>();
            int A = S.IndexOf('0');
            while(A != -1)
            {
                ind.Add(A);
                int B = S.IndexOf('1', A + 1);
                if(B == -1)
                {
                    len.Add(S.Length - A);
                    A = -1;
                }
                else
                {
                    len.Add(B - A);
                    A = S.IndexOf('0', B + 1);
                }
            }
            int num = ind.Count;
            if (K >= num)
            {
                Console.WriteLine(S.Length);
            }
            else
            {
                int con = num - K + 1;
                int leng = 0;
                int max = 0;
                for(int i = 0; i < con; i++)
                {
                    if (i == 0)
                    {
                        leng = ind[K];
                        max = leng;
                    }
                    else
                    {
                        int indx = 0;
                        if (K + i >= num)
                        {
                            indx = S.Length;
                        }
                        else
                        {
                            indx = ind[K + i];
                        }
                        leng = indx - (ind[i-1] + len[i-1]);
                        max = Math.Max(max, leng);
                    }
                }
                Console.WriteLine(max);
            }
        }
    }
}



Measured memory_bytes: 12384
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define EPS 1e-9
#define MOD 1000000007
#define range 
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
int main(){

   // freopen("input.txt","r",stdin);
    IOS;
    clock_t clk = clock();
    
    int n; cin >> n;
    string s;
    cin >> s;
    int ans = 1;
    forn1(i, n - 1) {
        if(s[i] != s[i - 1]) ans ++;
    }         

    cout << ans;

    cerr << endl << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>

using namespace std;

void func(int n, int m, vector<int>res){

  if(n==0){
    for(int i=0;i<res.size();i++){
      cout << res[i];
      if(i==res.size()-1)cout << endl;
      else cout << " ";
    }
    return;
  }
  
  for(int i=m;i>0;i--){
    if(i>n)continue;
    res.push_back(i);
    func(n-i,i,res);
    res.pop_back();
  }
}

int main(void){

  int n;
  vector<int>res;

  while(cin >> n,n)
    func(n,n,res);

  return 0;
}

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

using namespace std;

#define ll                  long long
#define vi                  vector<int>
#define vl                  vector<ll>
#define pii                 pair<int, int>
#define vvi                 vector<vi>
#define vvl                 vector<vl>
#define all(x)              x.begin(), x.end()
#define contains(con, x)    con.find(x) != con.end()
#define fastread            ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)


int main() {
    fastread;

    int T = 1;
    // cin >> T;

    while (T--) {
        int N;
        cin >> N;

        vector<string> s(N);
        set<string> uniq;
        for (int i = 0; i < N; i++) {
            cin >> s[i];
            uniq.insert(s[i]);
        }
        cout << uniq.size() << '\n';
    }

}

Measured memory_bytes: 25056
#include<bits/stdc++.h>
using namespace std;
int M=1e9+7;
int dp[21][(1<<21)-1];
int A[21]; //save for every man with whome he is comfortable
int solve1(int n,int mask,int i){
	if(i==n && mask==0) return 1;
	if(i==n or mask==0) return 0;
	if(dp[i][mask]!=-1) return dp[i][mask];
	long long x=0;
	for(int j=0;j<n;j++){
		if(A[i]&(1<<j) && mask&(1<<j))
		{
			//matching jth woman with ith man
			x=(x+1LL*solve1(n,mask^(1<<j),i+1))%M;
		}
	}
	dp[i][mask]=x;
	return x;
}
void solve(){
	int n,m,x;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>x;
			if(x) A[i]|=(1<<j);
		}
	}
	memset(dp,-1,sizeof(dp));
	int mask=(1<<n)-1; //unmatchhed woman
	cout<<solve1(n,mask,0);
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();

}

Measured memory_bytes: 175664
# Your code here!
str = gets.split
w, h, x, y = str[0].to_i, str[1].to_i, str[2].to_i, str[3].to_i

# array = array.map{|n| n.to_i}

area = w * h / 2.0
if w / 2.0 == x.to_f && h / 2.0 == y.to_f
    print "#{area} 1"
else
    print "#{area} 0"
end


Measured memory_bytes: 1788
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
using namespace std;
int a = 0, b = 0, c = 0, d = 0, e[60][60], f[120], g[101000], h[10100], counto = 0, ans = 1000000000, x[100] = {}, y, z;
int64_t ab[10000] = {}, abc = 0, abcd = 0;
pair<int, int>manji[101] = {};
char rikka, toka[150][150] = {};
vector<int> train,code;
string saya, homu, kyok, mami[108], mado[100];
bool gg;
bool exist[1000];
int main() {
	cin >> a>>b;
	for (int i = 0; i < a; i++) {
		cin >> g[i];
	}
	sort(g, g + a);
	for (int i = 0; i <= a-b; i++) {
		ans = min(ans, g[i+b-1]-g[i]);
		if (ans == 0) {
			cout << '0' << endl;
			return 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
n = int(input())
primes = [0 for i in range(n+1)]
for i in range(2,n+1):
    cur = i
    for j in range(2,i+1):
        while cur % j == 0:
            cur = cur // j
            primes[j] += 1
def num(m):
    res = 0
    for i in primes:
        if i >= m-1:
            res += 1
    return res
print(num(75) + (num(5) - 1) * num(5) * (num(3) - 2) // 2
 + num(15) * (num(5) - 1) + num(25) * (num(3) - 1) )


Measured memory_bytes: 38512
import java.util.Scanner;


public class Main {
    public static void main(String[] args){

        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int sum = 0;
        int T[] = new int[N];
        for(int i = 0; i< N;i++) {
            T[i] = scan.nextInt();
            sum += T[i];
        }
        int M = scan.nextInt();
        int P[] = new int [M];
        int X[] = new int [M];
        for (int i = 0; i < M; i++){
            P[i] = scan.nextInt();
            X[i] = scan.nextInt();
        }

        int s = sum;
        for(int i = 0; i < M; i++){
            sum = sum - T[P[i]-1] +X[i];
            System.out.println(sum);
            sum = s;
        }

    }


}


Measured memory_bytes: 10188
from collections import Counter

N = int(input())
S = [0]*N
for i in range(N):
  S[i] = input()  
S.sort()
c = Counter(S)
m_num = c.most_common()[0][1]

for s in sorted(list(set(S))):
  if c[s] == m_num:
    print(s)

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

# define F first    
# define S second
# define mp make_pair
// everything go according to my plan      
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right  

using namespace std;

typedef pair <int, int> pii; 
typedef long long ll;
typedef long double ld;

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {   
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") { 
  if (fopen (in, "r"))
    freopen (in, "r", stdin);
  else
    cerr << "Warning: Input file not found" << endl;
}
int n;
       
int a[Sz];

int x;

const int N = 2001;
int mn[2*N][2*N];

int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();
  cin >> n >> x;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    a[i + n] = a[i];

  for (int i = 1; i <= 2*n; i++) {
    mn[i][i] = a[i];
    for (int j = i + 1; j <= 2*n; j++)
      mn[i][j] = min (mn[i][j - 1], a[j]);
  }
  ll ans = MXLL;      
  for (int t = 0; t <= n; t++) { 
    ll cost = t * 1ll * x;
    for (int i = n + 1; i <= 2*n; i++)
      cost += mn[i - t][i];
    ans = min (ans, cost);
  }
  cout << ans;
                

  return 0;
}






// Coded by Z..


Measured memory_bytes: 63744
#include <iostream>
#include <queue>
using namespace std;
int main(){
  int n,t,p,c=0;
  string s;
  cin>>n>>t;
  queue<pair<string,int> >a;
  while(n--){
    cin>>s>>p;
    a.push(make_pair(s,p));
  }
  while(!a.empty()){
    pair<string,int>b=a.front();
    a.pop();
    if(b.second<=t){
      c+=b.second;
      cout<<b.first<<' '<<c<<endl;
    }
    else{
      b.second-=t;
      c+=t;
      a.push(b);
    }
  }
}


Measured memory_bytes: 6160
#include <iostream>
using namespace std;
 
char c[55][55]; int H, W, cnt;
 
int main() {
	cin >> H >> W;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) cin >> c[i][j];
	}
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (c[i][j] == '#' && c[i][j - 1] != '#' && c[i - 1][j] != '#' && c[i][j + 1] != '#' && c[i + 1][j] != '#') cnt++;
		}
	}
	if (cnt == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        string S;
        getline(cin, S);
        if(S == ".") break;
        //cerr << S << endl;
        stack<int> sta;
        bool clear = true;
        for(int i = 0; i < S.size(); i++) {
            if(S[i] == '(') sta.push(0);
            if(S[i] == '[') sta.push(1);
            if(S[i] == ')') {
                //cerr << "a" << endl;
                if(sta.empty() || sta.top() != 0) clear = false;
                else sta.pop();
            }
            if(S[i] == ']') {
                //cerr << "b" << endl;
                //cerr << sta.top() << endl;
                if(sta.empty() || sta.top() != 1) clear = false;
                else sta.pop();
            }
        }
        if(!sta.empty()) clear = false;
        if(clear) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=5000+5;
const int mod=1e9+7;
ll dp[maxn][maxn];
inline ll fastpow(ll a,ll b) {
	ll ans=1;
	for(;b;b>>=1,a=a*a%mod) if(b&1) ans=ans*a%mod;
	return ans;
}
int main() {
    int n,k;cin>>n;string s;cin>>s;k=s.length();
    dp[0][0]=1;
    for(int i=1;i<=n;i++) {
    	dp[i][0]=(dp[i-1][0]+dp[i-1][1])%mod;
    	for(int j=1;j<=i;j++) {
    		dp[i][j]=(dp[i-1][j+1]+dp[i-1][j-1]*2)%mod;
    	}
    }
    cout<<dp[n][k]*fastpow(fastpow(2,k),mod-2)%mod<<endl;
    return 0;
}

Measured memory_bytes: 120280
import Control.Applicative


main = do
  [n,x] <- map read . words <$> getLine :: IO [Int]

  print $ n + f x (n-x)

  where
    f a b
      | a == 0 = 0
      | a > b = f b a
      | a <= b =
        if b `mod` a == 0 then
          2*a*(b`div`a)-a
        else
          2*a*(b`div`a) + f (b`mod`a) a


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

int main() {
  int K, S, count = 0;
  cin >> K >> S;
  
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= min(K, S - x); y++) {
      int z = S - x - y;
      if (z >= 0 && z <= K) count++;
    }
  }
  cout << count << endl;
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> x(n, 0);
    rep(i, n) cin >> x[i];

    sort(x.begin(), x.end());
    int ans = INT_MAX;
    for (int i=x[0]; i<=x[n-1]; i++) {
        int area = 0;
        for (int j=0; j<x.size(); j++) {
            area += (i-x[j]) * (i-x[j]);
        }
        ans = min(area, ans);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
int main(){
    int x[5],sum=0;
    for(int i=0;i<5;i++){
        scanf("%d",&x[i]);
        if(x[i]<40)
            x[i]=40;
        sum+=x[i];
    }
    printf("%d\n",sum/5);
    return 0;
}

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

int main() {
    std::cout<<std::fixed<<std::setprecision(10);
    
    int A, B; cin >> A >> B;
    int openin = A-B*2;
    if (openin >= 0) {
        cout << openin << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int n, m, x;

bool check(vector<int> b){
    bool res = true;
    for(int i = 0; i < m; i++){
        if(b[i] < x){
            res = false;
            break;
        }
    }
    return res;
}

int main(){
    int ans = INF;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 1; i < (1 << n); i++){
        vector<int> b(m);
        int t = 0;
        for(int j = 0; j < n; j++){
            if(((i >> j) & 1) == 0){
                continue;
            }
            for(int k = 0; k < m; k++){
                b[k] += a[j][k];
            }
            t += c[j];
        }
        if(check(b)){
            ans = min(ans, t);
        }
    }
    if(ans == INF){
        ans = -1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

vector<string> split(string &str) {
    int prev = 0;
    vector<string> ans;
    for (int i = 0; i < str.size(); i++) {
	if (str[i] == ' ') {
	    ans.push_back(str.substr(prev, i - prev));
	    prev = i + 1;
	}
    }
    return ans;
}

string kanglish[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts"};


int main() {
    int n;
    cin >> n;
    vector<string> vec;
    string com = "";
    for (int i = 0; i < n;) {
	string str;
	getline(cin, str);
	if (str.size() == 0) continue;
	i++;
	if (com.size() && com[com.size() - 1] != ' ') {
	    com += " ";
	}
	com += str;
    }
    com += " ";
    vec = split(com);
    
    map<string, map<string, int>> cnt;
    for (auto str: vec) {
	int index = 0;
	vector<string> slist;
	while (index < str.size()) {
	    int nxt = index + 1;
	    for (auto kang: kanglish) {
		if (str.substr(index, kang.size()) == kang) {
		    nxt = index + kang.size();
		}
	    }
	    string word = str.substr(index, nxt - index);
	    slist.push_back(word);
	    index = nxt;
	}
	for (int i = 0; i < slist.size() - 1; i++) {
	    cnt[slist[i]][slist[i + 1]]++;
	}
    }
    for (auto &s1: kanglish) {
	int mx = -1;
	string ans = "";
	for (auto &s2: kanglish) {
	    if (cnt[s1][s2] > mx) {
		mx = cnt[s1][s2];
		ans = s2;
	    }
	}
	cout << s1 << " " << ans << " " << mx << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3480
import java.util.*;
class Main {
	public static void main(String[] args) {
		int big=20;
		int sml=19;
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int[][] dat=new int[n][3];
		int[] ans=new int[n];
		for (int i=0;i<dat.length;i++){
			for(int j=0;j<3;j++){
				dat[i][j]=scn.nextInt();
			}
			int cnt=dat[i][0]+1;
			int bcnt=0;
			int scnt=0;
			int a=0;
			if(dat[i][1]%2==0){
				if(dat[i][0]%3==0){a++;}
				for(int d=dat[i][2];d<=sml;d++) a++;
			}else{
				for(int d=dat[i][2];d<=big;d++) a++;
			}
			for(int m=dat[i][1]+1;m<=10;m++){
				if(m%2==0&&dat[i][0]%3!=0){scnt++;}
				else{bcnt++;}
			}
			while(cnt<1000){
				if(cnt%3==0){
					bcnt+=10;
				}else{
					bcnt+=5;
					scnt+=5;
				}
				cnt++;
			}
			ans[i]=bcnt*big+scnt*sml+a;
		}

		for(int i=0;i<ans.length;i++){
			System.out.println(ans[i]);
		}
	}
}

Measured memory_bytes: 27004
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

const int INF = 100000;

int main() {
  int H, W;
  cin >> H >> W;
  char maze[H][W];
  int whites = 0;
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> maze[i][j];
      if (maze[i][j] == '.') {whites++;}
    }
  }
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  
  int dist[H][W];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      dist[i][j] = INF;
    }
  }
  queue<P> que;
  
  dist[0][0] = 0;
  que.push(P(0, 0));
  
  while (!que.empty()) {
    P p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int qx = p.first + dx[i];
      int qy = p.second + dy[i];
      if (dist[qx][qy] == INF && maze[qx][qy] == '.' && 0 <= qx && qx < H && 0 <= qy && qy < W) {
        dist[qx][qy] = dist[p.first][p.second] + 1;
        que.push(P(qx, qy));
      }
    }
  }
  
  int ans;
  if (dist[H-1][W-1] == INF) {ans = -1;}
  else {
    int survive = dist[H-1][W-1] + 1;
    ans = whites - survive;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256