akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n;

	while (scanf("%d", &n), n) {
        int s[5001];

		for (int i = 1; i <= n; ++i) {
			int a; scanf("%d", &a);
			s[i] = a + s[i - 1];
		}

        int ma = -100000;

		for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j) {
			ma = max(ma, s[i] - s[j - 1]);
		}

		printf("%d\n", ma);
	}
}

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

using namespace std;

int h, w;
char grid[1002][1002];
int memo[1002][1002] = {};
const int M = 1000000007;
int dp(int row, int col)
{
    if (row > h - 1 || col > w - 1)
        return 0;
    if (grid[row][col] == '#')
        return 0;
    if (memo[row][col] > 0)
        return memo[row][col] - 1;
    if (row == h - 1 && col == w - 1)
        return 1;
    int best = 0;
    best = dp(row + 1, col) + dp(row , col + 1);
    best %= M;
    memo[row][col] = best + 1;
    return best;
}

int main(void)
{
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    scanf("%d %d", &h, &w);
    for (int i = 0; i < h; i++)
    {
        scanf("%s", grid[i]);
    }
    int best;
    best = dp(0, 0);
    printf("%d\n", best);
    
}

Measured memory_bytes: 8704
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('\n');
   let xs1 = xs[0].trim().split(' ').map(v=>parseInt(v,10));
   let N = Number(xs1);
   let ans = 0;
   for(let i= 1; i<= N; i++){
    var l = xs[i].split(" ")[0];
    var r = xs[i].split(" ")[1];
    ans += (r - l) + 1;
  }
  console.log(ans);
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7612
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n),cnt(1e6+10);
    for(auto &i:a) cin>>i;
    for(auto &i:cnt) i=0;

    bool s=false,nt=false;

    int tmp = a[0];
    for(auto &i:a){
        tmp = __gcd(i,tmp);
    }
    if(tmp>=2) nt=true;

    for(auto &i:a){
        if(cnt[i]) s=true;
        if(i!=1){
            cnt[i]++;
        }
    }
    
    for(int i=2; i<1e6+10; i++){
        int c = 0;
        for(int j=1; j*i<1e6+10; j++){
            c += cnt[j*i];
        }
        if(c>1) s=true;
    }

    if(nt) cout<<"not coprime";
    else if(s) cout<<"setwise coprime";
    else cout<<"pairwise coprime";
    cout<<endl;
}

Measured memory_bytes: 11156
elst = [True for _ in range(10**5+2)]
elst[0] = False
elst[1] = False

for i, e in enumerate(elst):
  if e:
    for j in range(2 * i, 10**5+2, i):
      elst[j] = False

c = [0 for _ in range(10**5+2)]
for i in range(1, 10**5+2, 2):
  if elst[i] and elst[(i+1)//2]:
    c[i] += 1
for i in range(2, 10**5+2):
  c[i] += c[i-1]

q = int(input())
for _ in range(q):
  l, r = map(int, input().split())
  print(c[r] - c[l-1])


Measured memory_bytes: 7192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		String answer = scanner.next();
		int Q = scanner.nextInt();
		boolean didReverse = false;
		StringBuilder head = new StringBuilder();
		StringBuilder tail = new StringBuilder();

		for (int i = 0; i < Q; i++) {
			int T = scanner.nextInt();
			if (T == 1) didReverse = !didReverse;
			else {
				int F = scanner.nextInt();
				String C = scanner.next();
				if ((F == 1 && !didReverse) || (F == 2 && didReverse)) head.append(C);
				else tail.append(C);
			}
		}

		answer = head.reverse().append(answer).append(tail).toString();
		if (didReverse) {
			StringBuilder sb = new StringBuilder(answer);
			answer = sb.reverse().toString();
		}

		System.out.println(answer);
	}
}

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





int main(){
   int a,b;
   cin>>a>>b;
   if(b*2>=a){
      cout<<0<<endl;
   }else{
      cout<<a-b*2<<endl;
   }
   return 0;
}



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

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

  cout << n*n*n << endl;
}


Measured memory_bytes: 256
A, B, C, D = map(int,input().split())

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

lcm = int(C*D / gcd(C, D))

def func(x):
    return x - int(x//C) - int(x//D) + int(x//lcm)

print(func(B) - func(A-1))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, m;
	cin >> n >> m;
	
	vector< vector<int> > G(n);
	for(int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	vector<int> ans(n, -1), dist(n, -1);
	queue<int> q;
	
	dist[0] = 0;
	q.push(0);
	
	while( !q.empty() ) {
		int v = q.front();
		q.pop();
		
		for(auto& u : G[v]) {
			if( dist[u] != -1 ) continue;
			
			dist[u] = dist[v] + 1;		
			ans[u] = v;
			q.push(u);
		}
	}
	
	cout << "Yes" << endl;
	for(int i = 1; i < n; ++i) {
		cout << ans[i] + 1 << endl;
	}
	
	return 0;
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1e9)

int main(){
  char c;
  cin >> c;
  if(c == 'A')cout << 'T' << endl;
  if(c == 'C')cout << 'G' << endl;
  if(c == 'G')cout << 'C' << endl;
  if(c == 'T')cout << 'A' << endl;
}

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

int n, a[2005], ans = 0;

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	scanf("%d", &a[i]);
	sort(a + 1, a + 1 + n);
	for (int i = 1; i <= n; i++)
	for (int j = i + 1; j <= n; j++)
	for (int k = j + 1; k <= n; k++) 
	{
		if (a[i] + a[j] > a[k]) ans++;
		else break;
	}
	printf("%d", ans);
	return 0;
}



Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N=int(input())

print(N-1)
if input()=="Vacant":
    exit()
print(0)
who=input()
if who=="Male":
    start=0
elif who=="Female":
    start=1
else:
    exit()

high=N-1
low=0
while True:
    mid=(high+low)//2
    print(mid)
    who=input()
    if who=="Male":
        temp=0
    elif who=="Female":
        temp=1
    else:
        exit()
    
    if (mid%2)^start==temp:
        low=mid
    else:
        high=mid
    


Measured memory_bytes: 3660
#!/usr/bin/env python3
import sys


def solve(X: int):
    money = 100
    count = 0
    while True:
        money = int(money * 1.01)
        count += 1
        if money >= X:
            break
    print(count)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = []
for i in range(x):
    for j in range(y):
        ans.append(a[i]+b[j])
ans.sort(reverse=True)
ans = ans[:k]
ans2 = []
for i in range(len(ans)):
    for j in range(z):
        ans2.append(ans[i]+c[j])
ans2.sort(reverse=True)
for i in range(k):
    print(ans2[i])

Measured memory_bytes: 214744
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
int n,ans=INF;
int cal(int x){
	int res=0;
	while(x!=0){
		res+=x%10;
		x/=10;
	}
	return res;
}
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>n;
	for(int i=1;i<=(n+1)/2;i++){
		int j=n-i;
		int sol=cal(i)+cal(j);
		ans=min(ans,sol);
	}
	cout<<ans;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
    long N,A=0,B=0,C=0,D=0;
    cin>>N;
    vector<string>a(N);
    for(int i=0;i<N;i++){
        cin>>a[i];
        if(a[i]=="AC"){
            A++;
        }else if(a[i]=="WA"){
            B++;
        }else if(a[i]=="TLE"){
            C++;
        }else if(a[i]=="RE"){
            D++;
        }
    }
    cout<<"AC"<<" "<<"x"<<" "<<A<<endl;
    cout<<"WA"<<" "<<"x"<<" "<<B<<endl;
    cout<<"TLE"<<" "<<"x"<<" "<<C<<endl;
    cout<<"RE"<<" "<<"x"<<" "<<D<<endl;


}

Measured memory_bytes: 6420
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod =1e9+7;
const int N = (int)2e5 + 5;

void solve(){
	string s;
	cin>>s;
	int x=0;
	rep(i,sz(s)){
		x+= s[i]=='o';
	}
	cout<<700+100*x;
}
int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
 
int f(double i, LL K){
    int ans=0;
    while(K>i){
        ans++;
        i*=2;
    }
    return ans;
}
void solve(long long N, long long K){
    double ans=0;
    for(double i=1; i<=N; i++){
        if(i>=K)ans+=1/(double)N;
        else{
            ans+=(1/(double)N)*pow(0.5,f(i,K));
        }
    }
    cout<<std::setprecision(15)<<ans<<endl;
}
 
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}

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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())

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

string to_string(string s){
  return '"' + s + '"';
}
string to_string(const char *s){
  return to_string((string)s);
}
string to_string(bool b){
  return (b ? "true" : "false");
}
template<class A, class B>
string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template<class A, class B, class C>
string to_string(tuple<A, B, C> p){
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template<class A, class B, class C, class D>
string to_string(tuple<A, B, C, D> p){
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
template<class A>
string to_string(A v){
  bool first = true;
  string res = "{";
  for(const auto &x : v){
    if(!first){
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out(){cerr << endl;}
template<class Head, class... Tail>
void debug_out(Head H, Tail... T){
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL//compile with -DLOCAL
#define debug(...) cerr << "LINE" << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) void(0)
#endif

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


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,M;
  cin >> N >> M;
  vector<pair<pair<int,int>,int>> abc(M);
  vector<vector<pair<int,int>>> graph(N);
  rep(i,M){
    int a,b,c;
    cin >> a >> b >> c;
    a--;
    b--;
    abc.at(i) = m_p(m_p(a,b),c);
    graph.at(a).p_b(m_p(b,c));
    graph.at(b).p_b(m_p(a,c));
  }

  vector<bool> used(M,false);
  rep(i,N){
    vector<int> dist(N,1e9);
    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
    dist.at(i) = 0;
    pq.push(m_p(0,i));
    while(!pq.empty()){
      int cost = pq.top().fi;
      int v = pq.top().se;
      pq.pop();
      if(dist.at(v) < cost) continue;
      rep(j,sz(graph.at(v))){
        int nv = graph.at(v).at(j).fi;
        int nc = cost + graph.at(v).at(j).se;
        if(dist.at(nv) <= nc) continue;
        dist.at(nv) = nc;
        pq.push(m_p(nc,nv));
      }
    }

    rep(j,M){
      int a = abc.at(j).fi.fi;
      int b = abc.at(j).fi.se;
      int c = abc.at(j).se;
      if(abs(dist.at(a) - dist.at(b)) == c) used.at(j) = true;
    }
  }

  int ans = 0;
  rep(i,M){
    if(!used.at(i)) ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3652
#!/usr/bin/env python3
import sys
from collections import Counter


def solve(S: str):
    # S[i, j) % 2019 == 0となる(i, j)の数
    # S[i..n) - S[j, n) === 0 (mod 2019)
    # 累積mod c[i] = S[i:]
    n = len(S)
    c = [0] * (n + 1)  # c[i] = int(S[i:]) % 2019
    for i in reversed(range(n)):
        c[i] = (c[i + 1] + int(S[i]) * pow(10, n - 1 - i, 2019)) % 2019
    print(sum(v * (v - 1) // 2 for v in Counter(c).values()))


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == "__main__":
    main()


Measured memory_bytes: 17128
import java.util.Scanner;
public class Main {
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);

		int N = 0;
		N = sc.nextInt();

		if(N < 1000) {
			System.out.println("ABC");
		}else {
			System.out.println("ABD");
		}
	}
}


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

int main()
{int n,k,l,sum=0,a;
vector <int> y;
cin>>n>>k;
a=n-k;
for(int i=0;i<n;i++){cin>>l;y.push_back(l);}
sort(y.begin(),y.end());
for(int i=n-1;i>=a;i--){sum+=y[i];}
cout<<sum;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int N;
	scanf("%d", &N);
	if (N == 1)
	{
		printf("Hello World");
	}
	else if (N == 2)
	{
		int a, b,sum;
		scanf("%d", &a);
		scanf("%d", &b);
		sum = a + b;
		printf("%d", sum);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int a[9] = { 1, 3, 6, 10, 15, 21, 28, 36, 45 };

int fact(ll n) {
	int res = 0;
	for (ll i = 2; i * i <= n; i++) {
		if (n % i) { continue; }
		int p = 0; while (n % i == 0) { n /= i; p++; }
		res += upper_bound(a, a + 9, p) - a;
	}
	return res + (n != 1);
}

int main() {
	ll n; cin >> n;
	cout << fact(n) << '\n';
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) (a).begin(),(a).end()

template<typename T1, typename T2> inline void chkmin(T1 & x, const T2 & y) {if (y < x) x = y;}
template<typename T1, typename T2> inline void chkmax(T1 & x, const T2 & y) {if (x < y) x = y;}

#define int ll

const int N = 80;
int n;
int a[N];

void read() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
}

int now = 1000;
int ans = 1000;
int cnt = 0;

void run() {
	for (int i = 0; i + 1 < n; i++) {
		if (a[i] < a[i + 1]) {
			cnt += now / a[i];
			now %= a[i];
		} else {
			now += a[i] * cnt;
			cnt = 0;
		}
		chkmax(ans, now);
	}
	now += a[n - 1] * cnt;
	chkmax(ans, now);
}

void write() {
	cout << ans << endl;
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(20), cout.setf(ios::fixed);
	read();
	run();
	write();
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>

using namespace std;

int main(){
    int N;
    while(cin >> N){
        vector<long long> A(N);
        long long sum = 0;
        for(auto& t : A) cin >> t;
        sum = accumulate(A.begin(), A.end(), 0LL);
        long long res = (1LL << 60);
        long long s = 0;
        for(int i=0;i<N-1;i++){
            s += A[i];
            res = min(res, abs(sum-2*s));
        }
        cout << res << endl;
    }
}

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

int main()
{
  int n;
  cin >> n;
  string ans = "second";
  for (auto i = 0; i < n; i++) {
    uint u;
    cin >> u;
    if (u & 1) {
      ans = "first";
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <iostream>
#include <bitset>
#include <map>

#define db double
#define vi vector<int>
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define pp pair<int,int>
#define fix(n) fixed << setprecision(n)
#define gmax(a,b) __gcd(a,b)
#define gmin(a,b) a/__gcd(a,b)*b
using namespace std;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll 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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}



int main(){
    int n,k;cin>>n>>k;
	vi a(n);
	rep(i,n)cin>>a.at(i);
	sort(all(a));
	//bool c=false;
	
	 double ans=a.at(n-1);
	 double x;

	ll up=0,dp=a.at(n-1);
	while(dp-up>1){
		ll sum=0;
	x=(up+dp)/2;
	rep(i,n){
		sum+=ceil(a.at(i)/x)-1;
		if(sum>k)break;
	}
	if(sum<=k){
		ans=min(ans,x);
		dp=x;
	}else up=x;
	}
	int nas=ans;
	cout<<nas<<endl;

	
return 0;
}

Measured memory_bytes: 4008
#include <iostream>
#include <string>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int K;
  string S;
  cin >> K >> S;
  if (S.size() <= K) {
    cout << S << endl;
    return 0;
  }
  for (int i=0; i<K; i++) {
    cout << S[i];
  }
  cout << "..." << endl;
}

Measured memory_bytes: 3652
N = int(input())
a = [int(i) for i in input().split()]

colour = [0]*8
free = 0

for i in range(N):
    if a[i]>=1 and a[i]<=399:
        colour[0] = 1
    elif a[i]>=400 and a[i]<=799:
        colour[1] = 1
    elif a[i]>=800 and a[i]<=1199:
        colour[2] = 1
    elif a[i]>=1200 and a[i]<=1599:
        colour[3] = 1
    elif a[i]>=1600 and a[i]<=1999:
        colour[4] = 1
    elif a[i]>=2000 and a[i]<=2399:
        colour[5] = 1
    elif a[i]>=2400 and a[i]<=2799:
        colour[6] = 1
    elif a[i]>=2800 and a[i]<=3199:
        colour[7] = 1
    else:
        free += 1
        
kinds = 0
for i in range(8):
    if colour[i] == 1:
        kinds += 1

minimum = kinds
if kinds == 0:
    minimum = 1

maximum = kinds + free

    
print(minimum,maximum)



Measured memory_bytes: 3064
#include <iostream>

using namespace std;

#define MAX 45
int array[MAX];

void setNumber(int n) {
  array[0] = 1;
  array[1] = 1;
  for(int i = 2; i < n + 1; i++) {
    array[i] = array[i - 1] + array[i - 2];
  }
}


int main(void) {
  int n;
  cin >> n;

  setNumber(n);
  cout << array[n] << endl;

  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=2000001;
using namespace std;


ll fact[NMAX+1];
ll invfact[NMAX+1];

ll pow(ll a, ll b) {
  if (b == 0) {
    return 1;
  } else if (b % 2 == 0) {
    ll d = pow(a, b / 2);
    return (d * d) % MOD;
  } else {
    ll d = pow(a, b - 1);
    return (a * d) % MOD;
  }
}

int main(){
    ll k;
    string s;
    cin >> k >> s;
    ll str = s.length();
    ll len = k+str;

    fact[0] = 1;
    for(int i = 1; i <= NMAX; i++){
        fact[i] = fact[i-1]*i%MOD;
    }
    invfact[NMAX] = pow(fact[NMAX], MOD-2);
    invfact[0] = 1;
    for(int i = NMAX-1; i > 0; i--){
        invfact[i] = invfact[i+1]*(i+1)%MOD;
    }
    
    ll ans = 0;
    for(ll i = 0; i <= k; i++){
        ll tmp = pow(25L, k-i);
        tmp = tmp * pow(26L, i) % MOD;
        ll pat = fact[k-i+str-1]*invfact[k-i] % MOD;
        pat = pat*invfact[str-1] % MOD;
        tmp = tmp * pat % MOD;
        ans += tmp;
        ans %= MOD;
    }
    cout << ans << endl;
    
    return 0;
}

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

typedef std::pair<int, int> P;

int n;
int p[65001], j[65001];
long long sum, max = 0;

int main(){
	while(true){
		std::cin >> n;
		sum = 0, max = 0;
		
		if(n == 0)break;
		
		for(int i = 0; i < n; ++i){
			std::cin >> p[i];
			sum += p[i];
		}
		
		for(int i = 0; i < n - 1; ++i){
			std::cin >> j[i];
		}
		
		std::sort(j, j + n - 1, std::greater<int>());
		max = sum * n;
		
		for(int i = 0; i < n - 1; ++i){
			long long k = (sum + j[i]) * (n - 1);
			if(k > max){
				max = k;
				sum += j[i], --n;
			}
			else break;
		}
		
		std::cout << max << std::endl;
	}
	
	return 0;
}

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

int main() {
  int N, t, a = 0, b = 0;
  
  cin >> N;
  
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
		a += vec.at(i);
    } else {
    	b += vec.at(i);
    }
    
  }
  
  cout << a - b << endl;
}

Measured memory_bytes: 3628
A,B,C,K = map(int, input().split())


# 0 : a,b,c
# 1 : b+c, a+c, a+b
# 2 : 2a+b+c, 2b+a+c, 2c+a+b
# 3 : 2a+3b+3c, 2b+3a+3c, 2c+3a+3b

# 2a+3b+3c - 2b+3a+3c

# 0 :  a-b
# 1 : -a+b
# 2 :  a-b
# 3 : -a+b

ans = A - B
if K%2==0:
  print(ans)
else:
  print(-ans)


Measured memory_bytes: 9156
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>

using namespace std;


int main(int argc, char** argv) {
    long long N, K;

    cin >> N >> K;

    vector<long long> a(N), a_sum(N+1);

	for (int i = 0; i < N; i++) 
		cin >> a[i];
	
	a_sum[0] = 0;

	for (int i = 1; i <= N; i++)
		a_sum[i] = a_sum[i - 1] + a[i - 1] - K;

	long long ans = 0;
	int n_sqrt = int(sqrt(N)) + 1;
	vector<long long> sorted, unsorted;


	for (int i = 0; i <= N; i++) {
		// ソート済の部分は2分探索で
		ans += upper_bound(sorted.begin(), sorted.end(), a_sum[i]) - sorted.begin();

		// ソートしていない部分はナイーブに
		for (int j = 0; j < unsorted.size(); j++)
			ans += a_sum[i] >= unsorted[j];

		unsorted.push_back(a_sum[i]);

		if (unsorted.size() >= n_sqrt) {
			sort(unsorted.begin(), unsorted.end());
			int size = sorted.size();
			sorted.insert(sorted.end(), unsorted.begin(), unsorted.end());
			inplace_merge(sorted.begin(), sorted.begin() + size, sorted.end());
			unsorted.clear();
		}

	}

	cout << ans << endl;
}

Measured memory_bytes: 6388
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;

int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        vector<pii> data;
        rep(i,n){
            int a,b;
            cin>>a>>b;
            data.pb(pii(b,a));
        }
        sort(all(data));
        int now=0;
        bool flag=false;
        rep(i,n){
            now+=data[i].second;
            if(now>data[i].first)flag=true;
        }
        if(flag)cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}

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

using namespace std;

typedef long long int64;

int main()
{
  int N, A[100000];

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

  // さいしょをマイナスにする！
  int64 choku = 0, sum1 = 0;
  for(int i = 0; i < N; i++) {
    choku += A[i];
    if(i % 2 == 0) {
      sum1 += max(0LL, choku + 1);
      choku -= max(0LL, choku + 1);
    } else {
      sum1 += max(0LL, -choku + 1);
      choku += max(0LL, -choku + 1);
    }
  }

  // さいしょをぷらす
  int64 dai = 0, sum2 = 0;
  for(int i = 0; i < N; i++) {
    dai += A[i];
    if(i % 2 == 1) {
      sum2 += max(0LL, dai + 1);
      dai -= max(0LL, dai + 1);
    } else {
      sum2 += max(0LL, -dai + 1);
      dai += max(0LL, -dai + 1);
    }
  }

  cout << min(sum1, sum2) << endl;
}


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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    string str;
    cin >> n >> str;
    str.erase(unique(str.begin(), str.end()), str.end());
    cout << str.size() << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main()
{
	int n, t;
	cin >> n;
	int a[100005];
	for (int i=1; i<=n; i++)
	{
		cin >> t;
		a[t]=i;
	}
	cout << a[1];
	for (int i=2; i<=n; i++)
	{
		cout << " " << a[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1152
n = int(input())
positions = list(map(int, input().split()))

p_ave1 = sum(positions) // n
p_ave2 = sum(positions) // n + 1

stamina1 = sum([(p - p_ave1) * (p - p_ave1) for p in positions])
stamina2 = sum([(p - p_ave2) * (p - p_ave2) for p in positions])

print(min(stamina1, stamina2))

Measured memory_bytes: 3064
N = int(input())
S = [input()[0] for i in range(N)]
M = S.count('M')
A = S.count('A')
R = S.count('R')
C = S.count('C')
H = S.count('H')
print(M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + M*C*H + A*R*C + A*R*H + A*C*H + R*C*H)

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

void SieveOfEratosthenes(int n)
{
    int siz = 1000000;
    bool prime[siz];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=siz; p++)
    {
        if (prime[p] == true)
        {

            for (int i=p*p; i<=siz; i += p)
                prime[i] = false;
        }
    }

    for (int p=n; p<=siz; p++){
       if (prime[p]){
          cout << p << endl;
          break;
       }
    }
}

int main()
{
    int n; cin>>n;
    SieveOfEratosthenes(n);
    return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>

int main(void){
        int a,b,c,sum;
        scanf("%d",&a);
        scanf("%d",&b);
        scanf("%d",&c);

        if(a<b){
                if(b<c){
                        sum=a+b;
                }else{
                        sum=a+c;
                }
        }else{
                if(a<c){
                        sum=a+b;
                }else{
                        sum=b+c;
                }
        }
        printf("%d\n",sum);
        return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(" ").map { it.toInt() }

    val ans = solve(a, b)
    println(ans)
}

//ルート100100以下の平方数　-> 332
fun solve(a: Int, b: Int): String {
    val ab = "${a}${b}".toInt()
    val root = (1..332).map { it * it }
    return if (root.contains(ab)) {
        "Yes"
    } else {
        "No"
    }

}

/**
 * ファクション
 */
fun floor(target: Double): Double {
    return Math.floor(target)
}

fun ceil(target: Double): Double {
    return Math.ceil(target)
}


Measured memory_bytes: 36008
import java.util.Map;
import java.util.Scanner;

public class Main {

    /**
     * 本処理を実行します。
     */
    public static void execute() {
        Scanner sc = new Scanner(System.in);

        int x = Integer.parseInt(sc.next(), 16);
        int y = Integer.parseInt(sc.next(), 16);

        String res;
        if (x > y) {
            res = ">";
        } else if (x < y) {
            res = "<";
        } else {
            res = "=";
        }

        out(res);
    }

    /**
     * 次の標準入力をintで受け取ります。
     * @return 標準入力値(int)
     */
    public static int nextInt(Scanner sc) {
        return sc.nextInt();
    }

    /**
     * 次の標準入力をStringで受け取ります。
     * @return 標準入力値(String)
     */
    public static String nextString(Scanner sc) {
        return sc.next();
    }

    /**
     * 次の標準入力を指定回数分intで受け取ります。
     * @param n 取得回数
     * @return 取得した標準入力値の配列(int)
     */
    public static int[] nextInts(Scanner sc, int n) {
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = nextInt(sc);
        }

        return arr;
    }

    /**
     * 標準出力にオブジェクトを出力します。
     * @param o 出力対象
     */
    public static void out(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        execute();
    }

    public static void putCountMap(Map<Integer, Integer> map, int value) {
        if (map.containsKey(value)) {
            map.put(value, map.get(value) + 1);
        } else {
            map.put(value, 1);
        }
    }
}



Measured memory_bytes: 21972
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

ll llmax(ll x, ll y){
	if (x > y) return x;
	return y;
}


int main(){
	ll a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;
	if (v <= w){
		cout << "NO" << endl;
		return 0;
 	}
 	if ((v - w)*t >= llmax(b - a, a - b)){
 		cout << "YES" << endl;
 	}else{
 		cout << "NO" << endl;
 	}
	return 0;
}


Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;

int main() {
    
	int arr[3];
	for (int i=0; i<3; i++) cin >> arr[i];
	sort(arr, arr+3);
	int k;
	cin >> k;
	for (int i=0; i<k; i++) arr[2] = 2 * arr[2];
	cout << arr[0] + arr[1] + arr[2] << endl;
	
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int k = sc.nextInt();

		int num = 1;
		for(int i = 0; i < n; i++) {
			if(num < k)
				num *= 2;
			else
				num += k;
		}
		System.out.println(num);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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

}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include <set>

#define DIV 1000000007
using namespace std;
using ll = long long;

bool check_k(ll mid, vector<ll>& a, ll K) {
    bool flag = false;
    ll N = a.size();
    ll cnt = 0;

    for (int i = 0; i < N && !flag; i++) {
        if (a[i] == 0) {
            if (mid >= 0) {
                cnt += (N - i - 1);
            }
        }

        else if (a[i] > 0) {
            ll b = mid / a[i];
            auto it = a.begin();
            if (mid >= 0) it = upper_bound(a.begin(), a.end(), b);
            else {
                if(mid%a[i]!=0)
                it = lower_bound(a.begin(), a.end(), b);
                else
                    it = upper_bound(a.begin(), a.end(), b);
            }
            if (it != a.end()) {
                int id = it - a.begin();
                cnt += max(0, id - i - 1);
            }
            else {
                cnt += N - i - 1;
            }
        }

        else {
            ll b = mid / a[i];
            auto it = a.begin();
            if (mid >= 0)it = lower_bound(a.begin(), a.end(), b);
            else {
                if(mid%a[i]!=0)
                    it = upper_bound(a.begin(), a.end(), b);
                else
                    it = lower_bound(a.begin(), a.end(), b);
            }
            if (it != a.end()) {
                int id = it - a.begin();
                cnt += N-max(i + 1, id);
            }
            else {
                if (a[i] * a[N - 1] <= mid) {
                    cnt += (N - 1) - i;
                }
            }

        }
        /*
        if (abs(mid) <= 100) {
            cout << "i=" << i << " " << a[i] << " ";
            cout << "cnt=" << cnt << endl;
        }
        */
        if (cnt >= K) flag = true;
    }

    if (cnt >= K)
        return true;
    else
        return false;
}


int main() {
    ll N, K;
    cin >> N >> K;

    vector<ll> a(N);
    for (int i = 0; i < N; i++)
        cin >> a[i];

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

    ll left = -1e18 - 1, right = 1e18 + 1;
    while (left < right) {
        ll mid = (left + right - 1) / 2;
        /*
        if(abs(mid)<=100)
        cout << "mid= " << mid << endl;
        */
        if (check_k(mid, a, K)) right = mid;
        else left = mid + 1;
    }
    cout << left << endl;
}


Measured memory_bytes: 1792
def main():
    h,w = map(int,input().split())
    a = {}
    for i in range(h):
        a[i] = input()
    ans = 0
    L = []
    R = []
    D = []
    U = []
    for x in range(h):
        L.append([])
        R.append([])
        for y in range(w):
            if a[x][y] == "#":
                L[x].append(0)
            elif y == 0:
                L[x].append(1)
            else:
                L[x].append(L[x][y-1]+1)
        for y in range(w-1,-1,-1):
            if a[x][y] == "#":
                R[x].append(0)
            elif y == w-1:
                R[x].append(1)
            else:
                R[x].append(R[x][w-y-2]+1)
        R[x].reverse()
    for y in range(w):
        D.append([])
        U.append([])
        for x in range(h):
            if a[x][y] == "#":
                U[y].append(0)
            elif x == 0:
                U[y].append(1)
            else:
                U[y].append(U[y][x-1]+1)
        for x in range(h-1,-1,-1):
            if a[x][y] == "#":
                D[y].append(0)
            elif x == h-1:
                D[y].append(1)
            else:
                D[y].append(D[y][h-x-2]+1)
        D[y].reverse()

    for x in range(h):
        for y in range(w):
            ans = max(ans, R[x][y]+L[x][y]+U[y][x]+D[y][x]-3)
            
    print(ans)
main()

Measured memory_bytes: 186116
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str[1001];
	int q;
	char instruction[8];
 	int a, b;
	char p[1001];
	int i, j;
	char tmp;
	
	scanf("%s", str);
	scanf("%d", &q);
	
	for (i = 0; i < q; i++){
		scanf("%s", instruction);
		
		if (instruction[2] == 'i'){
			scanf("%d%d", &a, &b);
			for (j = a; j <= b; j++){
				printf("%c", str[j]);
			}
			printf("\n");
		}
		else if (instruction[2] == 'v'){
			scanf("%d%d", &a, &b);
			for (j = 0; j < (b - a + 1) / 2; j++){
				tmp = str[a + j];
				str[a + j] = str[b - j];
				str[b - j] = tmp;
			}
//		printf("<%s>", str);
		}
		else if (instruction[2] == 'p'){
			scanf("%d%d%s", &a, &b, p);
			strncpy(&str[a], p, b - a + 1);
//		printf("<%s>", str);
		}
	}
	return (0);
}
		
		


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define fast() ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lp(i, n) for(int i = 0; i < n; i++)
#define rlp(i, n) for(int i = n-1; i >= 0; i--)
#define loop(i, a, b) for(int i = a; i <= b; i++)
#define rloop(i, a, b) for(int i = a; i >= b; i--)
#define mem(a, val) memset(a, val, sizeof a);
#define test int t; cin>> t; while(t--)
#define all(v) v.begin(),v.end()
#define ll long long
#define ld long double
#define mp_ make_pair
#define pb push_back
#define sz(s) (int)s.size()
const int MAX = 1e5 + 5;
const int inf = 1e9+1;
const ll OO = 1e18;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
int n, a[MAX][3], dp[MAX][3];
int solve(int i = 0, int lst = -1){
    if(i == n) return 0;

    if(lst != -1 && dp[i][lst] != -1)
        return dp[i][lst];

    int mx = 0;
    lp(j, 3){
        if(j == lst) continue;
        mx = max(mx, solve(i + 1, j) + a[i][j]);
    }
    return dp[i][lst] = mx;
}
int main()
{
    cin>> n;
    lp(i, n){
        lp(j, 3) cin>> a[i][j];
    }
    mem(dp, -1);
    cout<< solve() <<"\n";

    return 0;
}


Measured memory_bytes: 12184
#include<bits/stdc++.h>
using namespace std;
int max(int a, int b) { return (a > b)? a : b; }

// Returns the maximum value that can be put in a knapsack of capacity W
long long int knapSack(int W, int wt[], int val[], int n)
{
int i, w;
long long int K[n+1][W+1];

// Build table K[][] in bottom up manner
for (i = 0; i <= n; i++)
{
	for (w = 0; w <= W; w++)
	{
		if (i==0 || w==0)
			K[i][w] = 0;
		else if (wt[i-1] <= w)
				K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]], K[i-1][w]);
		else
				K[i][w] = K[i-1][w];
	}
}

return K[n][W];
}

int main()
{

    int n,W;
    cin>>n>>W;

	//int val[] = {60, 100, 120};
	//int wt[] = {10, 20, 30};

	int val[n],wt[n];

	for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        wt[i] = a;
        val[i] = b;
	}

	//int W = 50;
	 n = sizeof(val)/sizeof(val[0]);
	printf("%lld", knapSack(W, wt, val, n));
	return 0;
}



Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pi pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/

signed main(){
  int s,w;
  cin>>s>>w;

  cout<<(w>=s?"unsafe":"safe")<<endl;
  return 0;
}


Measured memory_bytes: 3620
S = input()
if S=="RRR":
    print(3)
elif S=="RRS":
    print(2)
elif S=="RSS":
    print(1)
elif S=="SSS":
    print(0)
elif S=="RSR":
    print(1)
elif S=="SRR":
    print(2)
elif S=="SSR":
    print(1)
elif S=="SRS":
    print(1)

Measured memory_bytes: 9116
import itertools


def main():
    N = int(input())
    d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for _ in range(N):
        S = input()
        if S[0] in d:
            d[S[0]] += 1
    ans = 0
    for a, b, c in list(itertools.combinations(d.keys(), 3)):
        ans += d[a] * d[b] * d[c]
    print(ans)


main()


Measured memory_bytes: 3060