akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
ll num[100100];
int main()
{
	while(1)
	{
		int n,k;
		cin >> n >> k;
		if(n==0&&k==0)break;
		memset(num,0,sizeof(num));
		for(int i=1;i<=n;i++)
		{
			int p;
			cin >> p;
			num[i]=p;
		}
		for(int i=2;i<=n;i++)
		{
			num[i]+=num[i-1];
		}
		ll ans=-INF;
		for(int i=1;i<=n-k+1;i++)
		{
			ans=max(ans,num[i+k-1]-num[i-1]);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1944
# coding: utf-8
# Your code here!

def LI():return list(map(int,input().split()))

x=int(input())
# xは1<10**9
def make_divisor(x):
    pass

def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    return sorted(ass) #sortされていない
    
k=(divisor(x))
# l=len(k)
# print(k)
def f(a,b):
    return a**4+a**3*b+a**2*b**2+a*b**3+b**4
for i in k:
    # print(i)
    for a in range(0,int(x**0.5)+1):
        b=a-i
        # print("ab",a,b)
        # print(x//i,a**4+a**3*b+a**2*b**2+a*b**3+b**4)
        if x//i==f(a,b):
            print(a,b)
            exit()










# print(a,b)


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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

const ll INF = LLONG_MAX/4;

struct {
  struct edge { int to; ll cost; int rev; };
  int N;
  vector<vector<edge>> graph;
  vector<int> level;
  vector<int> iter;

  void init(int n) {
    graph.resize(n+1, vector<edge>());
    level.resize(n+1);
    iter.resize(n+1);
    N=n+1;
  }

  void add_edge(int from, int to, ll cost) {
    int r1 = graph[from].size();
    int r2 = graph[to].size();
    graph[from].push_back((edge){to, cost, r2});
    graph[to].push_back((edge){from, 0, r1});
  }

  void bfs(int s) {
    for(int i=0; i<N; i++) level[i] = -1;
    queue<int> que;
    level[s] = 0; que.push(s);
    while(!que.empty()) {
      int v = que.front(); que.pop();
      for(auto& e: graph[v]) {
        if (e.cost > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
      }
    }
  }

  ll dfs(int v, int t, ll f) {
    if (v == t) return f;
    for(int &i = iter[v]; i < graph[v].size(); i++) {
      iter[v] = i;
      edge &e = graph[v][i];
      if (e.cost > 0 && level[v] < level[e.to]) {
        ll d = dfs(e.to, t, min(f, e.cost));
        if (d > 0) {
          e.cost -= d;
          graph[e.to][e.rev].cost += d;
          return d;
        }
      }
    }
    return 0;
  }

  ll max_flow(int s, int t) {
    ll flow = 0;
    while(true) {
      bfs(s);
      if (level[t] < 0) return flow;
      for(int i=0; i<N; i++) iter[i] = 0;
      ll f;
      while((f = dfs(s, t, LLONG_MAX/4)) > 0) {
        flow += f;
      }
    }
  }
} D;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  D.init(n+1);
  ll ans = 0;
  for(int i=1; i<=n; i++) {
    ll c; cin >> c;
    if (c <= 0) {
      D.add_edge(0, i, -c);
    } else {
      D.add_edge(i, n+1, c);
      ans += c;
    }
    for(int k=i+i; k<=n; k+=i) {
      D.add_edge(i, k, INF);
    }
  }
  
  ll f = D.max_flow(0, n+1);
  debug(f);
  cout << ans-f << endl;
}

Measured memory_bytes: 256
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

import java.util.*;
import java.util.Collections; // sorting use
import java.io.*;
import static java.lang.System.*;

public class Main{
	public static void main(String[] args){
		int n;
		int cnt = 0;
		ArrayList<Integer> p = new ArrayList<Integer>(53);
		Scanner sc = new Scanner(System.in);

		p.add(0);
		n = sc.nextInt();
		for (int i = 1; i <= n; ++i) {
			p.add(sc.nextInt());
			if(p.get(i) != i)	++cnt;
		}
		if(cnt >= 3)	out.println("NO");
		else out.println("YES");
	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
const int maxn=2005;
int n,L[maxn],R[maxn],bj[maxn],mx,mi,ans; int tota,totb,len,que[maxn];
char a[maxn],b[maxn];
int cmpL(int a,int b) { return L[a]<L[b]; } int cmpR(int a,int b) { return R[a]<R[b]; }
int main() {
    scanf("%s%s",a+1,b+1); n=strlen(a+1); ans=2e9;
    for (int i=1;i<=n;++i) { if (a[i]=='1') tota++; if (b[i]=='1') totb++; } if (!totb) { if (!tota) return puts("0"),0; return puts("-1"),0; }
    for(int i=1;i<=n;++i){int ind=i,cnt=0;while(b[ind]!='1'){ind--;cnt++;if(ind==0)ind=n;}L[i]=cnt;ind=i;cnt=0;while(b[ind]!='1'){ind++;cnt++;if (ind==n+1)ind=1;}R[i]=cnt;}
    for (int i=1;i<=n;++i) {
      int ind,sum=0; if (i==1) ind=1; else ind=n-i+2; for (int j=1;j<=n;++j) bj[j]=0; for (int j=1;j<=n;++j) { if (a[ind]!=b[j]) sum++,bj[ind]=1; ind++; if (ind>n) ind=1; }
      int cnt; if (i==1) cnt=0; else cnt=n-i+1; len=0; for (int j=1;j<=n;++j) if (bj[j] && L[j]>cnt) que[++len]=j;
      sort(que+1,que+1+len,cmpR);mx=0;mi=2e9;if(len>0)mi=min(mi,R[que[len]]*2+cnt);for(int j=len;j>=1;--j){mx=max(mx,L[que[j]]);if(j>1)mi=min(mi,R[que[j-1]]*2+mx*2-cnt);}
      if (len>0) mi=min(mi,mx*2-cnt); if (!len) mi=cnt; ans=min(ans,mi+sum); cnt=i-1; len=0; for (int j=1;j<=n;++j) if (bj[j] && R[j]>cnt) que[++len]=j;
      sort(que+1,que+1+len,cmpL);mx=0;mi=2e9;if(len>0)mi=min(mi,L[que[len]]*2+cnt);for(int j=len;j>=1;--j){mx=max(mx,R[que[j]]);if (j>1) mi=min(mi,L[que[j-1]]*2+mx*2-cnt); }
      if (len>0) mi=min(mi,mx*2-cnt); if (!len) mi=cnt; ans=min(ans,mi+sum);
    } 
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
n, m, l = gets.chomp.split.map(&:to_i)

mat01 = Array.new(n) do
    Array.new(m)
end

mat02 = Array.new(m) do
    Array.new(l)
end

n.times do |i|
    mat01[i] = gets.chomp.split.map(&:to_i)
end

m.times do |i|
    mat02[i] = gets.chomp.split.map(&:to_i)
end

n.times do |i|
    l.times do |j|
        unless j == 0
            print " "
        end

        c = 0
        m.times do |k|
            c += mat01[i][k] * mat02[k][j]
        end
        print c
    end
    puts ""
end

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

int main()
{
    std::vector<int> a(3);
    for (int i = 0; i < 3; i++) {
        std::cin >> a[i];
    }

    std::sort(a.begin(), a.end());

    std::cout << a[2] - a[0] << std::endl;
}


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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var Instance = new Question();
			Instance.Exec();
		}
	}

	public class Question
	{
		void swap(ref long x, ref long y)
		{
			long temp = y;
			y = x;
			x = temp;
		}

		public void Exec()
		{
			var array = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
			long a = array[0];
			long b = array[1];
			long c = array[2];
			int count = 0;
			for (var i = a; i <= b; ++i) {
				if (c % i == 0) {
					++count;
				}
			}

			Console.WriteLine($"{count}");

			Console.ReadKey();
		}
	}
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

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

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



int n;
int b[101010] = {0};
void solve(){
	cin >> n;
	cout << 0 << endl;
	string s;
	cin >> s;
	if(s == "Vacant") return;
	if(s == "Male") b[0] = 1;
	if(s == "Female") b[0] = 2;
	
	int l = 0, r = n;
	while(1){
		int c = (l+r)/2;
		cout << c << endl;
		string re;
		cin >> re;
		if(re == "Vacant") return;
		if(re == "Male") b[c] = 1;
		if(re == "Female") b[c] = 2;
		
		if((b[c] ^ b[l] ^ (c-l)) & 1) r = c;
		else l = c;
	}
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 972
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder fr = new StringBuilder();
        StringBuilder be = new StringBuilder();
        boolean isFront = true;
        String S = sc.next();
        int Q = sc.nextInt();
        for(int i = 0; i < Q; i++) {
            int q = Integer.parseInt(sc.next());
            if(q == 1) {
                isFront = !isFront;
            } else {
                int f = Integer.parseInt(sc.next());
                if(f == 1) {
                    if(isFront) fr.append(sc.next());
                    else be.append(sc.next());
                } else {
                    if(isFront) be.append(sc.next());
                    else fr.append(sc.next());
                }
            }
        }
        S = reverse(fr.toString()) + S + be.toString();
        if(!isFront) {
            S = reverse(S);
        }
        System.out.println(S);
    }
    static String reverse(String s) {
        char[] ca = s.toCharArray();
        for(int i = 0; i < ca.length / 2; i++) {
            char t = ca[i];
            ca[i] = ca[ca.length - i - 1];
            ca[ca.length - i - 1] = t;
        }
        return String.valueOf(ca);
    }
}


Measured memory_bytes: 89012
#include<bits/stdc++.h>
using namespace std;
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define f(i,a,n)        for(int i=a;i<n;i++)
#define ve              vector
#define ss              second 
#define ff              first
#define pf              pop_front
#define pob             pop_back
#define psf             push_front
#define res(x)          cout<<x<<'\n'
#define read(t)         ll t;cin>>t

    

int main(){
  ll n;
  cin>>n;
  unordered_map<ll,ll>mp;
  ll sum=0;
  f(i,0,n){
      read(x);
      mp[x]++;
      sum+=x;
  }
  ll q;
  cin>>q;
  f(i,0,q){
      read(x);
      read(y);
      sum=sum-x*mp[x]+mp[x]*y;
      cout<<sum<<endl;
      mp[y]+=mp[x];
      mp[x]=0;
  }
}


Measured memory_bytes: 6932
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
const int MAX_SUM = 1e5;
const ll INF = LLONG_MAX;
 
int main () {
  ll n, W;
  cin >> n >> W;
  vector <ll> w(n), v(n);
  for (int i = 0; i < n; i++) cin >> w[i] >> v[i];
  vector <ll> dp(MAX_SUM + 1, INF);
  for (int i = 0; i < n; i++) {
    vector <ll> newDP(MAX_SUM + 1, INF);
    newDP[v[i]] = w[i];
    for (int j = 1; j <= MAX_SUM; j++) {
      newDP[j] = min(newDP[j], dp[j]);
      if (dp[j] < INF and j + v[i] <= MAX_SUM) newDP[j + v[i]] = min(newDP[j + v[i]], dp[j] + w[i]);
    }
    dp = newDP;
  }
  ll ans = 0;
  for (int val = 1; val <= MAX_SUM; val++) if (dp[val] <= W) ans = val;
  cout << ans << endl;
  return (0);
}

Measured memory_bytes: 1792
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 
vector<int> A;
vector<int> B;
int N;
int cnt;

int binary(int target){
    int left=0;
    int right;
    right = cnt; //n-1ではなくnなのは右端に解がある時のため
    int mid;
    if(target > B[0]){
        return 0;
    }else if(B[cnt-1] >= target){
        return N;
    }else{
        while(left<right){ //二分探索
            mid = (left+right)/2;
            if(target > B[mid] && B[mid-1] >= target){
                return mid;
            }else if(target > B[mid]){
                right = mid;
            }else if(B[mid] >= target){
                left = mid;
            }
        }
    }
}



int main(){
    cnt = 1;
    cin >> N;
    int tmp;
    cin >> tmp;
    A.push_back(tmp);

    int border_min;

    B.push_back(A[0]);
    int index;
    for( int ni = 1 ; ni <N ; ni++ ){
        cin >> tmp;
        A.push_back(tmp);
        index = binary(tmp);

        if(index==N){
            B.push_back(A[ni]);
            cnt++;
        }else{
            B[index] = A[ni];
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		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 {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

/////////////////////////////////////

int main() {
	ll A, B;
	cin >> A >> B;
	ll N = A + B;

	if (B >= A) {
		cout << "Impossible" << endl;
		return 0;
	}

	vector<ll> lis;
	ll c = 0;

	while (c < N) {
		if (lis.size() == 0) { lis.push_back(c);}
		else {
			ll x = lis[lis.size() - 1];
			cout << "? " << x << " " << c << endl;
			char ans;
			cin >> ans;
			if (ans == 'Y') { lis.push_back(c); }
			else { lis.pop_back(); }
		}
		c++;
	}

	ll hon = lis[lis.size() - 1];
	vector<ll> s(N);
	rep(i, N) {
		cout << "? " << hon << " " << i << endl;
		char ans;
		cin >> ans;
		if (ans == 'Y') { s[i] = 1; }
		else { s[i] = 0; }
	}

	cout << "! ";
	rep(i, N)cout << s[i];
	cout << endl;

	
}


Measured memory_bytes: 3780
import java.util.*;
class Main {
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		if((C-(A-B))>=0) {
		System.out.println(C-(A-B));}else {
			System.out.println(0);
		}
	}
}

Measured memory_bytes: 23124
import sys
import itertools
# import numpy as np
import time
import math
import heapq
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
# list(map(int, input().split()))

N = int(input())

ans = 1
for i in range(2, N + 1):
    x = N // i
    ans += i * ((x + 1) * x // 2 + 1)
print(ans)

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    string s; cin >> s;

    if(s.size()%2 != 0){ cout << "No" << endl; return 0;}
    for (int i = 0;i < s.size();i+=2){
        if(s[i] == 'h' && s[i+1] == 'i') continue;
        else{
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

	return 0;

}

Measured memory_bytes: 256
#include <cstdio>

int main(void)
{
    int n,a,b,c,d;
    long long w;
    int i;

    //freopen("x.in","r",stdin);

    scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);
    --n;

    for(i = 0;i <= n;++i)
    {
        w = a + 1ll * c * i - 1ll * d * (n - i);
        if(w > b)
            continue;
        if(b - w <= 1ll * (d - c) * n)
            return puts("YES"),0;
    }
    puts("NO");

    return 0;
}

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

#define ll long long
#define ld long double
#define xx first
#define yy second
#define vi vector<int>
#define pii pair<int,int>
#define all(v) v.begin(),v.end()

#define MAX 400005

vector<ll> h(MAX), g[MAX];

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

    ll n, m, u, v;
    cin >> n >> m;

    for(int i=1;i<=n;i++)
    {
        cin >> h[i];
    }

    for(int i=1;i<=m;i++)
    {
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        ll elv = h[i];
        ll tru=1;

        for(ll x: g[i])
        {
            if(h[x] >= elv) tru=0;
        }

        if(tru) ans++;
    }

    cout << ans << endl;


    return 0;
}

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

#define int long long
typedef pair<string, string> P;

int N;
string s;

signed main() {
  cin >> N >> s;

  map<P, int> cnt;  
  for ( int i = 0; i < (1<<N); i++ ) {
    string a = "", b = "";    
    for ( int j = 0; j < N; j++ ) {
      if ( i & (1<<j) ) a += s[j];
      else b += s[j];      
    }
    //cout << a << " " << b << endl;
    cnt[P(a, b)]++;    
  }

  int ans = 0;
  for ( int i = 0; i < (1<<N); i++ ) {
    string a = "", b = "";    
    for ( int j = N; j < 2*N; j++ ) {
      if ( i & (1<<(j-N)) ) a += s[j];
      else b += s[j];      
    }    
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    //cout << a << " " << b << endl;
    ans += cnt[P(b, a)];    
  }

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


Measured memory_bytes: 87040
#include<bits/stdc++.h>
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define Fr(i,a,b) for(int i=a;i<=b;i++)
#define RF(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<ll,int>
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define vpii vector<pii>
#define int long long
using namespace std;
vi a;vi bb;
int dp[405][405];
int rec(int l,int r){
    if(l==r){
        return 0;
    }
    if(dp[l][r]!=-1){
        return dp[l][r];
    }
    int u=1e18;
    for(int i=l;i<r;i++){
        u=min(u,rec(l,i)+rec(i+1,r)+bb[r+1]-bb[l]);
    }
    return dp[l][r]=u;
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   
    int t=1;

    while(t--){
        int n;
        cin>>n;
        a.clear();bb.clear();
        int x;
        bb.pb(0);
        for(int i=0;i<n;i++){
            cin>>x;
            int u=bb[bb.size()-1];
            bb.pb(u+x);
        }
        memset(dp,-1,sizeof(dp));
        cout<<rec(0,n-1)<<endl;
    }
    return 0;
} 

Measured memory_bytes: 1536
# Vector class
class Vector:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def is_orthogonal(self, v):
        if self.x * v.x + self.y * v.y == 0:
            return True
        else:
            return False
    def is_parallel(self, v):
        if self.x * v.y - self.y * v.x == 0:
            return True
        else:
            return False
    def dot_product(self, v):
        return self.x * v.x + self.y * v.y
    def quadrance(self):
        return self.x ** 2 + self. y ** 2
    def mul(self, k):
        return Vector(self.x * k, self.y *k)
    def __add__(self, v):
        return Vector(self.x + v.x, self.y + v.y)
    def __sub__(self, v):
        return Vector(self.x - v.x, self.y - v.y)
    def __str__(self):
        return "{0:.8f} {1:.8f}".format(self.x, self. y)
    def projection_on(self, v):
        return v.mul(self.dot_product(v) / v.quadrance())
    def rejection_from(self, v):
        return self - self.projection_on(v)

# Acceptance of input and Print the reflection point
import sys

file_input = sys.stdin

x_p1, y_p1, x_p2, y_p2 = map(int, file_input.readline().split())
p1_p2 = Vector(x_p2 - x_p1, y_p2 - y_p1)

q = int(file_input.readline())

for line in file_input:
    x_p, y_p = map(int, line.split())
    p1_p = Vector(x_p - x_p1, y_p - y_p1)
    r_v = p1_p.rejection_from(p1_p2)
    o_p = Vector(x_p, y_p)
    print(o_p - r_v.mul(2))

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll MOD = (ll)pow(10.0, 9.0) + 7;
pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll min(ll a, ll b)
{

	return (a < b) ? a : b;
}

ll max(ll a, ll b) { return (a > b) ? a : b; }
template<typename T>
struct edge {

	int src, to;
	T cost;

	edge(int to, T cost) : src(-1), to(to), cost(cost) {}

	edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

	bool operator<(const edge<T> e1) {
		return cost < e1.cost;
	}


	edge &operator=(const int &x) {
		to = x;
		return *this;
	}

	operator int() const { return to; }

};
template<typename T>
using Edge = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edge<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;


template<typename T>
vector<T> dijkstra(WeightedGraph<T> &g, int s) {
	const auto INF = numeric_limits<T>::max();
	vector<T> dist(g.size(), INF);

	using Pi = pair<T, int>;

	priority_queue<Pi, vector<Pi>, greater<Pi>> q;

	dist[s] = 0;

	q.emplace(dist[s], s);

	while (!q.empty()) {
		T cost;
		int idx;

		tie(cost, idx) = q.top();
		q.pop();
		if (dist[idx] < cost) continue;

		for (auto &e : g[idx]) {
			auto next_cost = cost + e.cost;
			if (dist[e.to] <= next_cost) continue;
			dist[e.to] = next_cost;
			q.emplace(dist[e.to], e.to);

		}
	}
	return dist;
}


ll H, W, K;

char A[805][805];

int ceil(int a, int K) {
	if (a < K)
		return 1;

	else if (a % K == 0)
		return a / K;
	
	return ((a / K) + 1);
}

int main() {

	cin >> H >> W >> K;

	WeightedGraph<ll> e2(2 * H * W);
	ll sx, sy;
	auto in = [&](int x, int y) {return x >= 0 && y >= 0 && x < H && y < W; };
	auto idx = [&](int x, int y) { return W * x + y; };

	rep(i, H)
		rep(j, W)
		cin >> A[i][j];


	rep(i, H) {
		rep(j, W) {
			if (A[i][j] == 'S') { sx = i; sy = j; }

			rep(k, 4) {
				int nx = i + dx[k].first, ny = j + dx[k].second;
				if (in(nx, ny) && A[nx][ny] != '#' && A[i][j] != '#') e2[idx(i, j)].emplace_back(idx(nx, ny), 1);
			}

		}
	}


	vector<ll> dist2 = dijkstra(e2, idx(sx, sy));


	ll m1 = inf;


	rep(i, H) {
		rep(j, W) {
			if (dist2[idx(i, j)] <= K) {
				m1 = min(m1, min(H - 1 - i, i));
				m1 = min(m1, min(W - 1 - j, j));
			}
		}

	}

	
	if (m1 != 0) {
		cout << (1 + ceil(m1, K)) << endl;
	}
	else {
		cout << 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 89856
# -*- coding: utf-8 -*-
from collections import Counter

n, k = list(map(int,input().split()))
a = list(map(int,input().split()))
counter = Counter(a)
if(k-len(counter)>=0):
    print(0)
else:
    ans = 0
    r = counter.most_common()
    for i in range(len(counter)-k):
        ans += r[len(r)-i-1][1]
    print(ans)

Measured memory_bytes: 39352
def solve(S):
  if 'N' in S and 'S' not in S: return False
  if 'S' in S and 'N' not in S: return False
  if 'E' in S and 'W' not in S: return False
  if 'W' in S and 'E' not in S: return False 
  return True
print('Yes' if solve(input()) else 'No')

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  string s; cin >> s;
  if (isupper(s[0])) {
    cout << 'A' << endl;
  } else {
    cout << 'a' << endl;
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

using namespace std;

//#がある行・列だけ出力
//まず#の場所を取得
int main(){
    int H,W;
    cin >> H >> W;
    string masu[H];
    for(int i=0;i<H;i++) cin >> masu[i];

    vector<int> h;
    vector<int> w;

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(masu[i][j]=='#'){
                h.push_back(i);
                w.push_back(j);
            }
        }
    }

    sort(h.begin(),h.end());
    h.erase(unique(h.begin(),h.end()),h.end());

    sort(w.begin(),w.end());
    w.erase(unique(w.begin(),w.end()),w.end());

    typedef vector<int>::iterator itr;
    for(itr it=h.begin();it!=h.end();it++){
        for(itr it2=w.begin();it2!=w.end();it2++){
            cout << masu[*it][*it2];
        }
        cout << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define _ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

#define sll(x) scanf("%I64d",&x)
#define sd(x)  scanf("%d",&x)
#define pll(x) printf("%I64d",x)
#define pd(x)  printf("%d",x)

#define clr(x) memset(x,0,sizeof x)
#define sf .second.first
#define ss .second.second
#define mid    ((l+r)>>1)
#define Pi acos(-1)
#define EPS 1e-12
#define MOD  1000000007
#define MOD1 1000000009
#define INF  1000000000

#define N 100005

string a,b;
int n,m;
int dp[4000][4000];


int main()
{
    _
    cin >>a>>b;
    n=a.size();
    m=b.size();

    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(i==0||j==0)
            dp[i][j]=0;
            else if(a[i-1]==b[j-1]){
                dp[i][j]=dp[i-1][j-1]+1;

                }

            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }

        }
    }
    int i=n,j=m;
    int cnt=dp[n][m];
    string ans;
    while(i>0&&j>0&&cnt){
        if(a[i-1]==b[j-1]){
            ans+=a[i-1];
            j--;i--;cnt--;
        }
        else{
            if(dp[i][j-1]>dp[i-1][j]){
                j--;
            }else{
                i--;
            }
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;


    //cout<<dp[n-1][m-1]<<endl;

    //cout<<dp[n][w]<<endl;
    return 0;
}


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

int main() {
    int N;
  int A;
  int B;
  
  cin>>N;
  
  if(N==1){
    cout<<"Hello World"<<endl;
    return 0;
  }
  
  if(N==2){
    cin>>A>>B;
    cout<<A+B<<endl;
  }
  
  
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
  int i, j, k, b, d, n, m;

  char buf[16] = {0};
  char *p;
  buf[15] = '\0';
  buf[14] = '\n';
  char *line = NULL;
  size_t linecap = 0;
  fgets(buf, 15, stdin);
  n = atoi(buf);
  int *a = (int*)malloc(sizeof(int)*n);
  getline(&line, &linecap, stdin);
  a[0] = 0;  
  i=0;
  for (p=line; *p!='\n'; p++) {
    if (*p == ' ') {
      i++;
      p++;
      a[i] = *p-'0';
    } else {
      a[i] = a[i] * 10 + *p - '0';
    }
  }
  fgets(buf, 15, stdin);
  m = atoi(buf);
  
  getline(&line, &linecap, stdin);
  p=line;
  i = j = 0;
  for (b = 0; *p>='0'; b = b * 10 + *(p++) - '0');
  p++;

  while (i<n-1) {
    if (a[i]<b) {
      d=a[i++];
      if (d==0) {
	fputs("0\n", stdout);
      } else {
	for (k=13; d>0; k--, d/=10)   buf[k] = '0' + (d%10);
	fputs(buf+k+1, stdout);
      }
    } else if (a[i]>b) {
      if (j<m-1) {
	for (b = 0; *p>='0'; b = b * 10 + *(p++) - '0');
	p++;
	j++;
      } else {
	d=a[i++];
	for (k=13; d>0; k--, d/=10)   buf[k] = '0' + (d%10);
	fputs(buf+k+1, stdout);
      }
    } else {
      i++;
      if (j<m-1) {
	for (b = 0; *p>='0'; b = b * 10 + *(p++) - '0');
	p++;
	j++;
      }
    }
  }
  for (; j<m; j++) {
    if (a[i]==b) break;
    for (b = 0; *p>='0'; b = b * 10 + *(p++) - '0');
    p++;
  }
  if (j==m) {
    d = a[i];
    if (d==0) {
      fputs("0\n", stdout);
    } else {
      for (k=13; d>0; k--, d/=10)   buf[k] = '0' + (d%10);
      fputs(buf+k+1, stdout);
    }
  }
  
  return 0;
}




Measured memory_bytes: 4448
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

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

  vector<vector <int> > node;
  vector<int> visited(N,0);
  vector<int> parent(N,0);
  vector<int> color(N,0);


  for(int i=0;i<N;i++){
	vector<int> tmp;
	node.push_back(tmp);
  }

  for(int i=0;i<N-1;i++){
	cin >> a >> b;
	node[a-1].push_back(b-1);
	node[b-1].push_back(a-1);
  }

  queue<int> q;

  q.push(0);
  visited[0]=1;
  color[0]=1;
  int num1=1;

  q.push(N-1);
  visited[N-1]=1;
  color[N-1]=-1;
  int num2=1;

  while(!q.empty()){
	int pos=q.front();
	q.pop();
	int size=node[pos].size();
	for(int i=0;i<size;i++){
	  int next=node[pos][i];
	  if(visited[next]==0){
		visited[next]=visited[pos]+1;
		parent[next]=pos;
		q.push(next);
		color[next]=color[pos];
		if(color[pos]>0){
		  num1++;
		}else{
		  num2++;
		}
	  }
	}
  }

  if(num1>num2){
	cout << "Fennec" << endl;
  }else {
	cout << "Snuke" << endl;
  }

  return 0;
}


Measured memory_bytes: 7536
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <functional>
#include <set>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main() {
	int X, N, diff=100, ans;
	ll K, num=0;
	set<int> st;

	cin >> X >> N;
	vector<int> p(N);

	rep(i,N) cin >> p[i];
	rep(i, N) st.insert(p[i]);

	rep(i, 102){
		if (st.count(i) == 0){
			if (diff > abs(X - i)){
				diff = abs(X - i);
				ans = i;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <utility>
using namespace std;

int main() {
	long long N;
	cin >> N;
	long long A[N];
	for(int i=0; i<N; i++){
		cin >> A[i];
	}
	
	sort(A,A+N);
	
	long long x=0,y=0;
	
	int cnt=0;
	long long tmp=A[0];
	for(int i=0; i<N; i++){
		if(tmp==A[i]){
			cnt++;
		}else{
			cnt=1;
			tmp=A[i];
		}
		
		if(cnt==2){
			if(x<=tmp){
				y=x;
				x=tmp;
				cnt=0;
			}
		}
	}
	cout<<x*y<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
int main(void)
{
    int n,i,a[100],flg[8],b=0,c=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
	    scanf("%d",&a[i]);
	}
	for(i=0;i<8;i++) flg[i]=0;
	for(i=0;i<n;i++){
	    if(a[i]<400) flg[0]=1;
		else if(a[i]<800) flg[1]=1;
		else if(a[i]<1200) flg[2]=1;
		else if(a[i]<1600) flg[3]=1;
		else if(a[i]<2000) flg[4]=1;
		else if(a[i]<2400) flg[5]=1;
		else if(a[i]<2800) flg[6]=1;
		else if(a[i]<3200) flg[7]=1;
		else if(a[i]>=3200) b++;
	}
	for(i=0;i<8;i++){
	    if(flg[i]==1){
		    b++;
			c++;
		}
	}
	if(c==0) c=1;
	printf("%d %d\n",c,b);
	return 0;
}

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

template <class t>
using vc = vector<t>;
template <class t>
using vvc = vector<vector<t>>;
typedef long long ll;
typedef vc<int> vi;
typedef vvc<int> vvi;
typedef pair<int, int> pi;

#define uset unordered_set
#define umap unordered_map

#define endl "\n"

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()

#define all(a) a.bg, a.ed

template <class t, class u>
ostream &operator<<(ostream &os, const pair<t, u> &p) {
    return os << "( " << p.k << ", " << p.v << " )";
}

template <class t>
ostream &operator<<(ostream &os, const vc<t> &v) {
    os << "[ ";
    for (int i = 0; i < v.size(); i++) {
        os << v[i];
        if (i != v.size() - 1) {
            os << ", ";
        }
    }
    return os << " ]";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // cout << fixed << setprecision(18);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution

    int n;
    cin >> n;
    int a[n];
    int twos_only = 0;
    int fours = 0;
    int odd = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] % 2 == 0 && a[i] % 4) {
            twos_only++;
        } else if (a[i] % 4 == 0) {
            fours++;
        } else {
            odd++;
        }
    }
    if (twos_only == 0) {
        cout << (fours >= n / 2 ? "Yes\n" : "No\n");
    } else {
        int left = n - twos_only + 1;
        cout << (fours >= left / 2 ? "Yes\n" : "No\n");
    }
}


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

int main(){
  string S;
  string T;
  cin >> S >> T;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] != T[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  string ans = "";
  for(int i = 0; i < S.size(); i++){
    char T = S.at(i);
    char A;
    
    A = T + N;
    if(A > 'Z') A = A - 26; 
    ans += A;
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main() {
    cin>>N>>K;
    ll ans = 0;
    while(N > 0) {
        ++ans;
        N /= K;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define si set <ll>
#define vi vector <ll>
#define popcount(x) __builtin_popcountll(x)
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define mem0(a) memset(a,0,sizeof(a))
#define rep(i,a,n) for( ll i=a ; i<n ; i++)
#define ld long double
#define rall(a) (a).rbegin(),(a).rend()

ll power(ll b,ll e,ll m)
{
  if(e==0) return 1;
  if(e&1) return b*power(b*b%m,e/2,m)%m;
  return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
  if(e==0) return 1;
  if(e&1) return b*power(b*b,e/2);
  return power(b*b,e/2);
}  
bool isPowerOfTwo(ll x)
{
    // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
    return (x && !(x & (x - 1)));
} 

void solve()
{
  string s;
  cin>>s;
  if(s[1]=='B') cout<<"ARC";
  else cout<<"ABC";
}
int main()       
{
  fastio
  ll tt=1;
  while(tt--)
  {
    solve();
    cout<<"\n";
  }
  return 0;
}

Measured memory_bytes: 3504
from sys import exit
s=input()
x,y=map(int,input().split())

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

s=groupby(s)
a,b=[],[]
turn=True
#初めまっすぐの場合
if s[0][0]=="F":
    x-=s[0][1]
    s.pop(0)
for i in s:
    if i[0]=="F":
        if turn:
            a.append(-i[1])
        else:
            b.append(-i[1])
    elif i[1]%2==1:
        turn=not turn
a.sort()
b.sort()
for i in a:
    x=abs(x)-abs(i)
if x!=0:
    print("No")
    exit()
for i in b:
    y=abs(y)-abs(i)
if y!=0:
    print("No")
    exit()
print("Yes")


Measured memory_bytes: 41200
#include <cstdio>
#include <iostream>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
int h,w;
char mp[22][22];
bool vis[22][22];
int xx[4]={0,0,1,-1};
int yy[4]={1,-1,0,0};
int bfs(int sx,int sy,int ex,int ey){
	queue<int> qx;
	queue<int> qy;
	queue<int> dis;
	for(int i=0;i<22;i++)for(int j=0;j<22;j++)vis[i][j]=false;
	qx.push(sx);
	qy.push(sy);
	dis.push(0);
	//cout<<"???"<<endl;
	while(!qx.empty()){
		int dx=qx.front();qx.pop();
		int dy=qy.front();qy.pop();
		//cout<<dx<<" "<<dy<<endl;
		int ddis=dis.front();dis.pop();
		if(dx==ex&&dy==ey)return ddis;
		for(int i=0;i<4;i++){
			int tx=dx+xx[i];
			int ty=dy+yy[i];
			if(tx>=0&&tx<h&&ty>=0&&ty<w&&!vis[tx][ty]&&mp[tx][ty]=='.'){
				qx.push(tx);
				qy.push(ty);
				dis.push(ddis+1);
				vis[tx][ty]=true;
			}
		}
	}
	return 0;
}
int main()
{
    //freopen("a.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>h>>w;
    for(int i=0;i<h;i++){
    	for(int j=0;j<w;j++){
    		cin>>mp[i][j];
    	}
    }
    /*for(int i=0;i<h;i++){
    	for(int j=0;j<w;j++){
    		cout<<mp[i][j];
    	}
    	cout<<endl;
    }*/
    int ans=0;
    for(int i=0;i<h;i++){
    	for(int j=0;j<w;j++){
    		for(int is=0;is<h;is++){
    			for(int ie=0;ie<w;ie++){
    				if(mp[i][j]=='.'&&mp[i][j]==mp[is][ie])ans=max(ans,bfs(i,j,is,ie));
    				//cout<<ans<<endl;
    			}
    		}
    	}
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    int b,d;
    if(k!=0) b=log2(k)+1;
    else b=0;
    ll e=0,f=0;
    for(int j=b-1;j>=0;j--){
        d=0;
        for(int i=0;i<n;i++){
            if(((a[i]>>j)&1)==1) d++;
        }
        if(d<=n/2){
            f=e+(1LL<<j);
            if(f<=k) e=f;
        }
    }
    ll h=0;
    for(int i=0;i<n;i++) h+=e^a[i];
    cout<<h<<endl;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  int d, x;
  cin >> d >> x;
  rep(i, n) {
    int a;
    cin >> a;
    rep(j, d) {
      if (j * a + 1 > d) break;
      x++;
    }
  }
  cout << x << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int  long long int
#define ld 	 long double
#define F 	 first
#define S 	 second
#define P 	 pair<int,int>
#define pb 	 push_back
#define mod  1000000007
#define inf  1e18
#define endl '\n'
const int N = 1e4 + 5; //change it when needed
int cache[N][105][2];
string K;
int  D;
int dp(int pos, int d, int tight) {
	int ub = (tight == 1) ? K[pos] - '0' : 9;
	if (pos == K.size() - 1) {
		int ans = 0;
		for (int i = 0; i <= ub; i++) {
			if (i % D == d) {
				ans++;
			}
		}
		return ans;
	}
	int &ans = cache[pos][d][tight];
	if (ans != -1)return ans;
	ans = 0;
	for (int i = 0; i <= ub; i++) {
		ans = (ans + dp(pos + 1, (D + d - i % D) % D, (tight & (i == ub)))) % mod;
	}
	return ans;
}
void solve() {

	cin >> K >> D;
	memset(cache, -1, sizeof(cache));
	cout << (mod + dp(0, 0, 1) - 1) % mod;
	//last -1 is because of 00000000 case
	// I am adding it to my answer
}

int32_t main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	// int t; cin >> t; while (t--)
	solve();
	return 0;
}

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

int main() {
    int i, j, a, b;
    cin >> i >> j;
    a = i % 2019;
    b = j % 2019;

    int mini = 2018;

    for (int k = a; k < b ; k++) {
        for (int l = a + 1; l < b + 1 ; l++) {
            mini = min ( ((k * l) % 2019) , mini);
        }
    }

    if ( b <= a)
        mini = 0;
    if ( j  - i >= 2018)
        mini = 0;

    cout << mini << endl;

}


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

int a,b,result;
string op;

int main(){
    while(1){
    cin>>a>>op>>b;
    if(op == "?"){
        break;
    }
    if(op == "+"){
        result=a+b;
    }
    else if(op == "-"){
        result=a-b;
    }
    else if(op == "*"){
        result=a*b;
    }
    else if(op == "/"){
        result=a/b;
    }
    cout<<result<<endl;
    }
    return 0;
}


Measured memory_bytes: 3140
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  string s; cin >> s;
  map<int, int> mp;
  for (char c : s) ++mp[c];
  cout << (mp.size() == 2 ? "Yes\n" : "No\n");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <algorithm>
#include <cctype>
using namespace std;
int main(){
    
    string key, t;
    int sum=0;
    
    cin >> key;
    while(1){
        cin >> t;
        if(t == "END_OF_TEXT"){
            break;
        }
        
        transform(t.begin(), t.end(), t.begin(), ::tolower);
        
        if(t == key){
            sum++;
        }
    }
    
    cout << sum << endl;
    
    return 0;
}


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

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  if (s[0] == '7' || s[1] == '7' || s[2] == '7')
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n,p;
int s[200005];
int f[200005];
map<int,int> mp;
int qpow(int x)
{
	int res=1,cur=10;
	while(x)
	{
		if(x&1) res*=cur;
		res%=p;
		cur=cur*cur%p;
		x>>=1;
	}
	return res;
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>p;
	for(int i=1;i<=n;i++)
	{
		char c;
		cin>>c;
		s[i]=c-'0';
	}
	if(p==2)
	{
		int ans=0;
		for(int i=1;i<=n;i++)
			if(s[i]%2==0)
				ans+=i;
		cout<<ans<<endl;
		return 0;
	}
	else if(p==5)
	{
		int ans=0;
		for(int i=1;i<=n;i++)
			if(s[i]%5==0)
				ans+=i;
		cout<<ans<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++)
		f[i]=(f[i-1]+s[i]*qpow(n-i))%p;
	for(int i=1;i<=n;i++)
		mp[f[i]]++;
	int ans=0;
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
		ans+=it->second*(it->second-1)/2;
	ans+=mp[0];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3968
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
const int INF = 1001001001;

int main()
{
    int n;
    in n;
    vector<int> a(n);
    rep(i,n)in a[i];
    sort(a.begin(), a.end());
    cout<<a[a.size()-1]-a[0]<<endl;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 110


signed main()
{
    int H, W;
    vector<string> ans;
    cin >> H >> W;
    string header = "";
    REP(i, W + 2) { header += '#'; }
    ans.push_back(header);
    REP(i, H) {
        string s;
        cin >> s;
        ans.push_back('#' + s + '#');
    }
    ans.push_back(header);
    REP(i, ans.size()) {
        printf("%s\n", ans[i].c_str());
    }

    return 0;
}


Measured memory_bytes: 256
# n人の人に聞く、m個のメニューの好き嫌い
n, m = gets.split(" ").map(&:to_i)
menu = []
m.times do
  menu << 0
end

n.times.each do |n|
  fav = gets.split(" ").map(&:to_i)
  fav_num = fav[0]
  fav.shift # fav[0]を削除
  fav_num.times.each do |i|
    menu[fav[i]-1] += 1
  end
end

count = 0
menu.each do |num|
  count += 1 if num == n
end

puts count


Measured memory_bytes: 1788